fix(test): wrap flaky homepage tests in travel_to blocks#2575
Merged
mroderick merged 1 commit intocodebar:masterfrom Apr 16, 2026
Merged
fix(test): wrap flaky homepage tests in travel_to blocks#2575mroderick merged 1 commit intocodebar:masterfrom
mroderick merged 1 commit intocodebar:masterfrom
Conversation
Fix time-dependent flaky tests by wrapping scenarios in travel_to blocks. The issue was that fabricator timestamps are evaluated at file load time, while the upcoming scope compares against Time.zone.now at query time. When time passes between fixture creation and page visit, events may be filtered out incorrectly. This follows the same pattern as commit 3f44835 which fixed similar flaky tests in other files.
KimberleyCook
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a flaky test failure in
spec/features/visiting_homepage_spec.rbthat was causing intermittent CI failures.Problem
The test scenario "i can view the next 5 upcoming events" was failing intermittently in CI with the following error:
The events were not appearing on the homepage because they were being filtered out by the
upcomingscope.Root Cause
This is a time synchronization issue between fabricator timestamps and database scope queries:
Fabricator timestamps are evaluated when the file loads:
The
upcomingscope compares againstTime.zone.nowat query time:The controller's
all_eventsmethod uses theupcomingscope:When time passes between fabricator file loading and test execution, events created with
Time.zone.now + 2.daysat file load time may actually be in the past relative toTime.zone.nowat query time, causing them to be filtered out.Solution
Wrap time-dependent test scenarios in
travel_to(Time.current)blocks to freeze time:This ensures both the fabricator timestamps and the scope queries use the same time reference.
Related Work
This follows the same pattern as commit
3f44835e("fix(test): freeze time in tests to prevent flaky failures") which resolved similar flaky tests in 15 other files:spec/features/listing_events_spec.rbspec/features/chapter_spec.rbspec/models/concerns/listable_spec.rbThe
visiting_homepage_spec.rbfile was missed in that earlier fix.Files Changed
spec/features/visiting_homepage_spec.rb- Addedtravel_toblocks around time-dependent scenariosTesting
References