Permalink
Browse files

Revert "methods are defined right after the module_eval, so we don't …

…need to do"

This change breaks tests in activesupport/test/core_ext/module_test.rb:

* test_delegation_exception_backtrace
* test_delegation_exception_backtrace_with_allow_nil

This reverts commit 0167765.
  • Loading branch information...
1 parent 2e0f9ed commit fbab7b2acc1db4b8f1a9212350721b7716e74ac8 @drogus drogus committed Jan 16, 2014
Showing with 2 additions and 2 deletions.
  1. +2 −2 activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -178,7 +178,7 @@ def delegate(*methods)
# whereas conceptually, from the user point of view, the delegator should
# be doing one call.
if allow_nil
- module_eval(<<-EOS, file, line)
+ module_eval(<<-EOS, file, line - 3)
def #{method_prefix}#{method}(#{definition}) # def customer_name(*args, &block)
_ = #{to} # _ = client
if !_.nil? || nil.respond_to?(:#{method}) # if !_.nil? || nil.respond_to?(:name)
@@ -189,7 +189,7 @@ def #{method_prefix}#{method}(#{definition}) # def customer_name(*args, &
else
exception = %(raise DelegationError, "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
- module_eval(<<-EOS, file, line)
+ module_eval(<<-EOS, file, line - 2)
def #{method_prefix}#{method}(#{definition}) # def customer_name(*args, &block)
_ = #{to} # _ = client
_.#{method}(#{definition}) # _.name(*args, &block)

2 comments on commit fbab7b2

Owner

tenderlove replied Jan 16, 2014

diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb
index 5b99fae..d482b02 100644
--- a/activesupport/test/core_ext/module_test.rb
+++ b/activesupport/test/core_ext/module_test.rb
@@ -245,8 +245,19 @@ class ModuleTest < ActiveSupport::TestCase
     end
   end

+  def test_delegation_line_number
+    file, line = Someone.instance_method(:foo).source_location
+    assert_equal Someone::FAILED_DELEGATE_LINE, line
+  end
+
+  def test_delegate_line_with_nil
+    file, line = Someone.instance_method(:bar).source_location
+    assert_equal Someone::FAILED_DELEGATE_LINE_2, line
+  end
+
   def test_delegation_exception_backtrace
     someone = Someone.new("foo", "bar")
+    p Someone::FAILED_DELEGATE_LINE
     someone.foo
   rescue NoMethodError => e
     file_and_line = "#{__FILE__}:#{Someone::FAILED_DELEGATE_LINE}"

Please fix this.

Member

drogus replied Jan 16, 2014

@tenderlove I'm sorry, I don't understand what you mean, fix what?

Please sign in to comment.