mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
FIX: Can't update status_type of topic timers.
https://meta.discourse.org/t/topic-timers-internal-error-500/64805
This commit is contained in:
parent
dd85c1098b
commit
4c98bd9d5f
3 changed files with 15 additions and 3 deletions
|
@ -988,9 +988,10 @@ SQL
|
||||||
# * based_on_last_post: True if time should be based on timestamp of the last post.
|
# * based_on_last_post: True if time should be based on timestamp of the last post.
|
||||||
# * category_id: Category that the update will apply to.
|
# * category_id: Category that the update will apply to.
|
||||||
def set_or_create_timer(status_type, time, by_user: nil, timezone_offset: 0, based_on_last_post: false, category_id: SiteSetting.uncategorized_category_id)
|
def set_or_create_timer(status_type, time, by_user: nil, timezone_offset: 0, based_on_last_post: false, category_id: SiteSetting.uncategorized_category_id)
|
||||||
topic_timer_options = { status_type: status_type, topic: self }
|
topic_timer_options = { topic: self }
|
||||||
topic_timer_options.merge!(user: by_user) unless TopicTimer.public_types[status_type]
|
topic_timer_options.merge!(user: by_user) unless TopicTimer.public_types[status_type]
|
||||||
topic_timer = TopicTimer.find_or_initialize_by(topic_timer_options)
|
topic_timer = TopicTimer.find_or_initialize_by(topic_timer_options)
|
||||||
|
topic_timer.status_type = status_type
|
||||||
|
|
||||||
if time.blank?
|
if time.blank?
|
||||||
topic_timer.trash!(trashed_by: by_user || Discourse.system_user)
|
topic_timer.trash!(trashed_by: by_user || Discourse.system_user)
|
||||||
|
|
|
@ -1267,6 +1267,16 @@ describe Topic do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should allow status_type to be updated' do
|
||||||
|
Timecop.freeze do
|
||||||
|
topic_timer = closing_topic.set_or_create_timer(
|
||||||
|
TopicTimer.types[:publish_to_category], 72, by_user: admin
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(topic_timer.execute_at).to eq(3.days.from_now)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "does not update topic's topic status created_at it was already set to close" do
|
it "does not update topic's topic status created_at it was already set to close" do
|
||||||
expect{
|
expect{
|
||||||
closing_topic.set_or_create_timer(TopicTimer.types[:close], 14)
|
closing_topic.set_or_create_timer(TopicTimer.types[:close], 14)
|
||||||
|
|
|
@ -260,7 +260,8 @@ RSpec.describe TopicTimer, type: :model do
|
||||||
open_topic_timer = Fabricate(:topic_timer,
|
open_topic_timer = Fabricate(:topic_timer,
|
||||||
status_type: described_class.types[:open],
|
status_type: described_class.types[:open],
|
||||||
execute_at: Time.zone.now - 1.hour,
|
execute_at: Time.zone.now - 1.hour,
|
||||||
created_at: Time.zone.now - 2.hour
|
created_at: Time.zone.now - 2.hour,
|
||||||
|
topic: Fabricate(:topic, closed: true)
|
||||||
)
|
)
|
||||||
|
|
||||||
Fabricate(:topic_timer)
|
Fabricate(:topic_timer)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue