diff --git a/app/models/topic.rb b/app/models/topic.rb index f497ca9b52c..fa3ade92609 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -912,8 +912,14 @@ class Topic < ActiveRecord::Base post_mover = PostMover.new(self, moved_by, post_ids) 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) + topic = post_mover.to_topic(opts[:destination_topic_id]) + + DiscourseEvent.trigger(:topic_merged, + post_mover.original_topic, + post_mover.destination_topic + ) + + topic elsif opts[:title] post_mover.to_new_topic(opts[:title], opts[:category_id], opts[:tags]) end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 205353adad7..cf08b4f1a47 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -201,11 +201,11 @@ 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) + expect(original_topic).to eq(topic) + expect(destination_topic).to eq(dest_topic) end end end