diff options
author | José Valim <jose.valim@gmail.com> | 2010-03-19 12:01:48 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-03-19 12:01:48 +0100 |
commit | fbe35656a95228f760a2cd09676423ba41fe70ab (patch) | |
tree | c250acd14fa2fead65ba64a7d2b7cfab84dda782 | |
parent | b395c81e3c56f03a1a49f470883507eb70bb5cb3 (diff) | |
download | rails-fbe35656a95228f760a2cd09676423ba41fe70ab.tar.gz rails-fbe35656a95228f760a2cd09676423ba41fe70ab.tar.bz2 rails-fbe35656a95228f760a2cd09676423ba41fe70ab.zip |
Singleton classes returns parent's methods with instance_methods(false) and this makes remove_method in Module#delegate fail. Add a test case and fix the bug.
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index d78cecc390..db6aea9b87 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/module/remove_method" + class Module # Provides a delegate class method to easily expose contained objects' methods # as your own. Pass one or more methods (specified as symbols or strings) @@ -121,7 +123,7 @@ class Module module_eval(<<-EOS, file, line) if instance_methods(false).map(&:to_s).include?("#{prefix}#{method}") - remove_method("#{prefix}#{method}") + remove_possible_method("#{prefix}#{method}") end def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block) diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 9edd7cc7c0..1712b0649b 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -141,6 +141,20 @@ class ModuleTest < Test::Unit::TestCase assert_equal 0.0, nil_project.to_f end + def test_delegation_does_not_raise_error_when_removing_singleton_instance_methods + parent = Class.new do + def self.parent_method; end + end + + assert_nothing_raised do + child = Class.new(parent) do + class << self + delegate :parent_method, :to => :superclass + end + end + end + end + def test_parent assert_equal Yz::Zy, Yz::Zy::Cd.parent assert_equal Yz, Yz::Zy.parent |