FIX: Delete topic timer after completion.

This commit is contained in:
Guo Xiang Tan 2017-05-12 10:28:51 +08:00
parent accd78cd8c
commit 8eecd42856
6 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -13,7 +13,7 @@ describe Jobs::PullHotlinkedImages do
it 'replaces image src' do
post = Fabricate(:post, raw: "<img src='http://wiki.mozilla.org/images/2/2e/Longcat1.png'>")
Jobs::PullHotlinkedImages.new.execute(post_id: post.id)
Jobs::PullHotl.inkedImages.new.execute(post_id: post.id)
post.reload
expect(post.raw).to match(/^<img src='\/uploads/)