Sha256: ee47dd9722088bed5bb0e3ad392e728f9679de884d62e36bfd0512cbd6ddb8c4

Contents?: true

Size: 1.88 KB

Versions: 65

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    shared_examples_for "UpdateAttachmentCollection command" do
      describe "call" do
        let(:organization) { create(:organization) }
        let(:attachment_collection) { create(:attachment_collection, collection_for: collection_for) }
        let(:form_params) do
          {
            "attachment_collection" => {
              "name_en" => "New title",
              "name_es" => "Title",
              "name_ca" => "Title",
              "description_en" => "Description",
              "description_es" => "Description",
              "description_ca" => "Description"
            }
          }
        end
        let(:form) do
          AttachmentCollectionForm.from_params(
            form_params,
            collection_for: collection_for
          ).with_context(
            current_organization: organization
          )
        end
        let(:command) { described_class.new(attachment_collection, form) }

        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 update the attachment collection" do
            command.call
            attachment_collection.reload

            expect(translated(attachment_collection.name)).not_to eq("New title")
          end
        end

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

          it "updates the attachment collection in the process" do
            command.call
            attachment_collection.reload

            expect(translated(attachment_collection.name)).to eq("New title")
          end
        end
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.9 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.8 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.7 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.5 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.4 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.3 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.2 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.0 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.0.rc2 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.26.0.rc1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.25.2 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.25.1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.25.0 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.25.0.rc4 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.25.0.rc3 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.25.0.rc2 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.25.0.rc1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.24.3 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb