From c5ebea5bda3a00b32abe46de979e3f36777610ed Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 5 Sep 2016 00:43:29 +0200 Subject: [PATCH] Fix randomly failing interacted_at spec also remove some unnecessary Timecop.return closes #7060 --- features/step_definitions/comment_steps.rb | 1 - spec/lib/evil_query_spec.rb | 2 -- spec/models/comment_spec.rb | 10 +++++----- spec/models/like_spec.rb | 7 ++++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb index 38f1428ad..d8993b175 100644 --- a/features/step_definitions/comment_steps.rb +++ b/features/step_definitions/comment_steps.rb @@ -31,5 +31,4 @@ Given /^"([^"]*)" has commented a lot on "([^"]*)"$/ do |email, post_text| user.comment!(post, "Comment #{n}") end end - Timecop.return end diff --git a/spec/lib/evil_query_spec.rb b/spec/lib/evil_query_spec.rb index d263fbc68..fed0c55ed 100644 --- a/spec/lib/evil_query_spec.rb +++ b/spec/lib/evil_query_spec.rb @@ -72,8 +72,6 @@ describe EvilQuery::Participation do alice.comment!(@status_messageE, "party") end - - Timecop.return end let(:posts) {EvilQuery::Participation.new(alice).posts} diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 276df3761..583217755 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -68,11 +68,11 @@ describe Comment, type: :model do describe "interacted_at" do it "sets the interacted at of the parent to the created at of the comment" do - Timecop.travel(Time.zone.now + 1.minute) - - comment = Comment::Generator.new(alice, status_bob, "why so formal?").build - comment.save - expect(status_bob.reload.interacted_at.to_i).to eq(comment.created_at.to_i) + Timecop.freeze(Time.zone.now + 1.minute) do + comment = Comment::Generator.new(alice, status_bob, "why so formal?").build + comment.save + expect(status_bob.reload.interacted_at.to_i).to eq(comment.created_at.to_i) + end end end diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb index bec11931d..a7899355a 100644 --- a/spec/models/like_spec.rb +++ b/spec/models/like_spec.rb @@ -47,9 +47,10 @@ describe Like, type: :model do it "doesn't change the interacted at timestamp of the parent" do interacted_at = status.reload.interacted_at.to_i - Timecop.travel(Time.zone.now + 1.minute) - Like::Generator.new(alice, status).build.save - expect(status.reload.interacted_at.to_i).to eq(interacted_at) + Timecop.travel(Time.zone.now + 1.minute) do + Like::Generator.new(alice, status).build.save + expect(status.reload.interacted_at.to_i).to eq(interacted_at) + end end end