Sha256: 591da683e5d2efbf8e2670d765daeaf21282d8a5378a651c588e60f30168cdc4

Contents?: true

Size: 1.86 KB

Versions: 40

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    shared_examples_for "CreateAttachmentCollection command" do
      describe "call" do
        let(:organization) { create(:organization) }
        let(:form_params) do
          {
            "attachment_collection" => {
              "name_en" => Decidim::Faker::Localized.sentence(3),
              "name_es" => Decidim::Faker::Localized.sentence(3),
              "name_ca" => Decidim::Faker::Localized.sentence(3),
              "description_en" => Decidim::Faker::Localized.paragraph(3),
              "description_es" => Decidim::Faker::Localized.paragraph(3),
              "description_ca" => Decidim::Faker::Localized.paragraph(3)
            }
          }
        end
        let(:form) do
          AttachmentCollectionForm.from_params(
            form_params,
            collection_for: collection_for
          ).with_context(
            current_organization: organization
          )
        end
        let(:command) { described_class.new(form, collection_for) }

        describe "when the form is not valid" do
          before do
            expect(form).to receive(:invalid?).and_return(true)
          end

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

          it "doesn't create an attachment collection" do
            expect do
              command.call
            end.not_to change(AttachmentCollection, :count)
          end
        end

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

          it "creates a new attachment collection" do
            expect do
              command.call
            end.to change(collection_for.attachment_collections, :count).by(1)
          end
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
decidim-admin-0.23.6 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.23.5 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.23.4 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.23.3 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.23.2 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.23.1 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.23.1.rc1 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.23.0 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.22.0 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.21.0 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.20.1 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.20.0 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.19.1 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.18.1 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.19.0 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.17.2 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.18.0 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.17.1 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.16.1 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb
decidim-admin-0.17.0 lib/decidim/admin/test/commands/create_attachment_collection_examples.rb