Skip to content

Commit

Permalink
Update travel_to usage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
javierm committed May 28, 2019
1 parent 307cf24 commit db6ed47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 8 additions & 12 deletions spec/features/polls/voter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,16 @@
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)

within("#poll_question_#{question.id}_answers") do
expect(page).to have_link(answer_yes.title)
expect(page).to have_link(answer_no.title)
end
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
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/models/poll/stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@

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
Expand Down

0 comments on commit db6ed47

Please sign in to comment.