koala 1.0.0 → 1.2.0
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/.autotest +12 -0
- data/.gitignore +3 -1
- data/.travis.yml +9 -0
- data/CHANGELOG +62 -2
- data/Gemfile +8 -0
- data/Rakefile +0 -1
- data/autotest/discover.rb +1 -0
- data/koala.gemspec +13 -14
- data/lib/koala/batch_operation.rb +74 -0
- data/lib/koala/graph_api.rb +145 -132
- data/lib/koala/graph_batch_api.rb +97 -0
- data/lib/koala/graph_collection.rb +59 -0
- data/lib/koala/http_service.rb +176 -0
- data/lib/koala/oauth.rb +191 -0
- data/lib/koala/realtime_updates.rb +23 -29
- data/lib/koala/rest_api.rb +13 -8
- data/lib/koala/test_users.rb +33 -17
- data/lib/koala/uploadable_io.rb +153 -87
- data/lib/koala/utils.rb +11 -0
- data/lib/koala/version.rb +3 -0
- data/lib/koala.rb +59 -217
- data/readme.md +92 -53
- data/spec/cases/{api_base_spec.rb → api_spec.rb} +31 -6
- data/spec/cases/error_spec.rb +32 -0
- data/spec/cases/graph_and_rest_api_spec.rb +12 -21
- data/spec/cases/graph_api_batch_spec.rb +582 -0
- data/spec/cases/graph_api_spec.rb +11 -14
- data/spec/cases/graph_collection_spec.rb +116 -0
- data/spec/cases/http_service_spec.rb +446 -0
- data/spec/cases/koala_spec.rb +54 -0
- data/spec/cases/oauth_spec.rb +319 -213
- data/spec/cases/realtime_updates_spec.rb +45 -31
- data/spec/cases/rest_api_spec.rb +23 -7
- data/spec/cases/test_users_spec.rb +123 -75
- data/spec/cases/uploadable_io_spec.rb +120 -37
- data/spec/cases/utils_spec.rb +10 -0
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/fixtures/facebook_data.yml +26 -24
- data/spec/fixtures/mock_facebook_responses.yml +203 -78
- data/spec/spec_helper.rb +30 -5
- data/spec/support/graph_api_shared_examples.rb +149 -118
- data/spec/support/json_testing_fix.rb +42 -0
- data/spec/support/koala_test.rb +187 -0
- data/spec/support/mock_http_service.rb +62 -58
- data/spec/support/ordered_hash.rb +205 -0
- data/spec/support/rest_api_shared_examples.rb +139 -15
- data/spec/support/uploadable_io_shared_examples.rb +2 -8
- metadata +90 -114
- data/lib/koala/http_services.rb +0 -146
- data/spec/cases/http_services/http_service_spec.rb +0 -54
- data/spec/cases/http_services/net_http_service_spec.rb +0 -350
- data/spec/cases/http_services/typhoeus_service_spec.rb +0 -144
- data/spec/support/live_testing_data_helper.rb +0 -40
- data/spec/support/setup_mocks_or_live.rb +0 -52
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
module Horse
|
|
5
|
-
include Koala::NetHTTPService
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
describe "NetHTTPService module holder class Horse" do
|
|
9
|
-
before :each do
|
|
10
|
-
# reset the always_use_ssl parameter
|
|
11
|
-
Horse.always_use_ssl = nil
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should define a make_request static module method" do
|
|
15
|
-
Horse.respond_to?(:make_request).should be_true
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should include the Koala::HTTPService module defining common features" do
|
|
19
|
-
Horse.included_modules.include?(Koala::HTTPService).should be_true
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "when making a request" do
|
|
23
|
-
before(:each) do
|
|
24
|
-
# Setup stubs for make_request to execute without exceptions
|
|
25
|
-
@mock_http_response = stub('Net::HTTPResponse', :code => 1)
|
|
26
|
-
@mock_body = stub('Net::HTTPResponse body')
|
|
27
|
-
@http_request_result = [@mock_http_response, @mock_body]
|
|
28
|
-
|
|
29
|
-
# to_ary is called in Ruby 1.9 to provide backwards compatibility
|
|
30
|
-
# with the response, body = http.get() syntax we use
|
|
31
|
-
@mock_http_response.stub!(:to_ary).and_return(@http_request_result)
|
|
32
|
-
|
|
33
|
-
@http_yield_mock = mock('Net::HTTP start yielded object')
|
|
34
|
-
|
|
35
|
-
@http_yield_mock.stub(:post).and_return(@http_request_result)
|
|
36
|
-
@http_yield_mock.stub(:get).and_return(@http_request_result)
|
|
37
|
-
|
|
38
|
-
@http_mock = stub('Net::HTTP object', 'use_ssl=' => true, 'verify_mode=' => true)
|
|
39
|
-
@http_mock.stub(:start).and_yield(@http_yield_mock)
|
|
40
|
-
|
|
41
|
-
Net::HTTP.stub(:new).and_return(@http_mock)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe "the connection" do
|
|
45
|
-
it "should use POST if verb is not GET" do
|
|
46
|
-
@http_yield_mock.should_receive(:post).and_return(@mock_http_response)
|
|
47
|
-
@http_mock.should_receive(:start).and_yield(@http_yield_mock)
|
|
48
|
-
|
|
49
|
-
Horse.make_request('anything', {}, 'anything')
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "should use GET if that verb is specified" do
|
|
53
|
-
@http_yield_mock.should_receive(:get).and_return(@mock_http_response)
|
|
54
|
-
@http_mock.should_receive(:start).and_yield(@http_yield_mock)
|
|
55
|
-
|
|
56
|
-
Horse.make_request('anything', {}, 'get')
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "should add the method to the arguments if it's not get or post" do
|
|
60
|
-
args = {}
|
|
61
|
-
method = "telekenesis"
|
|
62
|
-
# since the arguments get encoded later, we'll test for merge!
|
|
63
|
-
# even though that's somewhat testing internal implementation
|
|
64
|
-
args.should_receive(:merge!).with(:method => method)
|
|
65
|
-
|
|
66
|
-
Horse.make_request('anything', args, method)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
describe "if the request has an access token" do
|
|
71
|
-
before :each do
|
|
72
|
-
@args = {"access_token" => "123"}
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "should use SSL" do
|
|
76
|
-
@http_mock.should_receive('use_ssl=').with(true)
|
|
77
|
-
|
|
78
|
-
Horse.make_request('anything', @args, 'anything')
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should set the port to 443" do
|
|
82
|
-
Net::HTTP.should_receive(:new).with(anything, 443).and_return(@http_mock)
|
|
83
|
-
|
|
84
|
-
Horse.make_request('anything', @args, 'anything')
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
describe "if always_use_ssl is true" do
|
|
89
|
-
before :each do
|
|
90
|
-
Horse.always_use_ssl = true
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "should use SSL" do
|
|
94
|
-
@http_mock.should_receive('use_ssl=').with(true)
|
|
95
|
-
|
|
96
|
-
Horse.make_request('anything', {}, 'anything')
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should set the port to 443" do
|
|
100
|
-
Net::HTTP.should_receive(:new).with(anything, 443).and_return(@http_mock)
|
|
101
|
-
|
|
102
|
-
Horse.make_request('anything', {}, 'anything')
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
describe "if the use_ssl option is provided" do
|
|
107
|
-
it "should use SSL" do
|
|
108
|
-
@http_mock.should_receive('use_ssl=').with(true)
|
|
109
|
-
|
|
110
|
-
Horse.make_request('anything', {}, 'anything', :use_ssl => true)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "should set the port to 443" do
|
|
114
|
-
Net::HTTP.should_receive(:new).with(anything, 443).and_return(@http_mock)
|
|
115
|
-
|
|
116
|
-
Horse.make_request('anything', {}, 'anything', :use_ssl => true)
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe "if there's no token and always_use_ssl isn't true" do
|
|
121
|
-
it "should not use SSL" do
|
|
122
|
-
@http_mock.should_not_receive('use_ssl=')
|
|
123
|
-
Horse.make_request('anything', {}, 'anything')
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it "should not set the port" do
|
|
127
|
-
Net::HTTP.should_receive(:new).with(anything, nil).and_return(@http_mock)
|
|
128
|
-
Horse.make_request('anything', {}, 'anything')
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "should use the graph server by default" do
|
|
133
|
-
Net::HTTP.should_receive(:new).with(Koala::Facebook::GRAPH_SERVER, anything).and_return(@http_mock)
|
|
134
|
-
Horse.make_request('anything', {}, 'anything')
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "should use the REST server if the :rest_api option is true" do
|
|
138
|
-
Net::HTTP.should_receive(:new).with(Koala::Facebook::REST_SERVER, anything).and_return(@http_mock)
|
|
139
|
-
Horse.make_request('anything', {}, 'anything', :rest_api => true)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "no longer sets verify_mode to no verification" do
|
|
143
|
-
@http_mock.should_not_receive('verify_mode=')
|
|
144
|
-
|
|
145
|
-
Horse.make_request('anything', {}, 'anything')
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
it "should start an HTTP connection" do
|
|
149
|
-
@http_mock.should_receive(:start).and_yield(@http_yield_mock)
|
|
150
|
-
Horse.make_request('anything', {}, 'anything')
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it 'creates a HTTP Proxy object when options contain a proxy' do
|
|
154
|
-
Net::HTTP.should_receive(:new).with(anything, anything, 'proxy', 1234, 'user', 'pass').and_return(@http_mock)
|
|
155
|
-
Horse.make_request('anything', {}, 'anything', {:proxy => 'http://user:pass@proxy:1234'})
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
it 'sets both timeouts when options contains a timeout' do
|
|
159
|
-
@http_mock.should_receive(:open_timeout=).with(10)
|
|
160
|
-
@http_mock.should_receive(:read_timeout=).with(10)
|
|
161
|
-
Horse.make_request('anything', {}, 'anything', {:timeout => 10})
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
describe "via POST" do
|
|
165
|
-
it "should use Net::HTTP to make a POST request" do
|
|
166
|
-
@http_yield_mock.should_receive(:post).and_return(@http_request_result)
|
|
167
|
-
|
|
168
|
-
Horse.make_request('anything', {}, 'post')
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
it "should go to the specified path adding a / if it doesn't exist" do
|
|
172
|
-
path = mock('Path')
|
|
173
|
-
@http_yield_mock.should_receive(:post).with(path, anything).and_return(@http_request_result)
|
|
174
|
-
|
|
175
|
-
Horse.make_request(path, {}, 'post')
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
it "should use encoded parameters" do
|
|
179
|
-
args = {}
|
|
180
|
-
params = mock('Encoded parameters')
|
|
181
|
-
Horse.should_receive(:encode_params).with(args).and_return(params)
|
|
182
|
-
|
|
183
|
-
@http_yield_mock.should_receive(:post).with(anything, params).and_return(@http_request_result)
|
|
184
|
-
|
|
185
|
-
Horse.make_request('anything', args, 'post')
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
describe "with multipart/form-data" do
|
|
189
|
-
before(:each) do
|
|
190
|
-
Horse.stub(:encode_multipart_params)
|
|
191
|
-
Horse.stub("params_require_multipart?").and_return(true)
|
|
192
|
-
|
|
193
|
-
@multipart_request_stub = stub('Stub Multipart Request')
|
|
194
|
-
Net::HTTP::Post::Multipart.stub(:new).and_return(@multipart_request_stub)
|
|
195
|
-
|
|
196
|
-
@file_stub = stub('fake File', "kind_of?" => true, "path" => 'anypath.jpg')
|
|
197
|
-
|
|
198
|
-
@http_yield_mock.stub(:request).with(@multipart_request_stub).and_return(@http_request_result)
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
it "should use multipart/form-data if any parameter is a valid file hash" do
|
|
202
|
-
@http_yield_mock.should_receive(:request).with(@multipart_request_stub).and_return(@http_request_result)
|
|
203
|
-
|
|
204
|
-
Horse.make_request('anything', {}, 'post')
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
it "should use the given request path for the request" do
|
|
208
|
-
args = {"file" => @file_stub}
|
|
209
|
-
expected_path = 'expected/path'
|
|
210
|
-
|
|
211
|
-
Net::HTTP::Post::Multipart.should_receive(:new).with(expected_path, anything).and_return(@multipart_request_stub)
|
|
212
|
-
|
|
213
|
-
Horse.make_request(expected_path, {}, 'post')
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
it "should use multipart encoded arguments for the request" do
|
|
217
|
-
args = {"file" => @file_stub}
|
|
218
|
-
expected_params = stub('Stub Multipart Params')
|
|
219
|
-
|
|
220
|
-
Horse.should_receive(:encode_multipart_params).with(args).and_return(expected_params)
|
|
221
|
-
Net::HTTP::Post::Multipart.should_receive(:new).with(anything, expected_params).and_return(@multipart_request_stub)
|
|
222
|
-
|
|
223
|
-
Horse.make_request('anything', args, 'post')
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
describe "via GET" do
|
|
229
|
-
it "should use Net::HTTP to make a GET request" do
|
|
230
|
-
@http_yield_mock.should_receive(:get).and_return(@http_request_result)
|
|
231
|
-
|
|
232
|
-
Horse.make_request('anything', {}, 'get')
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
it "should use the correct path, including arguments" do
|
|
236
|
-
path = mock('Path')
|
|
237
|
-
params = mock('Encoded parameters')
|
|
238
|
-
args = {}
|
|
239
|
-
|
|
240
|
-
Horse.should_receive(:encode_params).with(args).and_return(params)
|
|
241
|
-
@http_yield_mock.should_receive(:get).with("#{path}?#{params}").and_return(@http_request_result)
|
|
242
|
-
|
|
243
|
-
Horse.make_request(path, args, 'get')
|
|
244
|
-
end
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
describe "the returned value" do
|
|
248
|
-
before(:each) do
|
|
249
|
-
@response = Horse.make_request('anything', {}, 'anything')
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
it "should return a Koala::Response object" do
|
|
253
|
-
@response.class.should == Koala::Response
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
it "should return a Koala::Response with the right status" do
|
|
257
|
-
@response.status.should == @mock_http_response.code
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
it "should reutrn a Koala::Response with the right body" do
|
|
261
|
-
@response.body.should == @mock_body
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
it "should return a Koala::Response with the Net::HTTPResponse object as headers" do
|
|
265
|
-
@response.headers.should == @mock_http_response
|
|
266
|
-
end
|
|
267
|
-
end # describe return value
|
|
268
|
-
end # describe when making a request
|
|
269
|
-
|
|
270
|
-
describe "when encoding parameters" do
|
|
271
|
-
it "should return an empty string if param_hash evaluates to false" do
|
|
272
|
-
Horse.encode_params(nil).should == ''
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
it "should convert values to JSON if the value is not a String" do
|
|
276
|
-
val = 'json_value'
|
|
277
|
-
not_a_string = 'not_a_string'
|
|
278
|
-
not_a_string.stub(:class).and_return('NotAString')
|
|
279
|
-
not_a_string.should_receive(:to_json).and_return(val)
|
|
280
|
-
|
|
281
|
-
string = "hi"
|
|
282
|
-
|
|
283
|
-
args = {
|
|
284
|
-
not_a_string => not_a_string,
|
|
285
|
-
string => string
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
result = Horse.encode_params(args)
|
|
289
|
-
result.split('&').find do |key_and_val|
|
|
290
|
-
key_and_val.match("#{not_a_string}=#{val}")
|
|
291
|
-
end.should be_true
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
it "should escape all values" do
|
|
295
|
-
args = Hash[*(1..4).map {|i| [i.to_s, "Value #{i}($"]}.flatten]
|
|
296
|
-
|
|
297
|
-
result = Horse.encode_params(args)
|
|
298
|
-
result.split('&').each do |key_val|
|
|
299
|
-
key, val = key_val.split('=')
|
|
300
|
-
val.should == CGI.escape(args[key])
|
|
301
|
-
end
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
it "should convert all keys to Strings" do
|
|
305
|
-
args = Hash[*(1..4).map {|i| [i, "val#{i}"]}.flatten]
|
|
306
|
-
|
|
307
|
-
result = Horse.encode_params(args)
|
|
308
|
-
result.split('&').each do |key_val|
|
|
309
|
-
key, val = key_val.split('=')
|
|
310
|
-
key.should == args.find{|key_val_arr| key_val_arr.last == val}.first.to_s
|
|
311
|
-
end
|
|
312
|
-
end
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
describe "when detecting if multipart posting is needed" do
|
|
316
|
-
it "should be true if any parameter value requires multipart post" do
|
|
317
|
-
koala_io = mock("Koala::IO")
|
|
318
|
-
koala_io.should_receive(:kind_of?).with(Koala::UploadableIO).and_return(true)
|
|
319
|
-
|
|
320
|
-
args = {
|
|
321
|
-
"key1" => "val",
|
|
322
|
-
"key2" => "val",
|
|
323
|
-
"key3" => koala_io,
|
|
324
|
-
"key4" => "val"
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
Horse.params_require_multipart?(args).should be_true
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
describe "when encoding multipart/form-data params" do
|
|
331
|
-
it "should replace Koala::UploadableIO values with UploadIO values" do
|
|
332
|
-
upload_io = UploadIO.new(__FILE__, "fake type")
|
|
333
|
-
|
|
334
|
-
uploadable_io = stub('Koala::UploadableIO')
|
|
335
|
-
uploadable_io.should_receive(:kind_of?).with(Koala::UploadableIO).and_return(true)
|
|
336
|
-
uploadable_io.should_receive(:to_upload_io).and_return(upload_io)
|
|
337
|
-
args = {
|
|
338
|
-
"not_a_file" => "not a file",
|
|
339
|
-
"file" => uploadable_io
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
result = Horse.encode_multipart_params(args)
|
|
343
|
-
|
|
344
|
-
result["not_a_file"] == args["not_a_file"]
|
|
345
|
-
result["file"] == upload_io
|
|
346
|
-
end
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
end
|
|
350
|
-
end
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
module Deer
|
|
5
|
-
include Koala::TyphoeusService
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
describe "TyphoeusService" do
|
|
9
|
-
|
|
10
|
-
describe "TyphoeusService module holder class Deer" do
|
|
11
|
-
before :each do
|
|
12
|
-
# reset the always_use_ssl parameter
|
|
13
|
-
Deer.always_use_ssl = nil
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "should define a make_request static module method" do
|
|
17
|
-
Deer.respond_to?(:make_request).should be_true
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should include the Koala::HTTPService module defining common features" do
|
|
21
|
-
Deer.included_modules.include?(Koala::HTTPService).should be_true
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe "when making a request" do
|
|
25
|
-
before(:each) do
|
|
26
|
-
# Setup stubs for make_request to execute without exceptions
|
|
27
|
-
@mock_body = stub('Typhoeus response body')
|
|
28
|
-
@mock_headers_hash = stub({:value => "headers hash"})
|
|
29
|
-
@mock_http_response = stub(Typhoeus::Response, :code => 1, :headers_hash => @mock_headers_hash, :body => @mock_body)
|
|
30
|
-
|
|
31
|
-
# Typhoeus is an included module, so we stub methods on Deer itself
|
|
32
|
-
Deer.stub(:post).and_return(@mock_http_response)
|
|
33
|
-
Deer.stub(:get).and_return(@mock_http_response)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "should use POST if verb is not GET" do
|
|
37
|
-
Deer.should_receive(:post).and_return(@mock_http_response)
|
|
38
|
-
Deer.make_request('anything', {}, 'anything')
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should use GET if that verb is specified" do
|
|
42
|
-
Deer.should_receive(:get).and_return(@mock_http_response)
|
|
43
|
-
Deer.make_request('anything', {}, 'get')
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe "the connection" do
|
|
47
|
-
it "should use SSL if the request has an access token" do
|
|
48
|
-
Deer.should_receive(:post).with(/https\:/, anything)
|
|
49
|
-
|
|
50
|
-
Deer.make_request('anything', {"access_token" => "123"}, 'anything')
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "should use SSL if always_use_ssl is true, even if there's no token" do
|
|
54
|
-
Deer.should_receive(:post).with(/https\:/, anything)
|
|
55
|
-
|
|
56
|
-
Deer.always_use_ssl = true
|
|
57
|
-
Deer.make_request('anything', {}, 'anything')
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should use SSL if the :use_ssl option is provided, even if there's no token" do
|
|
61
|
-
Deer.should_receive(:post).with(/https\:/, anything)
|
|
62
|
-
|
|
63
|
-
Deer.always_use_ssl = true
|
|
64
|
-
Deer.make_request('anything', {}, 'anything', :use_ssl => true)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "should not use SSL if always_use_ssl is false and there's no token" do
|
|
68
|
-
Deer.should_receive(:post).with(/http\:/, anything)
|
|
69
|
-
|
|
70
|
-
Deer.make_request('anything', {}, 'anything')
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should use the graph server by default" do
|
|
74
|
-
Deer.should_receive(:post).with(Regexp.new(Koala::Facebook::GRAPH_SERVER), anything)
|
|
75
|
-
|
|
76
|
-
Deer.make_request('anything', {}, 'anything')
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it "should use the REST server if the :rest_api option is true" do
|
|
80
|
-
Deer.should_receive(:post).with(Regexp.new(Koala::Facebook::REST_SERVER), anything)
|
|
81
|
-
|
|
82
|
-
Deer.make_request('anything', {}, 'anything', :rest_api => true)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it "should pass the arguments to Typhoeus under the :params key" do
|
|
87
|
-
args = {:a => 2}
|
|
88
|
-
Deer.should_receive(:post).with(anything, hash_including(:params => args))
|
|
89
|
-
|
|
90
|
-
Deer.make_request('anything', args, "post")
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "should add the method to the arguments if the method isn't get or post" do
|
|
94
|
-
method = "telekenesis"
|
|
95
|
-
Deer.should_receive(:post).with(anything, hash_including(:params => {:method => method}))
|
|
96
|
-
|
|
97
|
-
Deer.make_request('anything', {}, method)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "should pass :typhoeus_options to Typhoeus if provided" do
|
|
101
|
-
t_options = {:a => :b}
|
|
102
|
-
Deer.should_receive(:post).with(anything, hash_including(t_options))
|
|
103
|
-
|
|
104
|
-
Deer.make_request("anything", {}, "post", :typhoeus_options => t_options)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# for live tests, run the Graph API tests with Typhoues, which will run file uploads
|
|
108
|
-
it "should pass any files directly on to Typhoues" do
|
|
109
|
-
args = {:file => File.new(__FILE__, "r")}
|
|
110
|
-
Deer.should_receive(:post).with(anything, hash_including(:params => args)).and_return(Typhoeus::Response.new)
|
|
111
|
-
Deer.make_request("anything", args, :post)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "should include the path in the request" do
|
|
115
|
-
path = "/a/b/c/1"
|
|
116
|
-
Deer.should_receive(:post).with(Regexp.new(path), anything)
|
|
117
|
-
|
|
118
|
-
Deer.make_request(path, {}, "post")
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
describe "the returned value" do
|
|
122
|
-
before(:each) do
|
|
123
|
-
@response = Deer.make_request('anything', {}, 'anything')
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it "should return a Koala::Response object" do
|
|
127
|
-
@response.class.should == Koala::Response
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it "should return a Koala::Response with the right status" do
|
|
131
|
-
@response.status.should == @mock_http_response.code
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it "should reutrn a Koala::Response with the right body" do
|
|
135
|
-
@response.body.should == @mock_body
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it "should return a Koala::Response with the Typhoeus headers as headers" do
|
|
139
|
-
@response.headers.should == @mock_headers_hash
|
|
140
|
-
end
|
|
141
|
-
end # describe return value
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
module LiveTestingDataHelper
|
|
2
|
-
# in RSpec 2, included example groups no longer share any hooks or state with outside examples
|
|
3
|
-
# even if in the same block
|
|
4
|
-
# so we have to use a module to provide setup and teardown hooks for live testing
|
|
5
|
-
|
|
6
|
-
def self.included(base)
|
|
7
|
-
base.class_eval do
|
|
8
|
-
before :each do
|
|
9
|
-
@token = $testing_data["oauth_token"]
|
|
10
|
-
raise Exception, "Must supply access token to run FacebookWithAccessTokenTests!" unless @token
|
|
11
|
-
# track temporary objects created
|
|
12
|
-
@temporary_object_ids = []
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
after :each do
|
|
16
|
-
# clean up any temporary objects
|
|
17
|
-
@temporary_object_ids << @temporary_object_id if @temporary_object_id
|
|
18
|
-
count = @temporary_object_ids.length
|
|
19
|
-
errors = []
|
|
20
|
-
|
|
21
|
-
if count > 0
|
|
22
|
-
@temporary_object_ids.each do |id|
|
|
23
|
-
# get our API
|
|
24
|
-
api = @api || (@test_users ? @test_users.graph_api : nil)
|
|
25
|
-
raise "Unable to locate API when passed temporary object to delete!" unless api
|
|
26
|
-
|
|
27
|
-
# delete the object
|
|
28
|
-
result = (api.delete_object(id) rescue false)
|
|
29
|
-
# if we errored out or Facebook returned false, track that
|
|
30
|
-
errors << id unless result
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
unless errors.length == 0
|
|
34
|
-
puts "cleaned up #{count - errors.length} objects, but errored out on the following:\n #{errors.join(", ")}"
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# small helper method for live testing
|
|
2
|
-
module KoalaTest
|
|
3
|
-
def self.validate_user_info(token)
|
|
4
|
-
print "Validating permissions for live testing..."
|
|
5
|
-
# make sure we have the necessary permissions
|
|
6
|
-
api = Koala::Facebook::GraphAndRestAPI.new(token)
|
|
7
|
-
uid = api.get_object("me")["id"]
|
|
8
|
-
perms = api.fql_query("select read_stream, publish_stream, user_photos from permissions where uid = #{uid}")[0]
|
|
9
|
-
perms.each_pair do |perm, value|
|
|
10
|
-
unless value == 1
|
|
11
|
-
puts "failed!\n" # put a new line after the print above
|
|
12
|
-
raise ArgumentError, "Your access token must have the read_stream, publish_stream, and user_photos permissions. You have: #{perms.inspect}"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
puts "done!"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
unless ENV['LIVE']
|
|
21
|
-
# By default the Koala specs are run using stubs for HTTP requests
|
|
22
|
-
#
|
|
23
|
-
# Valid OAuth token and code are not necessary to run these
|
|
24
|
-
# specs. Because of this, specs do not fail due to Facebook
|
|
25
|
-
# imposed rate-limits or server timeouts.
|
|
26
|
-
#
|
|
27
|
-
# However as a result they are more brittle since
|
|
28
|
-
# we are not testing the latest responses from the Facebook servers.
|
|
29
|
-
# Therefore, to be certain all specs pass with the current
|
|
30
|
-
# Facebook services, run koala_spec_without_mocks.rb.
|
|
31
|
-
Koala.http_service = Koala::MockHTTPService
|
|
32
|
-
|
|
33
|
-
$testing_data = Koala::MockHTTPService::TEST_DATA
|
|
34
|
-
else
|
|
35
|
-
# Runs Koala specs through the Facebook servers
|
|
36
|
-
#
|
|
37
|
-
# Note that you need a valid OAuth token and code for these
|
|
38
|
-
# specs to run. See facebook_data.yml for more information.
|
|
39
|
-
|
|
40
|
-
# load testing data (see note in readme.md)
|
|
41
|
-
$testing_data = YAML.load_file(File.join(File.dirname(__FILE__), '../fixtures/facebook_data.yml'))
|
|
42
|
-
|
|
43
|
-
unless $testing_data["oauth_token"]
|
|
44
|
-
puts "Access token tests will fail until you store a valid token in facebook_data.yml"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
unless $testing_data["oauth_test_data"] && $testing_data["oauth_test_data"]["code"] && $testing_data["oauth_test_data"]["secret"]
|
|
48
|
-
puts "OAuth code tests will fail until you store valid data for the user's OAuth code and the app secret in facebook_data.yml"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
KoalaTest.validate_user_info $testing_data["oauth_token"]
|
|
52
|
-
end
|