Skip to content

Commit

Permalink
Revert "methods are defined right after the module_eval, so we don't …
Browse files Browse the repository at this point in the history
…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
drogus committed Jan 16, 2014
1 parent 2e0f9ed commit fbab7b2
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

2 comments on commit fbab7b2

@tenderlove
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@drogus
Copy link
Member Author

@drogus drogus commented on fbab7b2 Jan 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.