diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2014-06-23 16:09:40 +0300 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2014-06-23 16:11:06 +0300 |
commit | 0fa4c95d914d9f04553642f5181ee7c2cf4c6add (patch) | |
tree | 71a6c96eadab070dee60724fc289b0e883f23bca /activerecord/test | |
parent | 8a6b8c8a7991796ae961db2be0b0f683a1c1efc6 (diff) | |
download | rails-0fa4c95d914d9f04553642f5181ee7c2cf4c6add.tar.gz rails-0fa4c95d914d9f04553642f5181ee7c2cf4c6add.tar.bz2 rails-0fa4c95d914d9f04553642f5181ee7c2cf4c6add.zip |
Add AR::Base#validate! method
Acts same as valid? but raises AR::RecordInvalid exception
if validation fails
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/validations_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index a6e1dc72e5..55804f9576 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -78,6 +78,20 @@ class ValidationsTest < ActiveRecord::TestCase assert_equal r, invalid.record end + def test_validate_with_bang + assert_raise(ActiveRecord::RecordInvalid) do + WrongReply.new.validate! + end + end + + def test_validate_with_bang_and_context + assert_raise(ActiveRecord::RecordInvalid) do + WrongReply.new.validate!(:special_case) + end + r = WrongReply.new(:title => "Valid title", :author_name => "secret", :content => "Good") + assert r.validate!(:special_case) + end + def test_exception_on_create_bang_many assert_raise(ActiveRecord::RecordInvalid) do WrongReply.create!([ { "title" => "OK" }, { "title" => "Wrong Create" }]) |