6318 - New Supervisor System Spec Overhaul #6582
Merged
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.
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:
stub_requestfor theapi.short.ioURL shortener. This was causingWebMockerrors when a phone number was provided and is a best practice for system tests.expect(page).to have_text(...)) before checking thehave_current_path, ensuring the redirect or re-render has completed.context "with valid form submission". This block fills in and submits the form once in abeforeblock, making the suite faster.itblocks to test individual outcomes:context "with invalid form submission"to ensure validation errors are displayed and that no user is created.supervisorandvolunteerusers are correctly redirected with an "unauthorized" message.How is this tested? 💖💪
spec/system/supervisors/new_spec.rbScreenshots please 📸
Feelings gif