Permalink
Browse files

Merge branch '2-2-stable' of git@github.com:rails/rails into 2-2-stable

  • Loading branch information...
2 parents 5e55ed1 + 2f7c073 commit 3639c0bfa7dbef487c389297f6f643d00034369b @dhh dhh committed Nov 20, 2008
@@ -78,6 +78,10 @@ def delegate(*methods)
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
end
+ if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/
+ raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
+ end
+
prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
methods.each do |method|
@@ -106,6 +106,17 @@ def test_delegation_custom_prefix
assert_equal invoice.customer_city, "Chicago"
end
+ def test_delegation_prefix_with_instance_variable
+ assert_raise ArgumentError do
+ Class.new do
+ def initialize(client)
+ @client = client
+ end
+ delegate :name, :address, :to => :@client, :prefix => true
+ end
+ end
+ end
+
def test_parent
assert_equal Yz::Zy, Yz::Zy::Cd.parent
assert_equal Yz, Yz::Zy.parent

0 comments on commit 3639c0b

Please sign in to comment.