Sha256: 56517c9887456ac90ce8ad6541eb38623d4ea7488f48c8e6c40ac5db9263e0b6

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')

class AllowValueMatcherTest < Test::Unit::TestCase # :nodoc:

  context "an attribute with a format validation" do
    setup do
      define_model :example, :attr => :string do
        validates_format_of :attr, :with => /abc/
      end
      @model = Example.new
    end

    should "allow a good value" do
      assert_accepts allow_value("abcde").for(:attr), @model
    end
    
    should "not allow a bad value" do
      assert_rejects allow_value("xyz").for(:attr), @model
    end
  end

  context "an attribute with a format validation and a custom message" do
    setup do
      define_model :example, :attr => :string do
        validates_format_of :attr, :with => /abc/, :message => 'bad value'
      end
      @model = Example.new
    end

    should "allow a good value" do
      assert_accepts allow_value('abcde').for(:attr).with_message(/bad/),
                     @model
    end
    
    should "not allow a bad value" do
      assert_rejects allow_value('xyz').for(:attr).with_message(/bad/),
                     @model
    end
  end

end

Version data entries

10 entries across 10 versions & 5 rubygems

Version Path
Flamefork-shoulda-2.10.1 test/matchers/active_record/allow_value_matcher_test.rb
Flamefork-shoulda-2.10.2 test/matchers/active_record/allow_value_matcher_test.rb
francois-shoulda-2.10.1 test/matchers/active_record/allow_value_matcher_test.rb
technicalpickles-shoulda-2.10.0 test/matchers/active_record/allow_value_matcher_test.rb
thoughtbot-shoulda-2.10.0 test/matchers/active_record/allow_value_matcher_test.rb
thoughtbot-shoulda-2.10.1 test/matchers/active_record/allow_value_matcher_test.rb
thoughtbot-shoulda-2.9.2 test/matchers/active_record/allow_value_matcher_test.rb
shoulda-2.9.2 test/matchers/active_record/allow_value_matcher_test.rb
shoulda-2.10.0 test/matchers/active_record/allow_value_matcher_test.rb
shoulda-2.10.1 test/matchers/active_record/allow_value_matcher_test.rb