Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fixes a failing test in actionpack #3641

Closed
wants to merge 1 commit into from

4 participants

@quackingduck

The test on line 120 of actionpack/test/controller/new_base/render_template_test.rb:

test "rendering a template with error properly excerts the code" do
  get :with_error
  assert_status 500
  assert_match "undefined local variable or method `idontexist'", response.body
end

is currently failing on master. The test expects to see the message attached to the exception object (and a stack trace) but instead it gets the contents of the fixture 500.html.

It looks like the RoutedRackApp instance created for ActionDispatch::IntegrationTest in actionpack/test/abstract_unit.rb initializes the ActionDispatch::ShowExceptions middleware but doesn't explicitly tell it to consider all requests as local.

One way to way to make the test pass is to change line 167 of actionpack/test/abstract_unit.rb from:

middleware.use "ActionDispatch::ShowExceptions"

to

middleware.use "ActionDispatch::ShowExceptions", true

then all the requests in the test cases that subclass from ActionDispatch::IntegrationTest would be considered local.

Alternatively we could alter the logic in actionpack/lib/action_dispatch/http/request.rb that decides whether or not a request is local. Right now both Request#remote_addr and Request#remote_ip have to match one of [/^127\.0\.0\.\d{1,3}$/, "::1", /^0:0:0:0:0:0:0:1(%.*)?$/]. In the test cases Request#remote_addr is 127.0.0.1 but Request#remote_ip is an empty string. Changing the logic from:

LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }

to:

LOCALHOST.any? { |local_ip| local_ip === remote_addr || local_ip === remote_ip }

would make the test pass and all other test requests would be considered local.

In this patch I just updated the test to send the loopback IP with the request as it seemed the least intrusive way to get it to pass and can have no effect on any of the other tests:

test "rendering a template with error properly excerpts the code" do
  get :with_error, {}, { 'action_dispatch.remote_ip' => "127.0.0.1" }
  assert_status 500
  assert_match "undefined local variable or method `idontexist'", response.body
end
@josevalim
Owner
@indirect
@jonleighton
Collaborator

Closing this as @indirect is working on a fix that doesn't change the tests.

@likethesky likethesky referenced this pull request in jruby/jruby
Closed

IPv4 stack should be preferred to IPv6 #775

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 actionpack/test/controller/new_base/render_template_test.rb
View
4 actionpack/test/controller/new_base/render_template_test.rb
@@ -117,8 +117,8 @@ class TestWithoutLayout < Rack::TestCase
assert_response "{ final: json }"
end
- test "rendering a template with error properly excerts the code" do
- get :with_error
+ test "rendering a template with error properly excerpts the code" do
+ get :with_error, {}, { 'action_dispatch.remote_ip' => "127.0.0.1" }
assert_status 500
assert_match "undefined local variable or method `idontexist'", response.body
end
Something went wrong with that request. Please try again.