#541 ✓resolved
Mark Bates

Validations appear to not be working correctly

Reported by Mark Bates | August 22nd, 2008 @ 04:52 PM

The order of the validations seems to stop other validations if one trips. For example if I have a validates_present and a validates_is_unique the validates_is_unique won't fire because the validates_present seems to block all other validations for that column. it's the same regardless of order, or type of validation. The first guy in blocks the rest.


class User
  include DataMapper::Resource

  property :id, Serial
  property :username, String, :size => 20
  property :password, String

  attr_accessor :password_confirmation

  validates_present :username
  validates_is_unique :username
  validates_present :password
  validates_is_confirmed :password
end

u = User.new
u.valid? # => false
u.errors # => #<DataMapper::Validate::ValidationErrors:0x2557510 @errors={:username=>["Username must not be blank"], :password=>["Password must not be blank"]}>
u.username = 'existingusername'
u.valid? # => false
u.errors # => #<DataMapper::Validate::ValidationErrors:0x2557510 @errors={:password=>["Password must not be blank"]}>

Comments and changes to this ticket

  • Rob Westgeest

    Rob Westgeest August 23rd, 2008 @ 05:35 PM

    This seems to be a problem in Datamapper::Validate::GenericValidator.==(other):

      def ==(other)
        self.field_name == other.field_name &&
        self.if_clause == other.if_clause &&
        self.unless_clause == other.unless_clause &&
        self.instance_variable_get(:@options) == other.instance_variable_get(:@options)
      end
    

    == should test the class of validation as well in order to put multiple but differend kinds of validations on a model like so:

    module DataMapper module Validate

    class GenericValidator
      def ==(other)
        self.field_name == other.field_name &&
        self.if_clause == other.if_clause &&
        self.class == other.class &&
        self.unless_clause == other.unless_clause &&
        self.instance_variable_get(:@options) == other.instance_variable_get(:@options)
      end
    end
    

    end end

    Once i would find out how an where to controbute i would be glad to do so. At the moment it is difficult to find out cuz datamapper.org/development seems not responsive.

  • Mark Bates

    Mark Bates August 23rd, 2008 @ 09:05 PM

    The easiest way to contribute is to fork the project on github and then send sam a pull request with the changes. Also, if you could post the fix, or at the changeset link from github to this ticket, because I desperately need the fix for a project I'm working on. :)


    Mark Bates

    On Aug 23, 2008, at 6:36 PM, Lighthouse support@lighthouseapp.com wrote:

  • Rob Westgeest

    Rob Westgeest September 17th, 2008 @ 10:47 AM

    • Tag changed from bug, dm-more, validations to bug, dm-more, validations

    Should't this be closed now? I have seen this working correctly in >= 0.9.7

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 5th, 2008 @ 03:43 AM

    • State changed from “new” to “resolved”
    • Assigned user cleared.

    I've confirmed this is no longer an issue with the attached script.

    Mark, also a small tip, unless you are doing conditional validation with validates_present, you should almost always specify :nullable => false on the property. This will create the underlying DB column with the "NOT NULL" constraint. In those cases, the only real time to use validates_present explicitly is when you are specifying custom error messages.

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 »

People watching this ticket

Attachments

Pages