Forum: Ruby on Rails Weird Test::Unit / validates_format_of problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
38349301fc317d7ec7ddd7959d73778f?d=identicon&s=25 Tobias Neumann (Guest)
on 2006-02-16 16:07
(Received via mailing list)
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:in `test_name_length'

Thanks, Tobias
38349301fc317d7ec7ddd7959d73778f?d=identicon&s=25 Tobias Neumann (Guest)
on 2006-02-16 17:35
(Received via mailing list)
Ok problem solved.. I had a lock_version column with nil/null as its
default value and not zero.
This topic is locked and can not be replied to.