diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-03 22:43:13 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-03 22:43:13 +0000 |
commit | e72ff355c35879ffaf262f4bd91ce7612f028a8e (patch) | |
tree | 6ad1f9f497c79297c3ac107cef56b5f11ef728fd /activesupport/test/core_ext | |
parent | b85c5356c905add4ba2f3d68e9a67ab5e3b247d2 (diff) | |
download | rails-e72ff355c35879ffaf262f4bd91ce7612f028a8e.tar.gz rails-e72ff355c35879ffaf262f4bd91ce7612f028a8e.tar.bz2 rails-e72ff355c35879ffaf262f4bd91ce7612f028a8e.zip |
Fixed that Module#alias_method_chain should work with both foo? foo! and foo at the same time (closes #4954) [anna@wota.jp]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4429 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index bd51aa11c3..66e4afc918 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -109,8 +109,12 @@ module BarMethodAliaser bar_without_baz << '_with_baz' end - def quux_with_baz - quux_without_baz << '_with_baz' + def quux_with_baz! + quux_without_baz! << '_with_baz!' + end + + def quux_with_baz? + false end end @@ -148,12 +152,30 @@ class MethodAliasingTest < Test::Unit::TestCase def test_alias_method_chain_with_punctuation_method FooClassWithBarMethod.send(:define_method, 'quux!', Proc.new { 'quux' }) - assert !@instance.respond_to?(:quux_with_baz) + assert !@instance.respond_to?(:quux_with_baz!) FooClassWithBarMethod.send(:include, BarMethodAliaser) FooClassWithBarMethod.alias_method_chain :quux!, :baz - assert @instance.respond_to?(:quux_with_baz) + assert @instance.respond_to?(:quux_with_baz!) + + assert_equal 'quux_with_baz!', @instance.quux! + assert_equal 'quux', @instance.quux_without_baz! + end - assert_equal 'quux_with_baz', @instance.quux! - assert_equal 'quux', @instance.quux_without_baz + def test_alias_method_chain_with_same_names_between_predicates_and_bang_methods + FooClassWithBarMethod.send(:define_method, 'quux!', Proc.new { 'quux' }) + FooClassWithBarMethod.send(:define_method, 'quux?', Proc.new { true }) + assert !@instance.respond_to?(:quux_with_baz!) + assert !@instance.respond_to?(:quux_with_baz?) + + FooClassWithBarMethod.send(:include, BarMethodAliaser) + FooClassWithBarMethod.alias_method_chain :quux!, :baz + FooClassWithBarMethod.alias_method_chain :quux?, :baz + + assert @instance.respond_to?(:quux_with_baz!) + assert @instance.respond_to?(:quux_with_baz?) + assert_equal 'quux_with_baz!', @instance.quux! + assert_equal 'quux', @instance.quux_without_baz! + assert_equal false, @instance.quux? + assert_equal true, @instance.quux_without_baz? end end |