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.
This commit is contained in:
Javi Martín
2019-04-29 11:58:25 +02:00
parent 307cf24846
commit db6ed4772c
2 changed files with 9 additions and 11 deletions

View File

@@ -187,20 +187,16 @@ describe "Voter" do
expect(page).not_to have_link(answer_yes.title) expect(page).not_to have_link(answer_yes.title)
end end
travel_back
click_link "Sign out" click_link "Sign out"
# Time needs to pass between the moment we vote and the moment login_as user
# we log in; otherwise the link to vote won't be available. visit poll_path(poll)
# 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)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_answers") do
expect(page).to have_link(answer_yes.title) expect(page).to have_link(answer_yes.title)
expect(page).to have_link(answer_no.title) expect(page).to have_link(answer_no.title)
end
end end
end end
end end

View File

@@ -271,6 +271,8 @@ describe Poll::Stats do
expect(stats.version).to eq "v#{time.to_i}" expect(stats.version).to eq "v#{time.to_i}"
travel_back
travel_to 2.seconds.from_now do travel_to 2.seconds.from_now do
expect(stats.version).to eq "v#{time.to_i}" expect(stats.version).to eq "v#{time.to_i}"
end end