FIX: jobs/delete_replies: Add Time+Duration, not Time+Time #9314
Co-authored-by: Kane York <kanepyork@gmail.com>
This commit is contained in:
parent
8d5cc8956d
commit
82201fa466
|
@ -22,7 +22,7 @@ module Jobs
|
||||||
PostDestroyer.new(topic_timer.user, post, context: I18n.t("topic_statuses.auto_deleted_by_timer")).destroy
|
PostDestroyer.new(topic_timer.user, post, context: I18n.t("topic_statuses.auto_deleted_by_timer")).destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
topic_timer.execute_at = (replies.minimum(:created_at) || Time.zone.now) + topic_timer.duration.days.ago
|
topic_timer.execute_at = (replies.minimum(:created_at) || Time.zone.now) + topic_timer.duration.days
|
||||||
topic_timer.save
|
topic_timer.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Jobs::DeleteReplies do
|
||||||
|
fab!(:admin) { Fabricate(:admin) }
|
||||||
|
|
||||||
|
fab!(:topic) { Fabricate(:topic) }
|
||||||
|
fab!(:topic_timer) do
|
||||||
|
Fabricate(:topic_timer, status_type: TopicTimer.types[:delete_replies], duration: 2, user: admin, topic: topic, execute_at: 2.days.from_now)
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
3.times { create_post(topic: topic) }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can delete replies of a topic" do
|
||||||
|
freeze_time (2.days.from_now)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
||||||
|
}.to change { topic.posts.count }.by(-2)
|
||||||
|
|
||||||
|
topic_timer.reload
|
||||||
|
expect(topic_timer.execute_at).to eq_time(2.day.from_now)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue