From 27da0c5480ecf6b020e73f994d3240ae15b0646b Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 15 Aug 2011 13:56:04 +0100 Subject: Split up the definitions in Module#delegate depending on :allow_nil, and don't use exceptions for flow control in the :allow_nil => true case. --- activesupport/test/core_ext/module_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index c33ade8381..a24f013d4f 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -44,6 +44,9 @@ class Someone < Struct.new(:name, :place) FAILED_DELEGATE_LINE = __LINE__ + 1 delegate :foo, :to => :place + + FAILED_DELEGATE_LINE_2 = __LINE__ + 1 + delegate :bar, :to => :place, :allow_nil => true end Invoice = Struct.new(:client) do @@ -194,6 +197,15 @@ class ModuleTest < Test::Unit::TestCase "[#{e.backtrace.first}] did not include [#{file_and_line}]" end + def test_delegation_exception_backtrace_with_allow_nil + someone = Someone.new("foo", "bar") + someone.bar + rescue NoMethodError => e + file_and_line = "#{__FILE__}:#{Someone::FAILED_DELEGATE_LINE_2}" + assert e.backtrace.first.include?(file_and_line), + "[#{e.backtrace.first}] did not include [#{file_and_line}]" + end + def test_parent assert_equal Yz::Zy, Yz::Zy::Cd.parent assert_equal Yz, Yz::Zy.parent -- cgit v1.2.3