Sha256: 3e7f0c0738fab5c61a1c8209197b49e1d71d3732c37ac74ec16c6d5f2b5e3adf

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

require 'teststrap'

context "validates confirmation" do
  
  should "add a validation macro" do
    WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
  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

3 entries across 3 versions & 1 rubygems

Version Path
whyvalidationssuckin96-1.6.4 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.6.3 test/macros/validates_confirmation_test.rb
whyvalidationssuckin96-1.6.2 test/macros/validates_confirmation_test.rb