Sha256: 94c3a2cbdb48f8dd9c6563f8e700c8fc2b3b7f089fc473c0ca9cf89ac9f4c744

Contents?: true

Size: 1.88 KB

Versions: 9

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    describe CreateCategory, :db do
      describe "call" do
        let(:organization) { create(:organization) }
        let(:participatory_process) { create :participatory_process, organization: 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_process: participatory_process
          ).with_context(
            current_organization: organization
          )
        end
        let(:command) { described_class.new(form, participatory_process) }

        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_process.categories.count }.by(1)
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-0.4.4 decidim-admin/spec/commands/create_category_spec.rb
decidim-0.4.3 decidim-admin/spec/commands/create_category_spec.rb
decidim-0.4.2 decidim-admin/spec/commands/create_category_spec.rb
decidim-0.4.1 decidim-admin/spec/commands/create_category_spec.rb
decidim-0.4.0 decidim-admin/spec/commands/create_category_spec.rb
decidim-0.3.2 decidim-admin/spec/commands/create_category_spec.rb
decidim-0.3.1 decidim-admin/spec/commands/create_category_spec.rb
decidim-0.3.0 decidim-admin/spec/commands/create_category_spec.rb
decidim-0.2.0 decidim-admin/spec/commands/create_category_spec.rb