Permalink
Browse files

Deprecate assert_valid

  • Loading branch information...
1 parent 759183c commit d4754677a34d34d4a0955a04f2cc6571bdc5e82d @josh josh committed Nov 25, 2008
@@ -11,6 +11,7 @@ module ModelAssertions
# assert_valid(model)
#
def assert_valid(record)
+ ::ActiveSupport::Deprecation.warn("assert_valid is deprecated. Use assert record.valid? instead", caller)
clean_backtrace do
assert record.valid?, record.errors.full_messages.join("\n")
end
@@ -461,14 +461,14 @@ def test_redirected_to_with_nested_controller
def test_assert_valid
get :get_valid_record
- assert_valid assigns('record')
+ assert_deprecated { assert_valid assigns('record') }
end
def test_assert_valid_failing
get :get_invalid_record
begin
- assert_valid assigns('record')
+ assert_deprecated { assert_valid assigns('record') }
assert false
rescue ActiveSupport::TestCase::Assertion => e
end

6 comments on commit d475467

Contributor

yyyc514 replied Nov 26, 2008

Why is assert_valid being depreciated? I find it’s listing of validation errors to be very useful in testing.

assert @model.valid? is just going to show generically that true is not false, yes? Or am I missing something?

Contributor

stephencelis replied Nov 26, 2008

yyyc514: assert takes another argument that is called for inspection when it fails. Something like this should work:

assert @model.valid?, @model.errors
Member

josh replied Nov 26, 2008

It was supposed to be removed a while back, but we forgot about it.

Contributor

yyyc514 replied Nov 27, 2008

Ah, I knew assert took another argument but I never though of using it in such a fashion… rather obvious in hindsight. :-) And easy enough to code one’s own assert_valid to do just that I suppose.

Contributor

dgm replied Jun 22, 2012

using assert @model.valid?, @model.errors doesn't print anything useful, as it just prints: #ActiveModel::Errors:0x007fedc685ea60

I still can't see why this was depreciated and removed.

Contributor

calebthompson replied Aug 21, 2012

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

Is probably a little more useful, and can be put into your test/test_helper.rb file.

I'm a little unclear on why this was removed as well, as it seems like it is a pretty useful feature.

Please sign in to comment.