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.23.6 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.24.2 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.23.5 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.24.1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.24.0 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.24.0.rc2 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.23.4 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.24.0.rc1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.23.3 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.23.2 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.23.1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.23.1.rc1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.23.0 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.22.0 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.21.0 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.20.1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.20.0 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.19.1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.18.1 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb
decidim-admin-0.19.0 lib/decidim/admin/test/commands/update_attachment_collection_examples.rb