mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
user where as opposed to find to compensate for deleted topics
This commit is contained in:
parent
0c702522c4
commit
50767be722
2 changed files with 6 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue