Skip to content

Commit 6d698fd

Browse files
authored
Merge pull request rails#33973 from rails/remove-catch-all
Remove deprecated catch-all route in the AV tests
2 parents 4f12139 + 3301804 commit 6d698fd

19 files changed

+296
-78
lines changed

actionpack/lib/action_dispatch/testing/assertions/routing.rb

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ module ActionDispatch
99
module Assertions
1010
# Suite of assertions to test routes generated by \Rails and the handling of requests made to them.
1111
module RoutingAssertions
12+
def setup # :nodoc:
13+
@routes ||= nil
14+
super
15+
end
16+
1217
# Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
1318
# match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
1419
#

actionpack/test/abstract_unit.rb

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def self.test_routes(&block)
232232
routes = ActionDispatch::Routing::RouteSet.new
233233
routes.draw(&block)
234234
include routes.url_helpers
235+
routes
235236
end
236237
end
237238

actionview/test/abstract_unit.rb

+23-56
Original file line numberDiff line numberDiff line change
@@ -65,43 +65,6 @@ def render_erb(string)
6565
end
6666
end
6767

68-
SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
69-
70-
module ActionDispatch
71-
module SharedRoutes
72-
def before_setup
73-
@routes = SharedTestRoutes
74-
super
75-
end
76-
end
77-
78-
# Hold off drawing routes until all the possible controller classes
79-
# have been loaded.
80-
module DrawOnce
81-
class << self
82-
attr_accessor :drew
83-
end
84-
self.drew = false
85-
86-
def before_setup
87-
super
88-
return if DrawOnce.drew
89-
90-
ActiveSupport::Deprecation.silence do
91-
SharedTestRoutes.draw do
92-
get ":controller(/:action)"
93-
end
94-
95-
ActionDispatch::IntegrationTest.app.routes.draw do
96-
get ":controller(/:action)"
97-
end
98-
end
99-
100-
DrawOnce.drew = true
101-
end
102-
end
103-
end
104-
10568
class RoutedRackApp
10669
attr_reader :routes
10770

@@ -132,10 +95,11 @@ def config
13295
end
13396

13497
class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
135-
include ActionDispatch::SharedRoutes
136-
13798
def self.build_app(routes = nil)
138-
RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
99+
routes ||= ActionDispatch::Routing::RouteSet.new.tap { |rs|
100+
rs.draw {}
101+
}
102+
RoutedRackApp.new(routes) do |middleware|
139103
middleware.use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")
140104
middleware.use ActionDispatch::DebugExceptions
141105
middleware.use ActionDispatch::Callbacks
@@ -151,44 +115,48 @@ def self.build_app(routes = nil)
151115
def with_routing(&block)
152116
temporary_routes = ActionDispatch::Routing::RouteSet.new
153117
old_app, self.class.app = self.class.app, self.class.build_app(temporary_routes)
154-
old_routes = SharedTestRoutes
155-
silence_warnings { Object.const_set(:SharedTestRoutes, temporary_routes) }
156118

157119
yield temporary_routes
158120
ensure
159121
self.class.app = old_app
160-
silence_warnings { Object.const_set(:SharedTestRoutes, old_routes) }
161122
end
162123
end
163124

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

166127
module ActionController
167128
class Base
168-
# This stub emulates the Railtie including the URL helpers from a Rails application
169-
include SharedTestRoutes.url_helpers
170-
include SharedTestRoutes.mounted_helpers
171-
172129
self.view_paths = FIXTURE_LOAD_PATH
173130

174131
def self.test_routes(&block)
175132
routes = ActionDispatch::Routing::RouteSet.new
176133
routes.draw(&block)
177134
include routes.url_helpers
135+
routes
178136
end
179137
end
180138

181139
class TestCase
182140
include ActionDispatch::TestProcess
183-
include ActionDispatch::SharedRoutes
184-
end
185-
end
186141

187-
module ActionView
188-
class TestCase
189-
# Must repeat the setup because AV::TestCase is a duplication
190-
# of AC::TestCase
191-
include ActionDispatch::SharedRoutes
142+
def self.with_routes(&block)
143+
routes = ActionDispatch::Routing::RouteSet.new
144+
routes.draw(&block)
145+
include Module.new {
146+
define_method(:setup) do
147+
super()
148+
@routes = routes
149+
@controller.singleton_class.include @routes.url_helpers
150+
end
151+
}
152+
routes
153+
end
154+
155+
def with_routes(&block)
156+
@routes = ActionDispatch::Routing::RouteSet.new
157+
@routes.draw(&block)
158+
@routes
159+
end
192160
end
193161
end
194162

@@ -222,7 +190,6 @@ def stderr_logger
222190
end
223191

224192
class ActiveSupport::TestCase
225-
include ActionDispatch::DrawOnce
226193
include ActiveSupport::Testing::MethodCallAssertions
227194

