Fix json >= 3.0 compatibility - #115
Open
dblock wants to merge 1 commit into
Open
Conversation
Replace Faraday's built-in :json response middleware, which calls JSON.parse(body, options) positionally, with Strava::Web::JsonResponse, a subclass that calls JSON.parse(body) with a single argument. This works with both json < 3.0 and json >= 3.0, which made options keyword-only. Also uncomments the json-3 appraisal in CI now that it passes, and removes the json ~> 2.3 pin from the Gemfile since it's no longer needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Danger ReportNo issues found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #113.
Faraday's built-in
:jsonresponse middleware callsJSON.parse(body, options)positionally. Thejsongem 3.0 changedJSON.parseto accept options as keyword arguments only, so this raisedArgumentError: wrong number of arguments (given 2, expected 1), surfaced by Faraday asFaraday::ParsingError.This replaces the built-in middleware with
Strava::Web::JsonResponse, a subclass overriding#parseto callJSON.parse(body)with a single argument, which works with bothjson< 3.0 and >= 3.0.Now that the gem no longer depends on Faraday's buggy behavior:
json-3appraisal (previously commented out, added in Add Appraisals to test against multiple json gem versions #114) is uncommented in CI.gem 'json', '~> 2.3'pin added to theGemfilein Add Appraisals to test against multiple json gem versions #114 is removed, since it's no longer needed.Testing
Gemfile,gemfiles/json_2.gemfile, andgemfiles/json_3.gemfile(previously 18 failures under json 3.x).spec/strava/web/json_response_spec.rbcovering the new middleware's#parsemethod.gemfiles/rubocop.gemfile.