Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get rid of global variable in AR transactions test

  • Loading branch information...
commit a507c641ec78ab8781b18c42a75ccad75362af8e 1 parent ed05e92
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 7 additions and 7 deletions.
  1. +7 −7 activerecord/test/cases/transactions_test.rb
View
14 activerecord/test/cases/transactions_test.rb
@@ -36,24 +36,24 @@ def transaction_with_return
end
end
- # FIXME: Get rid of this fucking global variable!
def test_successful_with_return
- class << Topic.connection
+ committed = false
+
+ Topic.connection.class_eval do
alias :real_commit_db_transaction :commit_db_transaction
- def commit_db_transaction
- $committed = true
+ define_method(:commit_db_transaction) do
+ committed = true
real_commit_db_transaction
end
end
- $committed = false
transaction_with_return
- assert $committed
+ assert committed
assert Topic.find(1).approved?, "First should have been approved"
assert !Topic.find(2).approved?, "Second should have been unapproved"
ensure
- class << Topic.connection
+ Topic.connection.class_eval do
remove_method :commit_db_transaction
alias :commit_db_transaction :real_commit_db_transaction rescue nil
end

1 comment on commit a507c64

Please sign in to comment.
Something went wrong with that request. Please try again.