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.
This commit is contained in:
Vinoth Kannan 2020-03-19 21:45:05 +05:30
parent 22d5ba0f77
commit f6d6f1701f
5 changed files with 13 additions and 7 deletions

View File

@ -257,10 +257,14 @@ class Topic < ActiveRecord::Base
self.category.auto_close_hours && self.category.auto_close_hours &&
!public_topic_timer&.execute_at !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( self.set_or_create_timer(
TopicTimer.types[:close], TopicTimer.types[:close],
self.category.auto_close_hours, 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
end end

View File

@ -473,8 +473,9 @@ class PostCreator
topic_timer.duration > 0 topic_timer.duration > 0
@topic.set_or_create_timer(TopicTimer.types[:close], @topic.set_or_create_timer(TopicTimer.types[:close],
topic_timer.duration, nil,
based_on_last_post: topic_timer.based_on_last_post based_on_last_post: topic_timer.based_on_last_post,
duration: topic_timer.duration
) )
end end
end end

View File

@ -367,7 +367,8 @@ describe PostCreator do
Fabricate(:topic_timer, Fabricate(:topic_timer,
based_on_last_post: true, based_on_last_post: true,
execute_at: Time.zone.now - 12.hours, execute_at: Time.zone.now - 12.hours,
created_at: Time.zone.now - 24.hours created_at: Time.zone.now - 24.hours,
duration: 12
) )
end end

View File

@ -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 it 'can take a number of hours as a string and can handle based on last post' do
freeze_time now 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) expect(topic.topic_timers.first.execute_at).to eq_time(18.hours.from_now)
end end
@ -1750,7 +1750,7 @@ describe Topic do
it "should be able to override category's default auto close" do it "should be able to override category's default auto close" do
Jobs.run_immediately! 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) topic.set_or_create_timer(TopicTimer.types[:close], 2, by_user: admin)

View File

@ -59,7 +59,7 @@ describe TopicStatusUpdater do
Fabricate(:post, topic: topic) Fabricate(:post, topic: topic)
topic.set_or_create_timer( 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) TopicStatusUpdater.new(topic, admin).update!("autoclosed", true)