2013-05-21 02:39:51 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UserTrackingState do
|
|
|
|
|
|
|
|
let(:user) do
|
|
|
|
Fabricate(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:post) do
|
|
|
|
Fabricate(:post)
|
|
|
|
end
|
|
|
|
|
2013-05-23 01:21:07 -04:00
|
|
|
it "correctly gets the tracking state" do
|
|
|
|
report = UserTrackingState.report([user.id])
|
|
|
|
report.length.should == 0
|
2013-05-21 02:39:51 -04:00
|
|
|
|
|
|
|
new_post = post
|
|
|
|
|
2013-05-23 01:21:07 -04:00
|
|
|
report = UserTrackingState.report([user.id])
|
|
|
|
|
|
|
|
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
|
|
|
|
UserTrackingState.report([post.user_id]).should be_empty
|
|
|
|
|
|
|
|
# lets not return anything if we scope on non-existing topic
|
|
|
|
UserTrackingState.report([user.id], post.topic_id + 1).should be_empty
|
|
|
|
|
|
|
|
# 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-23 01:21:07 -04:00
|
|
|
report = UserTrackingState.report([post.user_id, user.id])
|
|
|
|
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
|
|
|
|
|
|
|
end
|
|
|
|
end
|