5
5
CACHE_DIR = 'test_cache'
6
6
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
7
7
FILE_STORE_PATH = File . join ( File . dirname ( __FILE__ ) , '/../temp/' , CACHE_DIR )
8
+
9
+ class CachingMetalController < ActionController ::Metal
10
+ abstract!
11
+
12
+ include ActionController ::Caching
13
+
14
+ self . page_cache_directory = FILE_STORE_PATH
15
+ self . cache_store = :file_store , FILE_STORE_PATH
16
+ end
17
+
18
+ class PageCachingMetalTestController < CachingMetalController
19
+ caches_page :ok
20
+
21
+ def ok
22
+ self . response_body = 'ok'
23
+ end
24
+ end
25
+
26
+ class PageCachingMetalTest < ActionController ::TestCase
27
+ tests PageCachingMetalTestController
28
+
29
+ def setup
30
+ FileUtils . rm_rf ( File . dirname ( FILE_STORE_PATH ) )
31
+ FileUtils . mkdir_p ( FILE_STORE_PATH )
32
+ end
33
+
34
+ def teardown
35
+ FileUtils . rm_rf ( File . dirname ( FILE_STORE_PATH ) )
36
+ end
37
+
38
+ def test_should_cache_get_with_ok_status
39
+ get :ok
40
+ assert_response :ok
41
+ assert File . exist? ( "#{ FILE_STORE_PATH } /page_caching_metal_test/ok.html" ) , 'get with ok status should have been cached'
42
+ end
43
+ end
44
+
8
45
ActionController ::Base . page_cache_directory = FILE_STORE_PATH
9
46
10
47
class CachingController < ActionController ::Base
@@ -862,7 +899,7 @@ def test_fragment_caching_in_partials
862
899
get :html_fragment_cached_with_partial
863
900
assert_response :success
864
901
assert_match ( /Old fragment caching in a partial/ , @response . body )
865
-
902
+
866
903
assert_match ( "Old fragment caching in a partial" ,
867
904
@store . read ( "views/test.host/functional_caching/html_fragment_cached_with_partial/#{ template_digest ( "functional_caching/_partial" , "html" ) } " ) )
868
905
end
@@ -872,7 +909,7 @@ def test_render_inline_before_fragment_caching
872
909
assert_response :success
873
910
assert_match ( /Some inline content/ , @response . body )
874
911
assert_match ( /Some cached content/ , @response . body )
875
- assert_match ( "Some cached content" ,
912
+ assert_match ( "Some cached content" ,
876
913
@store . read ( "views/test.host/functional_caching/inline_fragment_cached/#{ template_digest ( "functional_caching/inline_fragment_cached" , "html" ) } " ) )
877
914
end
878
915
@@ -883,7 +920,7 @@ def test_html_formatted_fragment_caching
883
920
884
921
assert_equal expected_body , @response . body
885
922
886
- assert_equal "<p>ERB</p>" ,
923
+ assert_equal "<p>ERB</p>" ,
887
924
@store . read ( "views/test.host/functional_caching/formatted_fragment_cached/#{ template_digest ( "functional_caching/formatted_fragment_cached" , "html" ) } " )
888
925
end
889
926
@@ -897,7 +934,7 @@ def test_xml_formatted_fragment_caching
897
934
assert_equal " <p>Builder</p>\n " ,
898
935
@store . read ( "views/test.host/functional_caching/formatted_fragment_cached/#{ template_digest ( "functional_caching/formatted_fragment_cached" , "xml" ) } " )
899
936
end
900
-
937
+
901
938
private
902
939
def template_digest ( name , format )
903
940
ActionView ::Digestor . digest ( name , format , @controller . lookup_context )
@@ -949,5 +986,5 @@ def test_safe_buffer
949
986
cache_helper . send :fragment_for , 'Test fragment name' , 'Test fragment' , &Proc . new { nil }
950
987
end
951
988
end
952
-
953
989
end
990
+
0 commit comments