Sha256: 6f88a31f1dc464b966c7bb170208ddc67e5b83597888dc0bd533adb3ecbb2011

Contents?: true

Size: 1.81 KB

Versions: 32

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    shared_examples_for "CreateCategory command" do
      describe "call" do
        let(:organization) { create(:organization) }
        let(:form_params) do
          {
            "category" => {
              "name_en" => Decidim::Faker::Localized.paragraph(3),
              "name_es" => Decidim::Faker::Localized.paragraph(3),
              "name_ca" => Decidim::Faker::Localized.paragraph(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
          CategoryForm.from_params(
            form_params,
            current_participatory_space: participatory_space
          ).with_context(
            current_organization: organization
          )
        end
        let(:command) { described_class.new(form, participatory_space) }

        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 a category" do
            expect do
              command.call
            end.not_to change { Category.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 category" do
            expect do
              command.call
            end.to change { participatory_space.categories.count }.by(1)
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
decidim-admin-0.9.3 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.9.2 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.9.1 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.9.0 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.8.4 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.8.3 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.8.2 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.8.1 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.8.0 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.7.4 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.7.3 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.7.2 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.7.1 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.7.0 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.6.8 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-0.6.8 decidim-admin/lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.6.7 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-0.6.7 decidim-admin/lib/decidim/admin/test/commands/create_category_examples.rb
decidim-admin-0.6.6 lib/decidim/admin/test/commands/create_category_examples.rb
decidim-0.6.6 decidim-admin/lib/decidim/admin/test/commands/create_category_examples.rb