Skip to content

A platform for community discussion. Free, open, simple.

FIX: use the new duration attribute in `set_or_create_timer` method.

Vinoth Kannanf6d6f1701f18
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)