Skip to content

Commit 954e4c5

Browse files
committed
Merge pull request #1003 from Rodrigora/fix-transient-test-failures
Fix transient test failures
2 parents 7757376 + 851d121 commit 954e4c5

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

test/serializers/cache_test.rb

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,38 @@ def test_associations_separately_cache
7272
assert_equal(nil, ActionController::Base.cache_store.fetch(@post.cache_key))
7373
assert_equal(nil, ActionController::Base.cache_store.fetch(@comment.cache_key))
7474

75-
post = render_object_with_cache(@post)
75+
Timecop.freeze(Time.now) do
76+
post = render_object_with_cache(@post)
7677

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
7981
end
8082

8183
def test_associations_cache_when_updated
8284
# Clean the Cache
8385
ActionController::Base.cache_store.clear
8486

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)
8790

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))
9194

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]
9699

97-
# Ask for the serialized object
98-
render_object_with_cache(@post)
100+
# Ask for the serialized object
101+
render_object_with_cache(@post)
99102

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
103107
end
104108

105109
def test_fragment_fetch_with_virtual_associations

0 commit comments

Comments
 (0)