From e3130f1b8405e2da3a5bafd05cffc74cbd8c21fc Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 29 Oct 2020 13:49:30 -0700 Subject: [PATCH] Revert "Raise when calling render with invalid options" --- .../lib/action_controller/metal/rendering.rb | 4 +--- actionpack/test/controller/render_test.rb | 9 +++++++++ actionpack/test/controller/renderers_test.rb | 4 ++-- .../action_view/renderer/abstract_renderer.rb | 6 +----- .../action_view/renderer/partial_renderer.rb | 7 ------- .../action_view/renderer/template_renderer.rb | 7 ------- actionview/lib/action_view/rendering.rb | 2 +- .../abstract/abstract_controller_test.rb | 8 ++++---- actionview/test/template/render_test.rb | 18 ++++-------------- 9 files changed, 22 insertions(+), 43 deletions(-) diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index d089ebbfe05..f0029f30d98 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -115,9 +115,7 @@ module ActionController # Process controller specific options, as status, content-type and location. def _process_options(options) - status = options.delete(:status) - content_type = options.delete(:content_type) - location = options.delete(:location) + status, content_type, location = options.values_at(:status, :content_type, :location) self.status = status if status self.content_type = content_type if content_type diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index d426d844cc6..474abff2341 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -371,6 +371,15 @@ class ExpiresInRenderTest < ActionController::TestCase end end + def test_permitted_dynamic_render_file_hash + assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__)) + assert_deprecated do + assert_raises ActionView::MissingTemplate do + get :dynamic_render_permit, params: { id: { file: '../\\../test/abstract_unit.rb' } } + end + end + end + def test_dynamic_render_file_hash assert_raises ArgumentError do get :dynamic_render, params: { id: { file: '../\\../test/abstract_unit.rb' } } diff --git a/actionpack/test/controller/renderers_test.rb b/actionpack/test/controller/renderers_test.rb index 209cf6d7c49..96cce664a4c 100644 --- a/actionpack/test/controller/renderers_test.rb +++ b/actionpack/test/controller/renderers_test.rb @@ -69,8 +69,8 @@ class RenderersTest < ActionController::TestCase ActionController.remove_renderer :simon end - def test_raises_argument_error_no_renderer - assert_raise ArgumentError do + def test_raises_missing_template_no_renderer + assert_raise ActionView::MissingTemplate do get :respond_to_mime, format: "csv" end assert_equal Mime[:csv], @response.media_type diff --git a/actionview/lib/action_view/renderer/abstract_renderer.rb b/actionview/lib/action_view/renderer/abstract_renderer.rb index ebfd0f43259..3e3fa098e05 100644 --- a/actionview/lib/action_view/renderer/abstract_renderer.rb +++ b/actionview/lib/action_view/renderer/abstract_renderer.rb @@ -158,7 +158,7 @@ module ActionView def extract_details(options) # :doc: details = nil - details_arguments.each do |key| + @lookup_context.registered_details.each do |key| value = options[key] if value @@ -168,10 +168,6 @@ module ActionView details || NO_DETAILS end - def details_arguments - @lookup_context.registered_details - end - def prepend_formats(formats) # :doc: formats = Array(formats) return if formats.empty? || @lookup_context.html_fallback_for_js diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index 0aca6964049..39d24bd4f87 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -256,13 +256,6 @@ module ActionView def initialize(lookup_context, options) super(lookup_context) - - options.assert_valid_keys( - :partial, :template, :renderable, :layout, - :locals, :collection, :object, :as, :cached, :spacer_template, - *details_arguments - ) - @options = options @locals = @options[:locals] || {} @details = extract_details(@options) diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb index 1ce7fd86a0c..ee159c08aaf 100644 --- a/actionview/lib/action_view/renderer/template_renderer.rb +++ b/actionview/lib/action_view/renderer/template_renderer.rb @@ -3,13 +3,6 @@ module ActionView class TemplateRenderer < AbstractRenderer #:nodoc: def render(context, options) - options.assert_valid_keys( - :body, :plain, :html, :file, :inline, :template, :renderable, - :layout, :locals, :prefixes, - :type, - *details_arguments - ) - @details = extract_details(options) template = determine_template(options) diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index 881bcbdd7a1..cecaee15d0a 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -165,7 +165,7 @@ module ActionView options[:prefixes] ||= _prefixes end - options[:template] ||= (options.delete(:action) || action_name).to_s + options[:template] ||= (options[:action] || action_name).to_s options end end diff --git a/actionview/test/actionpack/abstract/abstract_controller_test.rb b/actionview/test/actionpack/abstract/abstract_controller_test.rb index 868f32161d5..2de81596b5f 100644 --- a/actionview/test/actionpack/abstract/abstract_controller_test.rb +++ b/actionview/test/actionpack/abstract/abstract_controller_test.rb @@ -39,7 +39,7 @@ module AbstractController def render(options = {}) if options.is_a?(String) - options = { action: options } + options = { _template_name: options } end super end @@ -49,7 +49,7 @@ module AbstractController class Me2 < RenderingController def index - render "index" + render "index.erb" end def index_to_string @@ -58,7 +58,7 @@ module AbstractController def action_with_ivars @my_ivar = "Hello" - render "action_with_ivars" + render "action_with_ivars.erb" end def naked_render @@ -200,7 +200,7 @@ module AbstractController end def render_to_body(options = {}) - options[:layout] = options[:layout] || _default_layout({}) + options[:_layout] = options[:layout] || _default_layout({}) super end end diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 681a38d8f69..395891be987 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -68,16 +68,6 @@ module RenderTestCases assert_match(/You invoked render but did not give any of (.+) option\./, e.message) end - def test_render_throws_exception_when_given_partial_and_invalid_options - e = assert_raises(ArgumentError) { @view.render(template: "test/hello_world", invalid_option: true) } - assert_includes e.message, "Unknown key: :invalid_option" - end - - def test_render_throws_exception_when_given_template_and_invalid_options - e = assert_raises(ArgumentError) { @view.render(partial: "test/partial", invalid_option: true) } - assert_includes e.message, "Unknown key: :invalid_option" - end - def test_render_template assert_equal "Hello world!", @view.render(template: "test/hello_world") end @@ -749,7 +739,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase def test_render_utf8_template_with_magic_comment with_external_encoding Encoding::ASCII_8BIT do - result = @view.render(template: "test/utf8_magic", formats: [:html]) + result = @view.render(template: "test/utf8_magic", formats: [:html], layouts: "layouts/yield") assert_equal Encoding::UTF_8, result.encoding assert_equal "\nРусский \nтекст\n\nUTF-8\nUTF-8\nUTF-8\n", result end @@ -757,7 +747,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase def test_render_utf8_template_with_default_external_encoding with_external_encoding Encoding::UTF_8 do - result = @view.render(template: "test/utf8", formats: [:html]) + result = @view.render(template: "test/utf8", formats: [:html], layouts: "layouts/yield") assert_equal Encoding::UTF_8, result.encoding assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result end @@ -765,14 +755,14 @@ class LazyViewRenderTest < ActiveSupport::TestCase def test_render_utf8_template_with_incompatible_external_encoding with_external_encoding Encoding::SHIFT_JIS do - e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/utf8", formats: [:html], layout: "layouts/yield") } + e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/utf8", formats: [:html], layouts: "layouts/yield") } assert_match "Your template was not saved as valid Shift_JIS", e.cause.message end end def test_render_utf8_template_with_partial_with_incompatible_encoding with_external_encoding Encoding::SHIFT_JIS do - e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/utf8_magic_with_bare_partial", formats: [:html], layout: "layouts/yield") } + e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/utf8_magic_with_bare_partial", formats: [:html], layouts: "layouts/yield") } assert_match "Your template was not saved as valid Shift_JIS", e.cause.message end end