Fix Identity destruction callback ordering

ref: #2003

Co-authored-by: Dylan <dylan@restaurantcare.com.au>
This commit is contained in:
Mike Dalessio
2025-12-08 15:11:58 -05:00
parent 15fda97ac0
commit 3c4b838b25
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ class Identity < ApplicationRecord
has_one_attached :avatar
before_destroy :deactivate_users
before_destroy :deactivate_users, prepend: true
validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }
normalizes :email_address, with: ->(value) { value.strip.downcase.presence }
+15
View File
@@ -46,4 +46,19 @@ class IdentityTest < ActiveSupport::TestCase
assert_equal identity.email_address, user.name
end
end
test "destroy deactivates users before nullifying identity" do
identity = identities(:kevin)
user = users(:kevin)
assert_predicate user, :active?
assert_predicate user.accesses, :any?
identity.destroy!
user.reload
assert_nil user.identity_id, "identity should be nullified"
assert_not_predicate user, :active?
assert_empty user.accesses, "user accesses should be removed"
end
end