Skip to content

Conversation

@AudTheCodeWitch
Copy link
Contributor

@AudTheCodeWitch AudTheCodeWitch commented Oct 30, 2025

What github issue is this PR for, if any?

Resolves #6318

What changed, and why?

This PR refactors the system spec for creating a new supervisor (spec/system/supervisors/new_spec.rb) to make it more reliable, comprehensive, and readable.

The original tests were flaky because they checked the database (change(User, :count)) without explicitly waiting for the page to load after the form submission. They also didn't test for validation errors (the "sad path") or cover all user authorization cases.

Key changes:

  • Stubbed External API: Added a stub_request for the api.short.io URL shortener. This was causing WebMock errors when a phone number was provided and is a best practice for system tests.
  • Explicit Waits: Fixed flakiness in path-checking tests. We now wait for a success or error message (expect(page).to have_text(...)) before checking the have_current_path, ensuring the redirect or re-render has completed.
  • DRY "Happy Path": Refactored the admin tests into a shared context "with valid form submission". This block fills in and submits the form once in a before block, making the suite faster.
  • Single-Purpose Tests: Broke the "happy path" assertions into small, focused it blocks to test individual outcomes:
    • Shows a success message
    • Redirects to the correct page
    • Persists the data correctly in the database
    • Sends the invitation email
  • Added "Sad Path": Added a new context "with invalid form submission" to ensure validation errors are displayed and that no user is created.
  • Added Authorization Tests: Added contexts to verify that both supervisor and volunteer users are correctly redirected with an "unauthorized" message.

How is this tested? 💖💪

  • Refactored spec/system/supervisors/new_spec.rb
  • Ran 100 times locally with no flakes!

Screenshots please 📸

Screenshot 2025-10-30 at 12 29 28 PM

Feelings gif

A cartoon dog wearing large teal headphones sits in a purple gaming chair, typing at a computer in a cozy room at night. A purple lava lamp glows on the desk and a blue neon sign of the dog's head hangs on the wall.

…idations

Signed-off-by: Audrea Cook <audrea@codewitch.dev>
…th expectations

Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Signed-off-by: Audrea Cook <audrea@codewitch.dev>
…ent normalization flakes

Signed-off-by: Audrea Cook <audrea@codewitch.dev>
@github-actions github-actions bot added ruby Pull requests that update Ruby code Tests! 🎉💖👏 labels Oct 30, 2025
…tency

Signed-off-by: Audrea Cook <audrea@codewitch.dev>
Copy link
Collaborator

@compwron compwron left a comment

Choose a reason for hiding this comment

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

nice!

@compwron compwron merged commit 29a5b9a into rubyforgood:main Oct 31, 2025
11 checks passed
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.

System Test Overhaul spec/system/supervisors/new_spec.rb

2 participants