1
+
1
2
require 'test_helper'
2
3
3
4
module ActionController
@@ -56,7 +57,7 @@ def render_json_array_object_without_serializer
56
57
end
57
58
58
59
def update_and_render_object_with_cache_enabled
59
- @post . updated_at = DateTime . now
60
+ @post . updated_at = Time . now
60
61
61
62
generate_cached_serializer ( @post )
62
63
render json : @post
@@ -112,7 +113,7 @@ def render_fragment_changed_object_with_relationship
112
113
113
114
generate_cached_serializer ( like )
114
115
like . likable = comment2
115
- like . time = DateTime . now . to_s
116
+ like . time = Time . now . to_s
116
117
117
118
render json : like
118
119
end
@@ -224,9 +225,6 @@ def test_render_array_using_implicit_serializer_and_meta
224
225
end
225
226
226
227
def test_render_with_cache_enable
227
- ActionController ::Base . cache_store . clear
228
- get :render_object_with_cache_enabled
229
-
230
228
expected = {
231
229
id : 1 ,
232
230
title : 'New Post' ,
@@ -246,11 +244,16 @@ def test_render_with_cache_enable
246
244
}
247
245
}
248
246
249
- assert_equal 'application/json' , @response . content_type
250
- assert_equal expected . to_json , @response . body
247
+ ActionController ::Base . cache_store . clear
248
+ Timecop . freeze ( Time . now ) do
249
+ get :render_object_with_cache_enabled
251
250
252
- get :render_changed_object_with_cache_enabled
253
- assert_not_equal expected . to_json , @response . body
251
+ assert_equal 'application/json' , @response . content_type
252
+ assert_equal expected . to_json , @response . body
253
+
254
+ get :render_changed_object_with_cache_enabled
255
+ assert_equal expected . to_json , @response . body
256
+ end
254
257
255
258
ActionController ::Base . cache_store . clear
256
259
get :render_changed_object_with_cache_enabled
@@ -306,20 +309,23 @@ def test_render_with_fragment_except_cache_enable
306
309
307
310
def test_render_fragment_changed_object_with_relationship
308
311
ActionController ::Base . cache_store . clear
309
- get :render_fragment_changed_object_with_relationship
310
- response = JSON . parse ( @response . body )
311
312
312
- expected_return = {
313
- "id" => 1 ,
314
- "time" => DateTime . now . to_s ,
315
- "likeable" => {
313
+ Timecop . freeze ( Time . now ) do
314
+ get :render_fragment_changed_object_with_relationship
315
+ response = JSON . parse ( @response . body )
316
+
317
+ expected_return = {
316
318
"id" => 1 ,
317
- "body" => "ZOMG A COMMENT"
319
+ "time" => Time . now . to_s ,
320
+ "likeable" => {
321
+ "id" => 1 ,
322
+ "body" => "ZOMG A COMMENT"
323
+ }
318
324
}
319
- }
320
325
321
- assert_equal 'application/json' , @response . content_type
322
- assert_equal expected_return , response
326
+ assert_equal 'application/json' , @response . content_type
327
+ assert_equal expected_return , response
328
+ end
323
329
end
324
330
325
331
def test_cache_expiration_on_update
0 commit comments