# Assert\_valid in unit tests after upgrade to rails 2.3 doesn't work

**URL:** <https://www.ruby-forum.com/t/assert-valid-in-unit-tests-after-upgrade-to-rails-2-3-doesnt-work/164901>\
**Category:** Rails\
**Created:** [April 7, 2009, 8:35am UTC](https://www.ruby-forum.com/t/assert-valid-in-unit-tests-after-upgrade-to-rails-2-3-doesnt-work/164901 "2009-04-07T08:35:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [April 7, 2009, 8:35am UTC](https://www.ruby-forum.com/t/assert-valid-in-unit-tests-after-upgrade-to-rails-2-3-doesnt-work/164901/1 "2009-04-07T08:35:52Z")

</div>

def test\_valid  
assert\_valid State.first  
end

Error:  
test\_valid(StateTest):  
NoMethodError: undefined method `assert\_valid’ for #\<StateTest:  
0x7f0d60750318\>

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

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [April 14, 2009, 2:53pm UTC](https://www.ruby-forum.com/t/assert-valid-in-unit-tests-after-upgrade-to-rails-2-3-doesnt-work/164901/2 "2009-04-14T14:53:20Z")

</div>

Having the same problem here. But still didn’t find any solution.

On Apr 7, 11:34 am, Constantin G.

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [May 29, 2009, 3:53pm UTC](https://www.ruby-forum.com/t/assert-valid-in-unit-tests-after-upgrade-to-rails-2-3-doesnt-work/164901/3 "2009-05-29T15:53:34Z")

</div>

hi,

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

Tonypm

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [May 29, 2009, 4:41pm UTC](https://www.ruby-forum.com/t/assert-valid-in-unit-tests-after-upgrade-to-rails-2-3-doesnt-work/164901/4 "2009-05-29T16:41:39Z")

</div>

Ok, so

Rails Guide [Testing Rails Applications — Ruby on Rails Guides](http://guides.rubyonrails.org/testing.html)  
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”  
see  
[Deprecate assert\_valid · rails/rails@d475467 · GitHub](http://github.com/rails/rails/commit/d4754677a34d34d4a0955a04f2cc6571bdc5e82d)  
and  
[#1470 assert\_valid undefined in edge ActiveSupport::TestCase - Ruby on Rails - rails](https://rails.lighthouseapp.com/projects/8994/tickets/1470-assert_valid-undefined-in-edge-activesupporttestcase)

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”)  
end

Tonypm
