Weird Test::Unit / validates_format_of problem

Hi

I have a test that checks the length of a username

def test_name_length
	users(:bob).name = "mo"
	assert !users(:bob).save
	assert_equal 1, users(:bob).errors.count
end

The format of the username is validated this way:
validates_format_of :name, :with => /^[[:alnum:]_-]{3,30}$/i

This test works… but when I use a name longer than 2 (the minimum
chars in the regex - 1) characters, a NoMethodError is raised:

  1. Error:
    test_name_length(UserTest):
    NoMethodError: You have a nil object when you didn’t expect it!
    You might have expected an instance of Array.
    The error occured while evaluating nil.+

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/locking.rb:33:in
`update_without_callbacks’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/callbacks.rb:274:in
`update_without_timestamps’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/timestamp.rb:39:in
`update’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1431:in
`create_or_update_without_callbacks’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/callbacks.rb:249:in
`create_or_update’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1226:in
`save_without_validation’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/validations.rb:698:in
`save_without_transactions’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:126:in
`save’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/database_statements.rb:51:in
`transaction’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:91:in
`transaction’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:118:in
`transaction’

/sw/var/lib/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:126:in
save' test/unit/user_test.rb:36:intest_name_length’

Thanks, Tobias

Ok problem solved… I had a lock_version column with nil/null as its
default value and not zero.