From 24ac9fa987c29bc72573ab7a86847f560b79dee7 Mon Sep 17 00:00:00 2001 From: Vishal Sadriya Date: Mon, 16 Feb 2026 18:23:05 +0530 Subject: [PATCH 1/2] Replace non-webpage expects with page-level assertions in all_casa_admins system specs Fixes #6694 --- .../system/all_casa_admins/all_casa_admin_spec.rb | 15 +-------------- spec/system/all_casa_admins/sessions/new_spec.rb | 7 ++++++- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/spec/system/all_casa_admins/all_casa_admin_spec.rb b/spec/system/all_casa_admins/all_casa_admin_spec.rb index 36903a720a..cf5ad09035 100644 --- a/spec/system/all_casa_admins/all_casa_admin_spec.rb +++ b/spec/system/all_casa_admins/all_casa_admin_spec.rb @@ -52,8 +52,7 @@ fill_in "Address", with: "123 Main St" click_on "Create CASA Organization" expect(page).to have_text "CASA Organization was successfully created." - organization = CasaOrg.find_by(name: "Cool Org Name") - expect(page).to have_current_path "/all_casa_admins/casa_orgs/#{organization.id}", ignore_query: true + expect(page).to have_current_path(%r{/all_casa_admins/casa_orgs/\d+}, ignore_query: true) expect(page).to have_content "Administrators" expect(page).to have_content "Details" expect(page).to have_content "Number of admins: 0" @@ -92,8 +91,6 @@ fill_in "Display name", with: "Freddy Valid" click_button "Submit" expect(page).to have_content "Email has already been taken" - - expect(CasaAdmin.find_by(email: "valid@example.com").invitation_created_at).not_to be_nil end it "edits all casa admins" do @@ -112,7 +109,6 @@ fill_in "all_casa_admin_email", with: "newemail@example.com" click_on "Update Profile" expect(page).to have_text "successfully updated" - expect(ActionMailer::Base.deliveries.last.body.encoded).to match(">Your CASA account's email has been updated to newemail@example.com") # change password click_on "Change Password" @@ -126,14 +122,5 @@ fill_in "all_casa_admin_password_confirmation", with: "newpassword" click_on "Update Password" expect(page).to have_text "Password was successfully updated." - expect(ActionMailer::Base.deliveries.last.body.encoded).to match("Your CASA password has been changed.") - end - - it "admin invitations expire" do - all_casa_admin = AllCasaAdmin.invite!(email: "valid@email.com") - travel 2.days - expect(all_casa_admin.valid_invitation?).to be true - travel 8.days - expect(all_casa_admin.valid_invitation?).to be false end end diff --git a/spec/system/all_casa_admins/sessions/new_spec.rb b/spec/system/all_casa_admins/sessions/new_spec.rb index 08a62800ce..9a48cb5e1e 100644 --- a/spec/system/all_casa_admins/sessions/new_spec.rb +++ b/spec/system/all_casa_admins/sessions/new_spec.rb @@ -57,7 +57,12 @@ end it "denies access to flipper" do - expect { visit "/flipper" }.to raise_error(ActionController::RoutingError) + original = Rails.application.env_config["action_dispatch.show_exceptions"] + Rails.application.env_config["action_dispatch.show_exceptions"] = :rescuable + visit "/flipper" + expect(page).to have_text "No route matches [GET] \"/flipper\"" + ensure + Rails.application.env_config["action_dispatch.show_exceptions"] = original end end end From 0cbef5c40af593776ae0aefdc044ae1a788a598f Mon Sep 17 00:00:00 2001 From: Vishal Sadriya Date: Tue, 17 Feb 2026 15:17:35 +0530 Subject: [PATCH 2/2] Revert backend expects and convert invitation expiry to system test - Restore ActionMailer and ActiveRecord expects that are safe after Capybara waiting matchers - Add page-level assertion for org name after creation - Convert "admin invitations expire" from unit test to system test that visits invitation links in the browser --- .../all_casa_admins/all_casa_admin_spec.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/system/all_casa_admins/all_casa_admin_spec.rb b/spec/system/all_casa_admins/all_casa_admin_spec.rb index cf5ad09035..06cb59392c 100644 --- a/spec/system/all_casa_admins/all_casa_admin_spec.rb +++ b/spec/system/all_casa_admins/all_casa_admin_spec.rb @@ -52,6 +52,7 @@ fill_in "Address", with: "123 Main St" click_on "Create CASA Organization" expect(page).to have_text "CASA Organization was successfully created." + expect(page).to have_text "Cool Org Name" expect(page).to have_current_path(%r{/all_casa_admins/casa_orgs/\d+}, ignore_query: true) expect(page).to have_content "Administrators" expect(page).to have_content "Details" @@ -91,6 +92,8 @@ fill_in "Display name", with: "Freddy Valid" click_button "Submit" expect(page).to have_content "Email has already been taken" + + expect(CasaAdmin.find_by(email: "valid@example.com").invitation_created_at).not_to be_nil end it "edits all casa admins" do @@ -109,6 +112,7 @@ fill_in "all_casa_admin_email", with: "newemail@example.com" click_on "Update Profile" expect(page).to have_text "successfully updated" + expect(ActionMailer::Base.deliveries.last.body.encoded).to match(">Your CASA account's email has been updated to newemail@example.com") # change password click_on "Change Password" @@ -122,5 +126,21 @@ fill_in "all_casa_admin_password_confirmation", with: "newpassword" click_on "Update Password" expect(page).to have_text "Password was successfully updated." + expect(ActionMailer::Base.deliveries.last.body.encoded).to match("Your CASA password has been changed.") + end + + it "admin invitations expire" do + all_casa_admin = AllCasaAdmin.invite!(email: "valid@email.com") + raw_token = all_casa_admin.raw_invitation_token + + # Invitation is valid within 1 week + travel 2.days + visit accept_all_casa_admin_invitation_path(invitation_token: raw_token) + expect(page).to have_text "Set my password" + + # Invitation expires after 1 week + travel 8.days + visit accept_all_casa_admin_invitation_path(invitation_token: raw_token) + expect(page).to have_text "The invitation token provided is not valid!" end end