Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transient tests failures #970

Merged
merged 1 commit into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurko Any thoughts on this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I had suggested it to avoid time related issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have concerns about timecop?

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