From 30f62619bffab644d2f5ffbe8abf650a73605e01 Mon Sep 17 00:00:00 2001 From: dylangriffinshub Date: Fri, 17 Jul 2026 00:38:55 -0400 Subject: [PATCH] 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