Sha256: 4ec4e8d9644c8717b25d46e4a360534e7987e4f2ec2ac4871a03625df4cab51b

Contents?: true

Size: 1.74 KB

Versions: 64

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

shared_examples "publish amendment draft" do
  describe "when the form is valid" do
    it "broadcasts ok" do
      expect { command.call }.to broadcast(:ok)
    end

    it "publishes the amendment and the emendation" do
      command.call

      expect(Decidim::Amendment.last.draft?).to eq(false)
      expect(amendable.class.last.published?).to eq(true)
    end

    it "traces the action", versioning: true do
      expect(Decidim.traceability)
        .to receive(:perform_action!)
        .with(
          "publish",
          form.amendable.class,
          form.current_user,
          kind_of(Hash)
        ).and_call_original

      expect { command.call }.to change(Decidim::ActionLog, :count).by(1)
    end

    it "notifies the change" do
      expect(Decidim::EventsManager)
        .to receive(:publish)
        .with(
          event: "decidim.events.amendments.amendment_created",
          event_class: Decidim::Amendable::AmendmentCreatedEvent,
          resource: amendable,
          affected_users: [amendable.creator_author],
          followers: []
        )

      command.call
    end
  end

  context "when the form is not valid" do
    let(:form) { Decidim::Amendable::PublishForm.from_params(id: nil) }

    it "broadcasts invalid" do
      expect { command.call }.to broadcast(:invalid)
    end
  end

  context "when current user is not the author of the amendment" do
    let(:current_user) { other_user }

    it "broadcasts invalid" do
      expect { command.call }.to broadcast(:invalid)
    end
  end

  context "when amendment is not a draft" do
    before do
      amendment.update(state: "evaluating")
    end

    it "broadcasts invalid" do
      expect { command.call }.to broadcast(:invalid)
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
decidim-core-0.29.1 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.28.4 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.27.9 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.29.0 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.28.3 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.27.8 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.29.0.rc4 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.29.0.rc3 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.29.0.rc2 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.29.0.rc1 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.28.2 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.27.7 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.28.1 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.27.6 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.26.10 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.26.9 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.28.0 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.27.5 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.28.0.rc5 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb
decidim-core-0.28.0.rc4 lib/decidim/core/test/shared_examples/amendable/publish_amendment_draft_examples.rb