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

Replace the transaction {|transaction|..} semantics with a new Exception ActiveRecord::Rollback. Closes #8030 [Koz]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6754 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Michael Koziarski 2007-05-18 01:02:08 +00:00
parent 1ac7cd56fe
commit ebbe4fb0d4
4 changed files with 9 additions and 10 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Replace the transaction {|transaction|..} semantics with a new Exception ActiveRecord::Rollback. [Koz]
* Oracle: extract column length for CHAR also. #7866 [ymendel]
* Document :allow_nil option for validates_acceptance_of since it defaults to true. [tzaharia]

View file

@ -34,6 +34,8 @@ module ActiveRecord #:nodoc:
end
class ReadOnlyRecord < StandardError #:nodoc:
end
class Rollback < StandardError #:nodoc:
end
class AttributeAssignmentError < ActiveRecordError #:nodoc:
attr_reader :exception, :attribute

View file

@ -56,14 +56,14 @@ module ActiveRecord
begin_db_transaction
transaction_open = true
end
yield self
end
yield
end
rescue Exception => database_transaction_rollback
if transaction_open
transaction_open = false
rollback_db_transaction
end
raise
raise unless database_transaction_rollback.is_a? ActiveRecord::Rollback
end
ensure
commit_db_transaction if transaction_open
@ -79,11 +79,6 @@ module ActiveRecord
# done if the transaction block raises an exception or returns false.
def rollback_db_transaction() end
# Alias for rollback_db_transaction to be used when yielding the transaction
def rollback!
rollback_db_transaction
end
# Alias for #add_limit_offset!.
def add_limit!(sql, options)
add_limit_offset!(sql, options) if options

View file

@ -149,13 +149,13 @@ class TransactionTest < Test::Unit::TestCase
end
def test_manually_rolling_back_a_transaction
Topic.transaction do |transaction|
Topic.transaction do
@first.approved = true
@second.approved = false
@first.save
@second.save
transaction.rollback!
raise ActiveRecord::Rollback
end
assert @first.approved?, "First should still be changed in the objects"