koala 1.0.0.beta2.1 → 1.0.0.rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/CHANGELOG +6 -1
- data/Gemfile +3 -0
- data/Rakefile +13 -14
- data/koala.gemspec +35 -20
- data/lib/koala.rb +8 -17
- data/lib/koala/graph_api.rb +2 -2
- data/lib/koala/http_services.rb +32 -27
- data/lib/koala/test_users.rb +4 -4
- data/lib/koala/uploadable_io.rb +1 -1
- data/spec/cases/api_base_spec.rb +101 -0
- data/spec/cases/graph_and_rest_api_spec.rb +31 -0
- data/spec/cases/graph_api_spec.rb +25 -0
- data/spec/{koala/http_services/http_service_tests.rb → cases/http_services/http_service_spec.rb} +8 -5
- data/spec/cases/http_services/net_http_service_spec.rb +350 -0
- data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
- data/spec/cases/oauth_spec.rb +374 -0
- data/spec/cases/realtime_updates_spec.rb +184 -0
- data/spec/cases/rest_api_spec.rb +25 -0
- data/spec/{koala/test_users/test_users_tests.rb → cases/test_users_spec.rb} +34 -29
- data/spec/cases/uploadable_io_spec.rb +151 -0
- data/spec/{koala/assets → fixtures}/beach.jpg +0 -0
- data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +5 -5
- data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +311 -311
- data/spec/spec_helper.rb +18 -0
- data/spec/support/graph_api_shared_examples.rb +424 -0
- data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
- data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -94
- data/spec/{koala/rest_api/rest_api_tests.rb → support/rest_api_shared_examples.rb} +43 -0
- data/spec/support/setup_mocks_or_live.rb +52 -0
- data/spec/support/uploadable_io_shared_examples.rb +76 -0
- metadata +109 -53
- data/init.rb +0 -2
- data/spec/koala/api_base_tests.rb +0 -102
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -14
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -16
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -65
- data/spec/koala/graph_api/graph_api_tests.rb +0 -85
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -194
- data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
- data/spec/koala/http_services/net_http_service_tests.rb +0 -339
- data/spec/koala/http_services/typhoeus_service_tests.rb +0 -162
- data/spec/koala/oauth/oauth_tests.rb +0 -372
- data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -25
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -38
- data/spec/koala/uploadable_io/uploadable_io_tests.rb +0 -246
- data/spec/koala_spec.rb +0 -18
- data/spec/koala_spec_helper.rb +0 -74
- data/spec/koala_spec_without_mocks.rb +0 -19
data/init.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
class ApiBaseTests < Test::Unit::TestCase
|
2
|
-
|
3
|
-
describe "Koala API base class" do
|
4
|
-
before(:each) do
|
5
|
-
@service = Koala::Facebook::API.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should not include an access token if none was given" do
|
9
|
-
Koala.should_receive(:make_request).with(
|
10
|
-
anything,
|
11
|
-
hash_not_including('access_token' => 1),
|
12
|
-
anything,
|
13
|
-
anything
|
14
|
-
).and_return(Koala::Response.new(200, "", ""))
|
15
|
-
|
16
|
-
@service.api('anything')
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should include an access token if given" do
|
20
|
-
token = 'adfadf'
|
21
|
-
service = Koala::Facebook::API.new token
|
22
|
-
|
23
|
-
Koala.should_receive(:make_request).with(
|
24
|
-
anything,
|
25
|
-
hash_including('access_token' => token),
|
26
|
-
anything,
|
27
|
-
anything
|
28
|
-
).and_return(Koala::Response.new(200, "", ""))
|
29
|
-
|
30
|
-
service.api('anything')
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should have an attr_reader for access token" do
|
34
|
-
token = 'adfadf'
|
35
|
-
service = Koala::Facebook::API.new token
|
36
|
-
service.access_token.should == token
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should get the attribute of a Koala::Response given by the http_component parameter" do
|
40
|
-
http_component = :method_name
|
41
|
-
|
42
|
-
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
43
|
-
response.should_receive(http_component).and_return('')
|
44
|
-
|
45
|
-
Koala.stub(:make_request).and_return(response)
|
46
|
-
|
47
|
-
@service.api('anything', 'get', {}, :http_component => http_component)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return the body of the request as JSON if no http_component is given" do
|
51
|
-
response = stub('response', :body => 'body', :status => 200)
|
52
|
-
Koala.stub(:make_request).and_return(response)
|
53
|
-
|
54
|
-
json_body = mock('JSON body')
|
55
|
-
JSON.stub(:parse).and_return([json_body])
|
56
|
-
|
57
|
-
@service.api('anything').should == json_body
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should execute a block with the response body if passed one" do
|
61
|
-
body = '{}'
|
62
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(200, body, {}))
|
63
|
-
|
64
|
-
yield_test = mock('Yield Tester')
|
65
|
-
yield_test.should_receive(:pass)
|
66
|
-
|
67
|
-
@service.api('anything') do |arg|
|
68
|
-
yield_test.pass
|
69
|
-
arg.should == JSON.parse(body)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should raise an API error if the HTTP response code is greater than or equal to 500" do
|
74
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, 'response body', {}))
|
75
|
-
|
76
|
-
lambda { @service.api('anything') }.should raise_exception(Koala::Facebook::APIError)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should handle rogue true/false as responses" do
|
80
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'true', {}))
|
81
|
-
@service.api('anything').should be_true
|
82
|
-
|
83
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'false', {}))
|
84
|
-
@service.api('anything').should be_false
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "with regard to leading slashes" do
|
88
|
-
it "should add a leading / to the path if not present" do
|
89
|
-
path = "anything"
|
90
|
-
Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
91
|
-
@service.api(path)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "shouldn't change the path if a leading / is present" do
|
95
|
-
path = "/anything"
|
96
|
-
Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
97
|
-
@service.api(path)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class GraphAndRestAPINoTokenTests < Test::Unit::TestCase
|
2
|
-
describe "Koala GraphAndRestAPI without an access token" do
|
3
|
-
before(:each) do
|
4
|
-
@api = Koala::Facebook::GraphAndRestAPI.new
|
5
|
-
end
|
6
|
-
|
7
|
-
it_should_behave_like "Koala RestAPI"
|
8
|
-
it_should_behave_like "Koala RestAPI without an access token"
|
9
|
-
|
10
|
-
it_should_behave_like "Koala GraphAPI"
|
11
|
-
it_should_behave_like "Koala GraphAPI without an access token"
|
12
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
13
|
-
end
|
14
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class GraphAndRestAPIWithTokenTests < Test::Unit::TestCase
|
2
|
-
describe "Koala GraphAndRestAPI without an access token" do
|
3
|
-
include LiveTestingDataHelper
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@api = Koala::Facebook::GraphAndRestAPI.new(@token)
|
7
|
-
end
|
8
|
-
|
9
|
-
it_should_behave_like "Koala RestAPI"
|
10
|
-
it_should_behave_like "Koala RestAPI with an access token"
|
11
|
-
|
12
|
-
it_should_behave_like "Koala GraphAPI"
|
13
|
-
it_should_behave_like "Koala GraphAPI with an access token"
|
14
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
15
|
-
end
|
16
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
shared_examples_for "Koala GraphAPI without an access token" do
|
2
|
-
|
3
|
-
it "should not get private data about a user" do
|
4
|
-
result = @api.get_object("koppel")
|
5
|
-
# updated_time should be a pretty fixed test case
|
6
|
-
result["updated_time"].should be_nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should not be able to get data about 'me'" do
|
10
|
-
lambda { @api.get_object("me") }.should raise_error(Koala::Facebook::APIError)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "shouldn't be able to access connections from users" do
|
14
|
-
lambda { @api.get_connections("lukeshepard", "likes") }.should raise_error(Koala::Facebook::APIError)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should not be able to put an object" do
|
18
|
-
lambda { @result = @api.put_object("lukeshepard", "feed", :message => "Hello, world") }.should raise_error(Koala::Facebook::APIError)
|
19
|
-
puts "Error! Object #{@result.inspect} somehow put onto Luke Shepard's wall!" if @result
|
20
|
-
end
|
21
|
-
|
22
|
-
# these are not strictly necessary as the other put methods resolve to put_object, but are here for completeness
|
23
|
-
it "should not be able to post to a feed" do
|
24
|
-
(lambda do
|
25
|
-
attachment = {:name => "OAuth Playground", :link => "http://www.oauth.twoalex.com/"}
|
26
|
-
@result = @api.put_wall_post("Hello, world", attachment, "contextoptional")
|
27
|
-
end).should raise_error(Koala::Facebook::APIError)
|
28
|
-
puts "Error! Object #{@result.inspect} somehow put onto Context Optional's wall!" if @result
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should not be able to comment on an object" do
|
32
|
-
# random public post on the ContextOptional wall
|
33
|
-
lambda { @result = @api.put_comment("7204941866_119776748033392", "The hackathon was great!") }.should raise_error(Koala::Facebook::APIError)
|
34
|
-
puts "Error! Object #{@result.inspect} somehow commented on post 7204941866_119776748033392!" if @result
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should not be able to like an object" do
|
38
|
-
lambda { @api.put_like("7204941866_119776748033392") }.should raise_error(Koala::Facebook::APIError)
|
39
|
-
end
|
40
|
-
|
41
|
-
# DELETE
|
42
|
-
it "should not be able to delete posts" do
|
43
|
-
# test post on the Ruby SDK Test application
|
44
|
-
lambda { @result = @api.delete_object("115349521819193_113815981982767") }.should raise_error(Koala::Facebook::APIError)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should not be able to delete a like" do
|
48
|
-
lambda { @api.delete_like("7204941866_119776748033392") }.should raise_error(Koala::Facebook::APIError)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class FacebookNoAccessTokenTests < Test::Unit::TestCase
|
53
|
-
describe "Koala GraphAPI without an access token" do
|
54
|
-
include LiveTestingDataHelper
|
55
|
-
|
56
|
-
before :each do
|
57
|
-
@api = Koala::Facebook::GraphAPI.new
|
58
|
-
end
|
59
|
-
|
60
|
-
it_should_behave_like "Koala GraphAPI"
|
61
|
-
it_should_behave_like "Koala GraphAPI without an access token"
|
62
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
63
|
-
|
64
|
-
end
|
65
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
shared_examples_for "Koala GraphAPI" do
|
2
|
-
# all Graph API instances should pass these tests, regardless of configuration
|
3
|
-
|
4
|
-
# API
|
5
|
-
it "should never use the rest api server" do
|
6
|
-
Koala.should_receive(:make_request).with(
|
7
|
-
anything,
|
8
|
-
anything,
|
9
|
-
anything,
|
10
|
-
hash_not_including(:rest_api => true)
|
11
|
-
).and_return(Koala::Response.new(200, "", {}))
|
12
|
-
|
13
|
-
@api.api("anything")
|
14
|
-
end
|
15
|
-
|
16
|
-
# GRAPH CALL
|
17
|
-
describe "graph_call" do
|
18
|
-
it "should pass all arguments to the api method" do
|
19
|
-
args = ["koppel", {}, "get", {:a => :b}]
|
20
|
-
|
21
|
-
@api.should_receive(:api).with(*args)
|
22
|
-
|
23
|
-
@api.graph_call(*args)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should throw an APIError if the result hash has an error key" do
|
27
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, {"error" => "An error occurred!"}, {}))
|
28
|
-
lambda { @api.graph_call("koppel", {}) }.should raise_exception(Koala::Facebook::APIError)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# SEARCH
|
33
|
-
it "should be able to search" do
|
34
|
-
result = @api.search("facebook")
|
35
|
-
result.length.should be_an(Integer)
|
36
|
-
end
|
37
|
-
|
38
|
-
# DATA
|
39
|
-
# access public info
|
40
|
-
|
41
|
-
# get_object
|
42
|
-
it "should get public data about a user" do
|
43
|
-
result = @api.get_object("koppel")
|
44
|
-
# the results should have an ID and a name, among other things
|
45
|
-
(result["id"] && result["name"]).should_not be_nil
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should get public data about a Page" do
|
49
|
-
result = @api.get_object("contextoptional")
|
50
|
-
# the results should have an ID and a name, among other things
|
51
|
-
(result["id"] && result["name"]).should
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should be able to get multiple objects" do
|
55
|
-
results = @api.get_objects(["contextoptional", "naitik"])
|
56
|
-
results.length.should == 2
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be able to access a user's picture" do
|
60
|
-
@api.get_picture("chris.baclig").should =~ /http\:\/\//
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should be able to access a user's picture, given a picture type" do
|
64
|
-
@api.get_picture("chris.baclig", {:type => 'large'}).should =~ /^http\:\/\//
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should be able to access connections from public Pages" do
|
68
|
-
result = @api.get_connections("contextoptional", "photos")
|
69
|
-
result.should be_a(Array)
|
70
|
-
end
|
71
|
-
|
72
|
-
# SEARCH
|
73
|
-
it "should be able to search" do
|
74
|
-
result = @api.search("facebook")
|
75
|
-
result.length.should be_an(Integer)
|
76
|
-
end
|
77
|
-
|
78
|
-
# PAGING THROUGH COLLECTIONS
|
79
|
-
# see also graph_collection_tests
|
80
|
-
it "should make a request for a page when provided a specific set of page params" do
|
81
|
-
query = [1, 2]
|
82
|
-
@api.should_receive(:graph_call).with(*query)
|
83
|
-
@api.get_page(query)
|
84
|
-
end
|
85
|
-
end
|
@@ -1,194 +0,0 @@
|
|
1
|
-
shared_examples_for "Koala GraphAPI with an access token" do
|
2
|
-
|
3
|
-
it "should get private data about a user" do
|
4
|
-
result = @api.get_object("koppel")
|
5
|
-
# updated_time should be a pretty fixed test case
|
6
|
-
result["updated_time"].should_not be_nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should get data about 'me'" do
|
10
|
-
result = @api.get_object("me")
|
11
|
-
result["updated_time"].should
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be able to get multiple objects" do
|
15
|
-
result = @api.get_objects(["contextoptional", "naitik"])
|
16
|
-
result.length.should == 2
|
17
|
-
end
|
18
|
-
it "should be able to access connections from users" do
|
19
|
-
result = @api.get_connections("lukeshepard", "likes")
|
20
|
-
result.length.should > 0
|
21
|
-
end
|
22
|
-
|
23
|
-
# PUT
|
24
|
-
it "should be able to write an object to the graph" do
|
25
|
-
result = @api.put_wall_post("Hello, world, from the test suite!")
|
26
|
-
@temporary_object_id = result["id"]
|
27
|
-
@temporary_object_id.should_not be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
# DELETE
|
31
|
-
it "should be able to delete posts" do
|
32
|
-
result = @api.put_wall_post("Hello, world, from the test suite delete method!")
|
33
|
-
object_id_to_delete = result["id"]
|
34
|
-
delete_result = @api.delete_object(object_id_to_delete)
|
35
|
-
delete_result.should == true
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should be able to delete likes" do
|
39
|
-
result = @api.put_wall_post("Hello, world, from the test suite delete method!")
|
40
|
-
@temporary_object_id = result["id"]
|
41
|
-
@api.put_like(@temporary_object_id)
|
42
|
-
delete_like_result = @api.delete_like(@temporary_object_id)
|
43
|
-
delete_like_result.should == true
|
44
|
-
end
|
45
|
-
|
46
|
-
# additional put tests
|
47
|
-
it "should be able to verify messages posted to a wall" do
|
48
|
-
message = "the cats are asleep"
|
49
|
-
put_result = @api.put_wall_post(message)
|
50
|
-
@temporary_object_id = put_result["id"]
|
51
|
-
get_result = @api.get_object(@temporary_object_id)
|
52
|
-
|
53
|
-
# make sure the message we sent is the message that got posted
|
54
|
-
get_result["message"].should == message
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should be able to post a message with an attachment to a feed" do
|
58
|
-
result = @api.put_wall_post("Hello, world, from the test suite again!", {:name => "OAuth Playground", :link => "http://oauth.twoalex.com/"})
|
59
|
-
@temporary_object_id = result["id"]
|
60
|
-
@temporary_object_id.should_not be_nil
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should be able to post photos to the user's wall with an open file object" do
|
64
|
-
content_type = "image/jpg"
|
65
|
-
file = File.open(File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg"))
|
66
|
-
|
67
|
-
result = @api.put_picture(file, content_type)
|
68
|
-
@temporary_object_id = result["id"]
|
69
|
-
@temporary_object_id.should_not be_nil
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should be able to post photos to the user's wall without an open file object" do
|
73
|
-
content_type = "image/jpg",
|
74
|
-
file_path = File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg")
|
75
|
-
|
76
|
-
result = @api.put_picture(file_path, content_type)
|
77
|
-
@temporary_object_id = result["id"]
|
78
|
-
@temporary_object_id.should_not be_nil
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should be able to verify a photo posted to a user's wall" do
|
82
|
-
content_type = "image/jpg",
|
83
|
-
file_path = File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg")
|
84
|
-
|
85
|
-
expected_message = "This is the test message"
|
86
|
-
|
87
|
-
result = @api.put_picture(file_path, content_type, :message => expected_message)
|
88
|
-
@temporary_object_id = result["id"]
|
89
|
-
@temporary_object_id.should_not be_nil
|
90
|
-
|
91
|
-
get_result = @api.get_object(@temporary_object_id)
|
92
|
-
get_result["name"].should == expected_message
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should be able to verify a message with an attachment posted to a feed" do
|
96
|
-
attachment = {"name" => "OAuth Playground", "link" => "http://oauth.twoalex.com/"}
|
97
|
-
result = @api.put_wall_post("Hello, world, from the test suite again!", attachment)
|
98
|
-
@temporary_object_id = result["id"]
|
99
|
-
get_result = @api.get_object(@temporary_object_id)
|
100
|
-
|
101
|
-
# make sure the result we fetch includes all the parameters we sent
|
102
|
-
it_matches = attachment.inject(true) {|valid, param| valid && (get_result[param[0]] == attachment[param[0]])}
|
103
|
-
it_matches.should == true
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should be able to comment on an object" do
|
107
|
-
result = @api.put_wall_post("Hello, world, from the test suite, testing comments!")
|
108
|
-
@temporary_object_id = result["id"]
|
109
|
-
|
110
|
-
# this will be deleted when the post gets deleted
|
111
|
-
comment_result = @api.put_comment(@temporary_object_id, "it's my comment!")
|
112
|
-
comment_result.should_not be_nil
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should be able to verify a comment posted about an object" do
|
116
|
-
message_text = "Hello, world, from the test suite, testing comments!"
|
117
|
-
result = @api.put_wall_post(message_text)
|
118
|
-
@temporary_object_id = result["id"]
|
119
|
-
|
120
|
-
# this will be deleted when the post gets deleted
|
121
|
-
comment_text = "it's my comment!"
|
122
|
-
comment_result = @api.put_comment(@temporary_object_id, comment_text)
|
123
|
-
get_result = @api.get_object(comment_result["id"])
|
124
|
-
|
125
|
-
# make sure the text of the comment matches what we sent
|
126
|
-
get_result["message"].should == comment_text
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should be able to like an object" do
|
130
|
-
result = @api.put_wall_post("Hello, world, from the test suite, testing comments!")
|
131
|
-
@temporary_object_id = result["id"]
|
132
|
-
like_result = @api.put_like(@temporary_object_id)
|
133
|
-
like_result.should be_true
|
134
|
-
end
|
135
|
-
|
136
|
-
|
137
|
-
# test all methods to make sure they pass data through to the API
|
138
|
-
# we run the tests here (rather than in the common shared example group)
|
139
|
-
# since some require access tokens
|
140
|
-
describe "HTTP options" do
|
141
|
-
# Each of the below methods should take an options hash as their last argument
|
142
|
-
# ideally we'd use introspection to determine how many arguments a method has
|
143
|
-
# but some methods require specially formatted arguments for processing
|
144
|
-
# (and anyway, Ruby 1.8's arity method fails (for this) for methods w/ 2+ optional arguments)
|
145
|
-
# (Ruby 1.9's parameters method is perfect, but only in 1.9)
|
146
|
-
# so we have to double-document
|
147
|
-
{
|
148
|
-
:get_object => 3, :put_object => 4, :delete_object => 2,
|
149
|
-
:get_connections => 4, :put_connections => 4, :delete_connections => 4,
|
150
|
-
:put_wall_post => 4,
|
151
|
-
:put_comment => 3,
|
152
|
-
:put_like => 2, :delete_like => 2,
|
153
|
-
:search => 3,
|
154
|
-
# methods that have special arguments
|
155
|
-
:put_picture => ["x.jpg", "image/jpg", {}, "me"],
|
156
|
-
:get_objects => [["x"], {}]
|
157
|
-
}.each_pair do |method_name, params|
|
158
|
-
it "should pass http options through for #{method_name}" do
|
159
|
-
options = {:a => 2}
|
160
|
-
# graph call should ultimately receive options as the fourth argument
|
161
|
-
@api.should_receive(:graph_call).with(anything, anything, anything, options)
|
162
|
-
|
163
|
-
# if we supply args, use them (since some methods process params)
|
164
|
-
# the method should receive as args n-1 anythings and then options
|
165
|
-
args = (params.is_a?(Integer) ? ([{}] * (params - 1)) : params) + [options]
|
166
|
-
|
167
|
-
@api.send(method_name, *args)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# also test get_picture, which merges a parameter into options
|
172
|
-
it "should pass http options through for get_picture" do
|
173
|
-
options = {:a => 2}
|
174
|
-
# graph call should ultimately receive options as the fourth argument
|
175
|
-
@api.should_receive(:graph_call).with(anything, anything, anything, hash_including(options)).and_return({})
|
176
|
-
@api.send(:get_picture, "x", {}, options)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
class FacebookWithAccessTokenTests < Test::Unit::TestCase
|
182
|
-
describe "Koala GraphAPI with an access token" do
|
183
|
-
include LiveTestingDataHelper
|
184
|
-
|
185
|
-
before :each do
|
186
|
-
@api = Koala::Facebook::GraphAPI.new(@token)
|
187
|
-
end
|
188
|
-
|
189
|
-
it_should_behave_like "Koala GraphAPI"
|
190
|
-
it_should_behave_like "Koala GraphAPI with an access token"
|
191
|
-
it_should_behave_like "Koala GraphAPI with GraphCollection"
|
192
|
-
|
193
|
-
end
|
194
|
-
end
|