spec/cases/oauth_spec.rb in koala-1.7.0rc1 vs spec/cases/oauth_spec.rb in koala-1.8.0rc1
- old
+ new
@@ -26,12 +26,12 @@
@oauth = Koala::Facebook::OAuth.new(@app_id, @secret, @callback_url)
end
before :each do
@time = Time.now
- Time.stub!(:now).and_return(@time)
- @time.stub!(:to_i).and_return(1273363199)
+ Time.stub(:now).and_return(@time)
+ @time.stub(:to_i).and_return(1273363199)
end
describe ".new" do
it "properly initializes" do
@oauth.should
@@ -371,10 +371,50 @@
end
end
end
end
+ describe 'for generating a client code' do
+ describe '#generate_client_code' do
+ if KoalaTest.mock_interface? || KoalaTest.oauth_token
+ it 'makes a request using the correct endpoint' do
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
+ @oauth.generate_client_code(KoalaTest.oauth_token)
+ end
+
+ it 'gets a valid client code returned' do
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
+ result = @oauth.generate_client_code(KoalaTest.oauth_token)
+ result.should be_a(String)
+ result.should eq('fake_client_code')
+ end
+
+ it 'raises a BadFacebookResponse error when empty response body is returned' do
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '', {}))
+ lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::BadFacebookResponse)
+ end
+
+ it 'raises an OAuthTokenRequestError when empty response body is returned' do
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(400, '', {}))
+ lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::OAuthTokenRequestError)
+ end
+
+ it 'raises a ServerError when empty response body is returned' do
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(500, '', {}))
+ lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::ServerError)
+ end
+
+ it 'raises a KoalaError when empty response body is returned' do
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"client_code":"should_not_be_returned"}', {}))
+ lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::KoalaError)
+ end
+ else
+ pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
+ end
+ end
+ end
+
describe "for fetching access tokens" do
describe "#get_access_token_info" do
it "uses options[:redirect_uri] if provided" do
uri = "foo"
Koala.should_receive(:make_request).with(anything, hash_including(:redirect_uri => uri), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
@@ -668,10 +708,10 @@
MultiJson.stub(:load).and_return("algorithm" => "my fun algorithm")
lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
end
it "throws an error if the signature is invalid" do
- OpenSSL::HMAC.stub!(:hexdigest).and_return("i'm an invalid signature")
+ OpenSSL::HMAC.stub(:hexdigest).and_return("i'm an invalid signature")
lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
end
it "throws an error if the signature string is empty" do
# this occasionally happens due to Facebook error