Sha256: cb0416a480a882531d49f2c82cdf708cc602b59167663a1c3c07a3254edbef1b

Contents?: true

Size: 1.1 KB

Versions: 39

Compression:

Stored size: 1.1 KB

Contents

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

class ValidateFormatOfMatcherTest < ActiveSupport::TestCase # :nodoc:


  context "a postal code" do
    setup do
      define_model :example, :attr => :string do
        validates_format_of :attr, :with => /^\d{5}$/
      end
      @model = Example.new
    end
    
    should "be valid" do
      assert_accepts validate_format_of(:attr).with('12345'), @model
    end
    
    should "not be valid with alpha in zip" do
      assert_rejects validate_format_of(:attr).not_with('1234a'), @model, :message=>"is invalid"
    end
    
    should "not be valid with to few digits" do
      assert_rejects validate_format_of(:attr).not_with('1234'), @model, :message=>"is invalid"
    end
    
    should "not be valid with to many digits" do
      assert_rejects validate_format_of(:attr).not_with('123456'), @model, :message=>"is invalid"
    end
    
    should "raise error if you try to call both with and not_with" do
      assert_raise RuntimeError do
        validate_format_of(:attr).not_with('123456').with('12345')
      end
    end
    
  end


end

Version data entries

39 entries across 39 versions & 11 rubygems

Version Path
auser-poolparty-1.3.0 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.1 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.10 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.11 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.12 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.13 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.14 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.15 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.16 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.17 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.2 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.3 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.4 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.5 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.6 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.7 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
auser-poolparty-1.3.8 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
fairchild-poolparty-1.3.17 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
fairchild-poolparty-1.3.5 vendor/gems/shoulda/test/matchers/active_record/validate_format_of_matcher_test.rb
iGEL-shoulda-2.10.2 test/matchers/active_record/validate_format_of_matcher_test.rb