aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb2
-rw-r--r--activesupport/test/core_ext/module_test.rb14
2 files changed, 14 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb
index 8655288bc3..654e3a01c6 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -133,7 +133,7 @@ class Module
%(raise "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
end
- module_eval(<<-EOS, file, line - 5)
+ module_eval(<<-EOS, file, line - 1)
def #{method_prefix}#{method}(*args, &block) # def customer_name(*args, &block)
#{to}.#{call}*args, &block) # client.name(*args, &block)
rescue NoMethodError # rescue NoMethodError
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb
index 074a3412d4..c33ade8381 100644
--- a/activesupport/test/core_ext/module_test.rb
+++ b/activesupport/test/core_ext/module_test.rb
@@ -38,9 +38,12 @@ Somewhere = Struct.new(:street, :city) do
end
end
-Someone = Struct.new(:name, :place) do
+class Someone < Struct.new(:name, :place)
delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place
delegate :upcase, :to => "place.city"
+
+ FAILED_DELEGATE_LINE = __LINE__ + 1
+ delegate :foo, :to => :place
end
Invoice = Struct.new(:client) do
@@ -182,6 +185,15 @@ class ModuleTest < Test::Unit::TestCase
end
end
+ def test_delegation_exception_backtrace
+ someone = Someone.new("foo", "bar")
+ someone.foo
+ rescue NoMethodError => e
+ file_and_line = "#{__FILE__}:#{Someone::FAILED_DELEGATE_LINE}"
+ 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