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
|
2013-07-22 01:06:53 -04:00
|
|
|
create_post
|
2013-05-21 02:39:51 -04:00
|
|
|
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])
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(report.length).to eq(0)
|
2013-05-21 02:39:51 -04:00
|
|
|
|
|
|
|
new_post = post
|
2013-07-21 21:40:39 -04:00
|
|
|
post.topic.notifier.watch_topic!(post.topic.user_id)
|
2013-05-21 02:39:51 -04:00
|
|
|
|
2013-05-29 04:11:04 -04:00
|
|
|
report = TopicTrackingState.report([user.id])
|
2013-05-23 01:21:07 -04:00
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(report.length).to eq(1)
|
2013-05-23 01:21:07 -04:00
|
|
|
row = report[0]
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
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)
|
2013-05-23 01:21:07 -04:00
|
|
|
|
|
|
|
# lets not leak out random users
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(TopicTrackingState.report([post.user_id])).to be_empty
|
2013-05-23 01:21:07 -04:00
|
|
|
|
|
|
|
# lets not return anything if we scope on non-existing topic
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(TopicTrackingState.report([user.id], post.topic_id + 1)).to be_empty
|
2013-05-23 01:21:07 -04:00
|
|
|
|
|
|
|
# when we reply the poster should have an unread row
|
2013-07-22 01:06:53 -04:00
|
|
|
create_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])
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(report.length).to eq(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
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
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)
|
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
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(TopicTrackingState.report([post.user_id, user.id]).count).to eq(0)
|
2013-05-21 02:39:51 -04:00
|
|
|
end
|
|
|
|
end
|