Skip to content

Commit

Permalink
Merge pull request #33973 from rails/remove-catch-all
Browse files Browse the repository at this point in the history
Remove deprecated catch-all route in the AV tests
  • Loading branch information
tenderlove committed Sep 25, 2018
2 parents 4f12139 + 3301804 commit 6d698fd
Show file tree
Hide file tree
Showing 19 changed files with 296 additions and 78 deletions.
5 changes: 5 additions & 0 deletions actionpack/lib/action_dispatch/testing/assertions/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ module ActionDispatch
module Assertions
# Suite of assertions to test routes generated by \Rails and the handling of requests made to them.
module RoutingAssertions
def setup # :nodoc:
@routes ||= nil
super
end

# Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
# match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
#
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def self.test_routes(&block)
routes = ActionDispatch::Routing::RouteSet.new
routes.draw(&block)
include routes.url_helpers
routes
end
end

Expand Down
79 changes: 23 additions & 56 deletions actionview/test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,43 +65,6 @@ def render_erb(string)
end
end

SharedTestRoutes = ActionDispatch::Routing::RouteSet.new

module ActionDispatch
module SharedRoutes
def before_setup
@routes = SharedTestRoutes
super
end
end

# Hold off drawing routes until all the possible controller classes
# have been loaded.
module DrawOnce
class << self
attr_accessor :drew
end
self.drew = false

def before_setup
super
return if DrawOnce.drew

ActiveSupport::Deprecation.silence do
SharedTestRoutes.draw do
get ":controller(/:action)"
end

ActionDispatch::IntegrationTest.app.routes.draw do
get ":controller(/:action)"
end
end

DrawOnce.drew = true
end
end
end

class RoutedRackApp
attr_reader :routes

Expand Down Expand Up @@ -132,10 +95,11 @@ def config
end

class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
include ActionDispatch::SharedRoutes

def self.build_app(routes = nil)
RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
routes ||= ActionDispatch::Routing::RouteSet.new.tap { |rs|
rs.draw {}
}
RoutedRackApp.new(routes) do |middleware|
middleware.use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")
middleware.use ActionDispatch::DebugExceptions
middleware.use ActionDispatch::Callbacks
Expand All @@ -151,44 +115,48 @@ def self.build_app(routes = nil)
def with_routing(&block)
temporary_routes = ActionDispatch::Routing::RouteSet.new
old_app, self.class.app = self.class.app, self.class.build_app(temporary_routes)
old_routes = SharedTestRoutes
silence_warnings { Object.const_set(:SharedTestRoutes, temporary_routes) }

yield temporary_routes
ensure
self.class.app = old_app
silence_warnings { Object.const_set(:SharedTestRoutes, old_routes) }
end
end

ActionView::RoutingUrlFor.include(ActionDispatch::Routing::UrlFor)

module ActionController
class Base
# This stub emulates the Railtie including the URL helpers from a Rails application
include SharedTestRoutes.url_helpers
include SharedTestRoutes.mounted_helpers

self.view_paths = FIXTURE_LOAD_PATH

def self.test_routes(&block)
routes = ActionDispatch::Routing::RouteSet.new
routes.draw(&block)
include routes.url_helpers
routes
end
end

class TestCase
include ActionDispatch::TestProcess
include ActionDispatch::SharedRoutes
end
end

module ActionView
class TestCase
# Must repeat the setup because AV::TestCase is a duplication
# of AC::TestCase
include ActionDispatch::SharedRoutes
def self.with_routes(&block)
routes = ActionDispatch::Routing::RouteSet.new
routes.draw(&block)
include Module.new {
define_method(:setup) do
super()
@routes = routes
@controller.singleton_class.include @routes.url_helpers
end
}
routes
end

def with_routes(&block)
@routes = ActionDispatch::Routing::RouteSet.new
@routes.draw(&block)
@routes
end
end
end

Expand Down Expand Up @@ -222,7 +190,6 @@ def stderr_logger
end

class ActiveSupport::TestCase
include ActionDispatch::DrawOnce
include ActiveSupport::Testing::MethodCallAssertions

private
Expand Down
9 changes: 9 additions & 0 deletions actionview/test/actionpack/controller/capture_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def proper_block_detection
class CaptureTest < ActionController::TestCase
tests CaptureController

with_routes do
get :content_for, to: "test#content_for"
get :capturing, to: "test#capturing"
get :proper_block_detection, to: "test#proper_block_detection"
get :non_erb_block_content_for, to: "test#non_erb_block_content_for"
get :content_for_concatenated, to: "test#content_for_concatenated"
get :content_for_with_parameter, to: "test#content_for_with_parameter"
end

def setup
super
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
Expand Down
21 changes: 21 additions & 0 deletions actionview/test/actionpack/controller/layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class MultipleExtensions < LayoutTest
class LayoutAutoDiscoveryTest < ActionController::TestCase
include TemplateHandlerHelper

with_routes do
get :hello, to: "views#hello"
end

def setup
super
@request.host = "www.nextangle.com"
Expand Down Expand Up @@ -148,6 +152,11 @@ class LayoutSetInResponseTest < ActionController::TestCase
include ActionView::Template::Handlers
include TemplateHandlerHelper

with_routes do
get :hello, to: "views#hello"
get :hello, to: "views#goodbye"
end

def test_layout_set_when_using_default_layout
@controller = DefaultLayoutController.new
get :hello
Expand Down Expand Up @@ -234,6 +243,10 @@ class SetsNonExistentLayoutFile < LayoutTest
end

class LayoutExceptionRaisedTest < ActionController::TestCase
with_routes do
get :hello, to: "views#hello"
end

def test_exception_raised_when_layout_file_not_found
@controller = SetsNonExistentLayoutFile.new
assert_raise(ActionView::MissingTemplate) { get :hello }
Expand All @@ -247,6 +260,10 @@ def hello
end

class LayoutStatusIsRenderedTest < ActionController::TestCase
with_routes do
get :hello, to: "views#hello"
end

def test_layout_status_is_rendered
@controller = LayoutStatusIsRendered.new
get :hello
Expand All @@ -260,6 +277,10 @@ class LayoutSymlinkedTest < LayoutTest
end

class LayoutSymlinkedIsRenderedTest < ActionController::TestCase
with_routes do
get :hello, to: "views#hello"
end

def test_symlinked_layout_is_rendered
@controller = LayoutSymlinkedTest.new
get :hello
Expand Down
118 changes: 118 additions & 0 deletions actionview/test/actionpack/controller/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,124 @@ def determine_layout
class RenderTest < ActionController::TestCase
tests TestController

