Skip to content

Race condition check: invite volunteers system spec#6766

Merged
compwron merged 4 commits intorubyforgood:mainfrom
hexdevs:sb-volunteers-system-spec-take3-6698
Mar 11, 2026
Merged

Race condition check: invite volunteers system spec#6766
compwron merged 4 commits intorubyforgood:mainfrom
hexdevs:sb-volunteers-system-spec-take3-6698

Conversation

@stefannibrasil
Copy link
Copy Markdown
Contributor

@stefannibrasil stefannibrasil commented Mar 9, 2026

Related #6698

  • removes unused setup
  • removes test that does not have any user interaction and is already covered by a unit test
  • checks for what the user sees in the page when inviting volunteers, especially before checking the DB

@github-actions github-actions bot added ruby Pull requests that update Ruby code Tests! 🎉💖👏 labels Mar 9, 2026
@stefannibrasil stefannibrasil force-pushed the sb-volunteers-system-spec-take3-6698 branch from abf7235 to 6ffa551 Compare March 9, 2026 22:34
@stefannibrasil stefannibrasil marked this pull request as ready for review March 9, 2026 22:45
@FireLemons
Copy link
Copy Markdown
Collaborator

After reviewing the test, it turns out that most of the scenarios here are already being tested in the volunteers and invite request specs, so the system tests were redundant.

The request tests are unit tests

see: https://www.geeksforgeeks.org/software-testing/difference-between-unit-testing-and-system-testing/

@stefannibrasil
Copy link
Copy Markdown
Contributor Author

stefannibrasil commented Mar 9, 2026

Yes, that's correct. The only difference between what's being tested in the system tests vs the request tests was filling out the form vs submitting the params. So reviewing the system test showed that unit tests were being performed more than UI interaction. And the UI interaction that was left could be extracted to a view test.

I think using a view spec to verify that the form fields are rendered and relying on the request tests for validity is a good alternative, though. Otherwise, we're having duplicated logic being tested in several places.

Copy link
Copy Markdown
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 reduces CI load and avoids race-condition-prone assertions by removing redundant volunteer invitation system specs and relocating coverage into cheaper request and view specs, aligning with issue #6698’s guidance to avoid backend-only expectations in system tests.

Changes:

  • Removed spec/system/volunteers/invite_spec.rb (system-level invite/resend/acceptance scenarios).
  • Added/adjusted view specs to verify volunteer form fields render and that the resend-invitation UI is conditionally shown/hidden.
  • Refactored spec/requests/volunteers_spec.rb to cover invite/SMS/resend behaviors with less factory setup and more explicit redirect/flash assertions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
spec/views/volunteers/new.html.erb_spec.rb Adds a view spec asserting key fields render on the new volunteer form.
spec/views/volunteers/edit.html.erb_spec.rb Adds a view spec ensuring the resend-invitation UI is hidden once an invitation is accepted.
spec/system/volunteers/invite_spec.rb Removes expensive system coverage for invite/resend/accept flows.
spec/requests/volunteers_spec.rb Expands request coverage for volunteer creation/invitation, SMS behavior, unauthorized access behavior, and resend invitation emails.

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

@github-actions github-actions bot added the erb label Mar 10, 2026
@@ -1,5 +1,5 @@
<div class="password-box px-4 pb-3">
<h2 class="my-3">Send invitation</h2>
<h2 class="my-3">Set password</h2>
Copy link
Copy Markdown
Contributor Author

@stefannibrasil stefannibrasil Mar 10, 2026

Choose a reason for hiding this comment

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

Let me know if you have other ideas. This looks more relevant in this context 👀

@stefannibrasil
Copy link
Copy Markdown
Contributor Author

stefannibrasil commented Mar 10, 2026

@FireLemons @compwron I addressed copilot's comments in 9deee4c and added a new view test in fa8da1c

Let me know if you prefer to have the system test still. After reviewing it carefully, it shows that they can be replaced between the request and view specs to ensure the fields are displayed and the emails are sent, which is primarily what the system test was doing. Thanks for your reviews!

@stefannibrasil stefannibrasil force-pushed the sb-volunteers-system-spec-take3-6698 branch from fa8da1c to 97d472d Compare March 10, 2026 22:32
This test is not asserting against anything on the page.
There is already coverage for this in the
volunteers model spec.
@stefannibrasil stefannibrasil force-pushed the sb-volunteers-system-spec-take3-6698 branch from 97d472d to 6f0122d Compare March 11, 2026 18:47
end
end

describe "invitation expiration" do
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test is not an integration one because there is no UI interaction. It's also covered by this unit test already: https://github.com/rubyforgood/casa/blob/main/spec/models/volunteer_spec.rb#L388

Also, check for what the user sees in the page.
@stefannibrasil stefannibrasil force-pushed the sb-volunteers-system-spec-take3-6698 branch from 6f0122d to 19d56c4 Compare March 11, 2026 18:50
Copy link
Copy Markdown
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.

we could argue about tests forever but I am ok with merging this

@compwron compwron merged commit 6871686 into rubyforgood:main Mar 11, 2026
11 checks passed
@stefannibrasil
Copy link
Copy Markdown
Contributor Author

True! I did keep the PR more focused though. Thanks for reviewing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants