1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #6226 from gnufied/master

Update tranasaction state when record gets commited
This commit is contained in:
Aaron Patterson 2012-05-09 14:42:48 -07:00
commit 9bf1a0db4a
2 changed files with 33 additions and 6 deletions

View file

@ -302,12 +302,8 @@ module ActiveRecord
def remember_transaction_record_state #:nodoc:
@_start_transaction_state ||= {}
@_start_transaction_state[:id] = id if has_attribute?(self.class.primary_key)
unless @_start_transaction_state.include?(:new_record)
@_start_transaction_state[:new_record] = @new_record
end
unless @_start_transaction_state.include?(:destroyed)
@_start_transaction_state[:destroyed] = @destroyed
end
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1
end

View file

@ -290,3 +290,34 @@ class TransactionObserverCallbacksTest < ActiveRecord::TestCase
assert_equal %w{ after_rollback }, topic.history
end
end
class SaveFromAfterCommitBlockTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
class TopicWithSaveInCallback < ActiveRecord::Base
self.table_name = :topics
after_commit :cache_topic, :on => :create
after_commit :call_update, :on => :update
attr_accessor :cached, :record_updated
def call_update
self.record_updated = true
end
def cache_topic
unless cached
self.cached = true
self.save
else
self.cached = false
end
end
end
def test_after_commit_in_save
topic = TopicWithSaveInCallback.new()
topic.save
assert_equal true, topic.cached
assert_equal true, topic.record_updated
end
end