aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2019-02-04 13:21:18 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2019-02-04 13:21:24 -0800
commit0fa0107d2d87f751c6768fa8a0991149134de2df (patch)
tree38ac264dbc70dbf34ae0ad89d47b85d98c75e4bd
parentcc2d614e6310337a9d34ede3e67d634d84561cde (diff)
downloadrails-0fa0107d2d87f751c6768fa8a0991149134de2df.tar.gz
rails-0fa0107d2d87f751c6768fa8a0991149134de2df.tar.bz2
rails-0fa0107d2d87f751c6768fa8a0991149134de2df.zip
Take in to account optional arguments when deprecating
Refs: rails/jbuilder#452
-rw-r--r--actionview/lib/action_view/template/handlers.rb2
-rw-r--r--actionview/test/template/render_test.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/actionview/lib/action_view/template/handlers.rb b/actionview/lib/action_view/template/handlers.rb
index f2a2341b8e..ddaac7a100 100644
--- a/actionview/lib/action_view/template/handlers.rb
+++ b/actionview/lib/action_view/template/handlers.rb
@@ -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.
diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb
index f5d251da20..f89d087c34 100644
--- a/actionview/test/template/render_test.rb
+++ b/actionview/test/template/render_test.rb
@@ -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)