koala 1.4.0 → 1.5.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.
@@ -59,7 +59,7 @@ describe "Koala::Facebook::API" do
59
59
  Koala.stub(:make_request).and_return(response)
60
60
 
61
61
  json_body = mock('JSON body')
62
- MultiJson.stub(:decode).and_return([json_body])
62
+ MultiJson.stub(:load).and_return([json_body])
63
63
 
64
64
  @service.api('anything').should == json_body
65
65
  end
@@ -73,7 +73,7 @@ describe "Koala::Facebook::API" do
73
73
 
74
74
  @service.api('anything', {}, "get") do |arg|
75
75
  yield_test.pass
76
- arg.should == MultiJson.decode(body)
76
+ arg.should == MultiJson.load(body)
77
77
  end
78
78
  end
79
79
 
@@ -5,24 +5,27 @@ describe Koala::Facebook::APIError do
5
5
  Koala::Facebook::APIError.new.should be_a(StandardError)
6
6
  end
7
7
 
8
- it "has an accessor for fb_error_type" do
9
- Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:fb_error_type)
10
- Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:fb_error_type=)
11
- end
12
-
13
- it "has an accessor for raw_response" do
14
- Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:raw_response)
15
- Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:raw_response=)
8
+ [:fb_error_type, :fb_error_code, :fb_error_message, :raw_response].each do |accessor|
9
+ it "has an accessor for #{accessor}" do
10
+ Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(accessor)
11
+ Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:"#{accessor}=")
12
+ end
16
13
  end
17
14
 
18
15
  it "sets raw_response to the provided error details" do
19
16
  error_response = {"type" => "foo", "other_details" => "bar"}
20
17
  Koala::Facebook::APIError.new(error_response).raw_response.should == error_response
21
18
  end
22
-
23
- it "sets fb_error_type to details['type']" do
24
- type = "foo"
25
- Koala::Facebook::APIError.new("type" => type).fb_error_type.should == type
19
+
20
+ {
21
+ :fb_error_type => 'type',
22
+ :fb_error_message => 'message',
23
+ :fb_error_code => 'code'
24
+ }.each_pair do |accessor, key|
25
+ it "sets #{accessor} to details['#{key}']" do
26
+ value = "foo"
27
+ Koala::Facebook::APIError.new(key => value).send(accessor).should == value
28
+ end
26
29
  end
27
30
 
28
31
  it "sets the error message details['type']: details['message']" do
@@ -304,7 +304,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
304
304
  Koala::Facebook::GraphBatchAPI::BatchOperation.stub(:new).and_return(op)
305
305
 
306
306
  # two requests should generate two batch operations
307
- expected = MultiJson.encode([op.to_batch_params(access_token), op.to_batch_params(access_token)])
307
+ expected = MultiJson.dump([op.to_batch_params(access_token), op.to_batch_params(access_token)])
308
308
  Koala.should_receive(:make_request).with(anything, hash_including("batch" => expected), anything, anything).and_return(@fake_response)
309
309
  Koala::Facebook::API.new(access_token).batch do |batch_api|
310
310
  batch_api.get_object('me')
@@ -381,6 +381,13 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
381
381
  }.to raise_exception(Koala::Facebook::APIError)
382
382
  end
383
383
 
384
+ it "raises an APIError if the body is empty" do
385
+ Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, "", {}))
386
+ expect {
387
+ Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
388
+ }.to raise_exception(Koala::Facebook::APIError)
389
+ end
390
+
384
391
  context "with the old style" do
385
392
  before :each do
386
393
  Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, '{"error":190,"error_description":"Error validating access token."}', {}))
@@ -13,11 +13,11 @@ describe Koala::Facebook::GraphCollection do
13
13
  it "subclasses Array" do
14
14
  Koala::Facebook::GraphCollection.ancestors.should include(Array)
15
15
  end
16
-
16
+
17
17
  it "creates an array-like object" do
18
18
  Koala::Facebook::GraphCollection.new(@result, @api).should be_an(Array)
19
19
  end
20
-
20
+
21
21
  it "contains the result data" do
22
22
  @result["data"].each_with_index {|r, i| @collection[i].should == r}
23
23
  end
@@ -26,19 +26,19 @@ describe Koala::Facebook::GraphCollection do
26
26
  @collection.methods.map(&:to_sym).should include(:paging)
27
27
  @collection.methods.map(&:to_sym).should_not include(:paging=)
