#782 ✓resolved
Aanand Prasad

validates_present :foo, :bar, :if => :condition? skips :if filter for second argument

Reported by Aanand Prasad | January 22nd, 2009 @ 11:50 AM | in 0.10.0

If I pass two properties and an :if option to validates_present, the validation is always run on the second property, i.e. the :if option is ignored.

This test passes under DM 0.9.9 but not 0.9.10:


require 'dm-core'
require 'dm-validations'

require 'test/unit'

DataMapper.setup(:default, :adapter => 'in_memory')

module Common
  def self.included(model)
    model.class_eval do
      include DataMapper::Resource

      property :id, DataMapper::Types::Serial

      property :foo, String
      property :bar, String
    end
  end
end  

class SinglePropertyArgument
  include Common

  validates_present :foo, :if => proc { false }
  validates_present :bar, :if => proc { false }
end

class MultiplePropertyArguments
  include Common

  validates_present :foo, :bar, :if => proc { false }
end

class ValidatesPresentTest < Test::Unit::TestCase
  # passes
  def test_single_property_argument
    assert SinglePropertyArgument.new.valid?
  end

  # fails
  def test_multiple_property_arguments
    assert MultiplePropertyArguments.new.valid?
  end
end

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Pages