1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove deprecated support to passing relative paths to render file:

This commit is contained in:
Rafael Mendonça França 2020-05-05 15:58:55 -04:00
parent 4d77dcad09
commit d52d773946
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
16 changed files with 74 additions and 195 deletions

View file

@ -7,78 +7,25 @@ module RenderFile
self.view_paths = __dir__
def index
render file: File.expand_path("../../fixtures/test/hello_world", __dir__)
end
def with_instance_variables
@secret = "in the sauce"
render file: File.expand_path("../../fixtures/test/render_file_with_ivar", __dir__)
end
def relative_path
@secret = "in the sauce"
render file: "../actionpack/test/fixtures/test/render_file_with_ivar"
end
def relative_path_with_dot
@secret = "in the sauce"
render file: "../actionpack/test/fixtures/test/dot.directory/render_file_with_ivar"
render file: File.expand_path("../../fixtures/test/hello_world.erb", __dir__)
end
def pathname
@secret = "in the sauce"
render file: Pathname.new(__dir__).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar])
end
def with_locals
path = File.expand_path("../../fixtures/test/render_file_with_locals", __dir__)
render file: path, locals: { secret: "in the sauce" }
render file: Pathname.new(__dir__).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb])
end
end
class TestBasic < Rack::TestCase
testing RenderFile::BasicController
test "rendering simple template" do
assert_deprecated do
get :index
end
test "rendering simple file" do
get :index
assert_response "Hello world!"
end
test "rendering template with ivar" do
assert_deprecated do
get :with_instance_variables
end
assert_response "The secret is in the sauce\n"
end
test "rendering a relative path" do
assert_deprecated do
get :relative_path
end
assert_response "The secret is in the sauce\n"
end
test "rendering a relative path with dot" do
assert_deprecated do
get :relative_path_with_dot
end
assert_response "The secret is in the sauce\n"
end
test "rendering a Pathname" do
assert_deprecated do
get :pathname
end
assert_response "The secret is in the sauce\n"
end
test "rendering file with locals" do
assert_deprecated do
get :with_locals
end
assert_response "The secret is in the sauce\n"
get :pathname
assert_response "The secret is <%= @secret %>\n"
end
end
end

View file

@ -343,10 +343,8 @@ class ExpiresInRenderTest < ActionController::TestCase
def test_dynamic_render_with_file
assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__))
assert_deprecated do
assert_raises ActionView::MissingTemplate do
get :dynamic_render_with_file, params: { id: '../\\../test/abstract_unit.rb' }
end
assert_raises ArgumentError do
get :dynamic_render_with_file, params: { id: '../\\../test/abstract_unit.rb' }
end
end
@ -373,10 +371,8 @@ class ExpiresInRenderTest < ActionController::TestCase
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
assert_raises ArgumentError do
get :dynamic_render_permit, params: { id: { file: '../\\../test/abstract_unit.rb' } }
end
end

View file

@ -41,7 +41,7 @@ class RendererTest < ActiveSupport::TestCase
test "rendering with an instance renderer" do
renderer = ApplicationController.renderer.new
content = assert_deprecated { renderer.render file: "test/hello_world" }
content = renderer.render template: "test/hello_world"
assert_equal "Hello world!", content
end

View file

@ -1,3 +1,7 @@
* Remove deprecated support to passing relative paths to `render file:`.
*Rafael Mendonça França*
* Remove support to template handlers that don't accept two arguments.
*Rafael Mendonça França*

View file

@ -26,8 +26,7 @@ module ActionView
if File.exist?(options[:file])
Template::RawFile.new(options[:file])
else
ActiveSupport::Deprecation.warn "render file: should be given the absolute path to a file"
@lookup_context.with_fallbacks.find_template(options[:file], nil, false, keys, @details)
raise ArgumentError, "`render file:` should be given the absolute path to a file. '#{options[:file]}' was given instead"
end
elsif options.key?(:inline)
handler = Template.handler_for_extension(options[:type] || "erb")

View file

