提交 f28d073a 编写于 作者: J Julia López

fix with_routing when testing api only controllers

上级 8c547838
* Make `with_routing` test helper work when testing controllers inheriting from `ActionController::API`
*Julia López*
* Use accept header in integration tests with `as: :json`
Instead of appending the `format` to the request path, Rails will figure
......
......@@ -152,8 +152,11 @@ def with_routing
_routes = @routes
@controller.singleton_class.include(_routes.url_helpers)
@controller.view_context_class = Class.new(@controller.view_context_class) do
include _routes.url_helpers
if @controller.respond_to? :view_context_class
@controller.view_context_class = Class.new(@controller.view_context_class) do
include _routes.url_helpers
end
end
end
yield @routes
......
......@@ -128,6 +128,16 @@ def redirect_to_top_level_named_route
end
end
class ApiOnlyController < ActionController::API
def nothing
head :ok
end
def redirect_to_new_route
redirect_to new_route_url
end
end
class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_render_file_absolute_path
get :render_file_absolute_path
......@@ -170,6 +180,20 @@ def test_string_constraint
end
end
def test_with_routing_works_with_api_only_controllers
@controller = ApiOnlyController.new
with_routing do |set|
set.draw do
get "new_route", to: "api_only#nothing"
get "redirect_to_new_route", to: "api_only#redirect_to_new_route"
end
process :redirect_to_new_route
assert_redirected_to "http://test.host/new_route"
end
end
def test_assert_redirect_to_named_route_failure
with_routing do |set|
set.draw do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册