diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2018-09-24 14:49:26 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2018-09-24 15:39:15 -0700 |
commit | 4f96e739c215331562c09cd215536c35a85508fd (patch) | |
tree | 22ab11502954a40ce72f51efdfbc2f206a189a09 /actionview | |
parent | 0a829f7db10263c5bf5f8b4ee04ea92a05ecdd39 (diff) | |
download | rails-4f96e739c215331562c09cd215536c35a85508fd.tar.gz rails-4f96e739c215331562c09cd215536c35a85508fd.tar.bz2 rails-4f96e739c215331562c09cd215536c35a85508fd.zip |
Remove deprecated catch-all route in the AV tests
This commit removes a deprecated catch-all route in the AV tests. It
defines and includes the necessary routes for each test such that we
don't need the catch-all anymore.
This also helps push us toward #33970
Diffstat (limited to 'actionview')
17 files changed, 290 insertions, 78 deletions
diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index f20a66c2d2..f842e2c76d 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -65,43 +65,6 @@ module RenderERBUtils 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 @@ -132,10 +95,11 @@ class BasicController 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 @@ -151,13 +115,10 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase 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 @@ -165,30 +126,37 @@ 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 @@ -222,7 +190,6 @@ module ActionDispatch end class ActiveSupport::TestCase - include ActionDispatch::DrawOnce include ActiveSupport::Testing::MethodCallAssertions # Skips the current run on Rubinius using Minitest::Assertions#skip diff --git a/actionview/test/actionpack/controller/capture_test.rb b/actionview/test/actionpack/controller/capture_test.rb index 09309e5b6d..d02125bafa 100644 --- a/actionview/test/actionpack/controller/capture_test.rb +++ b/actionview/test/actionpack/controller/capture_test.rb @@ -37,6 +37,15 @@ end 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 diff --git a/actionview/test/actionpack/controller/layout_test.rb b/actionview/test/actionpack/controller/layout_test.rb index ff66ff2a1a..14acb737f9 100644 --- a/actionview/test/actionpack/controller/layout_test.rb +++ b/actionview/test/actionpack/controller/layout_test.rb @@ -48,6 +48,10 @@ end class LayoutAutoDiscoveryTest < ActionController::TestCase include TemplateHandlerHelper + with_routes do + get :hello, to: 'views#hello' + end + def setup super @request.host = "www.nextangle.com" @@ -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 @@ -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 } @@ -247,6 +260,10 @@ class LayoutStatusIsRendered < LayoutTest 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 @@ -260,6 +277,10 @@ unless Gem.win_platform? 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 diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb index 3e6b55a87e..204903c60c 100644 --- a/actionview/test/actionpack/controller/render_test.rb +++ b/actionview/test/actionpack/controller/render_test.rb @@ -632,6 +632,124 @@ end 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". diff --git a/actionview/test/actionpack/controller/view_paths_test.rb b/actionview/test/actionpack/controller/view_paths_test.rb index 45c662f0ce..7f3fe0fa08 100644 --- a/actionview/test/actionpack/controller/view_paths_test.rb +++ b/actionview/test/actionpack/controller/view_paths_test.rb @@ -24,11 +24,17 @@ class ViewLoadPathsTest < ActionController::TestCase 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 @@ -109,6 +115,10 @@ class ViewLoadPathsTest < ActionController::TestCase 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 diff --git a/actionview/test/active_record_unit.rb b/actionview/test/active_record_unit.rb index 7f48b515a0..e4ea6a426d 100644 --- a/actionview/test/active_record_unit.rb +++ b/actionview/test/active_record_unit.rb @@ -74,6 +74,18 @@ end 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] diff --git a/actionview/test/activerecord/controller_runtime_test.rb b/actionview/test/activerecord/controller_runtime_test.rb index 42b171ea07..7cbd3aaf89 100644 --- a/actionview/test/activerecord/controller_runtime_test.rb +++ b/actionview/test/activerecord/controller_runtime_test.rb @@ -39,6 +39,14 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase include ActiveSupport::LogSubscriber::TestHelper tests LogSubscriberController + with_routes do + get :show, to: "#{LogSubscriberController.controller_path}#show" + get :zero, to: "#{LogSubscriberController.controller_path}#zero" + get :db_after_render, to: "#{LogSubscriberController.controller_path}#db_after_render" + get :redirect, to: "#{LogSubscriberController.controller_path}#redirect" + post :create, to: "#{LogSubscriberController.controller_path}#create" + end + def setup @old_logger = ActionController::Base.logger super diff --git a/actionview/test/activerecord/form_helper_activerecord_test.rb b/actionview/test/activerecord/form_helper_activerecord_test.rb index 1472ee8def..22626de6cb 100644 --- a/actionview/test/activerecord/form_helper_activerecord_test.rb +++ b/actionview/test/activerecord/form_helper_activerecord_test.rb @@ -23,9 +23,12 @@ class FormHelperActiveRecordTest < ActionView::TestCase @developer.projects << @project @developer.save + super + @controller.singleton_class.include Routes.url_helpers end def teardown + super Project.delete(321) Developer.delete(123) end diff --git a/actionview/test/activerecord/polymorphic_routes_test.rb b/actionview/test/activerecord/polymorphic_routes_test.rb index 4b931f793f..724129a7d9 100644 --- a/actionview/test/activerecord/polymorphic_routes_test.rb +++ b/actionview/test/activerecord/polymorphic_routes_test.rb @@ -62,10 +62,14 @@ module Weblog end class PolymorphicRoutesTest < ActionController::TestCase - include SharedTestRoutes.url_helpers + Routes = ActionDispatch::Routing::RouteSet.new + Routes.draw { } + include Routes.url_helpers + default_url_options[:host] = "example.com" def setup + super @project = Project.new @task = Task.new @step = Step.new @@ -763,9 +767,11 @@ class DirectRoutesTest < ActionView::TestCase include Routes.url_helpers def setup + super @category = Category.new("1") @collection = Collection.new("2") @product = Product.new("3") + @controller.singleton_class.include Routes.url_helpers end def test_direct_routes diff --git a/actionview/test/activerecord/relation_cache_test.rb b/actionview/test/activerecord/relation_cache_test.rb index 56e17e67a8..a6befc3ee5 100644 --- a/actionview/test/activerecord/relation_cache_test.rb +++ b/actionview/test/activerecord/relation_cache_test.rb @@ -6,6 +6,7 @@ class RelationCacheTest < ActionView::TestCase tests ActionView::Helpers::CacheHelper def setup + super view_paths = ActionController::Base.view_paths lookup_context = ActionView::LookupContext.new(view_paths, {}, ["test"]) @view_renderer = ActionView::Renderer.new(lookup_context) diff --git a/actionview/test/activerecord/render_partial_with_record_identification_test.rb b/actionview/test/activerecord/render_partial_with_record_identification_test.rb index 3a698fa42e..2bb3cfeb5b 100644 --- a/actionview/test/activerecord/render_partial_with_record_identification_test.rb +++ b/actionview/test/activerecord/render_partial_with_record_identification_test.rb @@ -3,6 +3,16 @@ require "active_record_unit" class RenderPartialWithRecordIdentificationController < ActionController::Base + ROUTES = test_routes do + get :render_with_record_collection, to: "render_partial_with_record_identification#render_with_record_collection" + get :render_with_scope, to: "render_partial_with_record_identification#render_with_scope" + get :render_with_record, to: "render_partial_with_record_identification#render_with_record" + get :render_with_has_many_association, to: "render_partial_with_record_identification#render_with_has_many_association" + get :render_with_has_many_and_belongs_to_association, to: "render_partial_with_record_identification#render_with_has_many_and_belongs_to_association" + get :render_with_has_one_association, to: "render_partial_with_record_identification#render_with_has_one_association" + get :render_with_record_collection_and_spacer_template, to: "render_partial_with_record_identification#render_with_record_collection_and_spacer_template" + end + def render_with_has_many_and_belongs_to_association @developer = Developer.find(1) render partial: @developer.projects @@ -89,6 +99,11 @@ end module Fun class NestedController < ActionController::Base + ROUTES = test_routes do + get :render_with_record_in_nested_controller, to: "fun/nested#render_with_record_in_nested_controller" + get :render_with_record_collection_in_nested_controller, to: "fun/nested#render_with_record_collection_in_nested_controller" + end + def render_with_record_in_nested_controller render partial: Game.new("Pong") end @@ -100,6 +115,11 @@ module Fun module Serious class NestedDeeperController < ActionController::Base + ROUTES = test_routes do + get :render_with_record_in_deeper_nested_controller, to: "fun/serious/nested_deeper#render_with_record_in_deeper_nested_controller" + get :render_with_record_collection_in_deeper_nested_controller, to: "fun/serious/nested_deeper#render_with_record_collection_in_deeper_nested_controller" + end + def render_with_record_in_deeper_nested_controller render partial: Game.new("Chess") end diff --git a/actionview/test/template/erb/form_for_test.rb b/actionview/test/template/erb/form_for_test.rb index b6ecf003a5..b3a47e17a4 100644 --- a/actionview/test/template/erb/form_for_test.rb +++ b/actionview/test/template/erb/form_for_test.rb @@ -6,7 +6,11 @@ require "template/erb/helper" module ERBTest class TagHelperTest < BlockTestCase test "form_for works" do - output = render_content "form_for(:staticpage, :url => {:controller => 'blah', :action => 'update'})", "" + routes = ActionDispatch::Routing::RouteSet.new + routes.draw do + get "/blah/update", to: "blah#update" + end + output = render_content "form_for(:staticpage, :url => {:controller => 'blah', :action => 'update'})", "", routes assert_match %r{<form.*action="/blah/update".*method="post">.*</form>}, output end end diff --git a/actionview/test/template/erb/helper.rb b/actionview/test/template/erb/helper.rb index 57d6cb1be3..727cc3dcf2 100644 --- a/actionview/test/template/erb/helper.rb +++ b/actionview/test/template/erb/helper.rb @@ -3,7 +3,6 @@ module ERBTest class ViewContext include ActionView::Helpers::UrlHelper - include SharedTestRoutes.url_helpers include ActionView::Helpers::TagHelper include ActionView::Helpers::JavaScriptHelper include ActionView::Helpers::FormHelper @@ -14,9 +13,15 @@ module ERBTest end class BlockTestCase < ActiveSupport::TestCase - def render_content(start, inside) + def render_content(start, inside, routes = nil) + routes ||= ActionDispatch::Routing::RouteSet.new.tap do |rs| + rs.draw { } + end + context = Class.new(ViewContext) { + include routes.url_helpers + }.new template = block_helper(start, inside) - ActionView::Template::Handlers::ERB.erb_implementation.new(template).evaluate(ViewContext.new) + ActionView::Template::Handlers::ERB.erb_implementation.new(template).evaluate(context) end def block_helper(str, rest) diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index c30176349c..c807f81052 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -290,6 +290,7 @@ class FormWithActsLikeFormForTest < FormWithTest @post_delegator.title = "Hello World" @car = Car.new("#000FFF") + @controller.singleton_class.include Routes.url_helpers end Routes = ActionDispatch::Routing::RouteSet.new @@ -308,10 +309,6 @@ class FormWithActsLikeFormForTest < FormWithTest root to: "main#index" end - def _routes - Routes - end - include Routes.url_helpers def url_for(object) diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 38bb1e1d24..09da067495 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -140,6 +140,7 @@ class FormHelperTest < ActionView::TestCase @post_delegator.title = "Hello World" @car = Car.new("#000FFF") + @controller.singleton_class.include Routes.url_helpers end Routes = ActionDispatch::Routing::RouteSet.new diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index d98fd4f9a2..27f5a7cc3e 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -217,8 +217,14 @@ module ActionView test "is able to use routes" do controller.request.assign_parameters(@routes, "foo", "index", {}, "/foo", []) - assert_equal "/foo", url_for - assert_equal "/bar", url_for(controller: "bar") + with_routing do |set| + set.draw { + get :foo, to: "foo#index" + get :bar, to: "bar#index" + } + assert_equal "/foo", url_for + assert_equal "/bar", url_for(controller: "bar") + end end test "is able to use named routes" do @@ -244,6 +250,8 @@ module ActionView set.draw { mount app => "/foo", :as => "foo_app" } + singleton_class.include set.mounted_helpers + assert_equal "/foo/bar", foo_app.bar_path end end diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 9d91dbb72b..dd52b8b6a3 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -704,7 +704,7 @@ end class UrlHelperControllerTest < ActionController::TestCase class UrlHelperController < ActionController::Base - test_routes do + ROUTES = test_routes do get "url_helper_controller_test/url_helper/show/:id", to: "url_helper_controller_test/url_helper#show", as: :show @@ -768,6 +768,11 @@ class UrlHelperControllerTest < ActionController::TestCase helper_method :override_url_helper_path end + def setup + super + @routes = UrlHelperController::ROUTES + end + tests UrlHelperController def test_url_for_shows_only_path @@ -828,7 +833,7 @@ class UrlHelperControllerTest < ActionController::TestCase end class TasksController < ActionController::Base - test_routes do + ROUTES = test_routes do resources :tasks end @@ -850,6 +855,11 @@ end class LinkToUnlessCurrentWithControllerTest < ActionController::TestCase tests TasksController + def setup + super + @routes = TasksController::ROUTES + end + def test_link_to_unless_current_to_current get :index assert_equal "tasks\ntasks", @response.body @@ -882,7 +892,7 @@ class Session end class WorkshopsController < ActionController::Base - test_routes do + ROUTES = test_routes do resources :workshops do resources :sessions end @@ -905,7 +915,7 @@ class WorkshopsController < ActionController::Base end class SessionsController < ActionController::Base - test_routes do + ROUTES = test_routes do resources :workshops do resources :sessions end @@ -932,6 +942,11 @@ class SessionsController < ActionController::Base end class PolymorphicControllerTest < ActionController::TestCase + def setup + super + @routes = WorkshopsController::ROUTES + end + def test_new_resource @controller = WorkshopsController.new @@ -946,6 +961,20 @@ class PolymorphicControllerTest < ActionController::TestCase assert_equal %{/workshops/1\n<a href="/workshops/1">Workshop</a>}, @response.body end + def test_current_page_when_options_does_not_respond_to_to_hash + @controller = WorkshopsController.new + + get :edit, params: { id: 1 } + assert_equal "false", @response.body + end +end + +class PolymorphicSessionsControllerTest < ActionController::TestCase + def setup + super + @routes = SessionsController::ROUTES + end + def test_new_nested_resource @controller = SessionsController.new @@ -966,11 +995,4 @@ class PolymorphicControllerTest < ActionController::TestCase get :edit, params: { workshop_id: 1, id: 1, format: "json" } assert_equal %{/workshops/1/sessions/1.json\n<a href="/workshops/1/sessions/1.json">Session</a>}, @response.body end - - def test_current_page_when_options_does_not_respond_to_to_hash - @controller = WorkshopsController.new - - get :edit, params: { id: 1 } - assert_equal "false", @response.body - end end |