Permalink
Browse files

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

… case.
  • Loading branch information...
1 parent 57423d8 commit 2e2f3f5a469cb441e52fb161647ea5fd27d98d81 @jonleighton jonleighton committed Aug 15, 2011
View
1 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)
View
8 activesupport/test/core_ext/module_test.rb
@@ -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

0 comments on commit 2e2f3f5

Please sign in to comment.