Skip to content

Commit

Permalink
Merge pull request #1003 from Rodrigora/fix-transient-test-failures
Browse files Browse the repository at this point in the history
Fix transient test failures
  • Loading branch information
joaomdmoura committed Jul 14, 2015
2 parents 7757376 + 851d121 commit 954e4c5
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions test/serializers/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,38 @@ def test_associations_separately_cache
assert_equal(nil, ActionController::Base.cache_store.fetch(@post.cache_key))
assert_equal(nil, ActionController::Base.cache_store.fetch(@comment.cache_key))

post = render_object_with_cache(@post)
Timecop.freeze(Time.now) do
post = render_object_with_cache(@post)

assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
assert_equal(@comment_serializer.attributes, ActionController::Base.cache_store.fetch(@comment.cache_key))
assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
assert_equal(@comment_serializer.attributes, ActionController::Base.cache_store.fetch(@comment.cache_key))
end
end

def test_associations_cache_when_updated
# Clean the Cache
ActionController::Base.cache_store.clear

# Generate a new Cache of Post object and each objects related to it.
render_object_with_cache(@post)
Timecop.freeze(Time.now) do
# Generate a new Cache of Post object and each objects related to it.
render_object_with_cache(@post)

# Check if it cached the objects separately
assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
assert_equal(@comment_serializer.attributes, ActionController::Base.cache_store.fetch(@comment.cache_key))
# Check if it cached the objects separately
assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
assert_equal(@comment_serializer.attributes, ActionController::Base.cache_store.fetch(@comment.cache_key))

# Simulating update on comments relationship with Post
new_comment = Comment.new(id: 2, body: 'ZOMG A NEW COMMENT')
new_comment_serializer = CommentSerializer.new(new_comment)
@post.comments = [new_comment]
# Simulating update on comments relationship with Post
new_comment = Comment.new(id: 2, body: 'ZOMG A NEW COMMENT')
new_comment_serializer = CommentSerializer.new(new_comment)
@post.comments = [new_comment]

# Ask for the serialized object
render_object_with_cache(@post)
# Ask for the serialized object
render_object_with_cache(@post)

# Check if the the new comment was cached
assert_equal(new_comment_serializer.attributes, ActionController::Base.cache_store.fetch(new_comment.cache_key))
assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
# Check if the the new comment was cached
assert_equal(new_comment_serializer.attributes, ActionController::Base.cache_store.fetch(new_comment.cache_key))
assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
end
end

def test_fragment_fetch_with_virtual_associations
Expand Down

0 comments on commit 954e4c5

Please sign in to comment.