From 2e70f44123cb6fab9124b52a6cc02ff453b8397f Mon Sep 17 00:00:00 2001 From: Henrik Nyh Date: Sun, 23 Mar 2014 12:09:55 +0100 Subject: ActiveRecord/ActiveModel '#validate' alias for 'valid?' It's unintuitive to call '#valid?' when you want to run validations but don't care about the return value. The alias in ActiveRecord isn't strictly necessary (the ActiveModel alias is still in effect), but it clarifies. --- activerecord/test/cases/validations_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index de618902aa..d80da06e27 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -52,6 +52,21 @@ class ValidationsTest < ActiveRecord::TestCase assert r.save(:context => :special_case) end + def test_validate + r = WrongReply.new + + r.validate + assert_empty r.errors[:author_name] + + r.validate(:special_case) + assert_not_empty r.errors[:author_name] + + r.author_name = "secret" + + r.validate(:special_case) + assert_empty r.errors[:author_name] + end + def test_invalid_record_exception assert_raise(ActiveRecord::RecordInvalid) { WrongReply.create! } assert_raise(ActiveRecord::RecordInvalid) { WrongReply.new.save! } -- cgit v1.2.3