From db6ed4772ca4395a0394ab5f1090ee7ac6b6af71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 29 Apr 2019 11:58:25 +0200 Subject: [PATCH] Update `travel_to` usage In Rails 5.1, calling `travel_to` inside another `travel_to` block will result in a RuntimeError: > Calling `travel_to` with a block, when we have previously already made > a call to `travel_to`, can lead to confusing time stubbing. --- spec/features/polls/voter_spec.rb | 18 +++++++----------- spec/models/poll/stats_spec.rb | 2 ++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 2365d9345..7063b40db 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -187,20 +187,16 @@ describe "Voter" do expect(page).not_to have_link(answer_yes.title) end + travel_back + click_link "Sign out" - # Time needs to pass between the moment we vote and the moment - # we log in; otherwise the link to vote won't be available. - # It's safe to advance one second because this test isn't - # affected by possible date changes. - travel 1.second do - login_as user - visit poll_path(poll) + login_as user + visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do - expect(page).to have_link(answer_yes.title) - expect(page).to have_link(answer_no.title) - end + within("#poll_question_#{question.id}_answers") do + expect(page).to have_link(answer_yes.title) + expect(page).to have_link(answer_no.title) end end end diff --git a/spec/models/poll/stats_spec.rb b/spec/models/poll/stats_spec.rb index 8f8b3583d..fad205da3 100644 --- a/spec/models/poll/stats_spec.rb +++ b/spec/models/poll/stats_spec.rb @@ -271,6 +271,8 @@ describe Poll::Stats do expect(stats.version).to eq "v#{time.to_i}" + travel_back + travel_to 2.seconds.from_now do expect(stats.version).to eq "v#{time.to_i}" end