From 5dc72378b783e924c5bf079ca660388ec4ac9224 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 5 Jun 2018 00:27:43 +0900 Subject: Fix `collection.create` to could be rolled back by `after_save` In `_create_record`, explicit `transaction` block requires rollback handling manually when `insert_record` is failed. We need to handle it in `_create_record`, not in `insert_record`, since our test cases expect a record added to target and returned even if `insert_record` is failed, Closes #31488. --- activerecord/test/models/company.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 6219f57fa1..d4d5275b78 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -150,6 +150,16 @@ class Client < Company throw :abort if throw_on_save end + attr_accessor :rollback_on_save + after_save do + raise ActiveRecord::Rollback if rollback_on_save + end + + attr_accessor :rollback_on_create_called + after_rollback(on: :create) do |client| + client.rollback_on_create_called = true + end + class RaisedOnDestroy < RuntimeError; end attr_accessor :raise_on_destroy before_destroy do -- cgit v1.2.3