Sha256: 04af3e09649454112df28e1eddfc97e1382d4d48e90040c43d8dd14837d46c3f

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require "rails_helper"

module Archangel
  RSpec.describe Field, type: :model do
    context "validations" do
      it { is_expected.to validate_presence_of(:classification) }
      it { is_expected.to validate_presence_of(:collection_id).on(:update) }
      it { is_expected.to validate_presence_of(:label) }
      it { is_expected.to validate_presence_of(:slug) }

      it { is_expected.to allow_value(true).for(:required) }
      it { is_expected.to allow_value(1).for(:required) }
      it { is_expected.to allow_value(false).for(:required) }
      it { is_expected.to allow_value(0).for(:required) }

      it { is_expected.to_not allow_value(nil).for(:required) }

      it "allows certain classifications" do
        expect(subject).to(
          validate_inclusion_of(:classification)
            .in_array(Archangel::Field::CLASSIFICATIONS)
        )
      end

      it "has a unique slug scoped to Collection" do
        resource = build(:field)

        expect(resource).to(
          validate_uniqueness_of(:slug).scoped_to(:collection_id)
        )
      end
    end

    context "associations" do
      it { is_expected.to belong_to(:collection) }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
archangel-0.3.0 spec/models/archangel/field_spec.rb
archangel-0.0.8 spec/models/archangel/field_spec.rb
archangel-0.0.7 spec/models/archangel/field_spec.rb
archangel-0.0.6 spec/models/archangel/field_spec.rb