Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ruby 2.6 compatibility and tests #636

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ rvm:
- 2.3.8
- 2.4.5
- 2.5.3
- 2.6.0
bundler_args: --without development
before_install: gem install bundler
9 changes: 9 additions & 0 deletions lib/httparty/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ def inspect
alias_method :multiple_choice?, :multiple_choices?
end

# Support old status codes method from pre 2.6.0 era.
if ::RUBY_VERSION >= "2.6.0" && ::RUBY_PLATFORM != "java"
alias_method :gateway_time_out?, :gateway_timeout?
alias_method :request_entity_too_large?, :payload_too_large?
alias_method :request_time_out?, :request_timeout?
alias_method :request_uri_too_long?, :uri_too_long?
alias_method :requested_range_not_satisfiable?, :range_not_satisfiable?
end

def nil?
response.nil? || response.body.nil? || response.body.empty?
end
Expand Down
9 changes: 9 additions & 0 deletions spec/httparty/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ def response_mock(klass)
SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices
end

# Ruby 2.6, those status codes have been updated.
if RUBY_VERSION >= "2.6.0" && ::RUBY_PLATFORM != "java"
SPECIFIC_CODES[:gateway_timeout?] = Net::HTTPGatewayTimeout
SPECIFIC_CODES[:payload_too_large?] = Net::HTTPPayloadTooLarge
SPECIFIC_CODES[:request_timeout?] = Net::HTTPRequestTimeout
SPECIFIC_CODES[:uri_too_long?] = Net::HTTPURITooLong
SPECIFIC_CODES[:range_not_satisfiable?] = Net::HTTPRangeNotSatisfiable
end

SPECIFIC_CODES.each do |method, klass|
it "responds to #{method}" do
net_response = response_mock(klass)
Expand Down