1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

savepoint_name should return nil for non-savepoint transactions

Also add test to assets the savepoint name
This commit is contained in:
Arthur Neves 2014-07-28 13:25:19 -04:00
parent 97bb76dc28
commit d37bcc1d5a
No known key found for this signature in database
GPG key ID: 04A390FB1E433E17
3 changed files with 27 additions and 4 deletions

View file

@ -69,6 +69,10 @@ module ActiveRecord
def state
@state
end
def savepoint_name
nil
end
end
class TransactionState
@ -233,7 +237,8 @@ module ActiveRecord
super
@savepoint_name = "active_record_#{number}"
# Savepoint name only counts the Savepoint transactions, so we need to subtract 1
@savepoint_name = "active_record_#{number - 1}"
connection.create_savepoint(@savepoint_name)
end

View file

@ -358,9 +358,7 @@ module ActiveRecord
end
def current_savepoint_name
if current_transaction.is_a? SavepointTransaction
current_transaction.savepoint_name
end
current_transaction.savepoint_name
end
# Check the connection back in to the connection pool

View file

@ -424,6 +424,26 @@ class TransactionTest < ActiveRecord::TestCase
end
end
def test_savepoints_name
Topic.transaction do
assert_nil Topic.connection.current_savepoint_name
assert_nil Topic.connection.current_transaction.savepoint_name
Topic.transaction(requires_new: true) do
assert_equal "active_record_1", Topic.connection.current_savepoint_name
assert_equal "active_record_1", Topic.connection.current_transaction.savepoint_name
Topic.transaction(requires_new: true) do
assert_equal "active_record_2", Topic.connection.current_savepoint_name
assert_equal "active_record_2", Topic.connection.current_transaction.savepoint_name
end
assert_equal "active_record_1", Topic.connection.current_savepoint_name
assert_equal "active_record_1", Topic.connection.current_transaction.savepoint_name
end
end
end
def test_rollback_when_commit_raises
Topic.connection.expects(:begin_db_transaction)
Topic.connection.expects(:commit_db_transaction).raises('OH NOES')