-
-
Notifications
You must be signed in to change notification settings - Fork 518
Race condition check: new volunteers system spec #6745
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
Merged
compwron
merged 6 commits into
rubyforgood:main
from
hexdevs:sb-volunteers-system-spec-6698
Mar 7, 2026
+39
−43
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e48e065
Check for what users see when creating volunteers
stefannibrasil 13212c3
Reorganize volunteer context
stefannibrasil c42192e
Refactor volunteer creation email invitation system test
stefannibrasil 333d570
Avoid creating factories when possible
stefannibrasil 4824ece
linter
stefannibrasil 58b73cc
less code to check for the same thing
stefannibrasil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,52 @@ | ||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "volunteers/new", type: :system do | ||
| context "when admin" do | ||
| let(:admin) { create(:casa_admin) } | ||
|
|
||
| it "creates a new volunteer and sends invitation" do | ||
| sign_in admin | ||
| visit new_volunteer_path | ||
|
|
||
| fill_in "Email", with: "new_volunteer@example.com" | ||
| fill_in "Display name", with: "New Volunteer Display Name" | ||
| fill_in "Date of birth", with: Date.new(2001, 8, 8) | ||
|
|
||
| click_on "Create Volunteer" | ||
|
|
||
| last_email = ActionMailer::Base.deliveries.last | ||
| expect(last_email.to).to eq ["new_volunteer@example.com"] | ||
| expect(last_email.subject).to have_text "CASA Console invitation instructions" | ||
| expect(last_email.html_part.body.encoded).to have_text "your new Volunteer account." | ||
| expect(Volunteer.find_by(email: "new_volunteer@example.com").invitation_created_at).not_to be_nil | ||
| end | ||
| end | ||
|
|
||
| context "when supervisor" do | ||
| let(:supervisor) { create(:supervisor) } | ||
|
|
||
| it "lets Supervisor create new volunteer" do | ||
| it "creates a new volunteer", :js do | ||
| sign_in supervisor | ||
| visit new_volunteer_path | ||
|
|
||
| fill_in "Email", with: "new_volunteer2@example.com" | ||
| fill_in "Display name", with: "New Volunteer Display Name 2" | ||
| fill_in "Date of birth", with: Date.new(2000, 1, 2) | ||
|
|
||
| expect do | ||
| click_on "Create Volunteer" | ||
| end.to change(User, :count).by(1) | ||
| click_on "Create Volunteer" | ||
|
|
||
| visit volunteers_path | ||
| expect(page).to have_text("New Volunteer Display Name 2") | ||
| expect(page).to have_text("new_volunteer2@example.com") | ||
| expect(page).to have_text("Active") | ||
| end | ||
| end | ||
|
|
||
| context "volunteer user" do | ||
| let(:volunteer) { create(:volunteer) } | ||
|
|
||
| before { sign_in volunteer } | ||
|
|
||
| it "redirects the user with an error message" do | ||
| volunteer = create(:volunteer) | ||
| sign_in volunteer | ||
|
|
||
| visit new_volunteer_path | ||
|
|
||
| expect(page).to have_selector(".alert", text: "Sorry, you are not authorized to perform this action.") | ||
| end | ||
| end | ||
|
|
||
| it "displays learning hour topic for volunteers when enabled", :js do | ||
| organization = create(:casa_org, learning_topic_active: true) | ||
| volunteer = create(:volunteer, casa_org: organization) | ||
| it "displays learning hour topic when enabled", :js do | ||
| organization = build(:casa_org, learning_topic_active: true) | ||
| volunteer = create(:volunteer, casa_org: organization) | ||
|
|
||
| sign_in volunteer | ||
| visit new_learning_hour_path | ||
| expect(page).to have_text("Learning Topic") | ||
| end | ||
| sign_in volunteer | ||
| visit new_learning_hour_path | ||
| expect(page).to have_text("Learning Topic") | ||
| end | ||
|
|
||
| it "learning hour topic hidden when disabled", :js do | ||
| organization = create(:casa_org) | ||
| volunteer = create(:volunteer, casa_org: organization) | ||
| it "does not display learning hour topic when disabled", :js do | ||
| organization = build(:casa_org) | ||
| volunteer = create(:volunteer, casa_org: organization) | ||
|
|
||
| sign_in volunteer | ||
| visit new_learning_hour_path | ||
| expect(page).not_to have_text("Learning Topic") | ||
| sign_in volunteer | ||
| visit new_learning_hour_path | ||
| expect(page).not_to have_text("Learning Topic") | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example only checks
ActionMailer::Base.deliveries.last, which can be a weaker assertion if other mail is delivered in the same example (or if delivery behavior changes). Consider asserting the delivery count change aroundvolunteer.invite!(and then using the resulting last email) so the spec proves the invite action triggered exactly one email.