Skip to content

Commit

Permalink
remove typecast and add version check to check for numeric type vs st…
Browse files Browse the repository at this point in the history
…ring type
  • Loading branch information
yuenmichelle1 committed Jul 4, 2024
1 parent f3a94cc commit c1d2503
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/username_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def results
def query
<<-SQL
select
id::text,
id,
login,
display_name
Expand Down
8 changes: 7 additions & 1 deletion spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@
it{ is_expected.to be_successful }

it 'should return the usernames' do
# TODO: Remove version check once on Rails 5
# In Rails versions < 5, PG results when casted to_a,
# numeric types will get converted to string.
# After Rails 5, there is no typecasting, unless stated.
# See https://github.com/rails/rails/commit/c51f9b61ce1e167f5f58f07441adcfa117694301
expected_user_id = Rails.version.starts_with?('5') ? user.id : user.id.to_s
expect(response.json[:usernames]).to match_array [{
'id' => user.id.to_s,
'id' => expected_user_id,
'login' => user.login,
'display_name' => user.display_name
}]
Expand Down

0 comments on commit c1d2503

Please sign in to comment.