diff options
author | Dave Yeu <daveyeu@gmail.com> | 2012-04-29 22:38:32 -0400 |
---|---|---|
committer | Dave Yeu <daveyeu@gmail.com> | 2012-08-11 21:54:00 -0400 |
commit | a4801a792a1e47d7f156c6646f662232c46eefa2 (patch) | |
tree | 2b8a504e0c4ce822a3432f56b318113a1e7599aa /activerecord/test | |
parent | a513cc1862cc61fd9605352a58c5e36cc40cb574 (diff) | |
download | rails-a4801a792a1e47d7f156c6646f662232c46eefa2.tar.gz rails-a4801a792a1e47d7f156c6646f662232c46eefa2.tar.bz2 rails-a4801a792a1e47d7f156c6646f662232c46eefa2.zip |
Restore state on create when ActiveRecord::RecordInvalid is raised
This fixes issue #3217.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/transactions_test.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index a9ccd00fac..d5597a68ad 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -204,6 +204,23 @@ class TransactionTest < ActiveRecord::TestCase end end + def test_callback_rollback_in_create_with_record_invalid_exception + begin + Topic.class_eval <<-eoruby, __FILE__, __LINE__ + 1 + remove_method(:after_create_for_transaction) + def after_create_for_transaction + raise ActiveRecord::RecordInvalid.new(Author.new) + end + eoruby + + new_topic = Topic.create(:title => "A new topic") + assert !new_topic.persisted?, "The topic should not be persisted" + assert_nil new_topic.id, "The topic should not have an ID" + ensure + remove_exception_raising_after_create_callback_to_topic + end + end + def test_nested_explicit_transactions Topic.transaction do Topic.transaction do |