small medium large xlarge

Generic-user-small
20 Mar 2009, 16:24
SC (15 posts)

Has this been deprecated? I’m trying to write some tests

eg.

category = Category.new(:name => “Some category”) assert_valid?(category)

And rake test:units keep returning NoMethodError: undefined method etc

I looked up the source and it said that it was depcreated and to use assert record.valid? instead? Anyone confirm this?

Cheers Simon

Samr_small_pragsmall
20 Mar 2009, 20:29
Sam Ruby (634 posts)

Try “assert_valid”:http://api.rubyonrails.org/classes/ActionController/Assertions/ModelAssertions.html , i.e., without the trailing question mark.

Brent_pragsmall
13 May 2011, 15:30
Brent Nordquist (4 posts)

It seems @assert_valid object@ is deprecated now, in favor of @assert object.valid?@

But this page http://tinyurl.com/assert-valid had a good idea: Implement @assert_valid()@ as a test helper, which dumps the error(s) out so you can easily see why it didn’t validate:

def assert_valid(record) 
  assert record.valid?, record.errors.full_messages.join("\n") 
end
You must be logged in to comment