Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace the transaction {|transaction|..} semantics with a new Except…

…ion ActiveRecord::Rollback. Closes #8030  [Koz]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6754 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit ebbe4fb0d41feb45628715cd045d89e7bb8ab117 1 parent 1ac7cd5
@NZKoz NZKoz authored
View
2  activerecord/CHANGELOG
@@ -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
2  activerecord/lib/active_record/base.rb
@@ -34,6 +34,8 @@ class ConfigurationError < StandardError #:nodoc:
end
class ReadOnlyRecord < StandardError #:nodoc:
end
+ class Rollback < StandardError #:nodoc:
+ end
class AttributeAssignmentError < ActiveRecordError #:nodoc:
attr_reader :exception, :attribute
View
11 activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -56,14 +56,14 @@ def transaction(start_db_transaction = true)
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 @@ def commit_db_transaction() end
# 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
4 activerecord/test/transactions_test.rb
@@ -149,13 +149,13 @@ def test_nested_explicit_transactions
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"
Please sign in to comment.
Something went wrong with that request. Please try again.