Fix Identity destruction callback ordering
ref: #2003 Co-authored-by: Dylan <dylan@restaurantcare.com.au>
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user