spec/cases/oauth_spec.rb in koala-1.0.0.rc vs spec/cases/oauth_spec.rb in koala-1.0.0
- old
+ new
@@ -155,11 +155,10 @@
lambda { oauth2.url_for_oauth_code }.should raise_error(ArgumentError)
end
end
describe "for access token URLs" do
-
# url_for_access_token
it "should generate a properly formatted OAuth token URL when provided a code" do
url = @oauth.url_for_access_token(@code)
url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{@callback_url}&client_secret=#{@secret}&code=#{@code}"
end
@@ -202,22 +201,34 @@
end
it "should raise an error when get_access_token is called with a bad code" do
lambda { @oauth.get_access_token("foo") }.should raise_error(Koala::Facebook::APIError)
end
+
+ it "should pass on any options provided to make_request" do
+ options = {:a => 2}
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
+ @oauth.get_access_token(@code, options)
+ end
end
describe "get_app_access_token_info" do
it "should properly get and parse an app's access token as a hash" do
result = @oauth.get_app_access_token_info
result.should be_a(Hash)
end
-
+
it "should include the access token" do
result = @oauth.get_app_access_token_info
result["access_token"].should
end
+
+ it "should pass on any options provided to make_request" do
+ options = {:a => 2}
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
+ @oauth.get_app_access_token_info(options)
+ end
end
describe "get_app_acess_token" do
it "should use get_access_token_info to get and parse an access token token results" do
result = @oauth.get_app_access_token
@@ -227,10 +238,16 @@
it "should return the access token as a string" do
result = @oauth.get_app_access_token
original = @oauth.get_app_access_token_info
result.should == original["access_token"]
end
+
+ it "should pass on any options provided to make_request" do
+ options = {:a => 2}
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
+ @oauth.get_app_access_token(options)
+ end
end
describe "protected methods" do
# protected methods
@@ -297,16 +314,22 @@
it "should throw an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
@oauth.should_receive(:fetch_token_string).and_return("")
lambda { @oauth.get_token_info_from_session_keys(@oauth_data["multiple_session_keys"]) }.should raise_error(Koala::Facebook::APIError)
end
+
+ it "should pass on any options provided to make_request" do
+ options = {:a => 2}
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
+ @oauth.get_token_info_from_session_keys([], options)
+ end
end
describe "with get_tokens_from_session_keys" do
it "should call get_token_info_from_session_keys" do
args = @oauth_data["multiple_session_keys"]
- @oauth.should_receive(:get_token_info_from_session_keys).with(args).and_return([])
+ @oauth.should_receive(:get_token_info_from_session_keys).with(args, anything).and_return([])
@oauth.get_tokens_from_session_keys(args)
end
it "should return an array of strings" do
args = @oauth_data["multiple_session_keys"]
@@ -323,16 +346,22 @@
it "should properly handle a mix of valid and invalid session keys" do
result = @oauth.get_tokens_from_session_keys(["foo"].concat(@oauth_data["multiple_session_keys"]))
# it should return nil for each of the invalid ones
result.each_with_index {|r, index| index > 0 ? r.should(be_a(String)) : r.should(be_nil)}
end
+
+ it "should pass on any options provided to make_request" do
+ options = {:a => 2}
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
+ @oauth.get_tokens_from_session_keys([], options)
+ end
end
describe "get_token_from_session_key" do
it "should call get_tokens_from_session_keys when the get_token_from_session_key is called" do
key = @oauth_data["session_key"]
- @oauth.should_receive(:get_tokens_from_session_keys).with([key]).and_return([])
+ @oauth.should_receive(:get_tokens_from_session_keys).with([key], anything).and_return([])
@oauth.get_token_from_session_key(key)
end
it "should get back the access token string from get_token_from_session_key" do
result = @oauth.get_token_from_session_key(@oauth_data["session_key"])
@@ -346,9 +375,15 @@
end
it "should properly handle an invalid session key" do
result = @oauth.get_token_from_session_key("foo")
result.should be_nil
+ end
+
+ it "should pass on any options provided to make_request" do
+ options = {:a => 2}
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
+ @oauth.get_token_from_session_key("", options)
end
end
end
describe "for parsing signed requests" do
\ No newline at end of file