Sha256: f0deac0e383d0001904911babfb62bac67a57b7eeccb8fd5aa5192a7fcb50fb8

Contents?: true

Size: 1.98 KB

Versions: 18

Compression:

Stored size: 1.98 KB

Contents

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

module Functional
  class ValidatesConfirmationOfTest < Test::Unit::TestCase
    test "given non matching attributes, when validated, then error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name, :name_confirmation
        validates_confirmation_of :name
      end
      instance = klass.new
      instance.name = "foo"
      instance.name_confirmation = "bar"
      instance.valid?
      assert_equal "doesn't match confirmation", instance.errors.on(:name)
    end

    test "given matching attributes, when validated, then no error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name, :name_confirmation
        validates_confirmation_of :name
      end
      instance = klass.new
      instance.name = "foo"
      instance.name_confirmation = "foo"
      assert_equal true, instance.valid?
    end

    test "given matching attributes of different case, when validated with case sensitive false, then no error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name, :name_confirmation
        validates_confirmation_of :name, :case_sensitive => false
      end
      instance = klass.new
      instance.name = "foo"
      instance.name_confirmation = "FOO"
      assert_equal true, instance.valid?
    end

    test "given matching attributes of different case, when validated with case sensitive true, then error is in the objects error collection" do
      klass = Class.new do
        include Validatable
        attr_accessor :name, :name_confirmation
        validates_confirmation_of :name
      end
      instance = klass.new
      instance.name = "foo"
      instance.name_confirmation = "FOO"
      assert_equal false, instance.valid?
      assert_equal "doesn't match confirmation", instance.errors.on(:name)
      
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
mack-notifier-0.8.3 lib/gems/validatable-1.6.7/test/functional/validates_confirmation_of_test.rb
mack-notifier-0.8.3.1 lib/gems/validatable-1.6.7/test/functional/validates_confirmation_of_test.rb
mack-notifier-0.8.2 lib/gems/validatable-1.6.7/test/functional/validates_confirmation_of_test.rb
validatable-1.6.3 test/functional/validates_confirmation_of_test.rb
validatable-1.6.7 test/functional/validates_confirmation_of_test.rb
validatable-1.3.2 test/functional/validates_confirmation_of_test.rb
validatable-1.2.1 test/functional/validates_confirmation_of_test.rb
validatable-1.3.4 test/functional/validates_confirmation_of_test.rb
validatable-1.4.0 test/functional/validates_confirmation_of_test.rb
validatable-1.6.1 test/functional/validates_confirmation_of_test.rb
validatable-1.6.6 test/functional/validates_confirmation_of_test.rb
validatable-1.2.2 test/functional/validates_confirmation_of_test.rb
validatable-1.5.0 test/functional/validates_confirmation_of_test.rb
validatable-1.6.0 test/functional/validates_confirmation_of_test.rb
validatable-1.3.0 test/functional/validates_confirmation_of_test.rb
validatable-1.6.4 test/functional/validates_confirmation_of_test.rb
validatable-1.5.2 test/functional/validates_confirmation_of_test.rb
validatable-1.6.2 test/functional/validates_confirmation_of_test.rb