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