Sha256: ce878f0e4a44e7694803c1bea95397ff77c984fe2130eac8436fb4993e398980

Contents?: true

Size: 1.38 KB

Versions: 51

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

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

    it "creates an amendment (draft) and the emendation (not published)" do
      expect { command.call }
        .to change(Decidim::Amendment, :count)
        .by(1)
        .and change(amendable.class, :count)
        .by(1)

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

    it "traces the action without creating a PaperTrail version for the emendation", versioning: true do
      expect(Decidim.traceability)
        .to receive(:perform_action!)
        .with(
          :create,
          amendable.class,
          form.current_user,
          kind_of(Hash)
        ).and_call_original

      expect { command.call }.to change(Decidim::ActionLog, :count).by(1)
      expect(amendable.class.last.versions.count).to eq(0)
    end
  end

  context "when the form is invalid" do
    let(:title) { "Too short" }

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

    it "doesn't create an amendment and the emendation" do
      expect { command.call }
        .to change(Decidim::Amendment, :count)
        .by(0)
        .and change(amendable.class, :count)
        .by(0)
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.8 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.7 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.6 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.26.10 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.26.9 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.5 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.26.8 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.4 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.3 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.26.7 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.26.5 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.2 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.1 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.26.4 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.0 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.26.3 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.0.rc2 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.27.0.rc1 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
decidim-core-0.26.2 lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb