提交 e09df779 编写于 作者: E Eugene Kenny

Merge pull request #38990 from eugeneius/transaction_callbacks_object_id

Use __id__ to dedup records for transactional callbacks
上级 1077089e
......@@ -98,7 +98,7 @@ def materialized?
end
def rollback_records
ite = records.uniq(&:object_id)
ite = records.uniq(&:__id__)
already_run_callbacks = {}
while record = ite.shift
trigger_callbacks = record.trigger_transactional_callbacks?
......@@ -117,7 +117,7 @@ def before_commit_records
end
def commit_records
ite = records.uniq(&:object_id)
ite = records.uniq(&:__id__)
already_run_callbacks = {}
while record = ite.shift
if @run_commit_callbacks
......
......@@ -502,6 +502,43 @@ def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_sh
assert flag
end
def test_saving_two_records_that_override_object_id_should_run_after_commit_callbacks_for_both
klass = Class.new(TopicWithCallbacks) do
define_method(:object_id) { 42 }
end
records = [klass.new, klass.new]
klass.transaction do
records.each do |record|
record.after_commit_block { |r| r.history << :after_commit }
record.save!
end
end
assert_equal [:after_commit], records.first.history
assert_equal [:after_commit], records.second.history
end
def test_saving_two_records_that_override_object_id_should_run_after_rollback_callbacks_for_both
klass = Class.new(TopicWithCallbacks) do
define_method(:object_id) { 42 }
end
records = [klass.new, klass.new]
klass.transaction do
records.each do |record|
record.after_rollback_block { |r| r.history << :after_rollback }
record.save!
end
raise ActiveRecord::Rollback
end
assert_equal [:after_rollback], records.first.history
assert_equal [:after_rollback], records.second.history
end
private
def add_transaction_execution_blocks(record)
record.after_commit_block(:create) { |r| r.history << :commit_on_create }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册