diff options
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 884b44030c..73ab371da5 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -129,6 +129,10 @@ module BarMethods def quux_with_baz=(v) send(:quux_without_baz=, v) << '_with_baz' end + + def duck_with_orange + duck_without_orange << '_with_orange' + end end class MethodAliasingTest < Test::Unit::TestCase @@ -226,4 +230,45 @@ class MethodAliasingTest < Test::Unit::TestCase end assert block_called end + + def test_alias_method_chain_preserves_private_method_status + FooClassWithBarMethod.send(:define_method, 'duck', Proc.new { 'duck' }) + FooClassWithBarMethod.send(:include, BarMethodAliaser) + FooClassWithBarMethod.send(:private, :duck) + + FooClassWithBarMethod.alias_method_chain :duck, :orange + + assert_raises NoMethodError do + @instance.duck + end + + assert_equal 'duck_with_orange', @instance.send(:duck) + assert FooClassWithBarMethod.private_method_defined?(:duck) + end + + def test_alias_method_chain_preserves_protected_method_status + FooClassWithBarMethod.send(:define_method, 'duck', Proc.new { 'duck' }) + FooClassWithBarMethod.send(:include, BarMethodAliaser) + FooClassWithBarMethod.send(:protected, :duck) + + FooClassWithBarMethod.alias_method_chain :duck, :orange + + assert_raises NoMethodError do + @instance.duck + end + + assert_equal 'duck_with_orange', @instance.send(:duck) + assert FooClassWithBarMethod.protected_method_defined?(:duck) + end + + def test_alias_method_chain_preserves_public_method_status + FooClassWithBarMethod.send(:define_method, 'duck', Proc.new { 'duck' }) + FooClassWithBarMethod.send(:include, BarMethodAliaser) + FooClassWithBarMethod.send(:public, :duck) + + FooClassWithBarMethod.alias_method_chain :duck, :orange + + assert_equal 'duck_with_orange', @instance.duck + assert FooClassWithBarMethod.public_method_defined?(:duck) + end end |