Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Issue with high_quality_article_monitor_spec #6190

Merged

Conversation

Formasitchijoh
Copy link
Contributor

What this PR does

This PR addresses the recent CI build failure and improves upon the previous fix, which was inefficient.

Issue with the Previous Fix:

  • The travel_to helper method was only applied when creating the course, meaning that subsequent interactions in the test used the current system time instead of the intended past time. This caused failures when the test logic compared dates, as the current time was beyond the course end date.

  • The previous fix also relied on Date.new, which does not account for time zones, making it ineffective for this scenario.

Improvements in This Fix:

  • Replaced Date.new with Time.zone.local which is Rails-specific and handle time zones .
  • Moved travel_to into the before block to ensure that all test interactions occur within the correct time frame.
  • Ensured proper reset to the system time after the test completes using travel_back method .
Screenshot 2025-02-10 at 21 24 06

This fix travels to a time between the start and end date to ensures that all test blocks operate within the intended date context, leading to more reliable and consistent test execution.

A detail explanation of how these helpers work is found here

@gabina , your assumption about how travel_to was used previously is correct. Thank you for your input

@Formasitchijoh Formasitchijoh changed the title Fix: call travel_to in before block to ensure correct past time and r… Fix: Issue with high_quality_article_monitor_spec Feb 10, 2025
@ragesoss ragesoss merged commit 820cf98 into WikiEducationFoundation:master Feb 10, 2025
1 check passed
Comment on lines +51 to +53
after do
travel_back
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? Or is it just a good practice?

According to the travel_to docs:

Changes current time to the given time by stubbing Time.now, Time.new, Date.today, and DateTime.now to return the time or date passed into this method. The stubs are automatically removed at the end of the test.

So I understand that it is not strictly necessary but perhaps it is considered a good practice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you are right, just wanted to make sure the time is reset back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants