mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Take in to account optional arguments when deprecating
Refs: rails/jbuilder#452
This commit is contained in:
parent
cc2d614e63
commit
0fa0107d2d
2 changed files with 10 additions and 1 deletions
|
@ -43,7 +43,7 @@ module ActionView #:nodoc:
|
|||
handler.method(:call).parameters
|
||||
end
|
||||
|
||||
unless params.find_all { |type, _| type == :req }.length >= 2
|
||||
unless params.find_all { |type, _| type == :req || type == :opt }.length >= 2
|
||||
ActiveSupport::Deprecation.warn <<~eowarn
|
||||
Single arity template handlers are deprecated. Template handlers must
|
||||
now accept two parameters, the view object and the source for the view object.
|
||||
|
|
|
@ -471,6 +471,15 @@ module RenderTestCases
|
|||
ActionView::Template.unregister_template_handler :ruby_handler
|
||||
end
|
||||
|
||||
def test_optional_second_arg_works_without_deprecation
|
||||
assert_not_deprecated do
|
||||
ActionView::Template.register_template_handler :ruby_handler, ->(view, source = nil) { source }
|
||||
end
|
||||
assert_equal "3", @view.render(inline: "(1 + 2).to_s", type: :ruby_handler)
|
||||
ensure
|
||||
ActionView::Template.unregister_template_handler :ruby_handler
|
||||
end
|
||||
|
||||
def test_render_inline_with_compilable_custom_type
|
||||
ActionView::Template.register_template_handler :foo, CustomHandler
|
||||
assert_equal 'source: "Hello, World!"', @view.render(inline: "Hello, World!", type: :foo)
|
||||
|
|
Loading…
Reference in a new issue