2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-02-05 14:16:51 -05:00
|
|
|
require 'unread'
|
|
|
|
|
|
|
|
describe Unread do
|
|
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
@topic = Fabricate(:topic, posts_count: 13, highest_post_number: 13)
|
2013-07-21 21:40:39 -04:00
|
|
|
@topic.notifier.watch_topic!(@topic.user_id)
|
2013-02-05 14:16:51 -05:00
|
|
|
@topic_user = TopicUser.get(@topic, @topic.user)
|
2013-03-06 15:17:07 -05:00
|
|
|
@topic_user.stubs(:notification_level).returns(TopicUser.notification_levels[:tracking])
|
|
|
|
@topic_user.notification_level = TopicUser.notification_levels[:tracking]
|
2013-02-05 14:16:51 -05:00
|
|
|
@unread = Unread.new(@topic, @topic_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unread_posts' do
|
|
|
|
it 'should have 0 unread posts if the user has seen all posts' do
|
|
|
|
@topic_user.stubs(:last_read_post_number).returns(13)
|
2014-10-30 18:40:35 -04:00
|
|
|
@topic_user.stubs(:highest_seen_post_number).returns(13)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(@unread.unread_posts).to eq(0)
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
it 'should have 6 unread posts if the user has seen all but 6 posts' do
|
|
|
|
@topic_user.stubs(:last_read_post_number).returns(5)
|
2014-10-30 18:40:35 -04:00
|
|
|
@topic_user.stubs(:highest_seen_post_number).returns(11)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(@unread.unread_posts).to eq(6)
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
it 'should have 0 unread posts if the user has seen more posts than exist (deleted)' do
|
|
|
|
@topic_user.stubs(:last_read_post_number).returns(100)
|
2014-10-30 18:40:35 -04:00
|
|
|
@topic_user.stubs(:highest_seen_post_number).returns(13)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(@unread.unread_posts).to eq(0)
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'new_posts' do
|
|
|
|
it 'should have 0 new posts if the user has read all posts' do
|
|
|
|
@topic_user.stubs(:last_read_post_number).returns(13)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(@unread.new_posts).to eq(0)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 0 when the topic is the same length as when you last saw it' do
|
2014-10-30 18:40:35 -04:00
|
|
|
@topic_user.stubs(:highest_seen_post_number).returns(13)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(@unread.new_posts).to eq(0)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has 3 new posts if the user has read 10 posts' do
|
2014-10-30 18:40:35 -04:00
|
|
|
@topic_user.stubs(:highest_seen_post_number).returns(10)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(@unread.new_posts).to eq(3)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
it 'has 0 new posts if the user has read 10 posts but is not tracking' do
|
2014-10-30 18:40:35 -04:00
|
|
|
@topic_user.stubs(:highest_seen_post_number).returns(10)
|
2013-03-06 15:17:07 -05:00
|
|
|
@topic_user.stubs(:notification_level).returns(TopicUser.notification_levels[:regular])
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(@unread.new_posts).to eq(0)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has 0 new posts if the user read more posts than exist (deleted)' do
|
2014-10-30 18:40:35 -04:00
|
|
|
@topic_user.stubs(:highest_seen_post_number).returns(16)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(@unread.new_posts).to eq(0)
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|