Constantin Gavrilescu
2009-Apr-07 06:34 UTC
assert_valid in unit tests after upgrade to rails 2.3 doesn''t work
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Mohamed Aslam
2009-Apr-14 12:17 UTC
Re: assert_valid in unit tests after upgrade to rails 2.3 doesn''t work
Having the same problem here. But still didn''t find any solution. On Apr 7, 11:34 am, Constantin Gavrilescu <comisarulmoldo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tonypm
2009-May-29 13:52 UTC
Re: assert_valid in unit tests after upgrade to rails 2.3 doesn''t work
hi, just upgrading to 2.3.2 and getting same, did you resolve this at all? Tonypm
Tonypm
2009-May-29 14:40 UTC
Re: assert_valid in unit tests after upgrade to rails 2.3 doesn''t work
Ok, so
Rails Guide 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
http://github.com/rails/rails/commit/d4754677a34d34d4a0955a04f2cc6571bdc5e82d
and
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