228195
private

actionview/test/actionpack/controller/capture_test.rb

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ def proper_block_detection
3737
class CaptureTest < ActionController::TestCase
3838
tests CaptureController
3939

40+
with_routes do
41+
get :content_for, to: "test#content_for"
42+
get :capturing, to: "test#capturing"
43+
get :proper_block_detection, to: "test#proper_block_detection"
44+
get :non_erb_block_content_for, to: "test#non_erb_block_content_for"
45+
get :content_for_concatenated, to: "test#content_for_concatenated"
46+
get :content_for_with_parameter, to: "test#content_for_with_parameter"
47+
end
48+
4049
def setup
4150
super
4251
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get

actionview/test/actionpack/controller/layout_test.rb

+21
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class MultipleExtensions < LayoutTest
4848
class LayoutAutoDiscoveryTest < ActionController::TestCase
4949
include TemplateHandlerHelper
5050

51+
with_routes do
52+
get :hello, to: "views#hello"
53+
end
54+
5155
def setup
5256
super
5357
@request.host = "www.nextangle.com"
@@ -148,6 +152,11 @@ class LayoutSetInResponseTest < ActionController::TestCase
148152
include ActionView::Template::Handlers
149153
include TemplateHandlerHelper
150154

155+
with_routes do
156+
get :hello, to: "views#hello"
157+
get :hello, to: "views#goodbye"
158+
end
159+
151160
def test_layout_set_when_using_default_layout
152161
@controller = DefaultLayoutController.new
153162
get :hello
@@ -234,6 +243,10 @@ class SetsNonExistentLayoutFile < LayoutTest
234243
end
235244

236245
class LayoutExceptionRaisedTest < ActionController::TestCase
246+
with_routes do
247+
get :hello, to: "views#hello"
248+
end
249+
237250
def test_exception_raised_when_layout_file_not_found
238251
@controller = SetsNonExistentLayoutFile.new
239252
assert_raise(ActionView::MissingTemplate) { get :hello }
@@ -247,6 +260,10 @@ def hello
247260
end
248261

249262
class LayoutStatusIsRenderedTest < ActionController::TestCase
263+
with_routes do
264+
get :hello, to: "views#hello"
265+
end
266+
250267
def test_layout_status_is_rendered
251268
@controller = LayoutStatusIsRendered.new
252269
get :hello
@@ -260,6 +277,10 @@ class LayoutSymlinkedTest < LayoutTest
260277
end
261278

262279
class LayoutSymlinkedIsRenderedTest < ActionController::TestCase
280+
with_routes do
281+
get :hello, to: "views#hello"
282+
end
283+
263284
def test_symlinked_layout_is_rendered
264285
@controller = LayoutSymlinkedTest.new
265286
get :hello

actionview/test/actionpack/controller/render_test.rb

+118
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,124 @@ def determine_layout
632632
class RenderTest < ActionController::TestCase
633633
tests TestController
634634

