koala 2.5.0 → 3.0.0.beta1
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/Gemfile +1 -1
- data/changelog.md +26 -0
- data/lib/koala/api/batch_operation.rb +3 -6
- data/lib/koala/api/graph_api.rb +6 -45
- data/lib/koala/api/graph_batch_api.rb +1 -2
- data/lib/koala/api/graph_collection.rb +1 -5
- data/lib/koala/api/graph_error_checker.rb +1 -1
- data/lib/koala/api.rb +3 -7
- data/lib/koala/errors.rb +1 -1
- data/lib/koala/http_service/multipart_request.rb +6 -10
- data/lib/koala/http_service/request.rb +139 -0
- data/lib/koala/http_service/response.rb +0 -4
- data/lib/koala/http_service/uploadable_io.rb +0 -4
- data/lib/koala/http_service.rb +16 -68
- data/lib/koala/oauth.rb +3 -3
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +2 -1
- data/readme.md +5 -26
- data/spec/cases/api_spec.rb +1 -7
- data/spec/cases/graph_api_batch_spec.rb +12 -22
- data/spec/cases/graph_api_spec.rb +0 -19
- data/spec/cases/graph_collection_spec.rb +18 -18
- data/spec/cases/graph_error_checker_spec.rb +6 -1
- data/spec/cases/http_service/request_spec.rb +240 -0
- data/spec/cases/http_service_spec.rb +102 -296
- data/spec/cases/koala_spec.rb +6 -1
- data/spec/cases/oauth_spec.rb +1 -1
- data/spec/cases/test_users_spec.rb +4 -1
- data/spec/cases/uploadable_io_spec.rb +31 -31
- data/spec/fixtures/mock_facebook_responses.yml +0 -37
- data/spec/spec_helper.rb +2 -2
- data/spec/support/graph_api_shared_examples.rb +6 -142
- data/spec/support/koala_test.rb +6 -6
- data/spec/support/mock_http_service.rb +6 -6
- data/spec/support/uploadable_io_shared_examples.rb +4 -4
- metadata +7 -7
- data/lib/koala/api/rest_api.rb +0 -135
- data/spec/support/rest_api_shared_examples.rb +0 -168
@@ -16,32 +16,32 @@ describe Koala::HTTPService do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "DEFAULT_MIDDLEWARE" do
|
19
|
-
|
20
|
-
|
21
|
-
allow(@builder).to receive(:request)
|
22
|
-
allow(@builder).to receive(:adapter)
|
23
|
-
allow(@builder).to receive(:use)
|
24
|
-
end
|
19
|
+
class FakeBuilder
|
20
|
+
attr_reader :requests, :uses, :adapters
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
def use(arg)
|
23
|
+
@uses ||= []
|
24
|
+
@uses << arg
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
def request(arg)
|
28
|
+
@requests ||= []
|
29
|
+
@requests << arg
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
def adapter(arg)
|
33
|
+
@adapters ||= []
|
34
|
+
@adapters << arg
|
35
|
+
end
|
38
36
|
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
let(:builder) { FakeBuilder.new }
|
39
|
+
|
40
|
+
it "adds the right default middleware" do
|
41
|
+
Koala::HTTPService::DEFAULT_MIDDLEWARE.call(builder)
|
42
|
+
expect(builder.requests).to eq([:url_encoded])
|
43
|
+
expect(builder.uses).to eq([Koala::HTTPService::MultipartRequest])
|
44
|
+
expect(builder.adapters).to eq([Faraday.default_adapter])
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -52,10 +52,6 @@ describe Koala::HTTPService do
|
|
52
52
|
expect(defaults[:graph_server]).to eq("graph.facebook.com")
|
53
53
|
end
|
54
54
|
|
55
|
-
it "defines the rest server" do
|
56
|
-
expect(defaults[:rest_server]).to eq("api.facebook.com")
|
57
|
-
end
|
58
|
-
|
59
55
|
it "defines the dialog host" do
|
60
56
|
expect(defaults[:dialog_host]).to eq("www.facebook.com")
|
61
57
|
end
|
@@ -73,86 +69,21 @@ describe Koala::HTTPService do
|
|
73
69
|
end
|
74
70
|
end
|
75
71
|
|
76
|
-
describe "server" do
|
77
|
-
describe "with no options" do
|
78
|
-
it "returns the REST server if options[:rest_api]" do
|
79
|
-
expect(Koala::HTTPService.server(:rest_api => true)).to eq(
|
80
|
-
"http://#{Koala.config.rest_server}"
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "returns the graph server if !options[:rest_api]" do
|
85
|
-
expect(Koala::HTTPService.server(:rest_api => false)).to eq(
|
86
|
-
"http://#{Koala.config.graph_server}"
|
87
|
-
)
|
88
|
-
expect(Koala::HTTPService.server({})).to eq(
|
89
|
-
"http://#{Koala.config.graph_server}"
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
context "with use_ssl" do
|
94
|
-
it "includes https" do
|
95
|
-
expect(Koala::HTTPService.server(use_ssl: true)).to eq(
|
96
|
-
"https://#{Koala.config.graph_server}"
|
97
|
-
)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "with options[:beta]" do
|
103
|
-
before :each do
|
104
|
-
@options = {:beta => true}
|
105
|
-
end
|
106
|
-
|
107
|
-
it "returns the beta REST server if options[:rest_api]" do
|
108
|
-
server = Koala::HTTPService.server(@options.merge(:rest_api => true))
|
109
|
-
expect(server).to match(Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, ".beta.facebook")))
|
110
|
-
end
|
111
|
-
|
112
|
-
it "returns the beta rest server if !options[:rest_api]" do
|
113
|
-
server = Koala::HTTPService.server(@options)
|
114
|
-
expect(server).to match(Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, ".beta.facebook")))
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "with options[:video]" do
|
119
|
-
before :each do
|
120
|
-
@options = {:video => true}
|
121
|
-
end
|
122
|
-
|
123
|
-
it "returns the REST video server if options[:rest_api]" do
|
124
|
-
server = Koala::HTTPService.server(@options.merge(:rest_api => true))
|
125
|
-
expect(server).to match(Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, "-video.facebook")))
|
126
|
-
end
|
127
|
-
|
128
|
-
it "returns the graph video server if !options[:rest_api]" do
|
129
|
-
server = Koala::HTTPService.server(@options)
|
130
|
-
expect(server).to match(Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, "-video.facebook")))
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
72
|
describe ".encode_params" do
|
136
73
|
it "returns an empty string if param_hash evaluates to false" do
|
137
74
|
expect(Koala::HTTPService.encode_params(nil)).to eq('')
|
138
75
|
end
|
139
76
|
|
140
77
|
it "converts values to JSON if the value is not a String" do
|
141
|
-
|
142
|
-
not_a_string = 'not_a_string'
|
143
|
-
allow(not_a_string).to receive(:is_a?).and_return(false)
|
144
|
-
expect(JSON).to receive(:dump).with(not_a_string).and_return(val)
|
145
|
-
|
146
|
-
string = "hi"
|
78
|
+
not_a_string = {not_a_string: 2}
|
147
79
|
|
148
80
|
args = {
|
149
|
-
|
150
|
-
string => string
|
81
|
+
:arg => not_a_string,
|
151
82
|
}
|
152
83
|
|
153
84
|
result = Koala::HTTPService.encode_params(args)
|
154
85
|
expect(result.split('&').find do |key_and_val|
|
155
|
-
key_and_val.match("
|
86
|
+
key_and_val.match("arg=#{CGI.escape not_a_string.to_json}")
|
156
87
|
end).to be_truthy
|
157
88
|
end
|
158
89
|
|
@@ -185,244 +116,119 @@ describe Koala::HTTPService do
|
|
185
116
|
end
|
186
117
|
|
187
118
|
describe ".make_request" do
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
@mock_headers_hash = double({:value => "headers hash"})
|
192
|
-
@mock_http_response = double("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
|
193
|
-
|
194
|
-
@mock_connection = double("Faraday connection")
|
195
|
-
allow(@mock_connection).to receive(:get).and_return(@mock_http_response)
|
196
|
-
allow(@mock_connection).to receive(:post).and_return(@mock_http_response)
|
197
|
-
allow(Faraday).to receive(:new).and_return(@mock_connection)
|
198
|
-
end
|
119
|
+
let(:mock_body) { "a body" }
|
120
|
+
let(:mock_headers_hash) { double(value: "headers hash") }
|
121
|
+
let(:mock_http_response) { double("Faraday Response", status: 200, headers: mock_headers_hash, body: mock_body) }
|
199
122
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
allow(Koala::HTTPService).to receive(:server).and_return(server)
|
204
|
-
expect(Faraday).to receive(:new).with(server, anything).and_return(@mock_connection)
|
205
|
-
Koala::HTTPService.make_request("anything", {}, "anything")
|
206
|
-
end
|
207
|
-
|
208
|
-
it "merges Koala::HTTPService.http_options into the request params" do
|
209
|
-
http_options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
|
210
|
-
Koala::HTTPService.http_options = http_options
|
211
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(http_options)).and_return(@mock_connection)
|
212
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
213
|
-
end
|
214
|
-
|
215
|
-
it "does not merge invalid Faraday options from Koala::HTTPService.http_options into the request params" do
|
216
|
-
http_options = {:invalid => "fake param"}
|
217
|
-
Koala::HTTPService.http_options = http_options
|
218
|
-
expect(Faraday).to receive(:new).with(anything, hash_not_including(http_options)).and_return(@mock_connection)
|
219
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
220
|
-
end
|
123
|
+
let(:verb) { "get" }
|
124
|
+
let(:options) { {} }
|
125
|
+
let(:request) { Koala::HTTPService::Request.new(path: "/foo", verb: verb, args: {"an" => :arg}, options: options) }
|
221
126
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
it "overrides Koala::HTTPService.http_options with any provided options for the request params" do
|
229
|
-
options = {:proxy => "http://user:password@proxy.org/", :request => { :timeout => 10 }}
|
230
|
-
http_options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
|
231
|
-
allow(Koala::HTTPService).to receive(:http_options).and_return(http_options)
|
232
|
-
|
233
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(http_options.merge(options))).and_return(@mock_connection)
|
234
|
-
Koala::HTTPService.make_request("anything", {}, "get", options)
|
235
|
-
end
|
236
|
-
|
237
|
-
it "forces use_ssl to true if an access token is present" do
|
238
|
-
options = {:use_ssl => false}
|
239
|
-
allow(Koala::HTTPService).to receive(:http_options).and_return(:use_ssl => false)
|
240
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
|
241
|
-
Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
|
242
|
-
end
|
243
|
-
|
244
|
-
it "defaults verify to true if use_ssl is true" do
|
245
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
|
246
|
-
Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get")
|
247
|
-
end
|
248
|
-
|
249
|
-
it "allows you to set other verify modes if you really want" do
|
250
|
-
options = {:ssl => {:verify => :foo}}
|
251
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(options)).and_return(@mock_connection)
|
252
|
-
Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
|
127
|
+
shared_examples_for :making_a_request do
|
128
|
+
before :each do
|
129
|
+
allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(mock_http_response)
|
130
|
+
allow_any_instance_of(Faraday::Connection).to receive(:post).and_return(mock_http_response)
|
253
131
|
end
|
254
132
|
|
255
|
-
it "
|
256
|
-
|
257
|
-
|
133
|
+
it "makes a Faraday request appropriately" do
|
134
|
+
expect_any_instance_of(Faraday::Connection).to receive(verb) do |instance, path, post_params|
|
135
|
+
expect(path).to eq(request.path)
|
136
|
+
expect(post_params).to eq(request.post_args)
|
137
|
+
expect(instance.params).to eq(request.options[:params])
|
138
|
+
expect(instance.url_prefix).to eq(URI.parse(request.server))
|
258
139
|
|
259
|
-
|
260
|
-
attr_accessor :path, :body, :headers, :status
|
261
|
-
def initialize
|
262
|
-
@headers = {}
|
263
|
-
end
|
140
|
+
mock_http_response
|
264
141
|
end
|
265
142
|
|
266
|
-
|
267
|
-
allow_any_instance_of(Faraday::Connection).to receive(:post).and_yield(mock_request)
|
268
|
-
|
269
|
-
path = "California"
|
270
|
-
args = {:a => 2, :c => "3"}
|
271
|
-
|
272
|
-
Koala::HTTPService.make_request(path, args, "post", format: :json)
|
273
|
-
|
274
|
-
expect(mock_request.path).to eq(path)
|
275
|
-
expect(mock_request.headers).to eq("Content-Type" => "application/json")
|
276
|
-
expect(mock_request.body).to eq(args.to_json)
|
277
|
-
end
|
278
|
-
|
279
|
-
it "calls server with the composite options" do
|
280
|
-
options = {:a => 2, :c => "3"}
|
281
|
-
http_options = {:a => :a}
|
282
|
-
allow(Koala::HTTPService).to receive(:http_options).and_return(http_options)
|
283
|
-
expect(Koala::HTTPService).to receive(:server).with(hash_including(http_options.merge(options))).and_return("foo")
|
284
|
-
Koala::HTTPService.make_request("anything", {}, "get", options)
|
143
|
+
Koala::HTTPService.make_request(request)
|
285
144
|
end
|
286
145
|
|
287
|
-
it "
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
expect(
|
292
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
293
|
-
end
|
294
|
-
|
295
|
-
it "uses the defined HTTPService.faraday_middleware block if defined" do
|
296
|
-
block = Proc.new { }
|
297
|
-
expect(Koala::HTTPService).to receive(:faraday_middleware).and_return(block)
|
298
|
-
expect(Faraday).to receive(:new).with(anything, anything, &block).and_return(@mock_connection)
|
299
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
146
|
+
it "returns the right response" do
|
147
|
+
response = Koala::HTTPService.make_request(request)
|
148
|
+
expect(response.status).to eq(mock_http_response.status)
|
149
|
+
expect(response.headers).to eq(mock_http_response.headers)
|
150
|
+
expect(response.body).to eq(mock_http_response.body)
|
303
151
|
|
304
|
-
context "with API versions" do
|
305
|
-
it "adds a version if specified by Koala.config" do
|
306
|
-
expect(Koala.config).to receive(:api_version).and_return("v11")
|
307
|
-
expect(@mock_connection).to receive(:get).with("/v11/anything", anything)
|
308
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
309
152
|
end
|
310
153
|
|
311
|
-
it "
|
312
|
-
|
313
|
-
|
314
|
-
expect(@mock_connection).to receive(:get).with("/v12/anything", anything)
|
315
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
316
|
-
end
|
317
|
-
|
318
|
-
it "doesn't add double slashes to the path" do
|
319
|
-
allow(Koala::HTTPService).to receive(:http_options).and_return({ api_version: 'v12' })
|
320
|
-
expect(@mock_connection).to receive(:get).with("/v12/anything", anything)
|
321
|
-
Koala::HTTPService.make_request("/anything", {}, "get")
|
322
|
-
end
|
154
|
+
it "logs verb, url and params to debug" do
|
155
|
+
log_message = "#{verb.upcase}: #{request.path} params: #{request.raw_args.inspect}"
|
156
|
+
expect(Koala::Utils.logger).to receive(:debug).with(log_message)
|
323
157
|
|
324
|
-
|
325
|
-
expect(Koala.config).to receive(:api_version).and_return("v11")
|
326
|
-
expect(@mock_connection).to receive(:get).with("/v12/anything", anything)
|
327
|
-
Koala::HTTPService.make_request("/v12/anything", {}, "get")
|
158
|
+
Koala::HTTPService.make_request(request)
|
328
159
|
end
|
329
160
|
end
|
330
161
|
|
331
|
-
|
332
|
-
|
333
|
-
Koala::HTTPService.make_request("anything", {}, "anything")
|
162
|
+
context "for gets" do
|
163
|
+
it_should_behave_like :making_a_request
|
334
164
|
end
|
335
165
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
Koala::HTTPService.make_request("anything", {}, verb)
|
340
|
-
end
|
166
|
+
# we don't need to test delete and put since those are translated into posts
|
167
|
+
context "for posts" do
|
168
|
+
let(:verb) { "post" }
|
341
169
|
|
342
|
-
|
343
|
-
expect(@mock_connection).to receive(:get).and_return(@mock_http_response)
|
344
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
170
|
+
it_should_behave_like :making_a_request
|
345
171
|
end
|
346
172
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
args = {"a" => :b, "c" => 3}
|
351
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(:params => args)).and_return(@mock_connection)
|
352
|
-
Koala::HTTPService.make_request("anything", args, "get")
|
353
|
-
end
|
173
|
+
context "for JSON requests" do
|
174
|
+
let(:verb) { "post" }
|
175
|
+
let(:options) { {format: :json} }
|
354
176
|
|
355
|
-
it "
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
177
|
+
it "makes a Faraday request appropriately" do
|
178
|
+
expect_any_instance_of(Faraday::Connection).to receive(verb) do |instance, path, &block|
|
179
|
+
faraday_request = Faraday::Request.new
|
180
|
+
faraday_request.headers = {}
|
181
|
+
block.call(faraday_request)
|
182
|
+
expect(faraday_request.path).to eq(request.path)
|
183
|
+
expect(faraday_request.body).to eq(request.post_args.to_json)
|
184
|
+
expect(faraday_request.headers).to include("Content-Type" => "application/json")
|
361
185
|
|
362
|
-
|
363
|
-
args = {"a" => :b, "c" => 3}
|
364
|
-
log_message_stem = "GET: anything params: "
|
365
|
-
expect(Koala::Utils.logger).to receive(:debug) do |log_message|
|
366
|
-
# unordered hashes are a bane
|
367
|
-
# Ruby in 1.8 modes tends to return different hash orderings,
|
368
|
-
# which makes checking the content of the stringified hash hard
|
369
|
-
# it's enough just to ensure that there's hash content in the string, I think
|
370
|
-
expect(log_message).to include(log_message_stem)
|
371
|
-
expect(log_message.match(/\{.*\}/)).not_to be_nil
|
186
|
+
mock_http_response
|
372
187
|
end
|
373
188
|
|
374
|
-
Koala::HTTPService.make_request(
|
189
|
+
Koala::HTTPService.make_request(request)
|
375
190
|
end
|
376
191
|
end
|
377
192
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
it "turns any UploadableIOs to UploadIOs" do
|
387
|
-
# technically this is done for all requests, but you don't send GET requests with files
|
388
|
-
upload_io = double("UploadIO")
|
389
|
-
u = Koala::UploadableIO.new("/path/to/stuff", "img/jpg")
|
390
|
-
allow(u).to receive(:to_upload_io).and_return(upload_io)
|
391
|
-
expect(@mock_connection).to receive(:post).with(anything, hash_including("source" => upload_io)).and_return(@mock_http_response)
|
392
|
-
Koala::HTTPService.make_request("anything", {:source => u}, "post")
|
393
|
-
end
|
193
|
+
it "uses the default builder block if HTTPService.faraday_middleware block is not defined" do
|
194
|
+
block = Proc.new { |builder|
|
195
|
+
builder.use Koala::HTTPService::MultipartRequest
|
196
|
+
builder.request :url_encoded
|
197
|
+
builder.use Koala::HTTPService::MultipartRequest
|
198
|
+
}
|
199
|
+
stub_const("Koala::HTTPService::DEFAULT_MIDDLEWARE", block)
|
200
|
+
allow(Koala::HTTPService).to receive(:faraday_middleware).and_return(nil)
|
394
201
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
# it's enough just to ensure that there's hash content in the string, I think
|
403
|
-
expect(log_message).to include(log_message_stem)
|
404
|
-
expect(log_message.match(/\{.*\}/)).not_to be_nil
|
405
|
-
end
|
406
|
-
Koala::HTTPService.make_request("anything", args, "post")
|
202
|
+
expect_any_instance_of(Faraday::Connection).to receive(:get) do |instance|
|
203
|
+
expect(instance.builder.handlers).to eq([
|
204
|
+
Koala::HTTPService::MultipartRequest,
|
205
|
+
Faraday::Request::UrlEncoded,
|
206
|
+
Koala::HTTPService::MultipartRequest
|
207
|
+
])
|
208
|
+
mock_http_response
|
407
209
|
end
|
408
|
-
end
|
409
|
-
end
|
410
210
|
|
411
|
-
|
412
|
-
it "works when the path is prefixed by a slash" do
|
413
|
-
expect(Koala::HTTPService.path_contains_api_version?('/v2.1/anything')).to be true
|
211
|
+
Koala::HTTPService.make_request(request)
|
414
212
|
end
|
415
213
|
|
416
|
-
it "
|
417
|
-
|
418
|
-
|
214
|
+
it "uses the defined HTTPService.faraday_middleware block if defined" do
|
215
|
+
block = Proc.new { |builder|
|
216
|
+
builder.use Koala::HTTPService::MultipartRequest
|
217
|
+
builder.request :url_encoded
|
218
|
+
builder.use Koala::HTTPService::MultipartRequest
|
219
|
+
}
|
220
|
+
expect(Koala::HTTPService).to receive(:faraday_middleware).and_return(block)
|
419
221
|
|
420
|
-
|
421
|
-
|
422
|
-
|
222
|
+
expect_any_instance_of(Faraday::Connection).to receive(:get) do |instance|
|
223
|
+
expect(instance.builder.handlers).to eq([
|
224
|
+
Koala::HTTPService::MultipartRequest,
|
225
|
+
Faraday::Request::UrlEncoded,
|
226
|
+
Koala::HTTPService::MultipartRequest
|
227
|
+
])
|
228
|
+
mock_http_response
|
229
|
+
end
|
423
230
|
|
424
|
-
|
425
|
-
expect(Koala::HTTPService.path_contains_api_version?('/anything')).to be false
|
231
|
+
Koala::HTTPService.make_request(request)
|
426
232
|
end
|
427
233
|
end
|
428
234
|
end
|
data/spec/cases/koala_spec.rb
CHANGED
@@ -19,7 +19,12 @@ describe Koala do
|
|
19
19
|
verb = "get"
|
20
20
|
options = {:c => :d}
|
21
21
|
|
22
|
-
expect(Koala.http_service).to receive(:make_request)
|
22
|
+
expect(Koala.http_service).to receive(:make_request) do |request|
|
23
|
+
expect(request.raw_path).to eq(path)
|
24
|
+
expect(request.raw_args).to eq(args)
|
25
|
+
expect(request.raw_verb).to eq(verb)
|
26
|
+
expect(request.raw_options).to eq(options)
|
27
|
+
end
|
23
28
|
Koala.make_request(path, args, verb, options)
|
24
29
|
end
|
25
30
|
end
|
data/spec/cases/oauth_spec.rb
CHANGED
@@ -584,7 +584,7 @@ describe "Koala::Facebook::OAuth" do
|
|
584
584
|
# the signed request code is ported directly from Facebook
|
585
585
|
# so we only need to test at a high level that it works
|
586
586
|
it "throws an error if the algorithm is unsupported" do
|
587
|
-
allow(JSON).to receive(:
|
587
|
+
allow(JSON).to receive(:parse).and_return("algorithm" => "my fun algorithm")
|
588
588
|
expect { @oauth.parse_signed_request(@signed_params) }.to raise_error(Koala::Facebook::OAuthSignatureError)
|
589
589
|
end
|
590
590
|
|
@@ -265,7 +265,10 @@ describe "Koala::Facebook::TestUsers" do
|
|
265
265
|
options = {:some_http_option => true}
|
266
266
|
# should come twice, once for each user
|
267
267
|
@stubbed = true
|
268
|
-
expect(Koala.http_service).to receive(:make_request).
|
268
|
+
expect(Koala.http_service).to receive(:make_request).twice do |request|
|
269
|
+
expect(request.raw_options).to eq(options)
|
270
|
+
Koala::HTTPService::Response.new(200, "{}", {})
|
271
|
+
end
|
269
272
|
@test_users.befriend(@user1, @user2, options)
|
270
273
|
end
|
271
274
|
end
|