Skip to content

Commit

Permalink
Merge pull request #970 from Rodrigora/fix-test-race-conditions
Browse files Browse the repository at this point in the history
Fix transient tests failures
  • Loading branch information
joaomdmoura committed Jun 26, 2015
2 parents 03ac94b + 7412c8d commit 059409b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions active_model_serializers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "rails", ">= 4.0"
spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "timecop", ">= 0.7"
spec.add_development_dependency "rake"
end
44 changes: 25 additions & 19 deletions test/action_controller/serialization_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

require 'test_helper'

module ActionController
Expand Down Expand Up @@ -56,7 +57,7 @@ def render_json_array_object_without_serializer
end

def update_and_render_object_with_cache_enabled
@post.updated_at = DateTime.now
@post.updated_at = Time.now

generate_cached_serializer(@post)
render json: @post
Expand Down Expand Up @@ -112,7 +113,7 @@ def render_fragment_changed_object_with_relationship

generate_cached_serializer(like)
like.likable = comment2
like.time = DateTime.now.to_s
like.time = Time.now.to_s

render json: like
end
Expand Down Expand Up @@ -224,9 +225,6 @@ def test_render_array_using_implicit_serializer_and_meta
end

def test_render_with_cache_enable
ActionController::Base.cache_store.clear
get :render_object_with_cache_enabled

expected = {
id: 1,
title: 'New Post',
Expand All @@ -246,11 +244,16 @@ def test_render_with_cache_enable
}
}

assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body
ActionController::Base.cache_store.clear
Timecop.freeze(Time.now) do
get :render_object_with_cache_enabled

get :render_changed_object_with_cache_enabled
assert_not_equal expected.to_json, @response.body
assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body

get :render_changed_object_with_cache_enabled
assert_equal expected.to_json, @response.body
end

ActionController::Base.cache_store.clear
get :render_changed_object_with_cache_enabled
Expand Down Expand Up @@ -306,20 +309,23 @@ def test_render_with_fragment_except_cache_enable

def test_render_fragment_changed_object_with_relationship
ActionController::Base.cache_store.clear
get :render_fragment_changed_object_with_relationship
response = JSON.parse(@response.body)

expected_return = {
"id"=>1,
"time"=>DateTime.now.to_s,
"likeable" => {
Timecop.freeze(Time.now) do
get :render_fragment_changed_object_with_relationship
response = JSON.parse(@response.body)

expected_return = {
"id"=>1,
"body"=>"ZOMG A COMMENT"
"time"=>Time.now.to_s,
"likeable" => {
"id"=>1,
"body"=>"ZOMG A COMMENT"
}
}
}

assert_equal 'application/json', @response.content_type
assert_equal expected_return, response
assert_equal 'application/json', @response.content_type
assert_equal expected_return, response
end
end

def test_cache_expiration_on_update
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'bundler/setup'

require 'timecop'
require 'rails'
require 'action_controller'
require 'action_controller/test_case'
Expand Down

0 comments on commit 059409b

Please sign in to comment.