提交 2e2f3f5a 编写于 作者: J Jon Leighton

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

上级 57423d81
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)
......
......@@ -27,6 +27,8 @@ class Cd
end
Somewhere = Struct.new(:street, :city) do
attr_accessor :name
protected
def protected_method
......@@ -40,6 +42,7 @@ def private_method
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 @@ def test_delegation_to_methods
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册