From 30f62619bffab644d2f5ffbe8abf650a73605e01 Mon Sep 17 00:00:00 2001 From: dylangriffinshub Date: Fri, 17 Jul 2026 00:38:55 -0400 Subject: [PATCH 1/2] refactor: update email handling for casa admins, supervisors, and volunteers to skip confirmation and improve user experience --- .../all_casa_admins/casa_admins_controller.rb | 5 ++- app/controllers/application_controller.rb | 8 ----- app/controllers/casa_admins_controller.rb | 5 ++- app/controllers/supervisors_controller.rb | 5 ++- app/controllers/volunteers_controller.rb | 5 ++- .../all_casa_admins/casa_admins_spec.rb | 12 +++---- spec/system/casa_admins/edit_spec.rb | 20 +++-------- spec/system/supervisors/edit_spec.rb | 22 ++++-------- spec/system/volunteers/edit_spec.rb | 34 ++++--------------- 9 files changed, 30 insertions(+), 86 deletions(-) diff --git a/app/controllers/all_casa_admins/casa_admins_controller.rb b/app/controllers/all_casa_admins/casa_admins_controller.rb index 033b6d57b7..24dbddf514 100644 --- a/app/controllers/all_casa_admins/casa_admins_controller.rb +++ b/app/controllers/all_casa_admins/casa_admins_controller.rb @@ -22,11 +22,10 @@ def edit def update @casa_admin = CasaAdmin.find(params[:id]) + @casa_admin.skip_reconfirmation! if @casa_admin.update(all_casa_admin_params) - notice = check_unconfirmed_email_notice(@casa_admin) - @casa_admin.filter_old_emails!(@casa_admin.email) - redirect_to edit_all_casa_admins_casa_org_casa_admin_path(@casa_org), notice: notice + redirect_to edit_all_casa_admins_casa_org_casa_admin_path(@casa_org), notice: "Casa admin was successfully updated." else render :edit, status: :unprocessable_content end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6b14da7b6a..00aadff0a2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -174,12 +174,4 @@ def unsupported_media_type end end end - - def check_unconfirmed_email_notice(user) - notice = "#{user.role} was successfully updated." - if user.saved_changes.include?("unconfirmed_email") - notice += " Confirmation Email Sent." - end - notice - end end diff --git a/app/controllers/casa_admins_controller.rb b/app/controllers/casa_admins_controller.rb index 5cfa6cc309..c05dc9c2cb 100644 --- a/app/controllers/casa_admins_controller.rb +++ b/app/controllers/casa_admins_controller.rb @@ -16,12 +16,11 @@ def edit def update authorize @casa_admin + @casa_admin.skip_reconfirmation! if @casa_admin.update(update_casa_admin_params) - notice = check_unconfirmed_email_notice(@casa_admin) - @casa_admin.filter_old_emails!(@casa_admin.email) respond_to do |format| - format.html { redirect_to edit_casa_admin_path(@casa_admin), notice: notice } + format.html { redirect_to edit_casa_admin_path(@casa_admin), notice: "Casa Admin was successfully updated." } format.json { render json: @casa_admin, status: :ok } end else diff --git a/app/controllers/supervisors_controller.rb b/app/controllers/supervisors_controller.rb index c6415ae021..8c65246d05 100644 --- a/app/controllers/supervisors_controller.rb +++ b/app/controllers/supervisors_controller.rb @@ -49,11 +49,10 @@ def edit def update authorize @supervisor + @supervisor.skip_reconfirmation! if @supervisor.update(update_supervisor_params) - notice = check_unconfirmed_email_notice(@supervisor) - @supervisor.filter_old_emails!(@supervisor.email) - redirect_to edit_supervisor_path(@supervisor), notice: notice + redirect_to edit_supervisor_path(@supervisor), notice: "Supervisor was successfully updated." else render :edit, status: :unprocessable_content end diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb index 0573c63b64..3ebfa8561d 100644 --- a/app/controllers/volunteers_controller.rb +++ b/app/controllers/volunteers_controller.rb @@ -61,11 +61,10 @@ def edit def update authorize @volunteer + @volunteer.skip_reconfirmation! if @volunteer.update(update_volunteer_params) - notice = check_unconfirmed_email_notice(@volunteer) - @volunteer.filter_old_emails!(@volunteer.email) - redirect_to edit_volunteer_path(@volunteer), notice: notice + redirect_to edit_volunteer_path(@volunteer), notice: "Volunteer was successfully updated." else render :edit, status: :unprocessable_content end diff --git a/spec/requests/all_casa_admins/casa_admins_spec.rb b/spec/requests/all_casa_admins/casa_admins_spec.rb index 050fa4d35a..8883fef8fe 100644 --- a/spec/requests/all_casa_admins/casa_admins_spec.rb +++ b/spec/requests/all_casa_admins/casa_admins_spec.rb @@ -67,21 +67,19 @@ context "with valid parameters" do let(:params) { {all_casa_admin: {email: "casa_admin@example.com"}} } - it "allows current user to begin to update other casa admin's email and send a confirmation email" do + it "allows current user to update other casa admin's email immediately, without requiring confirmation" do subject casa_admin.reload - expect(casa_admin.unconfirmed_email).to eq("casa_admin@example.com") - expect(ActionMailer::Base.deliveries.count).to eq(1) - expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message) - expect(ActionMailer::Base.deliveries.first.body.encoded) - .to match("Click here to confirm your email") + expect(casa_admin.email).to eq("casa_admin@example.com") + expect(casa_admin.unconfirmed_email).to be_nil + expect(ActionMailer::Base.deliveries.count).to eq(0) end it { is_expected.to redirect_to edit_all_casa_admins_casa_org_casa_admin_path(casa_org, casa_admin) } it "shows correct flash message" do subject - expect(flash[:notice]).to eq("Casa Admin was successfully updated. Confirmation Email Sent.") + expect(flash[:notice]).to eq("Casa Admin was successfully updated.") end end diff --git a/spec/system/casa_admins/edit_spec.rb b/spec/system/casa_admins/edit_spec.rb index 2bdbfb4ae1..c091032df3 100644 --- a/spec/system/casa_admins/edit_spec.rb +++ b/spec/system/casa_admins/edit_spec.rb @@ -38,24 +38,14 @@ admin.reload end - it "sends a confirmation email upon submission and does not change the user's displayed email" do - expect(ActionMailer::Base.deliveries.count).to eq(1) - expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message) - expect(ActionMailer::Base.deliveries.first.body.encoded) - .to match("Click here to confirm your email") - - expect(page).to have_text "Admin was successfully updated. Confirmation Email Sent." - expect(page).to have_field("Email", with: @old_email) - admin.reload - expect(admin.unconfirmed_email).to eq("new_admin_email@example.com") - end - - it "succesfully updates the user email once the user confirms the changes" do - admin.confirm - visit edit_casa_admin_path(admin) + it "updates the email immediately without requiring confirmation" do + expect(ActionMailer::Base.deliveries.count).to eq(0) + expect(page).to have_text "Casa Admin was successfully updated." expect(page).to have_field("Email", with: "new_admin_email@example.com") admin.reload + expect(admin.email).to eq("new_admin_email@example.com") + expect(admin.unconfirmed_email).to be_nil expect(admin.old_emails).to eq([@old_email]) end end diff --git a/spec/system/supervisors/edit_spec.rb b/spec/system/supervisors/edit_spec.rb index f08a10c900..e739a0b8f7 100644 --- a/spec/system/supervisors/edit_spec.rb +++ b/spec/system/supervisors/edit_spec.rb @@ -178,24 +178,14 @@ @supervisor.reload end - it "sends a confirmation email to the supervisor and displays current email" do - expect(page).to have_text "Supervisor was successfully updated. Confirmation Email Sent." - expect(page).to have_field("Email", with: @old_email) - expect(@supervisor.unconfirmed_email).to eq("new_supervisor_email@example.com") - - expect(ActionMailer::Base.deliveries.count).to eq(1) - expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message) - expect(ActionMailer::Base.deliveries.first.body.encoded) - .to match("Click here to confirm your email") - end - - it "correctly updates the supervisor email once confirmed" do - @supervisor.confirm - @supervisor.reload - visit edit_supervisor_path(@supervisor) - + it "updates the email immediately without requiring confirmation" do + expect(page).to have_text "Supervisor was successfully updated." expect(page).to have_field("Email", with: "new_supervisor_email@example.com") + expect(@supervisor.email).to eq("new_supervisor_email@example.com") + expect(@supervisor.unconfirmed_email).to be_nil expect(@supervisor.old_emails).to match([@old_email]) + + expect(ActionMailer::Base.deliveries.count).to eq(0) end end diff --git a/spec/system/volunteers/edit_spec.rb b/spec/system/volunteers/edit_spec.rb index 5d8988748b..84da051301 100644 --- a/spec/system/volunteers/edit_spec.rb +++ b/spec/system/volunteers/edit_spec.rb @@ -129,7 +129,7 @@ describe "updating a volunteer's email" do context "with a valid email" do - it "sends volunteer a confirmation email and does not change the displayed email" do + it "updates the email immediately without requiring confirmation" do organization = create(:casa_org) admin = create(:casa_admin, casa_org: organization) volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) @@ -141,35 +141,13 @@ fill_in "Email", with: "newemail@example.com" click_on "Submit" - expect(page).to have_text "Volunteer was successfully updated. Confirmation Email Sent." - expect(page).to have_field("Email", with: old_email) - expect(volunteer.reload.unconfirmed_email).to eq("newemail@example.com") - - expect(ActionMailer::Base.deliveries.count).to eq(1) - expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message) - expect(ActionMailer::Base.deliveries.first.body.encoded) - .to match("Click here to confirm your email") - end - - it "succesfully displays the new email once the user confirms" do - organization = create(:casa_org) - admin = create(:casa_admin, casa_org: organization) - volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) - old_email = volunteer.email - - sign_in admin - visit edit_volunteer_path(volunteer) - - fill_in "Email", with: "newemail@example.com" - click_on "Submit" - volunteer.reload - volunteer.confirm - - visit edit_volunteer_path(volunteer) - + expect(page).to have_text "Volunteer was successfully updated." expect(page).to have_field("Email", with: "newemail@example.com") - expect(page).not_to have_field("Email", with: old_email) + expect(volunteer.reload.email).to eq("newemail@example.com") + expect(volunteer.unconfirmed_email).to be_nil expect(volunteer.old_emails).to eq([old_email]) + + expect(ActionMailer::Base.deliveries.count).to eq(0) end end end From 8da6d3331d532e9d70e2eb4dfc59f2e3ddbec480 Mon Sep 17 00:00:00 2001 From: administrator Date: Mon, 27 Jul 2026 01:55:50 -0400 Subject: [PATCH 2/2] Fix specs for immediate email update behavior Request specs for casa_admins, volunteers, and supervisors still expected the old unconfirmed_email and confirmation mailer flow. Update them to match the controller behavior already changed in this branch: email updates apply immediately, no confirmation email is sent. Also fix a flash message casing mismatch in the all_casa_admins spec. --- .../all_casa_admins/casa_admins_spec.rb | 2 +- spec/requests/casa_admins_spec.rb | 10 ++++------ spec/requests/supervisors_spec.rb | 20 ++++++++----------- spec/requests/volunteers_spec.rb | 10 ++++------ 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/spec/requests/all_casa_admins/casa_admins_spec.rb b/spec/requests/all_casa_admins/casa_admins_spec.rb index 8883fef8fe..fb7d8976b7 100644 --- a/spec/requests/all_casa_admins/casa_admins_spec.rb +++ b/spec/requests/all_casa_admins/casa_admins_spec.rb @@ -79,7 +79,7 @@ it "shows correct flash message" do subject - expect(flash[:notice]).to eq("Casa Admin was successfully updated.") + expect(flash[:notice]).to eq("Casa admin was successfully updated.") end end diff --git a/spec/requests/casa_admins_spec.rb b/spec/requests/casa_admins_spec.rb index ec2bd5b123..eb85f99601 100644 --- a/spec/requests/casa_admins_spec.rb +++ b/spec/requests/casa_admins_spec.rb @@ -88,7 +88,7 @@ expect(response.request.flash[:notice]).to eq "Casa Admin was successfully updated." end - it "can update a casa admin user's email and send them a confirmation email", :aggregate_failures do + it "can update a casa admin user's email immediately, without requiring confirmation", :aggregate_failures do casa_admin = create(:casa_admin) expected_email = "admin2@casa.com" @@ -102,11 +102,9 @@ casa_admin.reload expect(response).to have_http_status(:redirect) - expect(casa_admin.unconfirmed_email).to eq("admin2@casa.com") - expect(ActionMailer::Base.deliveries.count).to eq(1) - expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message) - expect(ActionMailer::Base.deliveries.first.body.encoded) - .to match("Click here to confirm your email") + expect(casa_admin.email).to eq("admin2@casa.com") + expect(casa_admin.unconfirmed_email).to be_nil + expect(ActionMailer::Base.deliveries.count).to eq(0) end it "also respond as json", :aggregate_failures do diff --git a/spec/requests/supervisors_spec.rb b/spec/requests/supervisors_spec.rb index a4b0919df2..bd645816ad 100644 --- a/spec/requests/supervisors_spec.rb +++ b/spec/requests/supervisors_spec.rb @@ -148,7 +148,7 @@ expect(supervisor.phone_number).to eq "+14163218092" end - it "updates supervisor email and sends a confirmation email" do + it "updates supervisor email immediately, without requiring confirmation" do patch supervisor_path(supervisor), params: { supervisor: {email: "newemail@gmail.com"} } @@ -156,11 +156,9 @@ supervisor.reload expect(response).to have_http_status(:redirect) - expect(supervisor.unconfirmed_email).to eq("newemail@gmail.com") - expect(ActionMailer::Base.deliveries.count).to eq(1) - expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message) - expect(ActionMailer::Base.deliveries.first.body.encoded) - .to match("Click here to confirm your email") + expect(supervisor.email).to eq("newemail@gmail.com") + expect(supervisor.unconfirmed_email).to be_nil + expect(ActionMailer::Base.deliveries.count).to eq(0) end it "can set the supervisor to be inactive" do @@ -195,18 +193,16 @@ expect(supervisor).to be_active end - it "supervisor updates their own email and receives a confirmation email" do + it "supervisor updates their own email immediately, without requiring confirmation" do patch supervisor_path(supervisor), params: { supervisor: {email: "newemail@gmail.com"} } supervisor.reload expect(response).to have_http_status(:redirect) - expect(supervisor.unconfirmed_email).to eq("newemail@gmail.com") - expect(ActionMailer::Base.deliveries.count).to eq(1) - expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message) - expect(ActionMailer::Base.deliveries.first.body.encoded) - .to match("Click here to confirm your email") + expect(supervisor.email).to eq("newemail@gmail.com") + expect(supervisor.unconfirmed_email).to be_nil + expect(ActionMailer::Base.deliveries.count).to eq(0) end it "cannot change its own type" do diff --git a/spec/requests/volunteers_spec.rb b/spec/requests/volunteers_spec.rb index be863f2db7..a1ef204137 100644 --- a/spec/requests/volunteers_spec.rb +++ b/spec/requests/volunteers_spec.rb @@ -239,18 +239,16 @@ expect(volunteer.phone_number).to eq "15463457898" end - it "sends the volunteer a confirmation email upon email change" do + it "updates the volunteer's email immediately, without requiring confirmation" do patch volunteer_path(volunteer), params: { volunteer: {email: "newemail@gmail.com"} } expect(response).to have_http_status(:redirect) volunteer.reload - expect(volunteer.unconfirmed_email).to eq("newemail@gmail.com") - expect(ActionMailer::Base.deliveries.count).to eq(1) - expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message) - expect(ActionMailer::Base.deliveries.first.body.encoded) - .to match("Click here to confirm your email") + expect(volunteer.email).to eq("newemail@gmail.com") + expect(volunteer.unconfirmed_email).to be_nil + expect(ActionMailer::Base.deliveries.count).to eq(0) end end