mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-11 00:02:05 -05: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.
46 lines
1.7 KiB
Ruby
46 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
require_dependency 'jobs/base'
|
|
|
|
describe Jobs::CloseTopic do
|
|
|
|
let(:admin) { Fabricate.build(:admin) }
|
|
|
|
it 'closes a topic that is set to auto-close' do
|
|
topic = Fabricate.build(:topic, auto_close_at: Time.zone.now, user: admin)
|
|
topic.expects(:update_status).with('autoclosed', true, admin)
|
|
Topic.stubs(:find_by).returns(topic)
|
|
User.stubs(:find_by).returns(admin)
|
|
Jobs::CloseTopic.new.execute( topic_id: 123, user_id: 234 )
|
|
end
|
|
|
|
shared_examples_for "cases when CloseTopic does nothing" do
|
|
it 'does nothing to the topic' do
|
|
topic.expects(:update_status).never
|
|
Topic.stubs(:find_by).returns(topic)
|
|
User.stubs(:find_by).returns(admin)
|
|
Jobs::CloseTopic.new.execute( topic_id: 123, user_id: 234 )
|
|
end
|
|
end
|
|
|
|
context 'when topic is not set to auto-close' do
|
|
subject(:topic) { Fabricate.build(:topic, auto_close_at: nil, user: admin) }
|
|
it_behaves_like 'cases when CloseTopic does nothing'
|
|
end
|
|
|
|
context 'when user is not authorized to close topics' do
|
|
subject(:topic) { Fabricate.build(:topic, auto_close_at: 2.days.from_now, user: admin) }
|
|
before { Guardian.any_instance.stubs(:can_moderate?).returns(false) }
|
|
it_behaves_like 'cases when CloseTopic does nothing'
|
|
end
|
|
|
|
context 'the topic is already closed' do
|
|
subject(:topic) { Fabricate.build(:topic, auto_close_at: 2.days.from_now, user: admin, closed: true) }
|
|
it_behaves_like 'cases when CloseTopic does nothing'
|
|
end
|
|
|
|
context 'the topic has been deleted' do
|
|
subject(:topic) { Fabricate.build(:deleted_topic, auto_close_at: 2.days.from_now, user: admin) }
|
|
it_behaves_like 'cases when CloseTopic does nothing'
|
|
end
|
|
|
|
end
|