with_routes do
get :"hyphen-ated", to: "test#hyphen-ated"
get :accessing_action_name_in_template, to: "test#accessing_action_name_in_template"
get :accessing_controller_name_in_template, to: "test#accessing_controller_name_in_template"
get :accessing_local_assigns_in_inline_template, to: "test#accessing_local_assigns_in_inline_template"
get :accessing_logger_in_template, to: "test#accessing_logger_in_template"
get :accessing_params_in_template, to: "test#accessing_params_in_template"
get :accessing_params_in_template_with_layout, to: "test#accessing_params_in_template_with_layout"
get :accessing_request_in_template, to: "test#accessing_request_in_template"
get :action_talk_to_layout, to: "test#action_talk_to_layout"
get :builder_layout_test, to: "test#builder_layout_test"
get :builder_partial_test, to: "test#builder_partial_test"
get :clone, to: "test#clone"
get :determine_layout, to: "test#determine_layout"
get :double_redirect, to: "test#double_redirect"
get :double_render, to: "test#double_render"
get :empty_partial_collection, to: "test#empty_partial_collection"
get :formatted_html_erb, to: "test#formatted_html_erb"
get :formatted_xml_erb, to: "test#formatted_xml_erb"
get :greeting, to: "test#greeting"
get :hello_in_a_string, to: "test#hello_in_a_string"
get :hello_world, to: "fun/games#hello_world"
get :hello_world, to: "test#hello_world"
get :hello_world_file, to: "test#hello_world_file"
get :hello_world_from_rxml_using_action, to: "test#hello_world_from_rxml_using_action"
get :hello_world_from_rxml_using_template, to: "test#hello_world_from_rxml_using_template"
get :hello_world_with_layout_false, to: "test#hello_world_with_layout_false"
get :layout_overriding_layout, to: "test#layout_overriding_layout"
get :layout_test, to: "test#layout_test"
get :layout_test_with_different_layout, to: "test#layout_test_with_different_layout"
get :layout_test_with_different_layout_and_string_action, to: "test#layout_test_with_different_layout_and_string_action"
get :layout_test_with_different_layout_and_symbol_action, to: "test#layout_test_with_different_layout_and_symbol_action"
get :missing_partial, to: "test#missing_partial"
get :nested_partial_with_form_builder, to: "fun/games#nested_partial_with_form_builder"
get :new, to: "quiz/questions#new"
get :partial, to: "test#partial"
get :partial_collection, to: "test#partial_collection"
get :partial_collection_shorthand_with_different_types_of_records, to: "test#partial_collection_shorthand_with_different_types_of_records"
get :partial_collection_shorthand_with_locals, to: "test#partial_collection_shorthand_with_locals"
get :partial_collection_with_as, to: "test#partial_collection_with_as"
get :partial_collection_with_as_and_counter, to: "test#partial_collection_with_as_and_counter"
get :partial_collection_with_as_and_iteration, to: "test#partial_collection_with_as_and_iteration"
get :partial_collection_with_counter, to: "test#partial_collection_with_counter"
get :partial_collection_with_iteration, to: "test#partial_collection_with_iteration"
get :partial_collection_with_locals, to: "test#partial_collection_with_locals"
get :partial_collection_with_spacer, to: "test#partial_collection_with_spacer"
get :partial_collection_with_spacer_which_uses_render, to: "test#partial_collection_with_spacer_which_uses_render"
get :partial_formats_html, to: "test#partial_formats_html"
get :partial_hash_collection, to: "test#partial_hash_collection"
get :partial_hash_collection_with_locals, to: "test#partial_hash_collection_with_locals"
get :partial_html_erb, to: "test#partial_html_erb"
get :partial_only, to: "test#partial_only"
get :partial_with_counter, to: "test#partial_with_counter"
get :partial_with_form_builder, to: "test#partial_with_form_builder"
get :partial_with_form_builder_subclass, to: "test#partial_with_form_builder_subclass"
get :partial_with_hash_object, to: "test#partial_with_hash_object"
get :partial_with_locals, to: "test#partial_with_locals"
get :partial_with_nested_object, to: "test#partial_with_nested_object"
get :partial_with_nested_object_shorthand, to: "test#partial_with_nested_object_shorthand"
get :partial_with_string_locals, to: "test#partial_with_string_locals"
get :partials_list, to: "test#partials_list"
get :render_action_hello_world, to: "test#render_action_hello_world"
get :render_action_hello_world_as_string, to: "test#render_action_hello_world_as_string"
get :render_action_hello_world_with_symbol, to: "test#render_action_hello_world_with_symbol"
get :render_action_upcased_hello_world, to: "test#render_action_upcased_hello_world"
get :render_and_redirect, to: "test#render_and_redirect"
get :render_call_to_partial_with_layout, to: "test#render_call_to_partial_with_layout"
get :render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout, to: "test#render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout"
get :render_custom_code, to: "test#render_custom_code"
get :render_file_as_string_with_locals, to: "test#render_file_as_string_with_locals"
get :render_file_from_template, to: "test#render_file_from_template"
get :render_file_not_using_full_path, to: "test#render_file_not_using_full_path"
get :render_file_not_using_full_path_with_dot_in_path, to: "test#render_file_not_using_full_path_with_dot_in_path"
get :render_file_using_pathname, to: "test#render_file_using_pathname"
get :render_file_with_instance_variables, to: "test#render_file_with_instance_variables"
get :render_file_with_locals, to: "test#render_file_with_locals"
get :render_hello_world, to: "test#render_hello_world"
get :render_hello_world_from_variable, to: "test#render_hello_world_from_variable"
get :render_hello_world_with_forward_slash, to: "test#render_hello_world_with_forward_slash"
get :render_implicit_html_template_from_xhr_request, to: "test#render_implicit_html_template_from_xhr_request"
get :render_implicit_js_template_without_layout, to: "test#render_implicit_js_template_without_layout"
get :render_line_offset, to: "test#render_line_offset"
get :render_nothing_with_appendix, to: "test#render_nothing_with_appendix"
get :render_template_in_top_directory, to: "test#render_template_in_top_directory"
get :render_template_in_top_directory_with_slash, to: "test#render_template_in_top_directory_with_slash"
get :render_template_within_a_template_with_other_format, to: "test#render_template_within_a_template_with_other_format"
get :render_text_hello_world, to: "test#render_text_hello_world"
get :render_text_hello_world_with_layout, to: "test#render_text_hello_world_with_layout"
get :render_text_with_assigns, to: "test#render_text_with_assigns"
get :render_text_with_false, to: "test#render_text_with_false"
get :render_text_with_nil, to: "test#render_text_with_nil"
get :render_text_with_resource, to: "test#render_text_with_resource"
get :render_to_string_and_render, to: "test#render_to_string_and_render"
get :render_to_string_and_render_with_different_formats, to: "test#render_to_string_and_render_with_different_formats"
get :render_to_string_test, to: "test#render_to_string_test"
get :render_to_string_with_assigns, to: "test#render_to_string_with_assigns"
get :render_to_string_with_caught_exception, to: "test#render_to_string_with_caught_exception"
get :render_to_string_with_exception, to: "test#render_to_string_with_exception"
get :render_to_string_with_inline_and_render, to: "test#render_to_string_with_inline_and_render"
get :render_to_string_with_partial, to: "test#render_to_string_with_partial"
get :render_to_string_with_template_and_html_partial, to: "test#render_to_string_with_template_and_html_partial"
get :render_using_layout_around_block, to: "test#render_using_layout_around_block"
get :render_using_layout_around_block_in_main_layout_and_within_content_for_layout, to: "test#render_using_layout_around_block_in_main_layout_and_within_content_for_layout"
get :render_with_assigns_option, to: "test#render_with_assigns_option"
get :render_with_explicit_escaped_template, to: "test#render_with_explicit_escaped_template"
get :render_with_explicit_string_template, to: "test#render_with_explicit_string_template"
get :render_with_explicit_template, to: "test#render_with_explicit_template"
get :render_with_explicit_template_with_locals, to: "test#render_with_explicit_template_with_locals"
get :render_with_explicit_unescaped_template, to: "test#render_with_explicit_unescaped_template"
get :render_with_filters, to: "test#render_with_filters"
get :render_xml_hello, to: "test#render_xml_hello"
get :render_xml_hello_as_string_template, to: "test#render_xml_hello_as_string_template"
get :rendering_nothing_on_layout, to: "test#rendering_nothing_on_layout"
get :rendering_with_conflicting_local_vars, to: "test#rendering_with_conflicting_local_vars"
get :rendering_without_layout, to: "test#rendering_without_layout"
get :yield_content_for, to: "test#yield_content_for"
end

