From f6d6f1701f18de3589c742592e17b3ed505172c0 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 19 Mar 2020 21:45:05 +0530 Subject: [PATCH] FIX: use the new duration attribute in `set_or_create_timer` method. New `duration` attribute is introduced for the `set_or_create_timer` method in the commit aad12822b7d7c9c6ecd976e23d3a83626c052dce for "based on last post" and "auto delete replies" topic timers. --- app/models/topic.rb | 6 +++++- lib/post_creator.rb | 5 +++-- spec/components/post_creator_spec.rb | 3 ++- spec/models/topic_spec.rb | 4 ++-- spec/services/topic_status_updater_spec.rb | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index 13f3a8a798b..07b5c60c6e3 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -257,10 +257,14 @@ class Topic < ActiveRecord::Base self.category.auto_close_hours && !public_topic_timer&.execute_at + based_on_last_post = self.category.auto_close_based_on_last_post + duration = based_on_last_post ? self.category.auto_close_hours : nil + self.set_or_create_timer( TopicTimer.types[:close], self.category.auto_close_hours, - based_on_last_post: self.category.auto_close_based_on_last_post + based_on_last_post: based_on_last_post, + duration: duration ) end end diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 25cd341eea2..0e89a93ba18 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -473,8 +473,9 @@ class PostCreator topic_timer.duration > 0 @topic.set_or_create_timer(TopicTimer.types[:close], - topic_timer.duration, - based_on_last_post: topic_timer.based_on_last_post + nil, + based_on_last_post: topic_timer.based_on_last_post, + duration: topic_timer.duration ) end end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 1fae7727526..0b3999a322a 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -367,7 +367,8 @@ describe PostCreator do Fabricate(:topic_timer, based_on_last_post: true, execute_at: Time.zone.now - 12.hours, - created_at: Time.zone.now - 24.hours + created_at: Time.zone.now - 24.hours, + duration: 12 ) end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 17d49606ff0..64ad9b005d0 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1638,7 +1638,7 @@ describe Topic do it 'can take a number of hours as a string and can handle based on last post' do freeze_time now - topic.set_or_create_timer(TopicTimer.types[:close], '18', by_user: admin, based_on_last_post: true) + topic.set_or_create_timer(TopicTimer.types[:close], nil, by_user: admin, based_on_last_post: true, duration: 18) expect(topic.topic_timers.first.execute_at).to eq_time(18.hours.from_now) end @@ -1750,7 +1750,7 @@ describe Topic do it "should be able to override category's default auto close" do Jobs.run_immediately! - expect(topic.topic_timers.first.duration).to eq(4) + expect(topic.topic_timers.first.execute_at).to eq_time(topic.created_at + 4.hours) topic.set_or_create_timer(TopicTimer.types[:close], 2, by_user: admin) diff --git a/spec/services/topic_status_updater_spec.rb b/spec/services/topic_status_updater_spec.rb index 7bb6ab4abf8..593203eb510 100644 --- a/spec/services/topic_status_updater_spec.rb +++ b/spec/services/topic_status_updater_spec.rb @@ -59,7 +59,7 @@ describe TopicStatusUpdater do Fabricate(:post, topic: topic) topic.set_or_create_timer( - TopicTimer.types[:close], '10', based_on_last_post: true + TopicTimer.types[:close], nil, based_on_last_post: true, duration: 10 ) TopicStatusUpdater.new(topic, admin).update!("autoclosed", true)