diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-09-12 07:10:43 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-09-12 07:10:43 +0000 |
commit | 74f60c032e92b2473b5feeeb85782836c2b83fdd (patch) | |
tree | 97d9d1975e8d6a3a286a3e2fa20480f224493255 /activesupport/test/core_ext | |
parent | 3c0e7b1b51cb775e55a4b10a9872f74cecacd6a7 (diff) | |
download | rails-74f60c032e92b2473b5feeeb85782836c2b83fdd.tar.gz rails-74f60c032e92b2473b5feeeb85782836c2b83fdd.tar.bz2 rails-74f60c032e92b2473b5feeeb85782836c2b83fdd.zip |
alias_method_chain works with accessor= methods also. Closes #6153.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5091 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 2b51656509..9d86c84e21 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -108,12 +108,16 @@ module BarMethodAliaser end def quux_with_baz! - quux_without_baz! << '_with_baz!' + quux_without_baz! << '_with_baz' end def quux_with_baz? false end + + def quux_with_baz=(v) + send(:quux_without_baz=, v) << '_with_baz' + end end class MethodAliasingTest < Test::Unit::TestCase @@ -154,26 +158,35 @@ class MethodAliasingTest < Test::Unit::TestCase FooClassWithBarMethod.alias_method_chain :quux!, :baz assert @instance.respond_to?(:quux_with_baz!) - assert_equal 'quux_with_baz!', @instance.quux! + assert_equal 'quux_with_baz', @instance.quux! assert_equal 'quux', @instance.quux_without_baz! end 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 { 'quux!' }) FooClassWithBarMethod.send(:define_method, 'quux?', Proc.new { true }) + FooClassWithBarMethod.send(:define_method, 'quux=', Proc.new { 'quux=' }) assert !@instance.respond_to?(:quux_with_baz!) 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 @instance.respond_to?(:quux_with_baz=) + + + FooClassWithBarMethod.alias_method_chain :quux!, :baz + assert_equal 'quux!_with_baz', @instance.quux! + assert_equal 'quux!', @instance.quux_without_baz! + + FooClassWithBarMethod.alias_method_chain :quux?, :baz assert_equal false, @instance.quux? assert_equal true, @instance.quux_without_baz? + + FooClassWithBarMethod.alias_method_chain :quux=, :baz + assert_equal 'quux=_with_baz', @instance.send(:quux=, 1234) + assert_equal 'quux=', @instance.send(:quux_without_baz=, 1234) end def test_alias_method_chain_with_feature_punctuation @@ -183,7 +196,7 @@ class MethodAliasingTest < Test::Unit::TestCase FooClassWithBarMethod.alias_method_chain :quux, :baz! assert_nothing_raised do - assert_equal 'quux_with_baz!', @instance.quux_with_baz! + assert_equal 'quux_with_baz', @instance.quux_with_baz! end assert_raise(NameError) do |