Sha256: 637e5a0d5972a03240bd380393940e79d2b74d8f97104721d3d5a0259d52269a

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    describe DestroyCategory, :db do
      describe "call" do
        let(:organization) { create(:organization) }
        let(:participatory_process) { create :participatory_process, organization: organization }
        let(:category) { create(:category, participatory_process: participatory_process) }
        let(:command) { described_class.new(category) }

        describe "when the category is not present" do
          let(:category) { nil }

          it "broadcasts invalid" do
            expect { command.call }.to broadcast(:invalid)
          end
        end

        context "when the category is not empty" do
          let!(:subcategory) { create :subcategory, parent: category }

          it "doesn't destroy the category" do
            expect do
              command.call
            end.not_to change { Category.count }
          end
        end

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

          it "destroys the category in the process" do
            category
            expect do
              command.call
            end.to change { Category.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/destroy_category_spec.rb
decidim-0.4.3 decidim-admin/spec/commands/destroy_category_spec.rb
decidim-0.4.2 decidim-admin/spec/commands/destroy_category_spec.rb
decidim-0.4.1 decidim-admin/spec/commands/destroy_category_spec.rb
decidim-0.4.0 decidim-admin/spec/commands/destroy_category_spec.rb
decidim-0.3.2 decidim-admin/spec/commands/destroy_category_spec.rb
decidim-0.3.1 decidim-admin/spec/commands/destroy_category_spec.rb
decidim-0.3.0 decidim-admin/spec/commands/destroy_category_spec.rb
decidim-0.2.0 decidim-admin/spec/commands/destroy_category_spec.rb