diff options
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/base.rb | 14 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/csp_helper.rb | 6 | ||||
-rw-r--r-- | actionview/test/template/csp_helper_test.rb | 4 | ||||
-rw-r--r-- | actionview/test/template/render_test.rb | 7 |
4 files changed, 24 insertions, 7 deletions
diff --git a/actionview/lib/action_view/base.rb b/actionview/lib/action_view/base.rb index 56e0e3275c..556a5ee502 100644 --- a/actionview/lib/action_view/base.rb +++ b/actionview/lib/action_view/base.rb @@ -275,11 +275,15 @@ module ActionView #:nodoc: end def compiled_method_container - raise NotImplementedError, <<~msg - Subclasses of ActionView::Base must implement `compiled_method_container` - or use the class method `with_empty_template_cache` for constructing - an ActionView::Base subclass that has an empty cache. - msg + if self.class == ActionView::Base + ActiveSupport::Deprecation.warn <<~eowarn + ActionView::Base instances must implement `compiled_method_container` + or use the class method `with_empty_template_cache` for constructing + an ActionView::Base instances that has an empty cache. + eowarn + end + + self.class end def in_context(options, locals) diff --git a/actionview/lib/action_view/helpers/csp_helper.rb b/actionview/lib/action_view/helpers/csp_helper.rb index e2e065c218..4415018845 100644 --- a/actionview/lib/action_view/helpers/csp_helper.rb +++ b/actionview/lib/action_view/helpers/csp_helper.rb @@ -14,9 +14,11 @@ module ActionView # This is used by the Rails UJS helper to create dynamically # loaded inline <script> elements. # - def csp_meta_tag + def csp_meta_tag(**options) if content_security_policy? - tag("meta", name: "csp-nonce", content: content_security_policy_nonce) + options[:name] = "csp-nonce" + options[:content] = content_security_policy_nonce + tag("meta", options) end end end diff --git a/actionview/test/template/csp_helper_test.rb b/actionview/test/template/csp_helper_test.rb index 8bad25ba7d..1b7fd4665f 100644 --- a/actionview/test/template/csp_helper_test.rb +++ b/actionview/test/template/csp_helper_test.rb @@ -16,6 +16,10 @@ class CspHelperWithCspEnabledTest < ActionView::TestCase def test_csp_meta_tag assert_equal "<meta name=\"csp-nonce\" content=\"iyhD0Yc0W+c=\" />", csp_meta_tag end + + def test_csp_meta_tag_with_options + assert_equal "<meta property=\"csp-nonce\" name=\"csp-nonce\" content=\"iyhD0Yc0W+c=\" />", csp_meta_tag(property: "csp-nonce") + end end class CspHelperWithCspDisabledTest < ActionView::TestCase diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 5c00596b41..5068e00c7d 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -367,6 +367,13 @@ module RenderTestCases end end + def test_without_compiled_method_container_is_deprecated + view = ActionView::Base.with_view_paths(ActionController::Base.view_paths) + assert_deprecated("ActionView::Base instances must implement `compiled_method_container`") do + assert_equal "Hello world!", view.render(file: "test/hello_world") + end + end + def test_render_partial_without_object_does_not_put_partial_name_to_local_assigns assert_equal "false", @view.render(partial: "test/partial_name_in_local_assigns") end |