Sha256: c50552f277f1b6a20bc0a28c676ef7abd592fdcf958fa57b6af06b594a0e6501

Contents?: true

Size: 1.12 KB

Versions: 18

Compression:

Stored size: 1.12 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
      validating_acceptance.should matcher
    end

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

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

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

    it 'rejects when the message does not match' do
      validating_acceptance(:message => 'custom').
        should_not 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

18 entries across 17 versions & 2 rubygems

Version Path
shoulda-matchers-2.5.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.4.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.4.0.rc1 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.3.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
challah-1.0.0 vendor/bundle/gems/shoulda-matchers-2.2.0/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.2.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-2.1.0/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.1.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-2.0.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-1.5.6 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-1.5.5 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-1.5.4 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-1.5.2 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-1.5.1 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
shoulda-matchers-1.5.0 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb