Skip to content

Commit

Permalink
Fix transaction state not changing when after record gets commited
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed May 9, 2012
1 parent beea9f5 commit 44d1804
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
8 changes: 2 additions & 6 deletions activerecord/lib/active_record/transactions.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -302,12 +302,8 @@ def with_transaction_returning_status
def remember_transaction_record_state #:nodoc: def remember_transaction_record_state #:nodoc:
@_start_transaction_state ||= {} @_start_transaction_state ||= {}
@_start_transaction_state[:id] = id if has_attribute?(self.class.primary_key) @_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
@_start_transaction_state[:new_record] = @new_record @_start_transaction_state[:destroyed] = @destroyed
end
unless @_start_transaction_state.include?(:destroyed)
@_start_transaction_state[:destroyed] = @destroyed
end
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1 @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1
end end


Expand Down
25 changes: 25 additions & 0 deletions activerecord/test/cases/transaction_callbacks_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -290,3 +290,28 @@ def test_after_rollback_called
assert_equal %w{ after_rollback }, topic.history assert_equal %w{ after_rollback }, topic.history
end end
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

0 comments on commit 44d1804

Please sign in to comment.