From 0ebc8839593509889ad39555ffee79907f4f4769 Mon Sep 17 00:00:00 2001 From: yuenmichelle1 Date: Mon, 8 Jul 2024 09:39:21 -0500 Subject: [PATCH] Rails 5 - Fix users_controller_spec.rb (#343) * 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 --- spec/controllers/users_controller_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index e6ccdf92..11620dbf 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -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 }]