Rails 2.1 and validates_length_of

Hi,

I’m getting some weirdness when using validates_length_of and Rails
2.1

class User < ActiveRecord::Base
include Authentication
include Authentication::ByPassword
include Authentication::ByCookieToken

validates_presence_of :login
validates_length_of :login, :within => 3…40
validates_uniqueness_of :login, :case_sensitive => false
validates_format_of :login, :with => RE_LOGIN_OK, :message
=> MSG_LOGIN_BAD

validates_format_of :first_name, :last_name, :with =>
RE_NAME_OK, :message => MSG_NAME_BAD, :allow_nil => true
validates_length_of :first_name, :maximum => 50, :allow_nil
=> true
validates_length_of :last_name, :maximum => 50

validates_presence_of :email
validates_length_of :email, :within => 6…100 #removed_email_address@domain.invalid
validates_uniqueness_of :email, :case_sensitive => false
validates_format_of :email, :with => RE_EMAIL_OK, :message
=> MSG_EMAIL_BAD

belongs_to :company
validates_existence_of :company

Pretty straightforward so far.

I jump into script/console, and things get weird.

record = User.new({ :login => ‘quire’, :email => ‘[email protected]’, :password => ‘quire69’, :password_confirmation => ‘quire69’ })
=> #<User id: nil, login: “quire”, first_name: nil, last_name: nil,
email: “[email protected]”, crypted_password: nil, salt: nil,
created_at: nil, updated_at: nil, remember_token: nil,
remember_token_expires_at: nil, company_id: nil>

record.valid?
=> false

record.errors.full_messages
=> [“Company does not exist”, “First name is too long (maximum is 50
characters)”, “Last name is too long (maximum is 50 characters)”]

record.first_name
=> nil

By my reading of the documentation and the source, the :maximum
and :minimum methods shouldn’t flag, especially with :allow_nil set to
true on the first_name field.

This just seems to basic to miss, so I want to make sure I’m not
completely crazy before submitting a bug.

(OS X, Ruby 1.8.6 p110, Rails 2.1)

Thanks,

Andrew