28
28
  end
29
-
29
+
30
30
  it "sets paging to results['paging']" do
31
31
  @collection.paging.should == @result["paging"]
32
32
  end
33
-
33
+
34
34
  it "sets raw_response to the original results" do
35
35
  @collection.raw_response.should == @result
36
36
  end
37
-
37
+
38
38
  it "sets the API to the provided API" do
39
39
  @collection.api.should == @api
40
40
  end
41
-
41
+
42
42
  describe "when getting a whole page" do
43
43
  before(:each) do
44
44
  @second_page = {
@@ -87,16 +87,22 @@ describe Koala::Facebook::GraphCollection do
87
87
  @collection.parse_page_url(stub("url")).should == parsed_content
88
88
  end
89
89
  end
90
-
91
- describe ".parse_page_url" do
90
+
91
+ describe ".parse_page_url" do
92
92
  it "should return the base as the first array entry" do
93
93
  base = "url_path"
94
- Koala::Facebook::GraphCollection.parse_page_url("anything.com/#{base}?anything").first.should == base
94
+ Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?anything").first.should == base
95
95
  end
96
96
 
97
97
  it "should return the arguments as a hash as the last array entry" do
98
98
  args_hash = {"one" => "val_one", "two" => "val_two"}
99
- Koala::Facebook::GraphCollection.parse_page_url("anything.com/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last.should == args_hash
99
+ Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last.should == args_hash
100
+ end
101
+
102
+ it "works with non-.com addresses" do
103
+ base = "url_path"
104
+ args_hash = {"one" => "val_one", "two" => "val_two"}
105
+ Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").should == [base, args_hash]
100
106
  end
101
107
  end
102
108
  end
@@ -106,22 +112,22 @@ describe Koala::Facebook::GraphCollection do
106
112
  result = []
107
113
  Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
108
114
  end
109
-
115
+
110
116
  it "returns the original result if it's provided a nil result" do
111
117
  result = nil
112
118
  Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
113
119
  end
114
-
120
+
115
121
  it "returns the original result if the result doesn't have a data key" do
116
122
  result = {"paging" => {}}
117
123
  Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
118
124
  end
119
-
125
+
120
126
  it "returns the original result if the result's data key isn't an array" do
121
127
  result = {"data" => {}, "paging" => {}}
122
128
  Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
123
129
  end
124
-
130
+
125
131
  it "returns a new GraphCollection of the result if it has an array data key and a paging key" do
126
132
  result = {"data" => [], "paging" => {}}
127
133
  expected = :foo
@@ -10,7 +10,7 @@ describe "Koala::HTTPService" do
10
10
  Koala::HTTPService.should respond_to(:http_options)
11
11
  Koala::HTTPService.should respond_to(:http_options=)
12
12
  end
13
-
13
+
14
14
  it "sets http_options to {} by default" do
15
15
  Koala::HTTPService.http_options.should == {}
16
16
  end
@@ -99,7 +99,7 @@ describe "Koala::HTTPService" do
99
99
  val = 'json_value'
100
100
  not_a_string = 'not_a_string'
101
101
  not_a_string.stub(:is_a?).and_return(false)
102
- MultiJson.should_receive(:encode).with(not_a_string).and_return(val)
102
+ MultiJson.should_receive(:dump).with(not_a_string).and_return(val)
103
103
 
104
104
  string = "hi"
105
105
 
@@ -123,10 +123,10 @@ describe "Koala::HTTPService" do
123
123
  val.should == CGI.escape(args[key])
124
124
  end
125
125
  end
126
-
126
+
127
127
  it "encodes parameters in alphabetical order" do
128
128
  args = {:b => '2', 'a' => '1'}
129
-
129
+
130
130
  result = Koala::HTTPService.encode_params(args)
131
131
  result.split('&').map{|key_val| key_val.split('=')[0]}.should == ['a', 'b']
132
132
  end
@@ -184,33 +184,44 @@ describe "Koala::HTTPService" do
184
184
  Faraday.should_receive(:new).with(anything, hash_including(http_options.merge(options))).and_return(@mock_connection)
185
185
  Koala::HTTPService.make_request("anything", {}, "get", options)
186
186
  end
187
-
187
+
188
188
  it "forces use_ssl to true if an access token is present" do
189
189
  options = {:use_ssl => false}
190
190
  Koala::HTTPService.stub(:http_options).and_return(:use_ssl => false)
191
- Faraday.should_receive(:new).with(anything, hash_including(:use_ssl => true)).and_return(@mock_connection)
191
+ Faraday.should_receive(:new).with(anything, hash_including(:use_ssl => true, :ssl => {:verify => true})).and_return(@mock_connection)
192
192
  Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
193
193
  end
194
-
194
+
195
+ it "defaults verify to true if use_ssl is true" do
196
+ Faraday.should_receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
197
+ Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get")
198
+ end
199
+
200
+ it "allows you to set other verify modes if you really want" do
201
+ options = {:ssl => {:verify => :foo}}
202
+ Faraday.should_receive(:new).with(anything, hash_including(options)).and_return(@mock_connection)
203
+ Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
204
+ end
205
+
195
206
  it "calls server with the composite options" do
196
207
  options = {:a => 2, :c => "3"}
197
208
  http_options = {:a => :a}
198
209
  Koala::HTTPService.stub(:http_options).and_return(http_options)
199
210
  Koala::HTTPService.should_receive(:server).with(hash_including(http_options.merge(options))).and_return("foo")
200
- Koala::HTTPService.make_request("anything", {}, "get", options)
211
+ Koala::HTTPService.make_request("anything", {}, "get", options)
201
212
  end
202
213
 
203
214
  it "uses the default builder block if HTTPService.faraday_middleware block is not defined" do
204
- Koala::HTTPService.stub(:faraday_middleware).and_return(nil)
215
+ Koala::HTTPService.stub(:faraday_middleware).and_return(nil)
205
216
  Faraday.should_receive(:new).with(anything, anything, &Koala::HTTPService::DEFAULT_MIDDLEWARE).and_return(@mock_connection)
206
- Koala::HTTPService.make_request("anything", {}, "get")
217
+ Koala::HTTPService.make_request("anything", {}, "get")
207
218
  end
208
-
219
+
209
220
  it "uses the defined HTTPService.faraday_middleware block if defined" do
210
221
  block = Proc.new { }
211
222
  Koala::HTTPService.should_receive(:faraday_middleware).and_return(block)
212
223
  Faraday.should_receive(:new).with(anything, anything, &block).and_return(@mock_connection)
213
- Koala::HTTPService.make_request("anything", {}, "get")
224
+ Koala::HTTPService.make_request("anything", {}, "get")
214
225
  end
215
226
  end
216
227
 
@@ -244,6 +255,21 @@ describe "Koala::HTTPService" do
244
255
  @mock_connection.should_receive(:get).with(anything, {}).and_return(@mock_http_response)
245
256
  Koala::HTTPService.make_request("anything", args, "get")
246
257
  end
258
+
259
+ it "logs verb, url and params to debug" do
260
+ args = {"a" => :b, "c" => 3}
261
+ log_message_stem = "GET: anything params: "
262
+ Koala::Utils.logger.should_receive(:debug) do |log_message|
263
+ # unordered hashes are a bane
264
+ # Ruby in 1.8 modes tends to return different hash orderings,
265
+ # which makes checking the content of the stringified hash hard
266
+ # it's enough just to ensure that there's hash content in the string, I think
267
+ log_message.should include(log_message_stem)
268
+ log_message.match(/\{.*\}/).should_not be_nil
269
+ end
270
+
271
+ Koala::HTTPService.make_request("anything", args, "get")
272
+ end
247
273
  end
248
274
 
249
275
  describe "for POSTs" do
@@ -262,6 +288,20 @@ describe "Koala::HTTPService" do
262
288
  @mock_connection.should_receive(:post).with(anything, hash_including("source" => upload_io)).and_return(@mock_http_response)
263
289
  Koala::HTTPService.make_request("anything", {:source => u}, "post")
264
290
  end
291
+
292
+ it "logs verb, url and params to debug" do
293
+ args = {"a" => :b, "c" => 3}
294
+ log_message_stem = "POST: anything params: "
295
+ Koala::Utils.logger.should_receive(:debug) do |log_message|
296
+ # unordered hashes are a bane
297
+ # Ruby in 1.8 modes tends to return different hash orderings,
298
+ # which makes checking the content of the stringified hash hard
299
+ # it's enough just to ensure that there's hash content in the string, I think
300
+ log_message.should include(log_message_stem)
301
+ log_message.match(/\{.*\}/).should_not be_nil
302
+ end
303
+ Koala::HTTPService.make_request("anything", args, "post")
304
+ end
265
305
  end
266
306
  end
267
307
 
@@ -274,11 +314,11 @@ describe "Koala::HTTPService" do
274
314
  after :each do
275
315
  Koala.http_service = @service
276
316
  end
277
-
317
+
278
318
  {
279
319
  :timeout => :timeout,
280
320
  :always_use_ssl => :use_ssl,
281
- :proxy => :proxy
321
+ :proxy => :proxy
282
322
  }.each_pair do |deprecated_method, parameter|
283
323
  describe ".#{deprecated_method}" do
284
324
  context "read" do
@@ -287,13 +327,13 @@ describe "Koala::HTTPService" do
287
327
  Koala::HTTPService.http_options[parameter] = value
288
328
  Koala::HTTPService.send(deprecated_method).should == value
289
329
  end
290
-
330
+
291
331
  it "generates a deprecation warning" do
292
332
  Koala::Utils.should_receive(:deprecate)
293
333
  Koala::HTTPService.send(deprecated_method)
294
334
  end
295
335
  end
296
-
336
+
297
337
  context "write" do
298
338
  it "writes to http_options[:#{parameter}]" do
299
339
  Koala::HTTPService.http_options[parameter] = nil
@@ -301,7 +341,7 @@ describe "Koala::HTTPService" do
301
341
  Koala::HTTPService.send(:"#{deprecated_method}=", value)
302
342
  Koala::HTTPService.http_options[parameter].should == value
303
343
  end
304
-
344
+
305
345
  it "generates a deprecation warning" do
306
346
  Koala::Utils.should_receive(:deprecate)
307
347
  Koala::HTTPService.send(:"#{deprecated_method}=", 2)
@@ -309,7 +349,7 @@ describe "Koala::HTTPService" do
309
349
  end
310
350
  end
311
351
  end
312
-
352
+
313
353
  # ssl options
314
354
  [:ca_path, :ca_file, :verify_mode].each do |deprecated_method|
315
355
  describe ".#{deprecated_method}" do
@@ -319,7 +359,7 @@ describe "Koala::HTTPService" do
319
359
  Koala::HTTPService.http_options[:ssl] = {deprecated_method => value}
320
360
  Koala::HTTPService.send(deprecated_method).should == value
321
361
  end
322
-
362
+
323
363
  it "returns nil if http_options[:ssl] is not defined" do
324
364
  Koala::HTTPService.send(deprecated_method).should be_nil
325
365
  end
@@ -329,8 +369,8 @@ describe "Koala::HTTPService" do
329
369
  Koala::HTTPService.send(deprecated_method)
330
370
  end
331
371
  end
332
-
333
- context "write" do
372
+
373
+ context "write" do
334
374
  it "defines http_options[:ssl] if not defined" do
335
375
  Koala::HTTPService.http_options[:ssl] = nil
336
376
  value = "foo"
@@ -344,14 +384,14 @@ describe "Koala::HTTPService" do
344
384
  Koala::HTTPService.http_options[:ssl].should
345
385
  Koala::HTTPService.http_options[:ssl][deprecated_method].should == value
346
386
  end
347
-
387
+
348
388
  it "does not redefine http_options[:ssl] if already defined" do
349
389
  hash = {:a => 2}
350
390
  Koala::HTTPService.http_options[:ssl] = hash
351
391
  Koala::HTTPService.send(:"#{deprecated_method}=", 3)
352
392
  Koala::HTTPService.http_options[:ssl].should include(hash)
353
393
  end
354
-
394
+
355
395
  it "generates a deprecation warning" do
356
396
  Koala::Utils.should_receive(:deprecate)
357
397
  Koala::HTTPService.send(:"#{deprecated_method}=", 2)
@@ -359,7 +399,7 @@ describe "Koala::HTTPService" do
359
399
  end
360
400
  end
361
401
  end
362
-
402
+
363
403
  describe "per-request options" do
364
404
  before :each do
365
405
  # Setup stubs for make_request to execute without exceptions
@@ -372,18 +412,18 @@ describe "Koala::HTTPService" do
372
412
  @mock_connection.stub(:post).and_return(@mock_http_response)
373
413
  Faraday.stub(:new).and_return(@mock_connection)
374
414
  end
375
-
415
+
376
416
  describe ":typhoeus_options" do
377
417
  it "merges any typhoeus_options into options" do
378
418
  typhoeus_options = {:a => 2}
379
419
  Faraday.should_receive(:new).with(anything, hash_including(typhoeus_options)).and_return(@mock_connection)
380
- Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
420
+ Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
381
421
  end
382
-
422
+
383
423
  it "deletes the typhoeus_options key" do
384
424
  typhoeus_options = {:a => 2}
385
425
  Faraday.should_receive(:new).with(anything, hash_not_including(:typhoeus_options => typhoeus_options)).and_return(@mock_connection)
386
- Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
426
+ Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
387
427
  end
388
428
  end
389
429
 
@@ -400,7 +440,7 @@ describe "Koala::HTTPService" do
400
440
  Koala::HTTPService.make_request("anything", {}, "get", :ca_path => ca_path)
401
441
  end
402
442
  end
403
-
443
+
404
444
  describe ":ca_file" do
405
445
  it "sets any ca_file into options[:ssl]" do
406
446
  ca_file = :foo
@@ -414,7 +454,7 @@ describe "Koala::HTTPService" do
414
454
  Koala::HTTPService.make_request("anything", {}, "get", :ca_file => ca_file)
415
455
  end
416
456
  end
417
-
457
+
418
458
  describe ":verify_mode" do
419
459
  it "sets any verify_mode into options[:ssl]" do
420
460
  verify_mode = :foo
@@ -98,6 +98,12 @@ describe "Koala::Facebook::OAuth" do
98
98
  @oauth.stub(:parse_signed_request).and_return({})
99
99
  @oauth.get_user_info_from_cookies(@cookie).should be_nil
100
100
  end
101
+
102
+ it "logs a warning" do
103
+ @oauth.stub(:parse_signed_request).and_return({})
104
+ Koala::Utils.logger.should_receive(:warn)
105
+ @oauth.get_user_info_from_cookies(@cookie)
106
+ end
101
107
  end
102
108
 
103
109
  context "if the code is present" do
@@ -655,7 +661,7 @@ describe "Koala::Facebook::OAuth" do
655
661
  # the signed request code is ported directly from Facebook
656
662
  # so we only need to test at a high level that it works
657
663
  it "throws an error if the algorithm is unsupported" do
658
- MultiJson.stub(:decode).and_return("algorithm" => "my fun algorithm")
664
+ MultiJson.stub(:load).and_return("algorithm" => "my fun algorithm")
659
665
  lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
660
666
  end
661
667
 
@@ -31,4 +31,25 @@ describe Koala::Utils do
31
31
  Koala::Utils.deprecate(message)
32
32
  end
33
33
  end
34
+
35
+ describe ".logger" do
36
+ it "has an accessor for logger" do
37
+ Koala::Utils.methods.map(&:to_sym).should include(:logger)
38
+ Koala::Utils.methods.map(&:to_sym).should include(:logger=)
39
+ end
40
+
41
+ it "defaults to the standard ruby logger with level set to ERROR" do |variable|
42
+ Koala::Utils.logger.should be_kind_of(Logger)
43
+ Koala::Utils.logger.level.should == Logger::ERROR
44
+ end
45
+
46
+ logger_methods = [:debug, :info, :warn, :error, :fatal]
47
+
48
+ logger_methods.each do |logger_method|
49
+ it "should delegate #{logger_method} to the attached logger" do
50
+ Koala::Utils.logger.should_receive(logger_method)
51
+ Koala::Utils.send(logger_method, "Test #{logger_method} message")
52
+ end
53
+ end
54
+ end
34
55
  end
@@ -42,11 +42,11 @@ graph_api:
42
42
 
43
43
  # OAuth error response
44
44
  oauth_error: &oauth_error
45
- no_token: '{"error": {"type": "OAuthException", "message": "Error validating verification code."}}'
45
+ no_token: '{"error": {"code"=>2500, "type": "OAuthException", "message": "Error validating verification code."}}'
46
46
 
47
47
  # Subscription error response
48
48
  verification_error: &verification_error
49
- with_token: '{"error": {"type": "OAuthException", "message": "Error validating verification code."}}'
49
+ with_token: '{"error": {"code"=>2500, "type": "OAuthException", "message": "Error validating verification code."}}'
50
50
 
51
51
  test_user_uninstalled: &test_user_uninstalled
52
52
  post:
@@ -68,53 +68,53 @@ graph_api:
68
68
  no_token: '{"contextoptional":"{}","koppel":"{}"}'
69
69
 
70
70
  # Ruby 1.8.7 and 1.9.2 generate JSON with different key ordering, hence we have to dynamically generate it here
71
- batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me"},{"method" => "get", "relative_url" => "koppel"}]) %>:
71
+ batch=<%= MultiJson.dump([{"method" => "get", "relative_url" => "me"},{"method" => "get", "relative_url" => "koppel"}]) %>:
72
72
  post:
73
73
  with_token: '[{"body":"{\"id\":\"123\"}"}, {"body":"{\"id\":\"456\"}"}]'
74
- batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me/picture"}]) %>:
74
+ batch=<%= MultiJson.dump([{"method" => "get", "relative_url" => "me/picture"}]) %>:
75
75
  post:
76
76
  with_token: '[{"headers":[{"name":"Location","value":"http://google.com"}]}]'
77
- batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me"},{"method" => "get", "relative_url" => "me/friends"}]) %>:
77
+ batch=<%= MultiJson.dump([{"method" => "get", "relative_url" => "me"},{"method" => "get", "relative_url" => "me/friends"}]) %>:
78
78
  post:
79
79
  with_token: '[{"body":"{\"id\":\"123\"}"}, {"body":"{\"data\":[],\"paging\":{}}"}]'
80
- batch=<%= MultiJson.encode([{"method"=>"get", "relative_url"=>"me"}, {"method"=>"get", "relative_url"=>"#{OAUTH_DATA["app_id"]}/insights?access_token=#{CGI.escape APP_ACCESS_TOKEN}"}]) %>:
80
+ batch=<%= MultiJson.dump([{"method"=>"get", "relative_url"=>"me"}, {"method"=>"get", "relative_url"=>"#{OAUTH_DATA["app_id"]}/insights?access_token=#{CGI.escape APP_ACCESS_TOKEN}"}]) %>:
81
81
  post:
82
82
  with_token: '[{"body":"{\"id\":\"123\"}"}, {"body":"{\"data\":[],\"paging\":{}}"}]'
83
- batch=<%= MultiJson.encode([{"method"=>"get", "relative_url"=>"2/invalidconnection"}, {"method"=>"get", "relative_url"=>"koppel?access_token=#{CGI.escape APP_ACCESS_TOKEN}"}]) %>:
83
+ batch=<%= MultiJson.dump([{"method"=>"get", "relative_url"=>"2/invalidconnection"}, {"method"=>"get", "relative_url"=>"koppel?access_token=#{CGI.escape APP_ACCESS_TOKEN}"}]) %>:
84
84
  post:
85
85
  with_token: '[{"body": "{\"error\":{\"type\":\"AnError\", \"message\":\"An error occurred!.\"}}"},{"body":"{\"id\":\"123\"}"}]'
86
- batch=<%= MultiJson.encode([{"method"=>"post", "relative_url"=>"FEED_ITEM_BATCH/likes"}, {"method"=>"delete", "relative_url"=> "FEED_ITEM_BATCH"}]) %>:
86
+ batch=<%= MultiJson.dump([{"method"=>"post", "relative_url"=>"FEED_ITEM_BATCH/likes"}, {"method"=>"delete", "relative_url"=> "FEED_ITEM_BATCH"}]) %>:
87
87
  post:
88
88
  with_token: '[{"body": "{\"id\": \"MOCK_LIKE\"}"},{"body":true}]'
89
- batch=<%= MultiJson.encode([{"method" => "post", "relative_url" => "method/fql.query", "body" => "query=select+first_name+from+user+where+uid%3D2905623"}]) %>:
89
+ batch=<%= MultiJson.dump([{"method" => "post", "relative_url" => "method/fql.query", "body" => "query=select+first_name+from+user+where+uid%3D2905623"}]) %>:
90
90
  post:
91
91
  with_token: '[{"body":"[{\"first_name\":\"Alex\"}]"}]'
92
92
 
93
93
  # dependencies
94
- batch=<%= MultiJson.encode([{"method"=>"get", "relative_url"=>"me", "name" => "getme"}, {"method"=>"get", "relative_url"=>"koppel", "depends_on" => "getme"}]) %>:
94
+ batch=<%= MultiJson.dump([{"method"=>"get", "relative_url"=>"me", "name" => "getme"}, {"method"=>"get", "relative_url"=>"koppel", "depends_on" => "getme"}]) %>:
95
95
  post:
96
96
  with_token: '[null,{"body":"{\"id\":\"123\"}"}]'
97
- batch=<%= MultiJson.encode([{"method"=>"get", "relative_url"=>"2/invalidconnection", "name" => "getdata"}, {"method"=>"get", "relative_url"=>"koppel", "depends_on" => "getdata"}]) %>:
97
+ batch=<%= MultiJson.dump([{"method"=>"get", "relative_url"=>"2/invalidconnection", "name" => "getdata"}, {"method"=>"get", "relative_url"=>"koppel", "depends_on" => "getdata"}]) %>:
98
98
  post:
99
99
  with_token: '[{"body": "{\"error\":{\"type\":\"AnError\", \"message\":\"An error occurred!.\"}}"},null]'
100
- batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me/friends?limit=5", "name" => "get-friends"}, {"method" => "get", "relative_url" => "?ids=#{CGI.escape "{result=get-friends:$.data.*.id}"}"}]) %>:
100
+ batch=<%= MultiJson.dump([{"method" => "get", "relative_url" => "me/friends?limit=5", "name" => "get-friends"}, {"method" => "get", "relative_url" => "?ids=#{CGI.escape "{result=get-friends:$.data.*.id}"}"}]) %>:
101
101
  post:
102
102
  with_token: '[null,{"body":"{}"}]'
103
- batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me/friends?limit=5", "name" => "get-friends", "omit_response_on_success" => false}, {"method" => "get", "relative_url" => "?ids=#{CGI.escape "{result=get-friends:$.data.*.id}"}"}]) %>:
103
+ batch=<%= MultiJson.dump([{"method" => "get", "relative_url" => "me/friends?limit=5", "name" => "get-friends", "omit_response_on_success" => false}, {"method" => "get", "relative_url" => "?ids=#{CGI.escape "{result=get-friends:$.data.*.id}"}"}]) %>:
104
104
  post:
105
105
  with_token: '[{"body":"{\"data\":[],\"paging\":{}}"},{"body":"{}"}]'
106
- batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me/friends?limit=5"}, {"method" => "get", "relative_url" => "?ids=#{CGI.escape "{result=i-dont-exist:$.data.*.id}"}"}]) %>:
106
+ batch=<%= MultiJson.dump([{"method" => "get", "relative_url" => "me/friends?limit=5"}, {"method" => "get", "relative_url" => "?ids=#{CGI.escape "{result=i-dont-exist:$.data.*.id}"}"}]) %>:
107
107
  post:
108
108
  with_token: '{"error":190,"error_description":"Error validating access token."}'
109
109
 
110
110
  # attached files tests
111
- batch=<%= MultiJson.encode([{"method"=>"post", "relative_url"=>"me/photos", "attached_files" => "op1_file0"}]) %>&op1_file0=[FILE]:
111
+ batch=<%= MultiJson.dump([{"method"=>"post", "relative_url"=>"me/photos", "attached_files" => "op1_file0"}]) %>&op1_file0=[FILE]:
112
112
  post:
113
113
  with_token: '[{"body": "{\"error\":{\"type\":\"AnError\", \"message\":\"An error occurred!.\"}}"},null]'
114
- batch=<%= MultiJson.encode([{"method"=>"post", "relative_url"=>"me/photos", "attached_files" => "op1_file0"}]) %>&op1_file0=[FILE]:
114
+ batch=<%= MultiJson.dump([{"method"=>"post", "relative_url"=>"me/photos", "attached_files" => "op1_file0"}]) %>&op1_file0=[FILE]:
115
115
  post:
116
116
  with_token: '[{"body":"{\"id\": \"MOCK_PHOTO\"}"}]'
117
- batch=<%= MultiJson.encode([{"method"=>"post", "relative_url"=>"me/photos", "attached_files" => "op1_file0"}, {"method"=>"post", "relative_url"=>"koppel/photos", "attached_files" => "op2_file0"}]) %>&op1_file0=[FILE]&op2_file0=[FILE]:
117
+ batch=<%= MultiJson.dump([{"method"=>"post", "relative_url"=>"me/photos", "attached_files" => "op1_file0"}, {"method"=>"post", "relative_url"=>"koppel/photos", "attached_files" => "op2_file0"}]) %>&op1_file0=[FILE]&op2_file0=[FILE]:
118
118
  post:
119
119
  with_token: '[{"body":"{\"id\": \"MOCK_PHOTO\"}"}, {"body":"{\"id\": \"MOCK_PHOTO\"}"}]'
120
120
 
@@ -273,11 +273,11 @@ graph_api:
273
273
  get:
274
274
  <<: *token_required
275
275
  with_token: '[{"read_stream":1}]'
276
- 'q=<%= MultiJson.encode({"query1" => "select post_id from stream where source_id = me()", "query2" => "select fromid from comment where post_id in (select post_id from #query1)", "query3" => "select uid, name from user where uid in (select fromid from #query2)"}) %>':
276
+ 'q=<%= MultiJson.dump({"query1" => "select post_id from stream where source_id = me()", "query2" => "select fromid from comment where post_id in (select post_id from #query1)", "query3" => "select uid, name from user where uid in (select fromid from #query2)"}) %>':
277
277
  get:
278
278
  <<: *token_required
279
279
  with_token: '[{"name":"query1", "fql_result_set":[]},{"name":"query2", "fql_result_set":[]},{"name":"query3", "fql_result_set":[]}]'
280
- 'q=<%= MultiJson.encode({"query1" => "select uid, first_name from user where uid = 2901279", "query2" => "select uid, first_name from user where uid = 2905623"}) %>':
280
+ 'q=<%= MultiJson.dump({"query1" => "select uid, first_name from user where uid = 2901279", "query2" => "select uid, first_name from user where uid = 2905623"}) %>':
281
281
  get:
282
282
  with_token: '[{"name":"query1", "fql_result_set":[{"uid":2901279,"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"uid":"2905623","first_name":"Alex"}]}]'
283
283
  no_token: '[{"name":"query1", "fql_result_set":[{"uid":2901279,"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"uid":"2905623","first_name":"Alex"}]}]'
@@ -296,7 +296,7 @@ graph_api:
296
296
 
297
297
 
298
298
  '/<%= APP_ID %>':
299
- restrictions=<%= MultiJson.encode({"age_distr" => "13+"}) %>:
299
+ restrictions=<%= MultiJson.dump({"age_distr" => "13+"}) %>:
300
300
  post:
301
301
  with_token: "true"
302
302
 
@@ -158,7 +158,7 @@ shared_examples_for "Koala GraphAPI" do
158
158
  it "passes a queries argument" do
159
159
  queries = stub('query string')
160
160
  queries_json = "some JSON"
161
- MultiJson.stub(:encode).with(queries).and_return(queries_json)
161
+ MultiJson.stub(:dump).with(queries).and_return(queries_json)
162
162
 
163
163
  @api.should_receive(:get_object).with(anything, hash_including(:q => queries_json), anything)
164
164
  @api.fql_multiquery(queries)
@@ -426,7 +426,7 @@ shared_examples_for "Koala GraphAPI with an access token" do
426
426
  end
427
427
 
428
428
  it "JSON-encodes the restrictions" do
429
- @app_api.should_receive(:graph_call).with(anything, hash_including(:restrictions => MultiJson.encode(@restrictions)), anything, anything)
429
+ @app_api.should_receive(:graph_call).with(anything, hash_including(:restrictions => MultiJson.dump(@restrictions)), anything, anything)
430
430
  @app_api.set_app_restrictions(KoalaTest.app_id, @restrictions)
431
431
  end
432
432
 
@@ -592,10 +592,13 @@ shared_examples_for "Koala GraphAPI without an access token" do
592
592
  end
593
593
 
594
594
  it "can't put an object" do
595
+ lambda { @result = @api.put_connections(KoalaTest.user2, "feed", :message => "Hello, world") }.should raise_error(Koala::Facebook::APIError)
596
+ # legacy put_object syntax
595
597
  lambda { @result = @api.put_object(KoalaTest.user2, "feed", :message => "Hello, world") }.should raise_error(Koala::Facebook::APIError)
596
598
  end
597
599
 
598
- # these are not strictly necessary as the other put methods resolve to put_object, but are here for completeness
600
+ # these are not strictly necessary as the other put methods resolve to put_connections,
601
+ # but are here for completeness
599
602
  it "can't post to a feed" do
600
603
  (lambda do
601
604
  attachment = {:name => "OAuth Playground", :link => "http://oauth.twoalex.com/"}