mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Created state for a transaction and added tests.
This commit is contained in:
parent
f48a16bdb2
commit
0355962c27
3 changed files with 45 additions and 11 deletions
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -451,6 +451,26 @@ class TransactionTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_transactions_state_from_rollback
|
||||
connection = Topic.connection
|
||||
transaction = ActiveRecord::ConnectionAdapters::ClosedTransaction.new(connection).begin
|
||||
|
||||
assert transaction.open?
|
||||
transaction.perform_rollback
|
||||
|
||||
assert transaction.rolledback?
|
||||
end
|
||||
|
||||
def test_transactions_state_from_commit
|
||||
connection = Topic.connection
|
||||
transaction = ActiveRecord::ConnectionAdapters::ClosedTransaction.new(connection).begin
|
||||
|
||||
assert transaction.open?
|
||||
transaction.perform_commit
|
||||
|
||||
assert transaction.committed?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
%w(validation save destroy).each do |filter|
|
||||
|
|
Loading…
Reference in a new issue