Add a test for delegating a method ending in '=' as this is a special case.

This commit is contained in:
Jon Leighton 2011-08-15 16:07:49 +01:00
parent 57423d815b
commit 2e2f3f5a46
2 changed files with 9 additions and 0 deletions

View File

@ -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)

View File

@ -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