1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00

Enhance member removal process by destroying associated invitations and updating flash messages in ProfilesController. Add test to verify invitation deletion upon member removal.

Fixes #2066
This commit is contained in:
Josh Pigford 2025-04-20 20:15:49 -05:00
parent 08091d24f9
commit 1b1add38f2
2 changed files with 25 additions and 3 deletions

View file

@ -23,9 +23,11 @@ class Settings::ProfilesController < ApplicationController
end
if @user.destroy
flash[:notice] = t("settings.profiles.destroy.member_removed")
# Also destroy the invitation associated with this user for this family
Current.family.invitations.find_by(email: @user.email)&.destroy
flash[:notice] = "Member removed successfully."
else
flash[:alert] = t("settings.profiles.destroy.member_removal_failed")
flash[:alert] = "Failed to remove member."
end
redirect_to settings_profile_path

View file

@ -19,7 +19,7 @@ class Settings::ProfilesControllerTest < ActionDispatch::IntegrationTest
end
assert_redirected_to settings_profile_path
assert_equal I18n.t("settings.profiles.destroy.member_removed"), flash[:notice]
assert_equal "Member removed successfully.", flash[:notice]
assert_raises(ActiveRecord::RecordNotFound) { User.find(@member.id) }
end
@ -44,4 +44,24 @@ class Settings::ProfilesControllerTest < ActionDispatch::IntegrationTest
assert_equal I18n.t("settings.profiles.destroy.not_authorized"), flash[:alert]
assert User.find(@admin.id)
end
test "admin removing a family member also destroys their invitation" do
# Create an invitation for the member
invitation = @admin.family.invitations.create!(
email: @member.email,
role: "member",
inviter: @admin
)
sign_in @admin
assert_difference [ "User.count", "Invitation.count" ], -1 do
delete settings_profile_path(user_id: @member)
end
assert_redirected_to settings_profile_path
assert_equal "Member removed successfully.", flash[:notice]
assert_raises(ActiveRecord::RecordNotFound) { User.find(@member.id) }
assert_raises(ActiveRecord::RecordNotFound) { Invitation.find(invitation.id) }
end
end