Sha256: 71dcd8b8cde26538772aec47927368c6164a4240a951ec62035750a1b4c7b6dc
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
require 'spec_helper' shared_examples "it validates the single cardinality of the field" do it "should be valid when the field value is nil" do subject.field = nil expect(subject).to be_valid end it "should be valid when the field value is a scalar" do subject.field = "foo" expect(subject).to be_valid end context "when the field value is an enumerable" do it "should be valid if the value is empty" do subject.field = [] expect(subject).to be_valid end it "should be valid if the value has one element" do subject.field = ["foo"] expect(subject).to be_valid end it "should be invalid if the value has more than one element" do subject.field = ["foo", "bar"] expect(subject).not_to be_valid end end end describe Hydra::Validations::SingleCardinalityValidator do before(:all) do class Validatable include ActiveModel::Validations include Hydra::Validations attr_accessor :field end end before(:each) { Validatable.clear_validators! } after(:all) { Object.send(:remove_const, :Validatable) } subject { Validatable.new } describe ".validates" do before { Validatable.validates :field, single_cardinality: true } it_behaves_like "it validates the single cardinality of the field" end describe ".validates_single_cardinality_of" do before { Validatable.validates_single_cardinality_of :field } it_behaves_like "it validates the single cardinality of the field" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hydra-validations-0.1.0 | spec/validators/single_cardinality_validator_spec.rb |