Skip to content
This repository
Browse code

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

… case.
  • Loading branch information...
commit 2e2f3f5a469cb441e52fb161647ea5fd27d98d81 1 parent 57423d8
Jon Leighton authored August 15, 2011
1  activesupport/lib/active_support/core_ext/module/delegation.rb
... ...
@@ -1,4 +1,5 @@
1 1
 require 'active_support/core_ext/object/public_send'
  2
+
2 3
 class Module
3 4
   # Provides a delegate class method to easily expose contained objects' methods
4 5
   # as your own. Pass one or more methods (specified as symbols or strings)
8  activesupport/test/core_ext/module_test.rb
@@ -27,6 +27,8 @@ class Cd
27 27
 end
28 28
 
29 29
 Somewhere = Struct.new(:street, :city) do
  30
+  attr_accessor :name
  31
+
30 32
   protected
31 33
 
32 34
   def protected_method
@@ -40,6 +42,7 @@ def private_method
40 42
 
41 43
 class Someone < Struct.new(:name, :place)
42 44
   delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place
  45
+  delegate :name=, :to => :place, :prefix => true
43 46
   delegate :upcase, :to => "place.city"
44 47
 
45 48
   FAILED_DELEGATE_LINE = __LINE__ + 1
@@ -85,6 +88,11 @@ def test_delegation_to_methods
85 88
     assert_equal "Chicago", @david.city
86 89
   end
87 90
 
  91
+  def test_delegation_to_assignment_method
  92
+    @david.place_name = "Fred"
  93
+    assert_equal "Fred", @david.place.name
  94
+  end
  95
+
88 96
   def test_delegation_to_protected_method
89 97
     assert_raise(NoMethodError) { @david.protected_method }
90 98
   end

0 notes on commit 2e2f3f5

Please sign in to comment.
Something went wrong with that request. Please try again.