Sha256: fc7a55722025e5ff49895204b7ba9d4426132c13504b6578e2a835e39964ba21

Contents?: true

Size: 782 Bytes

Versions: 5

Compression:

Stored size: 782 Bytes

Contents

require 'spec_helper'

      ActiveModel::Validations::AtLeastOnePresentValidator
class ActiveModel::Validations::AtLeastOnePresentValidator

  class TestModel < Struct.new(:home_phone, :work_phone)
    include ActiveModel::Validations

    validates_with AtLeastOnePresentValidator, at_least_one_of: [:home_phone, :work_phone]
  end

  describe TestModel do

    context 'when we supply none of the required fields' do
      before { subject.valid? }
      its('errors.messages') { should == {base: ["at least 1 of these fields must be present: home_phone or work_phone"]} }
    end

    context 'when we only have home_phone' do
      before { subject.home_phone = '555-555-5555' }
      before { subject.valid? }
      its('errors.messages') { should == {} }
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activemodel-validators-3.0.1 spec/at_least_one_present_validator_spec.rb
activemodel-validators-3.0.0 spec/at_least_one_present_validator_spec.rb
activemodel-validators-2.0.0 spec/at_least_one_present_validator_spec.rb
activemodel-validators-1.2.0 spec/at_least_one_present_validator_spec.rb
activemodel-validators-1.1.0 spec/at_least_one_present_validator_spec.rb