diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-03 18:54:16 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-03 18:54:16 +0000 |
commit | 44d1420757e4a9ce564cc1f2606069b4d96b6470 (patch) | |
tree | 2ece0deceeeb10e728c4fee90e6d43d5ebde7498 /activerecord/test | |
parent | e024f2f1bff35fb4d0630684f6985c8e7da79ce2 (diff) | |
download | rails-44d1420757e4a9ce564cc1f2606069b4d96b6470.tar.gz rails-44d1420757e4a9ce564cc1f2606069b4d96b6470.tar.bz2 rails-44d1420757e4a9ce564cc1f2606069b4d96b6470.zip |
Add Model.create! to match existing model.save! method. When save! raises RecordInvalid, you can catch the exception, retrieve the invalid record (invalid_exception.record), and see its errors (invalid_exception.record.errors).
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2863 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/validations_test.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index be5d1fab70..f0d75c96cf 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -76,8 +76,16 @@ class ValidationsTest < Test::Unit::TestCase end def test_invalid_record_exception - r = Reply.new - assert_raises(ActiveRecord::RecordInvalid) { r.save! } + assert_raises(ActiveRecord::RecordInvalid) { Reply.create! } + assert_raises(ActiveRecord::RecordInvalid) { Reply.new.save! } + + begin + r = Reply.new + r.save! + flunk + rescue ActiveRecord::RecordInvalid => invalid + assert_equal r, invalid.record + end end def test_single_error_per_attr_iteration |