From a5636afb08ab41e2199ad2867b3337b16e8e6466 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Tue, 3 Dec 2024 13:16:20 -0600 Subject: [PATCH] DEV: Add posts_moved DiscourseEvent in PostMover (#30066) --- app/models/post_mover.rb | 5 +++++ spec/models/post_mover_spec.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 94785ea540b..8033bdebc0a 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -113,6 +113,11 @@ class PostMover close_topic_and_schedule_deletion if moving_all_posts destination_topic.reload + DiscourseEvent.trigger( + :posts_moved, + destination_topic_id: destination_topic.id, + original_topic_id: original_topic.id, + ) destination_topic end diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 4fbe37bf881..d397e8f18f0 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -811,6 +811,21 @@ RSpec.describe PostMover do expect(topic).to be_closed end + it "triggers posts_moved DiscourseEvent with correct args" do + events = + DiscourseEvent.track_events(:posts_moved) do + posts_to_move = [p1.id, p2.id, p3.id, p4.id] + topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id) + end + + expect( + events.detect do |e| + e[:params] == + [{ destination_topic_id: destination_topic.id, original_topic_id: topic.id }] + end, + ).to be_present + end + it "does not try to move small action posts" do small_action = Fabricate(