aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-01-20 11:04:22 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2013-01-20 11:04:22 -0800
commita1c0e51a2c99ec88fba59824b59f32f0d34a0aae (patch)
treed6d4cfd43d691f13f1e8eaf1f55f835f15e4a594 /activerecord/lib/active_record
parent5503796096eb0edbe1ed554a6c8d3fdc98314231 (diff)
parentbbcebb6ab276c71be88c3ae0548bb7bf4e18630d (diff)
downloadrails-a1c0e51a2c99ec88fba59824b59f32f0d34a0aae.tar.gz
rails-a1c0e51a2c99ec88fba59824b59f32f0d34a0aae.tar.bz2
rails-a1c0e51a2c99ec88fba59824b59f32f0d34a0aae.zip
Merge pull request #9006 from wangjohn/activerecord_transaction_state
Created state for a transaction and added tests.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/transaction.rb12
-rw-r--r--activerecord/lib/active_record/core.rb23
2 files changed, 24 insertions, 11 deletions
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..812f1ce5c5 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -365,17 +365,18 @@ 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
end
end
end