google-code-export / ruby-activeldap

Automatically exported from code.google.com/p/ruby-activeldap
Other
1 stars 1 forks source link

validates_uniqueness_of not working? #47

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Write a validates_uniqueness_of validation in your model
   e.g.

class User < ActiveLdap::Base
     ldap_mapping   :dn_attribute => 'cn',
                    :prefix => 'ou=People',
                    :classes => ['top','posixAccount']
     validates_uniqueness_of :uid
end

2. Try to save, it'll fail with the following error message

>> u = User.new
=> #<User objectClass:<top, posixAccount>, must:<cn, gidNumber, homeDirectory, 
objectClass, uid, uidNumber>, may:<description, gecos, loginShell, 
userPassword>, cn: [], commonName: [], description: [], gecos: [], gidNumber: 
[], homeDirectory: [], loginShell: [], objectClass: ["top", "posixAccount"], 
uid: [], uidNumber: [], userPassword: [], userid: []>
>> u.uid = "test"
=> "test"
>> u.valid?
ArgumentError: one hash required
        from gems/gems/gettext-2.1.0/lib/gettext/core_ext/string.rb:78:in `%'
        from gems/gems/activeldap-1.2.2/lib/active_ldap/validations.rb:137:in `validate_dn'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:178:in `send'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:178:in `evaluate_method'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:166:in `call'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `run'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `each'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `send'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `run'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:276:in `run_validations_without_active_ldap_support'
        from gems/gems/activeldap-1.2.2/lib/active_ldap/validations.rb:65:in `run_callbacks'
        from gems/gems/activerecord-2.3.8/lib/active_record/validations.rb:1110:in `valid_without_callbacks?'
        from gems/gems/activerecord-2.3.8/lib/active_record/callbacks.rb:315:in `valid?'
        from (irb):3

What version of the product are you using? On what operating system?
  I'm using current SVN-HEAD as ruby gem with rails 2.3.8

Original issue reported on code.google.com by A.Steinel@gmail.com on 17 Jun 2010 at 1:42

GoogleCodeExporter commented 9 years ago
Sorry, this is the correct second step which leads to the error message:

>> u = User.new; u.uid = "test"; u.dn = "test"; u.gidNumber=1; 
u.homeDirectory="/home/test"; u.uidNumber=1000; nil
=> nil
>> u.valid?
NoMethodError: undefined method `columns_hash' for #<Class:0x7fa260bcf2c8>
        from gems/gems/activerecord-2.3.8/lib/active_record/validations.rb:804:in `validates_uniqueness_of'
        from gems/gems/activerecord-2.3.8/lib/active_record/validations.rb:480
        from gems/gems/activerecord-2.3.8/lib/active_record/validations.rb:477:in `each'
        from gems/gems/activerecord-2.3.8/lib/active_record/validations.rb:477
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:182:in `call'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:182:in `evaluate_method'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:166:in `call'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `run'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `each'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `send'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `run'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:276:in `run_validations_without_active_ldap_support'
        from gems/gems/activeldap-1.2.2/lib/active_ldap/validations.rb:65:in `run_callbacks'
        from gems/gems/activerecord-2.3.8/lib/active_record/validations.rb:1110:in `valid_without_callbacks?'
        from gems/gems/activerecord-2.3.8/lib/active_record/callbacks.rb:315:in `valid?'
        from (irb):9

Original comment by A.Steinel@gmail.com on 17 Jun 2010 at 1:46

GoogleCodeExporter commented 9 years ago
Maybe not limited to validate_uniqueness_of.

Here I tried to store a valid entry twice and got the same error message (but 
different calling function)

ArgumentError: one hash required
        from gems/gems/gettext-2.1.0/lib/gettext/core_ext/string.rb:78:in `%'
        from gems/gems/activeldap-1.2.2/lib/active_ldap/validations.rb:102:in `validate_duplicated_dn_creation'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:178:in `send'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:178:in `evaluate_method'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:166:in `call'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `run'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `each'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `send'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in `run'
        from gems/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:276:in `run_validations_without_active_ldap_support'
        from gems/gems/activeldap-1.2.2/lib/active_ldap/validations.rb:65:in `run_callbacks'
        from gems/gems/activerecord-2.3.8/lib/active_record/validations.rb:1114:in `valid_without_callbacks?'
        from gems/gems/activerecord-2.3.8/lib/active_record/callbacks.rb:315:in `valid?'
        from gems/gems/activerecord-2.3.8/lib/active_record/validations.rb:1089:in `save'
        from (irb):15

Original comment by A.Steinel@gmail.com on 17 Jun 2010 at 1:59

GoogleCodeExporter commented 9 years ago
"ArgumentError: one hash required" has been fixed in trunk.

"NoMethodError: undefined method `columns_hash' for #<Class:0x7fa260bcf2c8>" 
isn't fixed yet.

Original comment by kou...@gmail.com on 21 Jun 2010 at 8:49