mirror of
https://github.com/discourse/discourse.git
synced 2025-04-01 11:16:42 +08:00
Add a DiscourseEvent
for when a topic is closed
This commit is contained in:
parent
3e13becf33
commit
7578d8fc44
@ -36,6 +36,10 @@ TopicStatusUpdater = Struct.new(:topic, :user) do
|
||||
result = false if rc == 0
|
||||
end
|
||||
|
||||
if status.manually_closing_topic?
|
||||
DiscourseEvent.trigger(:topic_closed, topic)
|
||||
end
|
||||
|
||||
if @topic_status_update
|
||||
if status.manually_closing_topic? || status.closing_topic?
|
||||
topic.delete_topic_timer(TopicTimer.types[:close])
|
||||
|
@ -40,6 +40,20 @@ describe TopicStatusUpdater do
|
||||
expect(last_post.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
|
||||
end
|
||||
|
||||
it "triggers a DiscourseEvent on close" do
|
||||
topic = create_topic
|
||||
|
||||
called = false
|
||||
updater = -> (topic) { called = true }
|
||||
|
||||
DiscourseEvent.on(:topic_closed, &updater)
|
||||
TopicStatusUpdater.new(topic, admin).update!("closed", true)
|
||||
DiscourseEvent.off(:topic_closed, &updater)
|
||||
|
||||
expect(topic).to be_closed
|
||||
expect(called).to eq(true)
|
||||
end
|
||||
|
||||
it "adds an autoclosed message based on last post" do
|
||||
topic = create_topic
|
||||
Fabricate(:post, topic: topic)
|
||||
|
Loading…
x
Reference in New Issue
Block a user