@ -18,17 +18,12 @@ module AbstractController
"renderer/string.erb" => "With String",
"renderer/symbol.erb" => "With Symbol",
"string/with_path.erb" => "With String With Path",
"some/file.erb" => "With File"
)]
def template
render template: "template"
end
def file
ActiveSupport::Deprecation.silence { render file: "some/file" }
end
def inline
render inline: "With <%= :Inline %>"
end
@ -64,11 +59,6 @@ module AbstractController
assert_equal "With Template", @controller.response_body
end
def test_render_file
assert_equal "With File", @controller.process(:file)
assert_equal "With File", @controller.response_body
end
def test_render_inline
assert_equal "With Inline", @controller.process(:inline)
assert_equal "With Inline", @controller.response_body

View file

@ -54,7 +54,7 @@ class TestController < ActionController::Base
end
def hello_world_file
render file: File.expand_path("../../fixtures/actionpack/hello", __dir__), formats: [:html]
render file: File.expand_path("../../fixtures/actionpack/hello.html", __dir__)
end
# :ported:
@ -121,41 +121,31 @@ class TestController < ActionController::Base
end
# :ported:
def render_file_with_instance_variables
def render_template_with_instance_variables
@secret = "in the sauce"
path = File.expand_path("../../fixtures/test/render_file_with_ivar", __dir__)
render file: path
render template: "test/render_template_with_ivar"
end
# :ported:
def render_file_not_using_full_path
@secret = "in the sauce"
render file: "test/render_file_with_ivar"
render file: "test/render_template_with_ivar"
end
def render_file_not_using_full_path_with_dot_in_path
def render_template_with_dot_in_path
@secret = "in the sauce"
render file: "test/dot.directory/render_file_with_ivar"
render template: "test/dot.directory/render_template_with_ivar"
end
def render_file_using_pathname
@secret = "in the sauce"
render file: Pathname.new(__dir__).join("..", "..", "fixtures", "test", "dot.directory", "render_file_with_ivar")
render file: Pathname.new(__dir__).join("..", "..", "fixtures", "test", "dot.directory", "render_template_with_ivar.erb")
end
def render_file_from_template
@secret = "in the sauce"
@path = File.expand_path("../../fixtures/test/render_file_with_ivar", __dir__)
@path = File.expand_path("../../fixtures/test/render_template_with_ivar.erb", __dir__)
end
def render_file_with_locals
path = File.expand_path("../../fixtures/test/render_file_with_locals", __dir__)
render file: path, locals: { secret: "in the sauce" }
end
def render_file_as_string_with_locals
path = File.expand_path("../../fixtures/test/render_file_with_locals", __dir__)
render file: path, locals: { secret: "in the sauce" }
def render_template_with_locals
render template: "test/render_template_with_locals", locals: { secret: "in the sauce" }
end
def accessing_request_in_template
@ -336,7 +326,7 @@ class TestController < ActionController::Base
end
def render_to_string_with_exception
render_to_string file: "exception that will not be caught - this will certainly not work"
render_to_string template: "exception that will not be caught - this will certainly not work"
end
def render_to_string_with_caught_exception
@ -372,7 +362,7 @@ class TestController < ActionController::Base
# :ported:
def render_with_explicit_template_with_locals
render template: "test/render_file_with_locals", locals: { secret: "area51" }
render template: "test/render_template_with_locals", locals: { secret: "area51" }
end
# :ported:
@ -705,13 +695,12 @@ class RenderTest < ActionController::TestCase
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_template_with_dot_in_path, to: "test#render_template_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_template_with_instance_variables, to: "test#render_template_with_instance_variables"
get :render_template_with_locals, to: "test#render_template_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"
@ -870,66 +859,45 @@ class RenderTest < ActionController::TestCase
end
# :ported:
def test_render_file_with_instance_variables
assert_deprecated do
get :render_file_with_instance_variables
end
def test_render_template_with_instance_variables
get :render_template_with_instance_variables
assert_equal "The secret is in the sauce\n", @response.body
end
def test_render_file
assert_deprecated do
get :hello_world_file
end
get :hello_world_file
assert_equal "Hello world!", @response.body
end
# :ported:
def test_render_file_not_using_full_path
assert_deprecated do
assert_raise(ArgumentError) do
get :render_file_not_using_full_path
end
assert_equal "The secret is in the sauce\n", @response.body
end
# :ported:
def test_render_file_not_using_full_path_with_dot_in_path
assert_deprecated do
get :render_file_not_using_full_path_with_dot_in_path
end
def test_render_template_with_dot_in_path
get :render_template_with_dot_in_path
assert_equal "The secret is in the sauce\n", @response.body
end
# :ported:
def test_render_file_using_pathname
assert_deprecated do
get :render_file_using_pathname
end
assert_equal "The secret is in the sauce\n", @response.body
get :render_file_using_pathname
assert_equal "The secret is <%= @secret %>\n", @response.body
end
# :ported:
def test_render_file_with_locals
assert_deprecated do
get :render_file_with_locals
end
assert_equal "The secret is in the sauce\n", @response.body
end
# :ported:
def test_render_file_as_string_with_locals
assert_deprecated do
get :render_file_as_string_with_locals
end
def test_render_template_with_locals
get :render_template_with_locals
assert_equal "The secret is in the sauce\n", @response.body
end
# :assessed:
def test_render_file_from_template
assert_deprecated do
get :render_file_from_template
end
assert_equal "The secret is in the sauce\n", @response.body
get :render_file_from_template
assert_equal "The secret is &lt;%= @secret %&gt;\n", @response.body
end
# :ported:
@ -1148,18 +1116,14 @@ class RenderTest < ActionController::TestCase
end
def test_bad_render_to_string_still_throws_exception
assert_deprecated do
assert_raise(ActionView::MissingTemplate) do
get :render_to_string_with_exception
end
assert_raise(ActionView::MissingTemplate) do
get :render_to_string_with_exception
end
end
def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
assert_deprecated do
assert_nothing_raised do
get :render_to_string_with_caught_exception
end
assert_nothing_raised do
get :render_to_string_with_caught_exception
end
assert_equal "i'm before the render", @controller.instance_variable_get(:@before)
assert_equal "i'm after the render", @controller.instance_variable_get(:@after)

