discourse/spec/models/topic_tracking_state_spec.rb
Luciano Sousa b3d769ff4f Update rspec syntax to v3
update rspec syntax to v3

change syntax to rspec v3

oops. fix typo

mailers classes with rspec3 syntax

helpers with rspec3 syntax

jobs with rspec3 syntax

serializers with rspec3 syntax

views with rspec3 syntax

support to rspec3 syntax

category spec with rspec3 syntax
2015-01-05 11:59:30 -03:00

62 lines
1.7 KiB
Ruby

require 'spec_helper'
describe TopicTrackingState do
let(:user) do
Fabricate(:user)
end
let(:post) do
create_post
end
it "can correctly publish unread" do
# TODO setup stuff and look at messages
TopicTrackingState.publish_unread(post)
end
it "correctly gets the tracking state" do
report = TopicTrackingState.report([user.id])
expect(report.length).to eq(0)
new_post = post
post.topic.notifier.watch_topic!(post.topic.user_id)
report = TopicTrackingState.report([user.id])
expect(report.length).to eq(1)
row = report[0]
expect(row.topic_id).to eq(post.topic_id)
expect(row.highest_post_number).to eq(1)
expect(row.last_read_post_number).to eq(nil)
expect(row.user_id).to eq(user.id)
# lets not leak out random users
expect(TopicTrackingState.report([post.user_id])).to be_empty
# lets not return anything if we scope on non-existing topic
expect(TopicTrackingState.report([user.id], post.topic_id + 1)).to be_empty
# when we reply the poster should have an unread row
create_post(user: user, topic: post.topic)
report = TopicTrackingState.report([post.user_id, user.id])
expect(report.length).to eq(1)
row = report[0]
expect(row.topic_id).to eq(post.topic_id)
expect(row.highest_post_number).to eq(2)
expect(row.last_read_post_number).to eq(1)
expect(row.user_id).to eq(post.user_id)
# when we have no permission to see a category, don't show its stats
category = Fabricate(:category, read_restricted: true)
post.topic.category_id = category.id
post.topic.save
expect(TopicTrackingState.report([post.user_id, user.id]).count).to eq(0)
end
end