Sha256: 7a194e2ee25953afd7c4aa1f16b63c7f398a0ea71dc038c9842f7f87b926ea79

Contents?: true

Size: 1.17 KB

Versions: 51

Compression:

Stored size: 1.17 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../test_helper')

module Functional
  class ValidatesFormatOfTest < Test::Unit::TestCase
    test "given invalid name format, when validated, then error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name
        validates_format_of :name, :with => /.+/
      end
      instance = klass.new
      instance.valid?
      assert_equal "is invalid", instance.errors.on(:name)
    end

    test "given invalid name format and nil name, when validated, then error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name
        validates_format_of :name, :with => /.+/, :if => Proc.new { !name.nil? }
      end
      assert_equal true, klass.new.valid?
    end
    
    test "given invalid name format and a name, when validated, then error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name
        validates_format_of :name, :with => /.+/, :if => Proc.new { name.nil? }
      end
      assert_equal false, klass.new.valid?
    end
  end
end

Version data entries

51 entries across 51 versions & 10 rubygems

Version Path
hashrocket-validatable-1.7.2 test/functional/test_validates_format_of.rb
hashrocket-validatable-1.7.4 test/functional/test_validates_format_of.rb
jnunemaker-validatable-1.7.0 test/functional/test_validates_format_of.rb
jnunemaker-validatable-1.7.1 test/functional/test_validates_format_of.rb
jnunemaker-validatable-1.7.2 test/functional/test_validates_format_of.rb
vizjerai-validatable-1.8.0 test/functional/test_validates_format_of.rb
vizjerai-validatable-1.9.0 test/functional/test_validates_format_of.rb
lgustafson-validatable-1.8.7 test/functional/test_validates_format_of.rb
lgustafson-validatable-1.8.6 test/functional/test_validates_format_of.rb
np422-validatable-1.8.5 test/functional/test_validates_format_of.rb
erotte-validatable-1.8.5 test/functional/test_validates_format_of.rb
mattmatt-validatable-1.8.4 test/functional/test_validates_format_of.rb
mattmatt-validatable-1.8.3 test/functional/test_validates_format_of.rb
jnunemaker-validatable-1.8.4 test/functional/test_validates_format_of.rb
jnunemaker-validatable-1.8.3 test/functional/test_validates_format_of.rb
jnunemaker-validatable-1.8.2 test/functional/test_validates_format_of.rb
jnunemaker-validatable-1.1.10 test/functional/test_validates_format_of.rb
jnunemaker-validatable-1.1.9 test/functional/test_validates_format_of.rb
durran-validatable-2.0.1 test/functional/test_validates_format_of.rb
durran-validatable-2.0.0 test/functional/test_validates_format_of.rb