Skip to content

Commit 5328d63

Browse files
authored
Merge pull request #2017 from basecamp/flavorjones/2003-identity-destroy-cleanup
Fix Identity destruction callback ordering
2 parents e4b5139 + 3c4b838 commit 5328d63

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/models/identity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Identity < ApplicationRecord
88

99
has_one_attached :avatar
1010

11-
before_destroy :deactivate_users
11+
before_destroy :deactivate_users, prepend: true
1212

1313
validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }
1414
normalizes :email_address, with: ->(value) { value.strip.downcase.presence }

test/models/identity_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,19 @@ class IdentityTest < ActiveSupport::TestCase
4646
assert_equal identity.email_address, user.name
4747
end
4848
end
49+
50+
test "destroy deactivates users before nullifying identity" do
51+
identity = identities(:kevin)
52+
user = users(:kevin)
53+
54+
assert_predicate user, :active?
55+
assert_predicate user.accesses, :any?
56+
57+
identity.destroy!
58+
user.reload
59+
60+
assert_nil user.identity_id, "identity should be nullified"
61+
assert_not_predicate user, :active?
62+
assert_empty user.accesses, "user accesses should be removed"
63+
end
4964
end

0 commit comments

Comments
 (0)