Skip to content

Commit

Permalink
Rails 5 - Fix users_controller_spec.rb (#343)
Browse files Browse the repository at this point in the history
* Update users_controller_spec.rb

* update sql query to convert id to int to ensure type of return value

* convert id to text in query to ensure correct type is being returned

* remove typecast and add version check to check for numeric type vs string type
  • Loading branch information
yuenmichelle1 authored Jul 8, 2024
1 parent da98794 commit 0ebc883
Showing 1 changed file with 7 additions and 1 deletion.
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 0ebc883

Please sign in to comment.