From 0355962c277e8fe696f5568037b5804d014cb1fe Mon Sep 17 00:00:00 2001 From: wangjohn Date: Sun, 20 Jan 2013 12:40:36 -0500 Subject: Created state for a transaction and added tests. --- .../connection_adapters/abstract/transaction.rb | 12 +++++++++++ activerecord/lib/active_record/core.rb | 24 ++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb index 4cca94e40b..2b8026dbf9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb @@ -5,7 +5,17 @@ module ActiveRecord def initialize(connection) @connection = connection + @state = nil end + + def committed? + @state == :commit + end + + def rolledback? + @state == :rollback + end + end class ClosedTransaction < Transaction #:nodoc: @@ -91,6 +101,7 @@ module ActiveRecord end def rollback_records + @state = :rollback records.uniq.each do |record| begin record.rolledback!(parent.closed?) @@ -101,6 +112,7 @@ module ActiveRecord end def commit_records + @state = :commit records.uniq.each do |record| begin record.committed! diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 94c6684700..8a54cebfcf 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -365,17 +365,19 @@ module ActiveRecord pk = self.class.primary_key @attributes[pk] = nil unless @attributes.key?(pk) - @aggregation_cache = {} - @association_cache = {} - @attributes_cache = {} - @previously_changed = {} - @changed_attributes = {} - @readonly = false - @destroyed = false - @marked_for_destruction = false - @new_record = true - @txn = nil - @_start_transaction_state = {} + @aggregation_cache = {} + @association_cache = {} + @attributes_cache = {} + @previously_changed = {} + @changed_attributes = {} + @readonly = false + @destroyed = false + @marked_for_destruction = false + @new_record = true + @txn = nil + @_start_transaction_state = {} + @transaction = nil + @reflects_transaction_state = false end end end -- cgit v1.2.3