Skip to content

Commit

Permalink
Merge pull request #113 from texasjusticar/master
Browse files Browse the repository at this point in the history
Adding ok? convenience method to HTTP:Message
  • Loading branch information
Hiroshi Nakamura committed Sep 3, 2012
2 parents c86ece5 + 8a1ecc5 commit 3ea5a66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/httpclient/http.rb
Expand Up @@ -1027,6 +1027,11 @@ def cookies
}
end
end

# Convenience method to return boolean of whether we had a successful request
def ok?
HTTP::Status.successful?(status)
end
end


Expand Down
11 changes: 11 additions & 0 deletions test/test_httpclient.rb
Expand Up @@ -1313,6 +1313,17 @@ def test_response_cookies
assert_equal('PART_NUMBER', res.cookies[1].name)
end

def test_ok_response_success
res = HTTP::Message.new_response('response')
assert_true res.ok?
res.status = 404
assert_false res.ok?
res.status = 500
assert_false res.ok?
res.status = 302
assert_false res.ok?
end

if !defined?(JRUBY_VERSION) and RUBY_VERSION < '1.9'
def test_timeout_scheduler
assert_equal('hello', @client.get_content(serverurl + 'hello'))
Expand Down

0 comments on commit 3ea5a66

Please sign in to comment.