Skip to content

Race Condition Check: spec/system/court_dates/edit_spec.rb#6733

Merged
compwron merged 5 commits intorubyforgood:mainfrom
hexdevs:sb-court-dates-system-spec
Feb 25, 2026
Merged

Race Condition Check: spec/system/court_dates/edit_spec.rb#6733
compwron merged 5 commits intorubyforgood:mainfrom
hexdevs:sb-court-dates-system-spec

Conversation

@stefannibrasil
Copy link
Contributor

@stefannibrasil stefannibrasil commented Feb 24, 2026

Closes #6329

  • fixes one factory creation (it was creating an admin twice)
  • removes unused context
  • avoids checking the database for changes, and checks for what the user sees when interacting with the page

@github-actions github-actions bot added ruby Pull requests that update Ruby code Tests! 🎉💖👏 labels Feb 24, 2026
Closes rubyforgood#6329

- fixes one factory creation (it was creating admin twice)
- checks for explicit values in the page
- avoids checking the database for changes, and
  checks for what the user sees when interacting with
  the page
@stefannibrasil stefannibrasil force-pushed the sb-court-dates-system-spec branch from d46d872 to fb59a36 Compare February 24, 2026 18:39
@stefannibrasil stefannibrasil marked this pull request as ready for review February 24, 2026 18:54
@stefannibrasil stefannibrasil changed the title Explicit text values and check for what user sees in the page Race Condition Check: spec/system/court_dates/edit_spec.rb Feb 24, 2026
Comment on lines +114 to +120
click_on casa_case.case_number
click_on "CINA-08-1001"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you DRY all these hard coded values? If multiple different but equal values are meant to refer to the same value, they should be referenced using the same variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that, sure. I agree with that for code outside of tests but not so much for tests. I am on the side that, especially for system tests, having explicit values like this is best for understanding the business logic of the app and debugging, when needed. By having explicit values, one does not need to evaluate the variable and jump straight to what the test is covering.

For example, checking for court_date.date.strftime("%B %-d, %Y") requires the developer to go and evaluate that when debugging a test. It's small but having the explicit date saves time, and keeps the test close to what the app renders.

Reverted it to your request in 39ee510

@stefannibrasil
Copy link
Contributor Author

@FireLemons the docker error is unrelated. Has this happened before? Thank you for your review!

@compwron compwron requested a review from Copilot February 25, 2026 21:13
@compwron compwron merged commit ebcd354 into rubyforgood:main Feb 25, 2026
13 of 14 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes race conditions in the court dates edit system spec by replacing database state checks with page content verifications. The changes ensure tests wait for browser interactions to complete before making assertions, preventing flaky test failures on slower GitHub servers.

Changes:

  • Fixed factory creation to use supervisor instead of creating admin twice
  • Replaced database count checks (expect(CourtDate.count)) with page content assertions
  • Improved test descriptions to use "allows/does not allow" naming convention
  • Modernized alert handling by replacing page.driver.browser.switch_to.alert.accept with accept_alert

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

accept_alert "Are you sure?" do
page.find("a", text: "Delete Future Court Date").click
end
expect(page).to have_content "Court date was successfully deleted"
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The expected success message is missing a period at the end. The controller at app/controllers/court_dates_controller.rb:58 returns "Court date was successfully deleted." with a period, but this test expects it without one. The supervisor test at line 105 has the correct expectation with the period. This inconsistency should be fixed to match the actual message returned by the controller.

Suggested change
expect(page).to have_content "Court date was successfully deleted"
expect(page).to have_content "Court date was successfully deleted."

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Pull requests that update Ruby code Tests! 🎉💖👏

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race Condition Check: spec/system/court_dates/edit_spec.rb

4 participants