From 049a10d4051a48136199fcdfd77bf35df9e9ad11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
 <rafaelmfranca@gmail.com>
Date: Wed, 29 Jan 2014 21:07:46 -0200
Subject: Alias the original method first to avoid warnings

---
 activesupport/lib/active_support/testing/time_helpers.rb | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'activesupport')

diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb
index 0e48456715..cd56ae1883 100644
--- a/activesupport/lib/active_support/testing/time_helpers.rb
+++ b/activesupport/lib/active_support/testing/time_helpers.rb
@@ -14,8 +14,11 @@ module ActiveSupport
           unstub_object(stub)
         end
 
-        @stubs[key] = Stub.new(object, method_name, object.method(method_name))
+        new_name = "__simple_stub__#{method_name}"
 
+        @stubs[key] = Stub.new(object, method_name, new_name)
+
+        object.singleton_class.send :alias_method, new_name, method_name
         object.define_singleton_method(method_name) { return_value }
       end
 
@@ -27,7 +30,9 @@ module ActiveSupport
       end
 
       def unstub_object(stub)
-        stub.object.define_singleton_method(stub.method_name, stub.original_method)
+        stub.object.singleton_class.send :undef_method, stub.method_name
+        stub.object.singleton_class.send :alias_method, stub.method_name, stub.original_method
+        stub.object.singleton_class.send :undef_method, stub.original_method
       end
     end
 
-- 
cgit v1.2.3