Skip to content

Commit

Permalink
Fix transient tests failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigora committed Jun 25, 2015
1 parent f67fd97 commit b247886
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ if version == "master"
else
gem "rails", "~> #{version}.0"
end

group :test do
gem "timecop"
end
41 changes: 23 additions & 18 deletions test/action_controller/serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,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 @@ -225,11 +222,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(DateTime.now) do
get :render_object_with_cache_enabled

get :render_changed_object_with_cache_enabled
assert_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 @@ -285,21 +287,24 @@ 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,
"post" => {
Timecop.freeze(DateTime.now) do
get :render_fragment_changed_object_with_relationship
response = JSON.parse(@response.body)

expected_return = {
"id"=>1,
"title"=>"New Post",
"body"=>"Body"
"time"=>DateTime.now.to_s,
"post" => {
"id"=>1,
"title"=>"New Post",
"body"=>"Body"
}
}
}

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 b247886

Please sign in to comment.