Sha256: 701d298f43514be58bb71baf0af23736bf18ab9aff8ca5aaec3216113c9eed55

Contents?: true

Size: 1.82 KB

Versions: 46

Compression:

Stored size: 1.82 KB

Contents

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

module Functional
  class ValidatesLengthOfTest < Test::Unit::TestCase
    test "given short value, when validated, then error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name
        validates_length_of :name, :minimum => 2
      end
      instance = klass.new
      instance.valid?
      assert_equal "is invalid", instance.errors.on(:name)
    end
    
    test "given is constraint, when validated, then error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name
        validates_length_of :name, :is => 2
      end

      instance = klass.new
      instance.valid?
      assert_equal "is invalid", instance.errors.on(:name)
    end

    test "given is constraint is met, when validated, then valid is true" do
      klass = Class.new do
        include Validatable
        attr_accessor :name
        validates_length_of :name, :is => 2
      end

      instance = klass.new
      instance.name = "bk"
      assert_equal true, instance.valid?
    end
    
    test "given within constraint, when validated, then error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name
        validates_length_of :name, :within => 2..4
      end

      instance = klass.new
      instance.valid?
      assert_equal "is invalid", instance.errors.on(:name)
    end

    test "given within constraint, when validated, then valid is true" do
      klass = Class.new do
        include Validatable
        attr_accessor :name
        validates_length_of :name, :within => 2..4
      end

      instance = klass.new
      instance.name = "bk"
      assert_equal true, instance.valid?
    end
  end
end

Version data entries

46 entries across 46 versions & 10 rubygems

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