Skip to content

Commit ec645d0

Browse files
authored
Merge pull request rails#40485 from rails/revert-39497-render_with_invalid_options
Revert "Raise when calling render with invalid options"
2 parents 00e7066 + e3130f1 commit ec645d0

File tree

9 files changed

+22
-43
lines changed

9 files changed

+22
-43
lines changed

actionpack/lib/action_controller/metal/rendering.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def _normalize_text(options)
115115

116116
# Process controller specific options, as status, content-type and location.
117117
def _process_options(options)
118-
status = options.delete(:status)
119-
content_type = options.delete(:content_type)
120-
location = options.delete(:location)
118+
status, content_type, location = options.values_at(:status, :content_type, :location)
121119

122120
self.status = status if status
123121
self.content_type = content_type if content_type

actionpack/test/controller/render_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,15 @@ def test_dynamic_render
371371
end
372372
end
373373

374+
def test_permitted_dynamic_render_file_hash
375+
assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__))
376+
assert_deprecated do
377+
assert_raises ActionView::MissingTemplate do
378+
get :dynamic_render_permit, params: { id: { file: '../\\../test/abstract_unit.rb' } }
379+
end
380+
end
381+
end
382+
374383
def test_dynamic_render_file_hash
375384
assert_raises ArgumentError do
376385
get :dynamic_render, params: { id: { file: '../\\../test/abstract_unit.rb' } }

actionpack/test/controller/renderers_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def test_using_custom_render_option
6969
ActionController.remove_renderer :simon
7070
end
7171

72-
def test_raises_argument_error_no_renderer
73-
assert_raise ArgumentError do
72+
def test_raises_missing_template_no_renderer
73+
assert_raise ActionView::MissingTemplate do
7474
get :respond_to_mime, format: "csv"
7575
end
7676
assert_equal Mime[:csv], @response.media_type

actionview/lib/action_view/renderer/abstract_renderer.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def format
158158

159159
def extract_details(options) # :doc:
160160
details = nil
161-
details_arguments.each do |key|
161+
@lookup_context.registered_details.each do |key|
162162
value = options[key]
163163

164164
if value
@@ -168,10 +168,6 @@ def extract_details(options) # :doc:
168168
details || NO_DETAILS
169169
end
170170

171-
def details_arguments
172-
@lookup_context.registered_details
173-
end
174-
175171
def prepend_formats(formats) # :doc:
176172
formats = Array(formats)
177173
return if formats.empty? || @lookup_context.html_fallback_for_js

actionview/lib/action_view/renderer/partial_renderer.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,6 @@ class PartialRenderer < AbstractRenderer
256256

257257
def initialize(lookup_context, options)
258258
super(lookup_context)
259-
260-
options.assert_valid_keys(
261-
:partial, :template, :renderable, :layout,
262-
:locals, :collection, :object, :as, :cached, :spacer_template,
263-
*details_arguments
264-
)
265-
266259
@options = options
267260
@locals = @options[:locals] || {}
268261
@details = extract_details(@options)

actionview/lib/action_view/renderer/template_renderer.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
module ActionView
44
class TemplateRenderer < AbstractRenderer #:nodoc:
55
def render(context, options)
6-
options.assert_valid_keys(
7-
:body, :plain, :html, :file, :inline, :template, :renderable,
8-
:layout, :locals, :prefixes,
9-
:type,
10-
*details_arguments
11-
)
12-
136
@details = extract_details(options)
147
template = determine_template(options)
158

actionview/lib/action_view/rendering.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def _normalize_options(options)
165165
options[:prefixes] ||= _prefixes
166166
end
167167

168-
options[:template] ||= (options.delete(:action) || action_name).to_s
168+
options[:template] ||= (options[:action] || action_name).to_s
169169
options
170170
end
171171
end

actionview/test/actionpack/abstract/abstract_controller_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _prefixes
3939

4040
def render(options = {})
4141
if options.is_a?(String)
42-
options = { action: options }
42+
options = { _template_name: options }
4343
end
4444
super
4545
end
@@ -49,7 +49,7 @@ def render(options = {})
4949

5050
class Me2 < RenderingController
5151
def index
52-
render "index"
52+
render "index.erb"
5353
end
5454

5555
def index_to_string
@@ -58,7 +58,7 @@ def index_to_string
5858

5959
def action_with_ivars
6060
@my_ivar = "Hello"
61-
render "action_with_ivars"
61+
render "action_with_ivars.erb"
6262
end
6363

6464
def naked_render
@@ -200,7 +200,7 @@ def self.layout(formats)
200200
end
201201

202202
def render_to_body(options = {})
203-
options[:layout] = options[:layout] || _default_layout({})
203+
options[:_layout] = options[:layout] || _default_layout({})
204204
super
205205
end
206206
end

actionview/test/template/render_test.rb

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ def test_render_without_options
6868
assert_match(/You invoked render but did not give any of (.+) option\./, e.message)
6969
end
7070

71-
def test_render_throws_exception_when_given_partial_and_invalid_options
72-
e = assert_raises(ArgumentError) { @view.render(template: "test/hello_world", invalid_option: true) }
73-
assert_includes e.message, "Unknown key: :invalid_option"
74-
end
75-
76-
def test_render_throws_exception_when_given_template_and_invalid_options
77-
e = assert_raises(ArgumentError) { @view.render(partial: "test/partial", invalid_option: true) }
78-
assert_includes e.message, "Unknown key: :invalid_option"
79-
end
80-
8171
def test_render_template
8272
assert_equal "Hello world!", @view.render(template: "test/hello_world")
8373
end
@@ -749,30 +739,30 @@ def setup
749739

750740
def test_render_utf8_template_with_magic_comment
751741
with_external_encoding Encoding::ASCII_8BIT do
752-
result = @view.render(template: "test/utf8_magic", formats: [:html])
742+
result = @view.render(template: "test/utf8_magic", formats: [:html], layouts: "layouts/yield")
753743
assert_equal Encoding::UTF_8, result.encoding
754744
assert_equal "\nРусский \nтекст\n\nUTF-8\nUTF-8\nUTF-8\n", result
755745
end
756746
end
757747

758748
def test_render_utf8_template_with_default_external_encoding
759749
with_external_encoding Encoding::UTF_8 do
760-
result = @view.render(template: "test/utf8", formats: [:html])
750+
result = @view.render(template: "test/utf8", formats: [:html], layouts: "layouts/yield")
761751
assert_equal Encoding::UTF_8, result.encoding
762752
assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result
763753
end
764754
end
765755

766756
def test_render_utf8_template_with_incompatible_external_encoding
767757
with_external_encoding Encoding::SHIFT_JIS do
768-
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/utf8", formats: [:html], layout: "layouts/yield") }
758+
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/utf8", formats: [:html], layouts: "layouts/yield") }
769759
assert_match "Your template was not saved as valid Shift_JIS", e.cause.message
770760
end
771761
end
772762

773763
def test_render_utf8_template_with_partial_with_incompatible_encoding
774764
with_external_encoding Encoding::SHIFT_JIS do
775-
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/utf8_magic_with_bare_partial", formats: [:html], layout: "layouts/yield") }
765+
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/utf8_magic_with_bare_partial", formats: [:html], layouts: "layouts/yield") }
776766
assert_match "Your template was not saved as valid Shift_JIS", e.cause.message
777767
end
778768
end

0 commit comments

Comments
 (0)