Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
15 changes: 15 additions & 0 deletions test/models/identity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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