aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-03-18 03:16:53 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-03-18 03:16:53 +0000
commit46f092097bf2e6e827a1a3c9485e326cafc0beb6 (patch)
tree715c4492eaa8465a3eaebe83694d4858973bc053 /activesupport/test/core_ext
parenta38f28fff1e9e3faeeb22ac9b7c6b3cdcb7e2b29 (diff)
downloadrails-46f092097bf2e6e827a1a3c9485e326cafc0beb6.tar.gz
rails-46f092097bf2e6e827a1a3c9485e326cafc0beb6.tar.bz2
rails-46f092097bf2e6e827a1a3c9485e326cafc0beb6.zip
alias_method_chain preserves the original method's visibility. Closes #7854.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6441 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/module_test.rb45
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