Fix transient tests failures

This commit is contained in:
Rodrigo Ra 2015-06-25 15:13:11 -03:00
parent 03ac94b9b4
commit 7412c8d1c8
3 changed files with 27 additions and 19 deletions

View File

@ -22,5 +22,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rails", ">= 4.0" spec.add_development_dependency "rails", ">= 4.0"
spec.add_development_dependency "bundler", "~> 1.6" spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "timecop", ">= 0.7"
spec.add_development_dependency "rake" spec.add_development_dependency "rake"
end end

View File

@ -1,3 +1,4 @@
require 'test_helper' require 'test_helper'
module ActionController module ActionController
@ -56,7 +57,7 @@ module ActionController
end end
def update_and_render_object_with_cache_enabled def update_and_render_object_with_cache_enabled
@post.updated_at = DateTime.now @post.updated_at = Time.now
generate_cached_serializer(@post) generate_cached_serializer(@post)
render json: @post render json: @post
@ -112,7 +113,7 @@ module ActionController
generate_cached_serializer(like) generate_cached_serializer(like)
like.likable = comment2 like.likable = comment2
like.time = DateTime.now.to_s like.time = Time.now.to_s
render json: like render json: like
end end
@ -224,9 +225,6 @@ module ActionController
end end
def test_render_with_cache_enable def test_render_with_cache_enable
ActionController::Base.cache_store.clear
get :render_object_with_cache_enabled
expected = { expected = {
id: 1, id: 1,
title: 'New Post', title: 'New Post',
@ -246,11 +244,16 @@ module ActionController
} }
} }
ActionController::Base.cache_store.clear
Timecop.freeze(Time.now) do
get :render_object_with_cache_enabled
assert_equal 'application/json', @response.content_type assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body assert_equal expected.to_json, @response.body
get :render_changed_object_with_cache_enabled get :render_changed_object_with_cache_enabled
assert_not_equal expected.to_json, @response.body assert_equal expected.to_json, @response.body
end
ActionController::Base.cache_store.clear ActionController::Base.cache_store.clear
get :render_changed_object_with_cache_enabled get :render_changed_object_with_cache_enabled
@ -306,12 +309,14 @@ module ActionController
def test_render_fragment_changed_object_with_relationship def test_render_fragment_changed_object_with_relationship
ActionController::Base.cache_store.clear ActionController::Base.cache_store.clear
Timecop.freeze(Time.now) do
get :render_fragment_changed_object_with_relationship get :render_fragment_changed_object_with_relationship
response = JSON.parse(@response.body) response = JSON.parse(@response.body)
expected_return = { expected_return = {
"id"=>1, "id"=>1,
"time"=>DateTime.now.to_s, "time"=>Time.now.to_s,
"likeable" => { "likeable" => {
"id"=>1, "id"=>1,
"body"=>"ZOMG A COMMENT" "body"=>"ZOMG A COMMENT"
@ -321,6 +326,7 @@ module ActionController
assert_equal 'application/json', @response.content_type assert_equal 'application/json', @response.content_type
assert_equal expected_return, response assert_equal expected_return, response
end end
end
def test_cache_expiration_on_update def test_cache_expiration_on_update
ActionController::Base.cache_store.clear ActionController::Base.cache_store.clear

View File

@ -1,5 +1,6 @@
require 'bundler/setup' require 'bundler/setup'
require 'timecop'
require 'rails' require 'rails'
require 'action_controller' require 'action_controller'
require 'action_controller/test_case' require 'action_controller/test_case'