-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix transient tests failures #970
Conversation
|
||
group :test do | ||
gem "timecop" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, any gem required for test to run should be in the gemspec as a development_dependency. your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It too bad we can't just use https://github.com/rails/rails/blob/4-1-stable/activesupport/lib/active_support/testing/time_helpers.rb since they aren't in Rails 4.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bf4 Ok. You're right. I'll move to gemspec file. I've found this article after your comment: http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
Another option is remove timecop
dependency and use fixed datetimes like: Date.new(2015,6,6)
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that would work because it wouldn't affect the updated_at
timestamps that Rails adds on save. You'd have to call model.update_column(:updated_at, Time.new(2015,6,6))
after the object was created ( see https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/persistence.rb#L271-L291 ) or whatever the id is in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but in these tests we don't use ActiveRecord inherited classes in tests.
The updated_at
method is created "by hand" : https://github.com/rails-api/active_model_serializers/blob/master/test%2Ffixtures%2Fporo.rb#L21
And, the problem here is that it assumes that all code is executed in the same second. That's why sometimes it fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call
Thanks! |
@@ -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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
LGTM, @Rodrigora could you please squash the commits and rebase it? 😁 |
d08e21c
to
7412c8d
Compare
@joaomdmoura Looks like @Rodrigora squashed 'em |
@joaomdmoura, done. 👍 |
Great team work here ppl! Congratz! I'm merging it. |
Fix transient tests failures
These changes fix the issue #961.
I added the timecop gem as suggested by @kurko.
Freezing the time in the two tests should fix the transient failures.