mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make sure assert_recognizes can still find routes mounted after engines
Before, if the application defined after an engine this method would not recognize the route since it was not defined insdie the engine.
This commit is contained in:
parent
80cc0d323b
commit
c92ea62792
2 changed files with 12 additions and 4 deletions
|
@ -855,7 +855,7 @@ module ActionDispatch
|
||||||
recognize_path_with_request(req, path, extras)
|
recognize_path_with_request(req, path, extras)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recognize_path_with_request(req, path, extras)
|
def recognize_path_with_request(req, path, extras, raise_on_missing: true)
|
||||||
@router.recognize(req) do |route, params|
|
@router.recognize(req) do |route, params|
|
||||||
params.merge!(extras)
|
params.merge!(extras)
|
||||||
params.each do |key, value|
|
params.each do |key, value|
|
||||||
|
@ -875,12 +875,14 @@ module ActionDispatch
|
||||||
|
|
||||||
return req.path_parameters
|
return req.path_parameters
|
||||||
elsif app.matches?(req) && app.engine?
|
elsif app.matches?(req) && app.engine?
|
||||||
path_parameters = app.rack_app.routes.recognize_path_with_request(req, path, extras)
|
path_parameters = app.rack_app.routes.recognize_path_with_request(req, path, extras, raise_on_missing: false)
|
||||||
return path_parameters
|
return path_parameters if path_parameters
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
raise ActionController::RoutingError, "No route matches #{path.inspect}"
|
if raise_on_missing
|
||||||
|
raise ActionController::RoutingError, "No route matches #{path.inspect}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# :startdoc:
|
# :startdoc:
|
||||||
|
|
|
@ -52,6 +52,8 @@ class RoutingAssertionsTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
mount engine => "/shelf"
|
mount engine => "/shelf"
|
||||||
|
|
||||||
|
get "/shelf/foo", controller: "query_articles", action: "index"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -154,6 +156,10 @@ class RoutingAssertionsTest < ActionController::TestCase
|
||||||
assert_match err.message, "This is a really bad msg"
|
assert_match err.message, "This is a really bad msg"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_assert_recognizes_continue_to_recoginize_after_it_tried_engines
|
||||||
|
assert_recognizes({ controller: "query_articles", action: "index" }, "/shelf/foo")
|
||||||
|
end
|
||||||
|
|
||||||
def test_assert_routing
|
def test_assert_routing
|
||||||
assert_routing("/articles", controller: "articles", action: "index")
|
assert_routing("/articles", controller: "articles", action: "index")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue