2016-04-01 05:33:25 +08:00
|
|
|
require 'rails_helper'
|
2013-10-01 15:04:02 +08:00
|
|
|
require_dependency 'jobs/base'
|
2013-05-08 02:25:41 +08:00
|
|
|
|
|
|
|
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)
|
2014-05-06 21:41:59 +08:00
|
|
|
Topic.stubs(:find_by).returns(topic)
|
|
|
|
User.stubs(:find_by).returns(admin)
|
2013-05-08 02:25:41 +08:00
|
|
|
Jobs::CloseTopic.new.execute( topic_id: 123, user_id: 234 )
|
|
|
|
end
|
|
|
|
|
2013-05-16 03:19:41 +08:00
|
|
|
shared_examples_for "cases when CloseTopic does nothing" do
|
|
|
|
it 'does nothing to the topic' do
|
|
|
|
topic.expects(:update_status).never
|
2014-05-06 21:41:59 +08:00
|
|
|
Topic.stubs(:find_by).returns(topic)
|
|
|
|
User.stubs(:find_by).returns(admin)
|
2013-05-16 03:19:41 +08:00
|
|
|
Jobs::CloseTopic.new.execute( topic_id: 123, user_id: 234 )
|
|
|
|
end
|
2013-05-08 02:25:41 +08:00
|
|
|
end
|
|
|
|
|
2013-05-16 03:19:41 +08:00
|
|
|
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'
|
2013-05-08 02:25:41 +08:00
|
|
|
end
|
|
|
|
|
2013-05-16 03:19:41 +08:00
|
|
|
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
|
2013-05-08 02:25:41 +08:00
|
|
|
|
2013-05-16 03:19:41 +08:00
|
|
|
end
|