@@ -72,34 +72,38 @@ def test_associations_separately_cache
72
72
assert_equal ( nil , ActionController ::Base . cache_store . fetch ( @post . cache_key ) )
73
73
assert_equal ( nil , ActionController ::Base . cache_store . fetch ( @comment . cache_key ) )
74
74
75
- post = render_object_with_cache ( @post )
75
+ Timecop . freeze ( Time . now ) do
76
+ post = render_object_with_cache ( @post )
76
77
77
- assert_equal ( @post_serializer . attributes , ActionController ::Base . cache_store . fetch ( @post . cache_key ) )
78
- assert_equal ( @comment_serializer . attributes , ActionController ::Base . cache_store . fetch ( @comment . cache_key ) )
78
+ assert_equal ( @post_serializer . attributes , ActionController ::Base . cache_store . fetch ( @post . cache_key ) )
79
+ assert_equal ( @comment_serializer . attributes , ActionController ::Base . cache_store . fetch ( @comment . cache_key ) )
80
+ end
79
81
end
80
82
81
83
def test_associations_cache_when_updated
82
84
# Clean the Cache
83
85
ActionController ::Base . cache_store . clear
84
86
85
- # Generate a new Cache of Post object and each objects related to it.
86
- render_object_with_cache ( @post )
87
+ Timecop . freeze ( Time . now ) do
88
+ # Generate a new Cache of Post object and each objects related to it.
89
+ render_object_with_cache ( @post )
87
90
88
- # Check if it cached the objects separately
89
- assert_equal ( @post_serializer . attributes , ActionController ::Base . cache_store . fetch ( @post . cache_key ) )
90
- assert_equal ( @comment_serializer . attributes , ActionController ::Base . cache_store . fetch ( @comment . cache_key ) )
91
+ # Check if it cached the objects separately
92
+ assert_equal ( @post_serializer . attributes , ActionController ::Base . cache_store . fetch ( @post . cache_key ) )
93
+ assert_equal ( @comment_serializer . attributes , ActionController ::Base . cache_store . fetch ( @comment . cache_key ) )
91
94
92
- # Simulating update on comments relationship with Post
93
- new_comment = Comment . new ( id : 2 , body : 'ZOMG A NEW COMMENT' )
94
- new_comment_serializer = CommentSerializer . new ( new_comment )
95
- @post . comments = [ new_comment ]
95
+ # Simulating update on comments relationship with Post
96
+ new_comment = Comment . new ( id : 2 , body : 'ZOMG A NEW COMMENT' )
97
+ new_comment_serializer = CommentSerializer . new ( new_comment )
98
+ @post . comments = [ new_comment ]
96
99
97
- # Ask for the serialized object
98
- render_object_with_cache ( @post )
100
+ # Ask for the serialized object
101
+ render_object_with_cache ( @post )
99
102
100
- # Check if the the new comment was cached
101
- assert_equal ( new_comment_serializer . attributes , ActionController ::Base . cache_store . fetch ( new_comment . cache_key ) )
102
- assert_equal ( @post_serializer . attributes , ActionController ::Base . cache_store . fetch ( @post . cache_key ) )
103
+ # Check if the the new comment was cached
104
+ assert_equal ( new_comment_serializer . attributes , ActionController ::Base . cache_store . fetch ( new_comment . cache_key ) )
105
+ assert_equal ( @post_serializer . attributes , ActionController ::Base . cache_store . fetch ( @post . cache_key ) )
106
+ end
103
107
end
104
108
105
109
def test_fragment_fetch_with_virtual_associations
0 commit comments