Skip to content

A platform for community discussion. Free, open, simple.

DEV: trigger single event when multiple posts are destroyed at once (#32731)

marstallce2729e676ee
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 93ce7768d46..983376edb52 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -424,6 +424,7 @@ class PostsController < ApplicationController
).destroy
end
end
+ DiscourseEvent.trigger(:posts_destroyed, posts, current_user)
render body: nil
end
diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb
index 20e1166b952..d9b24b96e6e 100644
--- a/spec/requests/posts_controller_spec.rb
+++ b/spec/requests/posts_controller_spec.rb
@@ -405,6 +405,18 @@ RSpec.describe PostsController do
delete "/posts/destroy_many.json", params: { post_ids: [post1.id, post2.id] }
expect(response.status).to eq(200)
end
+ # bookmark
+ it "triggers DiscourseEvent with :posts_destroyed and correct params" do
+ sign_in(poster)
+ events =
+ DiscourseEvent.track_events do
+ delete "/posts/destroy_many.json", params: { post_ids: [post1.id, post2.id] }
+ end
+ event = events.find { |e| e[:event_name] == :posts_destroyed }
+ expect(event).to be_present
+ expect(event[:params][0].length).to eq(2)
+ expect(event[:params][1]).to eq(poster)
+ end
it "updates the highest read data for the forum" do
sign_in(poster)