diff --git a/lib/jobs/close_topic.rb b/lib/jobs/close_topic.rb index 32565c48b..e9e7e8060 100644 --- a/lib/jobs/close_topic.rb +++ b/lib/jobs/close_topic.rb @@ -2,9 +2,9 @@ module Jobs class CloseTopic < Jobs::Base def execute(args) - topic = Topic.find(args[:topic_id]) + topic = Topic.where(id: args[:topic_id]).first if topic and topic.auto_close_at and !topic.closed? and !topic.deleted_at - closer = User.find(args[:user_id]) + closer = User.where(id: args[:user_id]).first if Guardian.new(closer).can_moderate?(topic) topic.update_status('autoclosed', true, closer) end diff --git a/spec/components/jobs/close_topic_spec.rb b/spec/components/jobs/close_topic_spec.rb index 2ff4a7808..9b7be667a 100644 --- a/spec/components/jobs/close_topic_spec.rb +++ b/spec/components/jobs/close_topic_spec.rb @@ -8,16 +8,16 @@ describe Jobs::CloseTopic do 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).returns(topic) - User.stubs(:find).returns(admin) + Topic.stubs(:where).returns([topic]) + User.stubs(:where).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).returns(topic) - User.stubs(:find).returns(admin) + Topic.stubs(:where).returns([topic]) + User.stubs(:where).returns([admin]) Jobs::CloseTopic.new.execute( topic_id: 123, user_id: 234 ) end end