@@ -42,6 +42,14 @@ def empty_action_with_template
4242 end
4343end
4444
45+ module Namespaced
46+ class ImplicitRenderTestController < ActionController ::Base
47+ def hello_world
48+ fresh_when ( etag : 'abc' )
49+ end
50+ end
51+ end
52+
4553class TestController < ActionController ::Base
4654 protect_from_forgery
4755
@@ -258,6 +266,19 @@ def determine_layout
258266 end
259267end
260268
269+ module TemplateModificationHelper
270+ private
271+ def modify_template ( name )
272+ path = File . expand_path ( "../../fixtures/#{ name } .erb" , __FILE__ )
273+ original = File . read ( path )
274+ File . write ( path , "#{ original } Modified!" )
275+ ActionView ::LookupContext ::DetailsKey . clear
276+ yield
277+ ensure
278+ File . write ( path , original )
279+ end
280+ end
281+
261282class MetalTestController < ActionController ::Metal
262283 include AbstractController ::Rendering
263284 include ActionView ::Rendering
@@ -487,6 +508,7 @@ def test_last_modified_works_with_less_than_too
487508
488509class EtagRenderTest < ActionController ::TestCase
489510 tests TestControllerWithExtraEtags
511+ include TemplateModificationHelper
490512
491513 def test_strong_etag
492514 @request . if_none_match = strong_etag ( [ 'strong' , 'ab' , :cde , [ :f ] ] )
@@ -535,7 +557,7 @@ def test_etag_reflects_template_digest
535557 get :with_template
536558 assert_response :not_modified
537559
538- modify_template ( : hello_world) do
560+ modify_template ( "test/ hello_world" ) do
539561 request . if_none_match = etag
540562 get :with_template
541563 assert_response :ok
@@ -552,7 +574,7 @@ def test_etag_reflects_implicit_template_digest
552574 get :with_implicit_template
553575 assert_response :not_modified
554576
555- modify_template ( : with_implicit_template) do
577+ modify_template ( "test/ with_implicit_template" ) do
556578 request . if_none_match = etag
557579 get :with_implicit_template
558580 assert_response :ok
@@ -568,16 +590,28 @@ def weak_etag(record)
568590 def strong_etag ( record )
569591 %("#{ Digest ::MD5 . hexdigest ( ActiveSupport ::Cache . expand_cache_key ( record ) ) } ")
570592 end
593+ end
571594
572- def modify_template ( name )
573- path = File . expand_path ( "../../fixtures/test/#{ name } .erb" , __FILE__ )
574- original = File . read ( path )
575- File . write ( path , "#{ original } Modified!" )
576- ActionView ::LookupContext ::DetailsKey . clear
577- yield
578- ensure
579- File . write ( path , original )
595+ class NamespacedEtagRenderTest < ActionController ::TestCase
596+ tests Namespaced ::ImplicitRenderTestController
597+ include TemplateModificationHelper
598+
599+ def test_etag_reflects_template_digest
600+ get :hello_world
601+ assert_response :ok
602+ assert_not_nil etag = @response . etag
603+
604+ request . if_none_match = etag
605+ get :hello_world
606+ assert_response :not_modified
607+
608+ modify_template ( "namespaced/implicit_render_test/hello_world" ) do
609+ request . if_none_match = etag
610+ get :hello_world
611+ assert_response :ok
612+ assert_not_equal etag , @response . etag
580613 end
614+ end
581615end
582616
583617class MetalRenderTest < ActionController ::TestCase
0 commit comments