Forum: Ruby on Rails assert_valid in unit tests after upgrade to rails 2.3 doesn't work

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
13de37c0466c10344a11a7e1f7a64c63?d=identicon&s=25 Constantin Gavrilescu (Guest)
on 2009-04-07 08:35
(Received via mailing list)
def test_valid
    assert_valid State.first

NoMethodError: undefined method `assert_valid' for #<StateTest:

I see that test_valid is now in
ActionController::Assertions::ModelAssertions. Does this mean that
test_valid is designed to be used i ActionController tests only?

I can change my assert_valid(State.first) into assert
(State.first.valid?) but assert_valid prints meaninful failure
messages, unlike assert which just tells me "nil is not true". How can
I use assert_valid in my unit tests? My test classes declared
something like this: class StateTest < ActiveSupport::TestCase
A310b2c20365cfb3625400b372eb671c?d=identicon&s=25 Mohamed Aslam (Guest)
on 2009-04-14 14:53
(Received via mailing list)
Having the same problem here. But still didn't find any solution.

On Apr 7, 11:34 am, Constantin Gavrilescu
Db7238007950074e9e73b76a81910406?d=identicon&s=25 Tonypm (Guest)
on 2009-05-29 15:53
(Received via mailing list)

just upgrading to 2.3.2 and getting same, did you resolve this at all?

Db7238007950074e9e73b76a81910406?d=identicon&s=25 Tonypm (Guest)
on 2009-05-29 16:41
(Received via mailing list)
Ok, so

Rails Guide
para 3.5 says it exists - I guess the guide needs amending?

It was deprecated at 2.2.2
 - "assert_valid is deprecated. Use assert record.valid? instead"

I didnt want to go change all my tests just at the moment, so putting
assert_valid in my test_helper gets me over that for the moment.  Bit
of a time waster, since I was going from 2.0.2 to 2.3 so had not seen
the dep error.

def assert_valid(record)
  assert record.valid?, record.errors.full_messages.join("\n")

This topic is locked and can not be replied to.