635+
with_routes do
636+
get :"hyphen-ated", to: "test#hyphen-ated"
637+
get :accessing_action_name_in_template, to: "test#accessing_action_name_in_template"
638+
get :accessing_controller_name_in_template, to: "test#accessing_controller_name_in_template"
639+
get :accessing_local_assigns_in_inline_template, to: "test#accessing_local_assigns_in_inline_template"
640+
get :accessing_logger_in_template, to: "test#accessing_logger_in_template"
641+
get :accessing_params_in_template, to: "test#accessing_params_in_template"
642+
get :accessing_params_in_template_with_layout, to: "test#accessing_params_in_template_with_layout"
643+
get :accessing_request_in_template, to: "test#accessing_request_in_template"
644+
get :action_talk_to_layout, to: "test#action_talk_to_layout"
645+
get :builder_layout_test, to: "test#builder_layout_test"
646+
get :builder_partial_test, to: "test#builder_partial_test"
647+
get :clone, to: "test#clone"
648+
get :determine_layout, to: "test#determine_layout"
649+
get :double_redirect, to: "test#double_redirect"
650+
get :double_render, to: "test#double_render"
651+
get :empty_partial_collection, to: "test#empty_partial_collection"
652+
get :formatted_html_erb, to: "test#formatted_html_erb"
653+
get :formatted_xml_erb, to: "test#formatted_xml_erb"
654+
get :greeting, to: "test#greeting"
655+
get :hello_in_a_string, to: "test#hello_in_a_string"
656+
get :hello_world, to: "fun/games#hello_world"
657+
get :hello_world, to: "test#hello_world"
658+
get :hello_world_file, to: "test#hello_world_file"
659+
get :hello_world_from_rxml_using_action, to: "test#hello_world_from_rxml_using_action"
660+
get :hello_world_from_rxml_using_template, to: "test#hello_world_from_rxml_using_template"
661+
get :hello_world_with_layout_false, to: "test#hello_world_with_layout_false"
662+
get :layout_overriding_layout, to: "test#layout_overriding_layout"
663+
get :layout_test, to: "test#layout_test"
664+
get :layout_test_with_different_layout, to: "test#layout_test_with_different_layout"
665+
get :layout_test_with_different_layout_and_string_action, to: "test#layout_test_with_different_layout_and_string_action"
666+
get :layout_test_with_different_layout_and_symbol_action, to: "test#layout_test_with_different_layout_and_symbol_action"
667+
get :missing_partial, to: "test#missing_partial"
668+
get :nested_partial_with_form_builder, to: "fun/games#nested_partial_with_form_builder"
669+
get :new, to: "quiz/questions#new"
670+
get :partial, to: "test#partial"
671+
get :partial_collection, to: "test#partial_collection"
672+
get :partial_collection_shorthand_with_different_types_of_records, to: "test#partial_collection_shorthand_with_different_types_of_records"
673+
get :partial_collection_shorthand_with_locals, to: "test#partial_collection_shorthand_with_locals"
674+
get :partial_collection_with_as, to: "test#partial_collection_with_as"
675+
get :partial_collection_with_as_and_counter, to: "test#partial_collection_with_as_and_counter"
676+
get :partial_collection_with_as_and_iteration, to: "test#partial_collection_with_as_and_iteration"
677+
get :partial_collection_with_counter, to: "test#partial_collection_with_counter"
678+
get :partial_collection_with_iteration, to: "test#partial_collection_with_iteration"
679+
get :partial_collection_with_locals, to: "test#partial_collection_with_locals"
680+
get :partial_collection_with_spacer, to: "test#partial_collection_with_spacer"
681+
get :partial_collection_with_spacer_which_uses_render, to: "test#partial_collection_with_spacer_which_uses_render"
682+
get :partial_formats_html, to: "test#partial_formats_html"
683+
get :partial_hash_collection, to: "test#partial_hash_collection"
684+
get :partial_hash_collection_with_locals, to: "test#partial_hash_collection_with_locals"
685+
get :partial_html_erb, to: "test#partial_html_erb"
686+
get :partial_only, to: "test#partial_only"
687+
get :partial_with_counter, to: "test#partial_with_counter"
688+
get :partial_with_form_builder, to: "test#partial_with_form_builder"
689+
get :partial_with_form_builder_subclass, to: "test#partial_with_form_builder_subclass"
690+
get :partial_with_hash_object, to: "test#partial_with_hash_object"
691+
get :partial_with_locals, to: "test#partial_with_locals"
692+
get :partial_with_nested_object, to: "test#partial_with_nested_object"
693+
get :partial_with_nested_object_shorthand, to: "test#partial_with_nested_object_shorthand"
694+
get :partial_with_string_locals, to: "test#partial_with_string_locals"
695+
get :partials_list, to: "test#partials_list"
696+
get :render_action_hello_world, to: "test#render_action_hello_world"
697+
get :render_action_hello_world_as_string, to: "test#render_action_hello_world_as_string"
698+
get :render_action_hello_world_with_symbol, to: "test#render_action_hello_world_with_symbol"
699+
get :render_action_upcased_hello_world, to: "test#render_action_upcased_hello_world"
700+
get :render_and_redirect, to: "test#render_and_redirect"
701+
get :render_call_to_partial_with_layout, to: "test#render_call_to_partial_with_layout"
702+
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"
703+
get :render_custom_code, to: "test#render_custom_code"
704+
get :render_file_as_string_with_locals, to: "test#render_file_as_string_with_locals"
705+
get :render_file_from_template, to: "test#render_file_from_template"
706+
get :render_file_not_using_full_path, to: "test#render_file_not_using_full_path"
707+
get :render_file_not_using_full_path_with_dot_in_path, to: "test#render_file_not_using_full_path_with_dot_in_path"
708+
get :render_file_using_pathname, to: "test#render_file_using_pathname"
709+
get :render_file_with_instance_variables, to: "test#render_file_with_instance_variables"
710+
get :render_file_with_locals, to: "test#render_file_with_locals"
711+
get :render_hello_world, to: "test#render_hello_world"
712+
get :render_hello_world_from_variable, to: "test#render_hello_world_from_variable"
713+
get :render_hello_world_with_forward_slash, to: "test#render_hello_world_with_forward_slash"
714+
get :render_implicit_html_template_from_xhr_request, to: "test#render_implicit_html_template_from_xhr_request"
715+
get :render_implicit_js_template_without_layout, to: "test#render_implicit_js_template_without_layout"
716+
get :render_line_offset, to: "test#render_line_offset"
717+
get :render_nothing_with_appendix, to: "test#render_nothing_with_appendix"
718+
get :render_template_in_top_directory, to: "test#render_template_in_top_directory"
719+
get :render_template_in_top_directory_with_slash, to: "test#render_template_in_top_directory_with_slash"
720+
get :render_template_within_a_template_with_other_format, to: "test#render_template_within_a_template_with_other_format"
721+
get :render_text_hello_world, to: "test#render_text_hello_world"
722+
get :render_text_hello_world_with_layout, to: "test#render_text_hello_world_with_layout"
723+
get :render_text_with_assigns, to: "test#render_text_with_assigns"
724+
get :render_text_with_false, to: "test#render_text_with_false"
725+
get :render_text_with_nil, to: "test#render_text_with_nil"
726+
get :render_text_with_resource, to: "test#render_text_with_resource"
727+
get :render_to_string_and_render, to: "test#render_to_string_and_render"
728+
get :render_to_string_and_render_with_different_formats, to: "test#render_to_string_and_render_with_different_formats"
729+
get :render_to_string_test, to: "test#render_to_string_test"
730+
get :render_to_string_with_assigns, to: "test#render_to_string_with_assigns"
731+
get :render_to_string_with_caught_exception, to: "test#render_to_string_with_caught_exception"
732+
get :render_to_string_with_exception, to: "test#render_to_string_with_exception"
733+
get :render_to_string_with_inline_and_render, to: "test#render_to_string_with_inline_and_render"
734+
get :render_to_string_with_partial, to: "test#render_to_string_with_partial"
735+
get :render_to_string_with_template_and_html_partial, to: "test#render_to_string_with_template_and_html_partial"
736+
get :render_using_layout_around_block, to: "test#render_using_layout_around_block"
737+
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"
738+
get :render_with_assigns_option, to: "test#render_with_assigns_option"
739+
get :render_with_explicit_escaped_template, to: "test#render_with_explicit_escaped_template"
740+
get :render_with_explicit_string_template, to: "test#render_with_explicit_string_template"
741+
get :render_with_explicit_template, to: "test#render_with_explicit_template"
742+
get :render_with_explicit_template_with_locals, to: "test#render_with_explicit_template_with_locals"
743+
get :render_with_explicit_unescaped_template, to: "test#render_with_explicit_unescaped_template"
744+
get :render_with_filters, to: "test#render_with_filters"
745+
get :render_xml_hello, to: "test#render_xml_hello"
746+
get :render_xml_hello_as_string_template, to: "test#render_xml_hello_as_string_template"
747+
get :rendering_nothing_on_layout, to: "test#rendering_nothing_on_layout"
748+
get :rendering_with_conflicting_local_vars, to: "test#rendering_with_conflicting_local_vars"
749+
get :rendering_without_layout, to: "test#rendering_without_layout"
750+
get :yield_content_for, to: "test#yield_content_for"
751+
end
752+
635753
def setup
636754
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
637755
# a more accurate simulation of what happens in "real life".

