Sha256: a2411dc9054e0eb41a9e9f9dbc98f13421bea127516a0bcd186a247ea1b574c1

Contents?: true

Size: 1.57 KB

Versions: 14

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
  it 'does not allow any types' do
    matcher('abcde').allowed_types.should == ''
  end

  context 'an attribute with a format validation' do
    it 'does not match if the value is allowed' do
      validating_format(:with => /abc/).should_not matcher('abcde').for(:attr)
    end

    it 'matches if the value is not allowed' do
      validating_format(:with => /abc/).should matcher('xyz').for(:attr)
    end
  end

  context 'an attribute with a format validation and a custom message' do
    it 'does not match if the value and message are both correct' do
      validating_format(:with => /abc/, :message => 'good message').
        should_not matcher('abcde').for(:attr).with_message('good message')
    end

    it "delegates its failure message to its allow matcher's negative failure message" do
      allow_matcher = stub_everything(:failure_message_for_should_not => 'allow matcher failure')
      Shoulda::Matchers::ActiveModel::AllowValueMatcher.stubs(:new).returns(allow_matcher)

      matcher = matcher('abcde').for(:attr).with_message('good message')
      matcher.matches?(validating_format(:with => /abc/, :message => 'good message'))

      matcher.failure_message_for_should.should == 'allow matcher failure'
    end

    it 'matches if the message is correct but the value is not' do
      validating_format(:with => /abc/, :message => 'good message').
        should matcher('xyz').for(:attr).with_message('good message')
    end
  end

  def matcher(value)
    described_class.new(value)
  end
end

Version data entries

14 entries across 13 versions & 2 rubygems

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