spec/cases/oauth_spec.rb in koala-1.6.0 vs spec/cases/oauth_spec.rb in koala-1.7.0rc1
- old
+ new
@@ -146,11 +146,10 @@
result.should be_a(Hash)
end
it "returns all the cookie components from valid cookie string" do
cookie_data = KoalaTest.oauth_test_data["valid_cookies"]
- puts cookie_data.inspect
parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
parsing_results.length.should == number_of_components
end
@@ -188,11 +187,11 @@
@cookie = KoalaTest.oauth_test_data["valid_signed_cookies"]
@oauth.stub(:get_access_token_info).and_return("access_token" => "my token")
end
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.should_not_receive(:get_user_info_from_cookies).with(@cookie)
@oauth.get_user_from_cookies(@cookie)
end
it "uses return the facebook user id string if the cookies are valid" do
result = @oauth.get_user_from_cookies(@cookie)
@@ -203,10 +202,15 @@
# make an invalid string by replacing some values
bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
result = @oauth.get_user_from_cookies(bad_cookie_hash)
result.should be_nil
end
+
+ it "is deprecated" do
+ Koala::Utils.should_receive(:deprecate)
+ @oauth.get_user_from_cookies({})
+ end
end
describe "for unsigned cookies" do
before :each do
# we don't actually want to make requests to Facebook to redeem the code
@@ -235,41 +239,41 @@
describe "for URL generation" do
describe "#url_for_oauth_code" do
it "generates a properly formatted OAuth code URL with the default values" do
url = @oauth.url_for_oauth_code
- url.should match_url("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
+ url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
end
it "generates a properly formatted OAuth code URL when a callback is given" do
callback = "foo.com"
url = @oauth.url_for_oauth_code(:callback => callback)
- url.should match_url("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}")
+ url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{callback}")
end
it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
permissions = "publish_stream,read_stream"
url = @oauth.url_for_oauth_code(:permissions => permissions)
- url.should match_url("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape @callback_url}")
+ url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape @callback_url}")
end
it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
permissions = ["publish_stream", "read_stream"]
url = @oauth.url_for_oauth_code(:permissions => permissions)
- url.should match_url("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&scope=#{CGI.escape permissions.join(",")}&redirect_uri=#{CGI.escape @callback_url}")
+ url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions.join(",")}&redirect_uri=#{CGI.escape @callback_url}")
end
it "generates a properly formatted OAuth code URL when both permissions and callback are provided" do
permissions = "publish_stream,read_stream"
callback = "foo.com"
url = @oauth.url_for_oauth_code(:callback => callback, :permissions => permissions)
- url.should match_url("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape callback}")
+ url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape callback}")
end
it "generates a properly formatted OAuth code URL when a display is given as a string" do
url = @oauth.url_for_oauth_code(:display => "page")
- url.should match_url("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&display=page&redirect_uri=#{CGI.escape @callback_url}")
+ url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&display=page&redirect_uri=#{CGI.escape @callback_url}")
end
it "raises an exception if no callback is given in initialization or the call" do
oauth2 = Koala::Facebook::OAuth.new(@app_id, @secret)
lambda { oauth2.url_for_oauth_code }.should raise_error(ArgumentError)
@@ -293,17 +297,17 @@
@code ||= "test_code"
end
it "generates a properly formatted OAuth token URL when provided a code" do
url = @oauth.url_for_access_token(@code)
- url.should match_url("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
+ url.should match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
end
it "generates a properly formatted OAuth token URL when provided a callback" do
callback = "foo.com"
url = @oauth.url_for_access_token(@code, :callback => callback)
- url.should match_url("https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape callback}")
+ url.should match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape callback}")
end
it "includes any additional options as URL parameters, appropriately escaped" do
params = {
:url => "http://foo.bar?c=2",
@@ -317,11 +321,11 @@
end
describe "#url_for_dialog" do
it "builds the base properly" do
dialog_type = "my_dialog_type"
- @oauth.url_for_dialog(dialog_type).should =~ /^http:\/\/#{Koala::Facebook::DIALOG_HOST}\/dialog\/#{dialog_type}/
+ @oauth.url_for_dialog(dialog_type).should =~ /^http:\/\/#{Koala.config.dialog_host}\/dialog\/#{dialog_type}/
end
it "adds the app_id/client_id to the url" do
automatic_params = {:app_id => @app_id, :client_id => @client_id}
url = @oauth.url_for_dialog("foo", automatic_params)
@@ -539,10 +543,10 @@
else
it "fetch_token_string code test will not be run since the code field in facebook_data.yml is blank."
end
it "fetches a proper token string from Facebook when asked for the app token" do
- result = @oauth.send(:fetch_token_string, {:type => 'client_cred'}, true)
+ result = @oauth.send(:fetch_token_string, {:grant_type => 'client_credentials'}, true)
result.should =~ /^access_token/
end
end
end