Merge pull request #2017 from basecamp/flavorjones/2003-identity-destroy-cleanup

Fix Identity destruction callback ordering
This commit is contained in:
Mike Dalessio
2025-12-08 15:21:54 -05:00
committed by GitHub
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