Sha256: 50ef17d0c4654206e34367bf4459fc6a5c44c773dfd4c3e063757e9f5d32c2a3

Contents?: true

Size: 1.76 KB

Versions: 97

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    shared_examples_for "UpdateCategory command" do
      describe "call" do
        let(:organization) { create(:organization) }
        let(:category) { create(:category, participatory_space: participatory_space) }
        let(:form_params) do
          {
            "category" => {
              "name_en" => "New title",
              "name_es" => "Title",
              "name_ca" => "Title",
              "description_en" => "Description",
              "description_es" => "Description",
              "description_ca" => "Description"
            }
          }
        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(category, 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 category" do
            command.call
            category.reload

            expect(translated(category.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 category in the process" do
            command.call
            category.reload

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

Version data entries

97 entries across 97 versions & 2 rubygems

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