diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-08-15 16:07:49 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-08-15 16:07:49 +0100 |
commit | 2e2f3f5a469cb441e52fb161647ea5fd27d98d81 (patch) | |
tree | 8e5dc08cd018c2be3aac5c78ceb72e0befc9713b | |
parent | 57423d815b3747aa382cd3859a15bffa538525ad (diff) | |
download | rails-2e2f3f5a469cb441e52fb161647ea5fd27d98d81.tar.gz rails-2e2f3f5a469cb441e52fb161647ea5fd27d98d81.tar.bz2 rails-2e2f3f5a469cb441e52fb161647ea5fd27d98d81.zip |
Add a test for delegating a method ending in '=' as this is a special case.
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 1 | ||||
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 72988fa6b5..4a899a7d84 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/object/public_send' + 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) diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index a24f013d4f..d4ce81fdfa 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -27,6 +27,8 @@ module Yz end Somewhere = Struct.new(:street, :city) do + attr_accessor :name + protected def protected_method @@ -40,6 +42,7 @@ end class Someone < Struct.new(:name, :place) delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place + delegate :name=, :to => :place, :prefix => true delegate :upcase, :to => "place.city" FAILED_DELEGATE_LINE = __LINE__ + 1 @@ -85,6 +88,11 @@ class ModuleTest < Test::Unit::TestCase assert_equal "Chicago", @david.city end + def test_delegation_to_assignment_method + @david.place_name = "Fred" + assert_equal "Fred", @david.place.name + end + def test_delegation_to_protected_method assert_raise(NoMethodError) { @david.protected_method } end |