Permalink
Browse files

Merge pull request #113 from texasjusticar/master

Adding ok? convenience method to HTTP:Message
  • Loading branch information...
2 parents c86ece5 + 8a1ecc5 commit 3ea5a66cc3eba21bb8124aa2124fedc4046dad75 @nahi committed Sep 3, 2012
Showing with 16 additions and 0 deletions.
  1. +5 −0 lib/httpclient/http.rb
  2. +11 −0 test/test_httpclient.rb
View
@@ -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
View
@@ -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'))

0 comments on commit 3ea5a66

Please sign in to comment.