Sha256: da14751b9bae49e733eed520f353ef2367c5a007ed11270cf011b1107438b4c2

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher do
  context 'a model with an acceptance validation' do
    it 'accepts when the attributes match' do
      expect(validating_acceptance).to matcher
    end

    it 'does not overwrite the default message with nil' do
      expect(validating_acceptance).to matcher.with_message(nil)
    end
  end

  context 'a model without an acceptance validation' do
    it 'rejects' do
      expect(define_model(:example, attr: :string).new).not_to matcher
    end
  end

  context 'an attribute which must be accepted with a custom message' do
    it 'accepts when the message matches' do
      expect(validating_acceptance(message: 'custom')).
        to matcher.with_message(/custom/)
    end

    it 'rejects when the message does not match' do
      expect(validating_acceptance(message: 'custom')).
        not_to matcher.with_message(/wrong/)
    end
  end

  def matcher
    validate_acceptance_of(:attr)
  end

  def validating_acceptance(options = {})
    define_model(:example, attr: :string) do
      validates_acceptance_of :attr, options
    end.new
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
shoulda-matchers-2.7.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.6.2 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
mcmire-shoulda-matchers-2.6.2.docs.1 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
mcmire-shoulda-matchers-2.6.1.docs.1 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.6.1 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.6.1.rc2 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.6.1.rc1 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.6.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
mcmire-shoulda-matchers-2.5.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb