diff --git a/app/jobs/regular/delete_topic.rb b/app/jobs/regular/delete_topic.rb index 2dbc7e43e48..e50cd9c2dae 100644 --- a/app/jobs/regular/delete_topic.rb +++ b/app/jobs/regular/delete_topic.rb @@ -13,6 +13,7 @@ module Jobs if Guardian.new(topic_timer.user).can_delete?(topic) first_post = topic.ordered_posts.first PostDestroyer.new(topic_timer.user, first_post, { context: I18n.t("topic_statuses.auto_deleted_by_timer") }).destroy + topic_timer.trash!(Discourse.system_user) end end diff --git a/app/models/topic.rb b/app/models/topic.rb index bec11a5f1e0..b0c7b86bb09 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -397,6 +397,7 @@ class Topic < ActiveRecord::Base def reload(options=nil) @post_numbers = nil + @topic_timer = nil super(options) end @@ -953,7 +954,7 @@ SQL end def topic_timer - @topic_timer ||= topic_timers.where('deleted_at IS NULL').first + @topic_timer ||= topic_timers.first end def topic_status_update diff --git a/spec/integration/topic_auto_close_spec.rb b/spec/integration/topic_auto_close_spec.rb index ed849d45662..c2d8737bb14 100644 --- a/spec/integration/topic_auto_close_spec.rb +++ b/spec/integration/topic_auto_close_spec.rb @@ -79,9 +79,11 @@ describe Topic do context 'topic is closed manually' do it 'should remove the schedule to auto-close the topic' do Timecop.freeze do + topic_timer_id = staff_topic.topic_timer.id + staff_topic.update_status('closed', true, admin) - expect(staff_topic.topic_status_update.reload.deleted_at) + expect(TopicTimer.with_deleted.find(topic_timer_id).deleted_at) .to be_within(1.second).of(Time.zone.now) end end diff --git a/spec/jobs/delete_topic_spec.rb b/spec/jobs/delete_topic_spec.rb index 5089bb556b0..404f7f52095 100644 --- a/spec/jobs/delete_topic_spec.rb +++ b/spec/jobs/delete_topic_spec.rb @@ -15,12 +15,14 @@ describe Jobs::DeleteTopic do SiteSetting.queue_jobs = true end - it "can close a topic" do + it "can delete a topic" do first_post + Timecop.freeze(2.hours.from_now) do described_class.new.execute(topic_timer_id: topic.topic_timer.id) expect(topic.reload).to be_trashed expect(first_post.reload).to be_trashed + expect(topic.reload.topic_timer).to eq(nil) end end diff --git a/spec/jobs/publish_topic_to_category_spec.rb b/spec/jobs/publish_topic_to_category_spec.rb index e06a686615d..fca2b8251e7 100644 --- a/spec/jobs/publish_topic_to_category_spec.rb +++ b/spec/jobs/publish_topic_to_category_spec.rb @@ -47,7 +47,7 @@ RSpec.describe Jobs::PublishTopicToCategory do topic.reload expect(topic.category).to eq(another_category) expect(topic.visible).to eq(true) - expect(TopicTimer.find_by(id: topic.topic_timer.id)).to eq(nil) + expect(topic.topic_timer).to eq(nil) %w{created_at bumped_at updated_at last_posted_at}.each do |attribute| expect(topic.public_send(attribute)).to be_within(1.second).of(Time.zone.now) diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb index bdae4fd3d4d..ee87a46dbf5 100644 --- a/spec/jobs/pull_hotlinked_images_spec.rb +++ b/spec/jobs/pull_hotlinked_images_spec.rb @@ -13,7 +13,7 @@ describe Jobs::PullHotlinkedImages do it 'replaces image src' do post = Fabricate(:post, raw: "") - Jobs::PullHotlinkedImages.new.execute(post_id: post.id) + Jobs::PullHotl.inkedImages.new.execute(post_id: post.id) post.reload expect(post.raw).to match(/^