Skip to content

Commit

Permalink
Refactor dispatched events in participatory space user roles (decidim…
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu authored Jul 27, 2023
1 parent 0386602 commit c290ea8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@ def initialize(role, current_user)
#
# Returns nothing.
def call
destroy_role!
dispatch_system_event
with_events do
destroy_role!
end

broadcast(:ok)
end

private

attr_reader :role, :current_user

def dispatch_system_event
ActiveSupport::Notifications.publish("decidim.system.participatory_space.admin.destroyed", role.class.name, role.id)
def event_arguments
{
class_name: role.class.name,
role: role.id
}
end

def destroy_role!
Expand Down
13 changes: 5 additions & 8 deletions decidim-admin/lib/decidim/admin/test/destroy_admin_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
expect(action_log.version.event).to eq "destroy"
end

it "fires an event" do
expect(ActiveSupport::Notifications).to receive(:publish).with(
"decidim.system.participatory_space.admin.destroyed",
role.class.name,
role.id
)

subject.call
it_behaves_like "fires an ActiveSupport::Notification event", "decidim.admin.participatory_space.destroy_admin:before" do
let(:command) { subject }
end
it_behaves_like "fires an ActiveSupport::Notification event", "decidim.admin.participatory_space.destroy_admin:after" do
let(:command) { subject }
end
end
2 changes: 1 addition & 1 deletion decidim-proposals/lib/decidim/proposals/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Engine < ::Rails::Engine
end

initializer "decidim_proposals.remove_space_admins" do
ActiveSupport::Notifications.subscribe("decidim.system.participatory_space.admin.destroyed") do |_event_name, klass, id|
ActiveSupport::Notifications.subscribe("decidim.admin.participatorty_space.destroy_admin:after") do |_event_name, klass, id|
Decidim::Proposals::ValuationAssignment.where(valuator_role_type: klass, valuator_role_id: id).destroy_all
end
end
Expand Down
6 changes: 3 additions & 3 deletions decidim-proposals/spec/lib/decidim/proposals/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

it "removes the record" do
expect do
ActiveSupport::Notifications.publish("decidim.system.participatory_space.admin.destroyed", valuator_role.class.name, valuator_role.id)
ActiveSupport::Notifications.publish("decidim.admin.participatorty_space.destroy_admin:after", valuator_role.class.name, valuator_role.id)
end.to change(Decidim::Proposals::ValuationAssignment, :count).by(-1)
end
end
Expand All @@ -29,7 +29,7 @@

it "removes the record" do
expect do
ActiveSupport::Notifications.publish("decidim.system.participatory_space.admin.destroyed", valuator_role.class.name, valuator_role.id)
ActiveSupport::Notifications.publish("decidim.admin.participatorty_space.destroy_admin:after", valuator_role.class.name, valuator_role.id)
end.to change(Decidim::Proposals::ValuationAssignment, :count).by(-1)
end
end
Expand All @@ -41,7 +41,7 @@

it "removes the record" do
expect do
ActiveSupport::Notifications.publish("decidim.system.participatory_space.admin.destroyed", valuator_role.class.name, valuator_role.id)
ActiveSupport::Notifications.publish("decidim.admin.participatorty_space.destroy_admin:after", valuator_role.class.name, valuator_role.id)
end.to change(Decidim::Proposals::ValuationAssignment, :count).by(-1)
end
end
Expand Down

0 comments on commit c290ea8

Please sign in to comment.