Sha256: 658fef0d55eade82d3b6438608055813845a1dd0363cc20db0f9824ce25266c7

Contents?: true

Size: 1.5 KB

Versions: 11

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    describe ScopeForm do
      let(:organization) { create :organization }
      let(:name) { Decidim::Faker::Localized.literal(::Faker::Address.unique.state) }
      let(:code) { ::Faker::Address.unique.state_abbr }
      let(:scope_type) { create :scope_type }
      let(:attributes) do
        {
          "scope" => {
            "name" => name,
            "code" => code,
            "scope_type" => scope_type
          }
        }
      end
      let(:context) do
        {
          "current_organization" => organization
        }
      end

      subject { described_class.from_params(attributes).with_context(context) }

      context "when everything is OK" do
        it { is_expected.to be_valid }
      end

      context "when name is missing" do
        let(:name) { {} }

        it { is_expected.to be_invalid }
      end

      context "when code is missing" do
        let(:code) { "" }

        it { is_expected.to be_invalid }
      end

      context "when code is not unique" do
        before do
          create(:scope, organization: organization, code: code)
        end

        it "is not valid" do
          expect(subject).not_to be_valid
          expect(subject.errors[:code]).not_to be_empty
        end
      end

      context "when the code exists in another organization" do
        before do
          create(:scope, code: code)
        end

        it { is_expected.to be_valid }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-0.6.8 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.6.7 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.6.6 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.6.5 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.6.4 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.6.3 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.6.2 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.6.1 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.6.0 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.5.1 decidim-admin/spec/forms/scope_form_spec.rb
decidim-0.5.0 decidim-admin/spec/forms/scope_form_spec.rb