mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 07:34:18 +08:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
65 lines
2.3 KiB
Ruby
65 lines
2.3 KiB
Ruby
require 'rails_helper'
|
|
require 'unread'
|
|
|
|
describe Unread do
|
|
|
|
|
|
before do
|
|
@topic = Fabricate(:topic, posts_count: 13, highest_post_number: 13)
|
|
@topic.notifier.watch_topic!(@topic.user_id)
|
|
@topic_user = TopicUser.get(@topic, @topic.user)
|
|
@topic_user.stubs(:notification_level).returns(TopicUser.notification_levels[:tracking])
|
|
@topic_user.notification_level = TopicUser.notification_levels[:tracking]
|
|
@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)
|
|
@topic_user.stubs(:highest_seen_post_number).returns(13)
|
|
expect(@unread.unread_posts).to eq(0)
|
|
end
|
|
|
|
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)
|
|
@topic_user.stubs(:highest_seen_post_number).returns(11)
|
|
expect(@unread.unread_posts).to eq(6)
|
|
end
|
|
|
|
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)
|
|
@topic_user.stubs(:highest_seen_post_number).returns(13)
|
|
expect(@unread.unread_posts).to eq(0)
|
|
end
|
|
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)
|
|
expect(@unread.new_posts).to eq(0)
|
|
end
|
|
|
|
it 'returns 0 when the topic is the same length as when you last saw it' do
|
|
@topic_user.stubs(:highest_seen_post_number).returns(13)
|
|
expect(@unread.new_posts).to eq(0)
|
|
end
|
|
|
|
it 'has 3 new posts if the user has read 10 posts' do
|
|
@topic_user.stubs(:highest_seen_post_number).returns(10)
|
|
expect(@unread.new_posts).to eq(3)
|
|
end
|
|
|
|
it 'has 0 new posts if the user has read 10 posts but is not tracking' do
|
|
@topic_user.stubs(:highest_seen_post_number).returns(10)
|
|
@topic_user.stubs(:notification_level).returns(TopicUser.notification_levels[:regular])
|
|
expect(@unread.new_posts).to eq(0)
|
|
end
|
|
|
|
it 'has 0 new posts if the user read more posts than exist (deleted)' do
|
|
@topic_user.stubs(:highest_seen_post_number).returns(16)
|
|
expect(@unread.new_posts).to eq(0)
|
|
end
|
|
|
|
end
|
|
end
|