Skip to content
Browse files

Wrote tests for OAuth2::Response

  • Loading branch information...
1 parent 0fe1413 commit 6c03b02fcc9667b8bf02f155800640b39cb297a9 @KentonWhite committed Dec 20, 2011
Showing with 32 additions and 2 deletions.
  1. +32 −2 test/unit/garb/request/data_test.rb
View
34 test/unit/garb/request/data_test.rb
@@ -51,7 +51,7 @@ class DataTest < MiniTest::Unit::TestCase
assert_received(data_request, :single_user_request)
end
- should "be able to send a request for an oauth user" do
+ should "be able to send a request for an oauth user (Net::HTTP)" do
@session.stubs(:single_user?).returns(false)
@session.stubs(:oauth_user?).returns(true)
response = mock('Net::HTTPOK') do |m|
@@ -65,7 +65,21 @@ class DataTest < MiniTest::Unit::TestCase
assert_received(data_request, :oauth_user_request)
end
- should "raise if the request is unauthorized" do
+ should "be able to send a request for an oauth user (OAuth2)" do
+ @session.stubs(:single_user?).returns(false)
+ @session.stubs(:oauth_user?).returns(true)
+ response = mock('OAuth2::Response') do |m|
+ m.expects(:status).returns(200)
+ end
+
+ data_request = Request::Data.new(@session, 'https://example.com/data', 'key' => 'value')
+ data_request.stubs(:oauth_user_request).returns(response)
+ data_request.send_request
+
+ assert_received(data_request, :oauth_user_request)
+ end
+
+ should "raise if the request is unauthorized (Net::HTTP)" do
@session.stubs(:single_user?).returns(false)
@session.stubs(:oauth_user?).returns(true)
response = mock('Net::HTTPUnauthorized', :body => 'Error')
@@ -78,6 +92,22 @@ class DataTest < MiniTest::Unit::TestCase
end
end
+ should "raise if the request is unauthorized (OAuth2)" do
+ @session.stubs(:single_user?).returns(false)
+ @session.stubs(:oauth_user?).returns(true)
+ response = mock('OAuth2::Response') do |m|
+ m.expects(:status).returns(401)
+ m.expects(:body).returns('Error')
+ end
+
+ data_request = Request::Data.new(@session, 'https://example.com/data', 'key' => 'value')
+ data_request.stubs(:oauth_user_request).returns(response)
+
+ assert_raises(Garb::Request::Data::ClientError) do
+ data_request.send_request
+ end
+ end
+
should "be able to request via the ouath access token" do
access_token = stub(:get => "responseobject")
@session.stubs(:access_token).returns(access_token)

0 comments on commit 6c03b02

Please sign in to comment.
Something went wrong with that request. Please try again.