aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorHemant Kumar <gethemant@gmail.com>2012-05-09 17:32:15 +0530
committerHemant Kumar <gethemant@gmail.com>2012-05-09 17:32:15 +0530
commit44d1804b0a86de02865c48c552bbc57da3dc7836 (patch)
tree4f9fefc3d5254e6deae380d1f19d8c31b534b0b2 /activerecord
parentbeea9f5d4eb96a6d13863a403ce100ae9710259a (diff)
downloadrails-44d1804b0a86de02865c48c552bbc57da3dc7836.tar.gz
rails-44d1804b0a86de02865c48c552bbc57da3dc7836.tar.bz2
rails-44d1804b0a86de02865c48c552bbc57da3dc7836.zip
Fix transaction state not changing when after record gets commited
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/transactions.rb8
-rw-r--r--activerecord/test/cases/transaction_callbacks_test.rb25
2 files changed, 27 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..9246157a13 100644
--- a/activerecord/test/cases/transaction_callbacks_test.rb
+++ b/activerecord/test/cases/transaction_callbacks_test.rb
@@ -290,3 +290,28 @@ 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
+ attr_accessor :cached
+
+ 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
+ end
+end