Skip to content

Commit

Permalink
support both multiple_choice? and multiple_choices?
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Lilienthal committed Mar 26, 2013
1 parent 494d95f commit a0a07c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/httparty/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def inspect
end
end

# Support old multiple_choice? method from pre 2.0.0 era.
if ::RUBY_VERSION >= "2.0.0"
alias_method :multiple_choice?, :multiple_choices?
end

def respond_to?(name)
return true if [:request, :response, :parsed_response, :body, :headers].include?(name)
parsed_response.respond_to?(name) || response.respond_to?(name)
Expand Down
11 changes: 9 additions & 2 deletions spec/httparty/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def response_mock(klass)
:length_required? => Net::HTTPLengthRequired,
:method_not_allowed? => Net::HTTPMethodNotAllowed,
:moved_permanently? => Net::HTTPMovedPermanently,
:multiple_choices? => Net::HTTPMultipleChoice,
:multiple_choice? => Net::HTTPMultipleChoice,
:no_content? => Net::HTTPNoContent,
:non_authoritative_information? => Net::HTTPNonAuthoritativeInformation,
:not_acceptable? => Net::HTTPNotAcceptable,
Expand All @@ -195,7 +195,14 @@ def response_mock(klass)
:unsupported_media_type? => Net::HTTPUnsupportedMediaType,
:use_proxy? => Net::HTTPUseProxy,
:version_not_supported? => Net::HTTPVersionNotSupported
}.each do |method, klass|
}

# Ruby 2.0, new name for this response.
if RUBY_VERSION >= "2.0.0"
SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices
end

SPECIFIC_CODES.each do |method, klass|
it "responds to #{method}" do
net_response = response_mock(klass)
response = HTTParty::Response.new(@request_object, net_response, '')
Expand Down

0 comments on commit a0a07c5

Please sign in to comment.