spec/cases/oauth_spec.rb in koala-1.3.0rc2 vs spec/cases/oauth_spec.rb in koala-1.3.0
- old
+ new
@@ -102,14 +102,30 @@
context "if the code is present" do
it "adds the access_token into the hash" do
@oauth.get_user_info_from_cookies(@cookie)["access_token"].should == @token
end
- it "returns nil if the call to FB fails" do
+ it "returns nil if the call to FB returns no data" do
@oauth.stub(:get_access_token_info).and_return(nil)
@oauth.get_user_info_from_cookies(@cookie).should be_nil
end
+
+ it "returns nil if the call to FB returns an expired code error" do
+ @oauth.stub(:get_access_token_info).and_raise(Koala::Facebook::APIError.new(
+ "type" => "OAuthException",
+ "message" => "Code was invalid or expired. Session has expired at unix time 1324044000. The current unix time is 1324300957."
+ ))
+ @oauth.get_user_info_from_cookies(@cookie).should be_nil
+ end
+
+ it "raises the error if the call to FB returns a different error" do
+ @oauth.stub(:get_access_token_info).and_raise(Koala::Facebook::APIError.new(
+ "type" => "OtherError",
+ "message" => "A Facebook Error"
+ ))
+ expect { @oauth.get_user_info_from_cookies(@cookie) }.to raise_exception(Koala::Facebook::APIError)
+ end
end
it "doesn't parse invalid cookies" do
# make an invalid string by replacing some values
bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
@@ -164,15 +180,15 @@
# we don't actually want to make requests to Facebook to redeem the code
@cookie = KoalaTest.oauth_test_data["valid_signed_cookies"]
@oauth.stub(:get_access_token_info).and_return("access_token" => "my token")
end
- it "uses get_user_info_from_cookies to parse the cookies" do
- @oauth.should_receive(:get_user_info_from_cookies).with(@cookie).and_return({})
+ it "does not uses get_user_info_from_cookies to parse the cookies" do
+ @oauth.should_not_receive(:get_user_info_from_cookies).with(@cookie).and_return({})
@oauth.get_user_from_cookies(@cookie)
end
- it "uses return the token string if the cookies are valid" do
+ it "uses return the facebook user id string if the cookies are valid" do
result = @oauth.get_user_from_cookies(@cookie)
result.should == "2905623" # the user who generated the original test cookie
end
it "returns nil if the cookies are invalid" do