Sha256: ccf1fb6238fd4fc57ff9cc99b947465a059f60c60b5e4e97d9307175943d4f98

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

require "spec_helper"

describe Decidim::Admin::CreateParticipatoryProcess do
  let(:organization) { create :organization }
  let(:errors) { double.as_null_object }
  let(:form) do
    double(
      :invalid? => invalid,
      title: {en: "title"},
      subtitle: {en: "subtitle"},
      slug: "slug",
      hashtag: "hashtag",
      hero_image: nil,
      banner_image: nil,
      promoted: nil,
      description: {en: "description"},
      short_description: {en: "short_description"},
      current_organization: organization,
      errors: errors
    )
  end
  let(:invalid) { false }

  subject { described_class.new(form) }

  context "when the form is not valid" do
    let(:invalid) { true }

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

  context "when the process is not persisted" do
    let(:invalid_process) do
      instance_double(
        Decidim::ParticipatoryProcess,
        persisted?: false,
        valid?: false,
        errors: {
          hero_image: "Image too big",
          banner_image: "Image too big"
        }
      ).as_null_object
    end

    before do
      expect(Decidim::ParticipatoryProcess).to receive(:new).and_return(invalid_process)
    end

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

    it "adds errors to the form" do
      expect(errors).to receive(:add).with(:hero_image, "Image too big")
      expect(errors).to receive(:add).with(:banner_image, "Image too big")
      subject.call
    end
  end

  context "when everything is ok" do
    it "creates a participatory process" do
      expect { subject.call }.to change { Decidim::ParticipatoryProcess.count }.by(1)
    end

    it "broadcasts ok" do
      expect { subject.call }.to broadcast(:ok)
    end

    it "adds the default step" do
      subject.call do
        on(:ok) do |process|
          expect(process.steps.count).to eq(1)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-0.0.5 decidim-admin/spec/commands/create_participatory_process_spec.rb
decidim-0.0.4 decidim-admin/spec/commands/create_participatory_process_spec.rb
decidim-0.0.3 decidim-admin/spec/commands/create_participatory_process_spec.rb