Skip to content

Commit

Permalink
add user id verification to user by external id
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Jul 25, 2024
1 parent eefff1e commit 711bcbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ def name
end

scope :by_external_identifier, lambda { |identifiers|
identifiers = [identifiers].flatten.compact.map(&:downcase)
joins('LEFT JOIN user_service_identifiers ON users.id = user_service_identifiers.user_id')
.where('lower(users.email) IN (:identifiers) OR lower(user_service_identifiers.identifier) IN (:identifiers)',
identifiers:)
}
identifiers = [identifiers].flatten.compact.map(&:to_s).map(&:downcase)
joins('LEFT JOIN user_service_identifiers ON users.id = user_service_identifiers.user_id')
.where('lower(users.email) IN (:identifiers) OR lower(user_service_identifiers.identifier) IN
(:identifiers) OR CAST(users.id AS TEXT) IN (:identifiers)',
identifiers:)
}

def self.by_name(full_name)
name_parts = full_name.split
Expand Down
6 changes: 6 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
user = create(:user, email: '[email protected]')
expect(User.by_external_identifier(user.email).first).to eql(user)
end

it 'returns the user by the user id' do
user = create(:user, email: '[email protected]')

expect(User.by_external_identifier(user.id).first).to eql(user)
end
end

context '#by_name' do
Expand Down

0 comments on commit 711bcbe

Please sign in to comment.