提交 77a27641 编写于 作者: G Godfrey Chan

Test using `ActionController::TestCase` with engines

Reference #17453

[Godfrey Chan, Washington Luiz]
上级 ede97c6b
require 'abstract_unit'
require 'controller/fake_controllers'
require 'active_support/json/decoding'
require 'rails/engine'
class TestCaseTest < ActionController::TestCase
class TestController < ActionController::Base
......@@ -753,6 +754,57 @@ def test_redirect_url_only_cares_about_location_header
end
end
module EngineControllerTests
class Engine < ::Rails::Engine
isolate_namespace EngineControllerTests
routes.draw do
get '/' => 'bar#index'
end
end
class BarController < ActionController::Base
def index
render :text => 'bar'
end
end
class BarControllerTest < ActionController::TestCase
tests BarController
def test_engine_controller_route
get :index
assert_equal @response.body, 'bar'
end
end
class BarControllerTestWithExplicitRouteSet < ActionController::TestCase
tests BarController
def setup
@routes = Engine.routes
end
def test_engine_controller_route
get :index
assert_equal @response.body, 'bar'
end
end
class BarControllerTestWithHostApplicationRouteSet < ActionController::TestCase
tests BarController
def test_use_route
with_routing do |set|
set.draw { mount Engine => '/foo' }
get :index, use_route: :foo
assert_equal @response.body, 'bar'
end
end
end
end
class InferringClassNameTest < ActionController::TestCase
def test_determine_controller_class
assert_equal ContentController, determine_class("ContentControllerTest")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册