View file

@ -73,16 +73,16 @@ module RenderTestCases
end
def test_render_file
assert_equal "Hello world!", assert_deprecated { @view.render(file: "test/hello_world") }
template_path = File.expand_path("../fixtures/test/hello_world.erb", __dir__)
assert_equal "Hello world!", @view.render(file: template_path)
end
def test_render_file_with_full_path_no_extension
template_path = File.expand_path("../fixtures/test/hello_world", __dir__)
assert_raise(ArgumentError) { @view.render(file: template_path) }
end
# Test if :formats, :locale etc. options are passed correctly to the resolvers.
def test_render_file_with_format
assert_match "<h1>No Comment</h1>", assert_deprecated { @view.render(file: "comments/empty", formats: [:html]) }
assert_match "<error>No Comment</error>", assert_deprecated { @view.render(file: "comments/empty", formats: [:xml]) }
assert_match "<error>No Comment</error>", assert_deprecated { @view.render(file: "comments/empty", formats: :xml) }
end
def test_render_template_with_format
assert_match "<h1>No Comment</h1>", @view.render(template: "comments/empty", formats: [:html])
assert_match "<error>No Comment</error>", @view.render(template: "comments/empty", formats: [:xml])
@ -112,26 +112,18 @@ module RenderTestCases
assert_includes(e.message, "Missing partial /_missing with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}.")
end
def test_render_file_with_locale
assert_equal "<h1>Kein Kommentar</h1>", assert_deprecated { @view.render(file: "comments/empty", locale: [:de]) }
assert_equal "<h1>Kein Kommentar</h1>", assert_deprecated { @view.render(file: "comments/empty", locale: :de) }
end
def test_render_template_with_locale
assert_equal "<h1>Kein Kommentar</h1>", @view.render(template: "comments/empty", locale: [:de])
assert_equal "<h1>Kein Kommentar</h1>", @view.render(template: "comments/empty", locale: :de)
end
def test_render_template_with_variants
assert_equal "<h1>No Comment</h1>\n", @view.render(template: "comments/empty", variants: :grid)
end
def test_render_file_with_handlers
assert_equal "<h1>No Comment</h1>\n", assert_deprecated { @view.render(file: "comments/empty", handlers: [:builder]) }
assert_equal "<h1>No Comment</h1>\n", assert_deprecated { @view.render(file: "comments/empty", handlers: :builder) }
end
def test_render_template_with_handlers
assert_equal "<h1>No Comment</h1>\n", @view.render(template: "comments/empty", handlers: [:builder])
assert_equal "<h1>No Comment</h1>\n", @view.render(template: "comments/empty", handlers: :builder)
end
def test_render_raw_template_with_handlers
@ -175,27 +167,17 @@ module RenderTestCases
assert_equal "Elastica", @view.render(template: "/shared")
end
def test_render_file_with_full_path_no_extension
template_path = File.expand_path("../fixtures/test/hello_world", __dir__)
assert_equal "Hello world!", assert_deprecated { @view.render(file: template_path) }
def test_render_template_with_instance_variable
assert_equal "The secret is in the sauce\n", @view.render(template: "test/render_template_with_ivar")
end
def test_render_file_with_full_path
template_path = File.expand_path("../fixtures/test/hello_world.erb", __dir__)
assert_equal "Hello world!", @view.render(file: template_path)
end
def test_render_file_with_instance_variables
assert_equal "The secret is in the sauce\n", assert_deprecated { @view.render(file: "test/render_file_with_ivar") }
end
def test_render_file_with_locals
def test_render_template_with_locals
locals = { secret: "in the sauce" }
assert_equal "The secret is in the sauce\n", assert_deprecated { @view.render(file: "test/render_file_with_locals", locals: locals) }
assert_equal "The secret is in the sauce\n", @view.render(template: "test/render_template_with_locals", locals: locals)
end
def test_render_file_not_using_full_path_with_dot_in_path
assert_equal "The secret is in the sauce\n", assert_deprecated { @view.render(file: "test/dot.directory/render_file_with_ivar") }
def test_render_template_with_dot_in_path
assert_equal "The secret is in the sauce\n", @view.render(template: "test/dot.directory/render_template_with_ivar")
end
def test_render_partial_from_default
@ -309,6 +291,15 @@ module RenderTestCases
assert_equal " 10: <p>Tenth paragraph</p>", error_lines.third
end
def test_render_template_with_errors
e = assert_raises(ActionView::Template::Error) { assert_deprecated { @view.render(template: "test/_raise") } }
assert_match %r!method.*doesnt_exist!, e.message
assert_equal "", e.sub_template_message
assert_equal "1", e.line_number
assert_equal "1: <%= doesnt_exist %>", e.annotated_source_code[0].strip
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
end
def test_render_sub_template_with_errors
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/sub_template_raise") }
assert_match %r!method.*doesnt_exist!, e.message
@ -317,15 +308,6 @@ module RenderTestCases
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
end
def test_render_file_with_errors
e = assert_raises(ActionView::Template::Error) { assert_deprecated { @view.render(file: File.expand_path("test/_raise", FIXTURE_LOAD_PATH)) } }
assert_match %r!method.*doesnt_exist!, e.message
assert_equal "", e.sub_template_message
assert_equal "1", e.line_number
assert_equal "1: <%= doesnt_exist %>", e.annotated_source_code[0].strip
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
end
def test_undefined_method_error_references_named_class
e = assert_raises(ActionView::Template::Error) { @view.render(inline: "<%= undefined %>") }
assert_match(/`undefined' for #<ActionView::Base:0x[0-9a-f]+>/, e.message)

View file

@ -47,12 +47,7 @@ class FiberedTest < SetupFiberedBase
end
def test_render_file
assert_equal "Hello world!", assert_deprecated { buffered_render(file: "test/hello_world") }
end
def test_render_file_with_locals
locals = { secret: "in the sauce" }
assert_equal "The secret is in the sauce\n", assert_deprecated { buffered_render(file: "test/render_file_with_locals", locals: locals) }
assert_equal "Hello world!", buffered_render(file: File.absolute_path("../fixtures/test/hello_world.erb", __dir__))
end
def test_render_partial

View file

@ -55,6 +55,8 @@ Please refer to the [Changelog][action-pack] for detailed changes.
### Removals
* Remove deprecated support to passing relative paths to `render file:`.
* Remove support to template handlers that don't accept two arguments.
* Remove deprecated `ActionDispatch::Http::ParameterFilter`.