2013-05-21 02:39:51 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-05-29 04:11:04 -04:00
|
|
|
describe TopicTrackingState do
|
2013-05-21 02:39:51 -04:00
|
|
|
|
|
|
|
let(:user) do
|
|
|
|
Fabricate(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:post) do
|
|
|
|
Fabricate(:post)
|
|
|
|
end
|
|
|
|
|
2013-05-29 04:11:04 -04:00
|
|
|
it "can correctly publish unread" do
|
|
|
|
# TODO setup stuff and look at messages
|
|
|
|
TopicTrackingState.publish_unread(post)
|
|
|
|
end
|
|
|
|
|
2013-05-23 01:21:07 -04:00
|
|
|
it "correctly gets the tracking state" do
|
2013-05-29 04:11:04 -04:00
|
|
|
report = TopicTrackingState.report([user.id])
|
2013-05-23 01:21:07 -04:00
|
|
|
report.length.should == 0
|
2013-05-21 02:39:51 -04:00
|
|
|
|
|
|
|
new_post = post
|
|
|
|
|
2013-05-29 04:11:04 -04:00
|
|
|
report = TopicTrackingState.report([user.id])
|
2013-05-23 01:21:07 -04:00
|
|
|
|
|
|
|
report.length.should == 1
|
|
|
|
row = report[0]
|
|
|
|
|
|
|
|
row.topic_id.should == post.topic_id
|
|
|
|
row.highest_post_number.should == 1
|
|
|
|
row.last_read_post_number.should be_nil
|
|
|
|
row.user_id.should == user.id
|
|
|
|
|
|
|
|
# lets not leak out random users
|
2013-05-29 04:11:04 -04:00
|
|
|
TopicTrackingState.report([post.user_id]).should be_empty
|
2013-05-23 01:21:07 -04:00
|
|
|
|
|
|
|
# lets not return anything if we scope on non-existing topic
|
2013-05-29 04:11:04 -04:00
|
|
|
TopicTrackingState.report([user.id], post.topic_id + 1).should be_empty
|
2013-05-23 01:21:07 -04:00
|
|
|
|
|
|
|
# when we reply the poster should have an unread row
|
|
|
|
Fabricate(:post, user: user, topic: post.topic)
|
2013-05-21 02:39:51 -04:00
|
|
|
|
2013-05-29 04:11:04 -04:00
|
|
|
report = TopicTrackingState.report([post.user_id, user.id])
|
2013-05-23 01:21:07 -04:00
|
|
|
report.length.should == 1
|
2013-05-21 02:39:51 -04:00
|
|
|
|
2013-05-23 01:21:07 -04:00
|
|
|
row = report[0]
|
2013-05-21 02:39:51 -04:00
|
|
|
|
2013-05-23 01:21:07 -04:00
|
|
|
row.topic_id.should == post.topic_id
|
|
|
|
row.highest_post_number.should == 2
|
|
|
|
row.last_read_post_number.should == 1
|
|
|
|
row.user_id.should == post.user_id
|
2013-05-21 02:39:51 -04:00
|
|
|
|
2013-05-23 23:32:41 -04:00
|
|
|
# when we have no permission to see a category, don't show its stats
|
2013-07-13 21:24:16 -04:00
|
|
|
category = Fabricate(:category, read_restricted: true)
|
2013-05-23 23:32:41 -04:00
|
|
|
|
|
|
|
post.topic.category_id = category.id
|
|
|
|
post.topic.save
|
|
|
|
|
2013-05-29 04:11:04 -04:00
|
|
|
TopicTrackingState.report([post.user_id, user.id]).count.should == 0
|
2013-05-21 02:39:51 -04:00
|
|
|
end
|
|
|
|
end
|