diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-09 14:42:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-09 14:42:48 -0700 |
commit | 9bf1a0db4acbbf9e8e6f707250269185224e7efe (patch) | |
tree | 928a985988d9b2271161946371a7a8aad7ea8489 | |
parent | fed97091b9546d369a240d10b184793d49247dd3 (diff) | |
parent | 041b6c6ccb2130ee8c87db2dd53736c22a79f3e8 (diff) | |
download | rails-9bf1a0db4acbbf9e8e6f707250269185224e7efe.tar.gz rails-9bf1a0db4acbbf9e8e6f707250269185224e7efe.tar.bz2 rails-9bf1a0db4acbbf9e8e6f707250269185224e7efe.zip |
Merge pull request #6226 from gnufied/master
Update tranasaction state when record gets commited
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/transaction_callbacks_test.rb | 31 |
2 files changed, 33 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 743dfc5a38..64e5640791 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -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[:new_record] = @new_record + @_start_transaction_state[:destroyed] = @destroyed @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1 end diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index f8b3e01a49..9846f5b12d 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -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 |