From a507c641ec78ab8781b18c42a75ccad75362af8e Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 20 Sep 2012 23:14:34 -0300 Subject: Get rid of global variable in AR transactions test --- activerecord/test/cases/transactions_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index 0b5fda3817..bb4f2c8064 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -36,24 +36,24 @@ class TransactionTest < ActiveRecord::TestCase 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 -- cgit v1.2.3