Sha256: c97199cb3404653540d270b372ff77a472aadf80cc218ffc86ae5e4a9237067b

Contents?: true

Size: 1.86 KB

Versions: 17

Compression:

Stored size: 1.86 KB

Contents

require 'teststrap'

context "validates confirmation" do
  
  should "add a validation macro" do
    WhyValidationsSuckIn96::ValidationBuilder.instance_methods
  end.includes('validates_confirmation_of')
  
  context "with some default options" do
    setup do
      WhyValidationsSuckIn96::ValidatesConfirmation.new(Object.new, :attribute => :password)
    end
  
    should "have a message accessor with a default message" do
      topic.message
    end.equals("does not match the confirmation")  
  end # with some default options
  
  context "validating an object" do
  
    context "without a confirmation field" do
      validatable = Class.new do
        def password
          "foo"
        end
      end.new

      setup do
        WhyValidationsSuckIn96::ValidatesConfirmation.new(validatable, :attribute => :password)
      end
      
      should "raise if a confirmation field isn't available" do
        topic.validates?
      end.raises(NoMethodError)
      
    end # without a confirmation field

    context "with a confirmation field" do
      validatable = OpenStruct.new(:password => "foo")

      setup do
        WhyValidationsSuckIn96::ValidatesConfirmation.new(validatable, :attribute => :password)
      end
      
      should "fail if field does not match the confirmation" do
        validatable.password = "foo"
        validatable.password_confirmation = "bleh"
        topic.validates?
      end.equals(false)
    
      should "pass if the field matches the confirmation" do
        validatable.password = validatable.password_confirmation = "foo"
        topic.validates?
      end
    
      should "skip the validation if the confirmation is nil" do
        validatable.password_confirmation = nil
        topic.validates?
        topic.has_run?
      end.equals(false)
    end # with a confirmation field
  end   # validating an object
end     # validates confirmation

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
whyvalidationssuckin96-1.6.1 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.6.0 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.5.5 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.5.4 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.5.3 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.5.2 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.5.1 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.5.0 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.4.0 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.3.1 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.3.0 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.2.3 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.2.2 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.2.1 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.2.0 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.1.0 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.0.0 test/macros/validates_confirmation_test.rb