def setup
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
# a more accurate simulation of what happens in "real life".
Expand Down
10 changes: 10 additions & 0 deletions actionview/test/actionpack/controller/view_paths_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ def hello_world; render(template: "test/hello_world"); end
end
end

with_routes do
get :hello_world, to: "test#hello_world"
get :hello_world_at_request_time, to: "test#hello_world_at_request_time"
end

def setup
@controller = TestController.new
@request = ActionController::TestRequest.create(@controller.class)
@response = ActionDispatch::TestResponse.new
@paths = TestController.view_paths
super
end

def teardown
Expand Down Expand Up @@ -109,6 +115,10 @@ def test_view_paths_override

def test_view_paths_override_for_layouts_in_controllers_with_a_module
@controller = Test::SubController.new
with_routes do
get :hello_world, to: "view_load_paths_test/test/sub#hello_world"
end

Test::SubController.view_paths = [ "#{FIXTURE_LOAD_PATH}/override", FIXTURE_LOAD_PATH, "#{FIXTURE_LOAD_PATH}/override2" ]
get :hello_world
assert_response :success
Expand Down
12 changes: 12 additions & 0 deletions actionview/test/active_record_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ def require_fixture_models
class ActiveRecordTestCase < ActionController::TestCase
include ActiveRecord::TestFixtures

def self.tests(controller)
super
if defined? controller::ROUTES
include Module.new {
define_method(:setup) do
super()
@routes = controller::ROUTES
end
}
end
end

# Set our fixture path
if ActiveRecordTestConnector.able_to_connect
self.fixture_path = [FIXTURE_LOAD_PATH]
Expand Down
Loading

0 comments on commit 6d698fd

Please sign in to comment.