FEATURE: Event on topic merge (#6057)

This commit is contained in:
Jordan Seanor 2018-07-09 21:28:57 -04:00 committed by Guo Xiang Tan
parent 6cc860be09
commit 10bc69a62f
2 changed files with 8 additions and 0 deletions

View File

@ -913,6 +913,7 @@ class Topic < ActiveRecord::Base
if opts[:destination_topic_id]
post_mover.to_topic opts[:destination_topic_id]
DiscourseEvent.trigger(:topic_merged, post_mover.original_topic, post_mover.destination_topic)
elsif opts[:title]
post_mover.to_new_topic(opts[:title], opts[:category_id], opts[:tags])
end

View File

@ -201,6 +201,13 @@ RSpec.describe TopicsController do
expect(result['success']).to eq(true)
expect(result['url']).to be_present
end
it "triggers an event on merge" do
DiscourseEvent.on(:topic_merged) do |original_topic, destination_topic|
expect(original_topic.id).to eq(topic.id)
expect(destination_topic.id).to eq(dest_topic.id)
end
end
end
context 'failure' do