@@ -171,6 +171,20 @@ def test_renders_button_to_component
171171 ActionController ::Base . allow_forgery_protection = old_value
172172 end
173173
174+ def test_renders_button_to_component_with_strict_helpers
175+ with_strict_helpers_config ( true ) do
176+ old_value = ActionController ::Base . allow_forgery_protection
177+ ActionController ::Base . allow_forgery_protection = true
178+
179+ render_inline ( ButtonToComponent . new ) { "foo" }
180+
181+ assert_selector ( "form[class='button_to'][action='/'][method='post']" )
182+ assert_selector ( "input[type='hidden'][name='authenticity_token']" , visible : false )
183+
184+ ActionController ::Base . allow_forgery_protection = old_value
185+ end
186+ end
187+
174188 def test_renders_component_with_variant
175189 with_variant :phone do
176190 render_inline ( VariantsComponent . new )
@@ -329,6 +343,22 @@ def test_renders_component_with_asset_url
329343 assert_match ( %r{http://assets.example.com/assets/application-\w +.css} , render_inline ( component ) . text )
330344 end
331345
346+ def test_renders_component_with_asset_url_with_strict_helpers
347+ with_strict_helpers_config ( true ) do
348+ component = AssetComponent . new
349+ assert_match ( %r{http://assets.example.com/assets/application-\w +.css} , render_inline ( component ) . text )
350+
351+ component . config . asset_host = nil
352+ assert_match ( %r{/assets/application-\w +.css} , render_inline ( component ) . text )
353+
354+ component . config . asset_host = "http://assets.example.com"
355+ assert_match ( %r{http://assets.example.com/assets/application-\w +.css} , render_inline ( component ) . text )
356+
357+ component . config . asset_host = "assets.example.com"
358+ assert_match ( %r{http://assets.example.com/assets/application-\w +.css} , render_inline ( component ) . text )
359+ end
360+ end
361+
332362 def test_template_changes_are_not_reflected_if_cache_is_not_cleared
333363 render_inline ( MyComponent . new )
334364
@@ -757,6 +787,14 @@ def test_renders_component_using_rails_config
757787 assert_text ( "http://assets.example.com" )
758788 end
759789
790+ def test_renders_component_using_rails_config_with_strict_helpers
791+ with_strict_helpers_config ( true ) do
792+ render_inline ( RailsConfigComponent . new )
793+
794+ assert_text ( "http://assets.example.com" )
795+ end
796+ end
797+
760798 def test_inherited_component_inherits_template
761799 render_inline ( InheritedTemplateComponent . new )
762800
@@ -1109,8 +1147,24 @@ def test_content_security_policy_nonce
11091147 assert_selector ( "script" , text : "\n //<![CDATA[\n \" alert('hello')\" \n \n //]]>\n " , visible : :hidden )
11101148 end
11111149
1150+ def test_content_security_policy_nonce_with_strict_helpers
1151+ with_strict_helpers_config ( true ) do
1152+ render_inline ( ContentSecurityPolicyNonceComponent . new )
1153+
1154+ assert_selector ( "script" , text : "\n //<![CDATA[\n \" alert('hello')\" \n \n //]]>\n " , visible : :hidden )
1155+ end
1156+ end
1157+
11121158 def test_use_helper
11131159 render_inline ( UseHelpersComponent . new )
11141160 assert_selector ".helper__message" , text : "Hello helper method"
11151161 end
1162+
1163+ def test_strict_helpers
1164+ with_strict_helpers_config ( true ) do
1165+ assert_raises ViewComponent ::StrictHelperError do
1166+ render_inline ( HelpersProxyComponent . new )
1167+ end
1168+ end
1169+ end
11161170end
0 commit comments