diff --git a/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal.rb b/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal.rb index 949fa6cb3cddb..71f8a03c33b45 100644 --- a/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal.rb +++ b/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal.rb @@ -40,9 +40,10 @@ def call create_attachment if process_attachments? create_gallery if process_gallery? link_author_meeeting if form.created_in_meeting? - send_notification end + send_notification + broadcast(:ok, proposal) end @@ -81,11 +82,13 @@ def link_author_meeeting end def send_notification + return unless proposal + Decidim::EventsManager.publish( event: "decidim.events.proposals.proposal_published", event_class: Decidim::Proposals::PublishProposalEvent, resource: proposal, - followers: @proposal.participatory_space.followers, + followers: proposal.participatory_space.followers, extra: { participatory_space: true } diff --git a/decidim-proposals/spec/commands/decidim/proposals/admin/create_proposal_spec.rb b/decidim-proposals/spec/commands/decidim/proposals/admin/create_proposal_spec.rb index ddf1f3593ec45..42f168ad79fd7 100644 --- a/decidim-proposals/spec/commands/decidim/proposals/admin/create_proposal_spec.rb +++ b/decidim-proposals/spec/commands/decidim/proposals/admin/create_proposal_spec.rb @@ -135,13 +135,11 @@ module Admin expect(action_log.version).to be_present end - it "notifies the space followers" do - follower = create(:user, organization: component.participatory_space.organization) - create(:follow, followable: component.participatory_space, user: follower) - - expect(Decidim::EventsManager) - .to receive(:publish) - .with( + context "when followers" do + let(:follower) { create(:user, organization: component.participatory_space.organization) } + let!(:follow) { create(:follow, followable: component.participatory_space, user: follower) } + let(:data) do + { event: "decidim.events.proposals.proposal_published", event_class: Decidim::Proposals::PublishProposalEvent, resource: kind_of(Decidim::Proposals::Proposal), @@ -149,9 +147,28 @@ module Admin extra: { participatory_space: true } - ) + } + end + + it "notifies the space followers" do + expect(Decidim::EventsManager).to receive(:publish).with(data) + + command.call + end - command.call + context "when active record is slow" do + let(:proposal) { build :proposal, component: component } + + before do + allow(command).to receive(:proposal).and_return(nil) + end + + it "does not notifies the space followers" do + expect(Decidim::EventsManager).not_to receive(:publish).with(data) + + command.call + end + end end context "when geocoding is enabled" do