actionview/test/actionpack/controller/view_paths_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ def hello_world; render(template: "test/hello_world"); end
2424
end
2525
end
2626

27+
with_routes do
28+
get :hello_world, to: "test#hello_world"
29+
get :hello_world_at_request_time, to: "test#hello_world_at_request_time"
30+
end
31+
2732
def setup
2833
@controller = TestController.new
2934
@request = ActionController::TestRequest.create(@controller.class)
3035
@response = ActionDispatch::TestResponse.new
3136
@paths = TestController.view_paths
37+
super
3238
end
3339

3440
def teardown
@@ -109,6 +115,10 @@ def test_view_paths_override
109115

110116
def test_view_paths_override_for_layouts_in_controllers_with_a_module
111117
@controller = Test::SubController.new
118+
with_routes do
119+
get :hello_world, to: "view_load_paths_test/test/sub#hello_world"
120+
end
121+
112122
Test::SubController.view_paths = [ "#{FIXTURE_LOAD_PATH}/override", FIXTURE_LOAD_PATH, "#{FIXTURE_LOAD_PATH}/override2" ]
113123
get :hello_world
114124
assert_response :success

actionview/test/active_record_unit.rb

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ def require_fixture_models
7474
class ActiveRecordTestCase < ActionController::TestCase
7575
include ActiveRecord::TestFixtures
7676

77+
def self.tests(controller)
78+
super
79+
if defined? controller::ROUTES
80+
include Module.new {
81+
define_method(:setup) do
82+
super()
83+
@routes = controller::ROUTES
84+
end
85+
}
86+
end
87+
end
88+
7789
# Set our fixture path
7890
if ActiveRecordTestConnector.able_to_connect
7991
self.fixture_path = [FIXTURE_LOAD_PATH]

0 commit comments

Comments
 (0)