koala 1.1.0rc2 → 1.1.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.
@@ -225,7 +225,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
225
225
 
226
226
  it "includes the method" do
227
227
  params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])
228
- params[:method].should == @args[:method].to_sym
228
+ params[:method].should == @args[:method].to_s
229
229
  end
230
230
 
231
231
  it "works with nil http_options" do
@@ -257,89 +257,45 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
257
257
  file_ids = batch_op.files.find_all {|k, v| v == @uploadable_io}.map {|k, v| k}
258
258
  params = batch_op.to_batch_params(nil)
259
259
  params[:attached_files].should == file_ids.join(",")
260
- end
260
+ end
261
261
  end
262
262
  end
263
-
263
+
264
264
  end
265
-
265
+
266
266
  describe "GraphAPI batch interface" do
267
- it "sets the batch_mode flag to false outside batch mode" do
268
- Koala::Facebook::GraphAPI.batch_mode?.should be_false
269
- end
270
-
271
- it "sets the batch_mode flag inside batch mode" do
272
- Koala::Facebook::GraphAPI.batch do
273
- Koala::Facebook::GraphAPI.batch_mode?.should be_true
274
- end
275
- end
276
-
277
- it "throws an error if you try to access the batch_calls queue outside a batch block" do
278
- expect { Koala::Facebook::GraphAPI.batch_calls << BatchOperation.new(:access_token => "2") }.to raise_exception(Koala::KoalaError)
279
- end
280
267
 
281
- it "clears the batch queue between requests" do
282
- Koala.stub(:make_request).and_return(Koala::Response.new(200, "[]", {}))
283
- Koala::Facebook::GraphAPI.batch { @api.get_object("me") }
284
- Koala.should_receive(:make_request).once.and_return(Koala::Response.new(200, "[]", {}))
285
- Koala::Facebook::GraphAPI.batch { @api.get_object("me") }
286
- end
287
-
288
268
  it "returns nothing for a batch operation" do
289
269
  Koala.stub(:make_request).and_return(Koala::Response.new(200, "[]", {}))
290
- Koala::Facebook::GraphAPI.batch do
291
- @api.get_object("me").should be_nil
292
- end
293
- end
294
-
295
- it "creates a BatchObject when making a GraphAPI request in batch mode" do
296
- Koala.should_receive(:make_request).once.and_return(Koala::Response.new(200, "[]", {}))
297
-
298
- args = {:a => :b}
299
- method = "post"
300
- http_options = {:option => true}
301
- url = "/a"
302
- access_token = "token"
303
- post_processing = lambda {}
304
- op = Koala::Facebook::BatchOperation.new(:access_token => access_token, :method => :get, :url => "/")
305
- Koala::Facebook::BatchOperation.should_receive(:new).with(
306
- :url => url,
307
- :args => args,
308
- :method => method,
309
- :access_token => access_token,
310
- :http_options => http_options,
311
- :post_processing => post_processing
312
- ).and_return(op)
313
-
314
- Koala::Facebook::GraphAPI.batch do
315
- Koala::Facebook::GraphAPI.new(access_token).graph_call(url, args, method, http_options, &post_processing)
270
+ @api.batch do |batch_api|
271
+ batch_api.get_object('me').should be_nil
316
272
  end
317
273
  end
318
274
 
319
- describe "#batch_api" do
275
+ describe "#batch" do
320
276
  before :each do
321
277
  @fake_response = Koala::Response.new(200, "[]", {})
322
278
  Koala.stub(:make_request).and_return(@fake_response)
323
279
  end
324
-
280
+
325
281
  describe "making the request" do
326
282
  context "with no calls" do
327
283
  it "does not make any requests if batch_calls is empty" do
328
284
  Koala.should_not_receive(:make_request)
329
- Koala::Facebook::GraphAPI.batch {}
285
+ @api.batch {|batch_api|}
330
286
  end
331
287
 
332
288
  it "returns []" do
333
- Koala::Facebook::GraphAPI.batch {}.should == []
289
+ @api.batch {|batch_api|}.should == []
334
290
  end
335
291
  end
336
-
292
+
337
293
  it "includes the first operation's access token as the main one in the args" do
338
294
  access_token = "foo"
339
295
  Koala.should_receive(:make_request).with(anything, hash_including("access_token" => access_token), anything, anything).and_return(@fake_response)
340
- Koala::Facebook::GraphAPI.batch do
341
- Koala::Facebook::GraphAPI.new(access_token).get_object('me')
342
- Koala::Facebook::GraphAPI.new("bar").get_object('me')
296
+ Koala::Facebook::GraphAPI.new(access_token).batch do |batch_api|
297
+ batch_api.get_object('me')
298
+ batch_api.get_object('me', {}, {'access_token' => 'bar'})
343
299
  end
344
300
  end
345
301
 
@@ -348,155 +304,180 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
348
304
  op = Koala::Facebook::BatchOperation.new(:access_token => access_token, :method => :get, :url => "/")
349
305
  op.stub(:to_batch_params).and_return({:a => 2})
350
306
  Koala::Facebook::BatchOperation.stub(:new).and_return(op)
351
-
307
+
352
308
  # two requests should generate two batch operations
353
- expected = [op.to_batch_params(access_token), op.to_batch_params(access_token)].to_json
309
+ expected = MultiJson.encode([op.to_batch_params(access_token), op.to_batch_params(access_token)])
354
310
  Koala.should_receive(:make_request).with(anything, hash_including("batch" => expected), anything, anything).and_return(@fake_response)
355
- Koala::Facebook::GraphAPI.batch do
356
- Koala::Facebook::GraphAPI.new(access_token).get_object('me')
357
- Koala::Facebook::GraphAPI.new(access_token).get_object('me')
358
- end
311
+ Koala::Facebook::GraphAPI.new(access_token).batch do |batch_api|
312
+ batch_api.get_object('me')
313
+ batch_api.get_object('me')
314
+ end
359
315
  end
360
-
316
+
361
317
  it "adds any files from the batch operations to the arguments" do
362
- # stub the batch operation
318
+ # stub the batch operation
363
319
  # we test above to ensure that files are properly assimilated into the BatchOperation instance
364
320
  # right now, we want to make sure that batch_api handles them properly
365
321
  @key = "file0_0"
366
322
  @uploadable_io = stub("UploadableIO")
367
323
  batch_op = stub("Koala Batch Operation", :files => {@key => @uploadable_io}, :to_batch_params => {}, :access_token => "foo")
368
324
  Koala::Facebook::BatchOperation.stub(:new).and_return(batch_op)
369
-
370
- Koala.should_receive(:make_request).with(anything, hash_including(@key => @uploadable_io), anything, anything).and_return(@fake_response)
371
- Koala::Facebook::GraphAPI.batch do
372
- Koala::Facebook::GraphAPI.new("bar").put_picture("path/to/file", "image/jpeg")
373
- end
325
+
326
+ Koala.should_receive(:make_request).with(anything, hash_including(@key => @uploadable_io), anything, anything).and_return(@fake_response)
327
+ Koala::Facebook::GraphAPI.new("bar").batch do |batch_api|
328
+ batch_api.put_picture("path/to/file", "image/jpeg")
329
+ end
374
330
  end
375
-
331
+
376
332
  it "preserves operation order" do
377
333
  access_token = "bar"
378
334
  # two requests should generate two batch operations
379
- Koala.should_receive(:make_request) do |url, args, method, options|
335
+ Koala.should_receive(:make_request) do |url, args, method, options|
380
336
  # test the batch operations to make sure they appear in the right order
381
337
  (args ||= {})["batch"].should =~ /.*me\/farglebarg.*otheruser\/bababa/
382
338
  @fake_response
383
339
  end
384
- Koala::Facebook::GraphAPI.batch do
385
- Koala::Facebook::GraphAPI.new(access_token).get_connections('me', "farglebarg")
386
- Koala::Facebook::GraphAPI.new(access_token).get_connections('otheruser', "bababa")
340
+ Koala::Facebook::GraphAPI.new(access_token).batch do |batch_api|
341
+ batch_api.get_connections('me', "farglebarg")
342
+ batch_api.get_connections('otheruser', "bababa")
387
343
  end
388
344
  end
389
-
345
+
390
346
  it "makes a POST request" do
391
347
  Koala.should_receive(:make_request).with(anything, anything, "post", anything).and_return(@fake_response)
392
- Koala::Facebook::GraphAPI.batch do
393
- Koala::Facebook::GraphAPI.new("foo").get_object('me')
348
+ Koala::Facebook::GraphAPI.new("foo").batch do |batch_api|
349
+ batch_api.get_object('me')
394
350
  end
395
351
  end
396
-
352
+
397
353
  it "makes a request to /" do
398
354
  Koala.should_receive(:make_request).with("/", anything, anything, anything).and_return(@fake_response)
399
- Koala::Facebook::GraphAPI.batch do
400
- Koala::Facebook::GraphAPI.new("foo").get_object('me')
355
+ Koala::Facebook::GraphAPI.new("foo").batch do |batch_api|
356
+ batch_api.get_object('me')
401
357
  end
402
358
  end
403
-
359
+
404
360
  it "includes any http options specified at the top level" do
405
361
  http_options = {"a" => "baz"}
406
362
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(http_options)).and_return(@fake_response)
407
- Koala::Facebook::GraphAPI.batch(http_options) do
408
- Koala::Facebook::GraphAPI.new("foo").get_object('me')
363
+ Koala::Facebook::GraphAPI.new("foo").batch(http_options) do |batch_api|
364
+ batch_api.get_object('me')
409
365
  end
410
366
  end
411
367
  end
412
-
368
+
413
369
  describe "processing the request" do
414
370
  it "throws an error if the response is not 200" do
415
371
  Koala.stub(:make_request).and_return(Koala::Response.new(500, "[]", {}))
416
- expect { Koala::Facebook::GraphAPI.batch do
417
- Koala::Facebook::GraphAPI.new("foo").get_object('me')
372
+ expect { Koala::Facebook::GraphAPI.new("foo").batch do |batch_api|
373
+ batch_api.get_object('me')
418
374
  end }.to raise_exception(Koala::Facebook::APIError)
419
375
  end
420
-
376
+
421
377
  it "throws an error if the response is a Batch API-style error" do
422
378
  Koala.stub(:make_request).and_return(Koala::Response.new(200, '{"error":190,"error_description":"Error validating access token."}', {}))
423
- expect { Koala::Facebook::GraphAPI.batch do
424
- Koala::Facebook::GraphAPI.new("foo").get_object('me')
425
- end }.to raise_exception(Koala::Facebook::APIError)
379
+ expect { Koala::Facebook::GraphAPI.new("foo").batch do |batch_api|
380
+ batch_api.get_object('me')
381
+ end }.to raise_exception(Koala::Facebook::APIError)
426
382
  end
427
-
383
+
428
384
  it "returns the result status if http_component is status" do
429
385
  Koala.stub(:make_request).and_return(Koala::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
430
- result = Koala::Facebook::GraphAPI.batch do
431
- @api.get_object("koppel", {}, :http_component => :status)
386
+ result = @api.batch do |batch_api|
387
+ batch_api.get_object("koppel", {}, :http_component => :status)
432
388
  end
433
389
  result[0].should == 203
434
390
  end
435
391
 
436
392
  it "returns the result headers as a hash if http_component is headers" do
437
393
  Koala.stub(:make_request).and_return(Koala::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
438
- result = Koala::Facebook::GraphAPI.batch do
439
- @api.get_object("koppel", {}, :http_component => :headers)
394
+ result = @api.batch do |batch_api|
395
+ batch_api.get_object("koppel", {}, :http_component => :headers)
440
396
  end
441
397
  result[0].should == {"Content-Type" => "text/javascript; charset=UTF-8"}
442
398
  end
443
399
  end
444
-
445
- it "is not available on the GraphAndRestAPI class" do
446
- Koala::Facebook::GraphAndRestAPI.should_not respond_to(:batch)
400
+
401
+ it "is thread safe" do
402
+ # ensure batch operations on one thread don't affect those on another
403
+ thread_one_count = 0
404
+ thread_two_count = 0
405
+ first_count = 20
406
+ second_count = 10
407
+
408
+ Koala.stub(:make_request).and_return(@fake_response)
409
+
410
+ thread1 = Thread.new do
411
+ @api.batch do |batch_api|
412
+ first_count.times {|i| batch_api.get_object("me"); sleep(0.01) }
413
+ thread_one_count = batch_api.batch_calls.count
414
+ end
415
+ end
416
+
417
+ thread2 = Thread.new do
418
+ @api.batch do |batch_api|
419
+ second_count.times {|i| batch_api.get_object("me"); sleep(0.01) }
420
+ thread_two_count = batch_api.batch_calls.count
421
+ end
422
+ end
423
+
424
+ thread1.join
425
+ thread2.join
426
+
427
+ thread_one_count.should == first_count
428
+ thread_two_count.should == second_count
447
429
  end
448
430
  end
449
431
  end
450
-
432
+
451
433
  describe "usage tests" do
452
- it "should be able get two results at once" do
453
- me, koppel = Koala::Facebook::GraphAPI.batch do
454
- @api.get_object('me')
455
- @api.get_object('koppel')
434
+ it "can get two results at once" do
435
+ me, koppel = @api.batch do |batch_api|
436
+ batch_api.get_object('me')
437
+ batch_api.get_object('koppel')
456
438
  end
457
439
  me['id'].should_not be_nil
458
440
  koppel['id'].should_not be_nil
459
441
  end
460
442
 
461
-
462
443
  it "works with GraphAndRestAPI instances" do
463
- me, koppel = Koala::Facebook::GraphAPI.batch do
464
- Koala::Facebook::GraphAndRestAPI.new(@api.access_token).get_object('me')
465
- @api.get_object('koppel')
444
+ me, koppel = Koala::Facebook::GraphAndRestAPI.new(@api.access_token).batch do |batch_api|
445
+ batch_api.get_object('me')
446
+ batch_api.get_object('koppel')
466
447
  end
467
448
  me['id'].should_not be_nil
468
449
  koppel['id'].should_not be_nil
469
450
  end
470
451
 
471
452
  it 'should be able to make mixed calls inside of a batch' do
472
- me, friends = Koala::Facebook::GraphAPI.batch do
473
- @api.get_object('me')
474
- @api.get_connections('me', 'friends')
453
+ me, friends = @api.batch do |batch_api|
454
+ batch_api.get_object('me')
455
+ batch_api.get_connections('me', 'friends')
475
456
  end
476
457
  me['id'].should_not be_nil
477
458
  friends.should be_an(Array)
478
459
  end
479
460
 
480
461
  it 'should be able to make a get_picture call inside of a batch' do
481
- pictures = Koala::Facebook::GraphAPI.batch do
482
- @api.get_picture('me')
462
+ pictures = @api.batch do |batch_api|
463
+ batch_api.get_picture('me')
483
464
  end
484
465
  pictures.first.should_not be_empty
485
466
  end
486
-
467
+
487
468
  it "should handle requests for two different tokens" do
488
- me, insights = Koala::Facebook::GraphAPI.batch do
489
- @api.get_object('me')
490
- @app_api.get_connections(@app_id, 'insights')
469
+ me, insights = @api.batch do |batch_api|
470
+ batch_api.get_object('me')
471
+ batch_api.get_connections(@app_id, 'insights', {}, {"access_token" => @app_api.access_token})
491
472
  end
492
473
  me['id'].should_not be_nil
493
474
  insights.should be_an(Array)
494
475
  end
495
-
476
+
496
477
  it "inserts errors in the appropriate place, without breaking other results" do
497
- failed_insights, koppel = Koala::Facebook::GraphAPI.batch do
498
- @api.get_connections(@app_id, 'insights')
499
- @app_api.get_object("koppel")
478
+ failed_insights, koppel = @api.batch do |batch_api|
479
+ batch_api.get_connections(@app_id, 'insights')
480
+ batch_api.get_object("koppel", {}, {"access_token" => @app_api.access_token})
500
481
  end
501
482
  failed_insights.should be_a(Koala::Facebook::APIError)
502
483
  koppel["id"].should_not be_nil
@@ -505,96 +486,124 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
505
486
  it "handles different request methods" do
506
487
  result = @api.put_wall_post("Hello, world, from the test suite batch API!")
507
488
  wall_post = result["id"]
508
-
509
- wall_post, koppel = Koala::Facebook::GraphAPI.batch do
510
- @api.put_like(wall_post)
511
- @api.delete_object(wall_post)
489
+
490
+ wall_post, koppel = @api.batch do |batch_api|
491
+ batch_api.put_like(wall_post)
492
+ batch_api.delete_object(wall_post)
512
493
  end
513
494
  end
514
-
495
+
515
496
  it "allows FQL" do
516
- result = Koala::Facebook::GraphAPI.batch do
517
- @api.graph_call("method/fql.query", {:query=>"select name from user where uid=4"}, "post")
497
+ result = @api.batch do |batch_api|
498
+ batch_api.graph_call("method/fql.query", {:query=>"select name from user where uid=4"}, "post")
518
499
  end
519
-
500
+
520
501
  fql_result = result[0]
521
502
  fql_result[0].should be_a(Hash)
522
503
  fql_result[0]["name"].should == "Mark Zuckerberg"
523
504
  end
524
-
505
+
525
506
  describe "binary files" do
526
507
  it "posts binary files" do
527
508
  file = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
528
509
 
529
- result = Koala::Facebook::GraphAPI.batch do
530
- @api.put_picture(file)
510
+ Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0)
511
+ result = @api.batch do |batch_api|
512
+ batch_api.put_picture(file)
531
513
  end
532
-
514
+
533
515
  @temporary_object_id = result[0]["id"]
534
516
  @temporary_object_id.should_not be_nil
535
517
  end
536
-
518
+
537
519
  it "posts binary files with multiple requests" do
538
520
  file = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
539
521
 
540
- results = Koala::Facebook::GraphAPI.batch do
541
- @api.put_picture(file)
542
- @api.put_picture(file, {}, "koppel")
522
+ Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0)
523
+ results = @api.batch do |batch_api|
524
+ batch_api.put_picture(file)
525
+ batch_api.put_picture(file, {}, "koppel")
543
526
  end
544
527
  results[0]["id"].should_not be_nil
545
528
  results[1]["id"].should_not be_nil
546
529
  end
547
530
  end
548
-
531
+
549
532
  describe "relating requests" do
550
533
  it "allows you create relationships between requests without omit_response_on_success" do
551
- results = Koala::Facebook::GraphAPI.batch do
552
- @api.get_connections("me", "friends", {:limit => 5}, :batch_args => {:name => "get-friends"})
553
- @api.get_objects("{result=get-friends:$.data.*.id}")
534
+ results = @api.batch do |batch_api|
535
+ batch_api.get_connections("me", "friends", {:limit => 5}, :batch_args => {:name => "get-friends"})
536
+ batch_api.get_objects("{result=get-friends:$.data.*.id}")
554
537
  end
555
-
538
+
556
539
  results[0].should be_nil
557
540
  results[1].should be_an(Hash)
558
541
  end
559
-
542
+
560
543
  it "allows you create relationships between requests with omit_response_on_success" do
561
- results = Koala::Facebook::GraphAPI.batch do
562
- @api.get_connections("me", "friends", {:limit => 5}, :batch_args => {:name => "get-friends", :omit_response_on_success => false})
563
- @api.get_objects("{result=get-friends:$.data.*.id}")
544
+ results = @api.batch do |batch_api|
545
+ batch_api.get_connections("me", "friends", {:limit => 5}, :batch_args => {:name => "get-friends", :omit_response_on_success => false})
546
+ batch_api.get_objects("{result=get-friends:$.data.*.id}")
564
547
  end
565
-
548
+
566
549
  results[0].should be_an(Array)
567
550
  results[1].should be_an(Hash)
568
551
  end
569
-
552
+
570
553
  it "allows you to create dependencies" do
571
- me, koppel = Koala::Facebook::GraphAPI.batch do
572
- @api.get_object("me", {}, :batch_args => {:name => "getme"})
573
- @api.get_object("koppel", {}, :batch_args => {:depends_on => "getme"})
554
+ me, koppel = @api.batch do |batch_api|
555
+ batch_api.get_object("me", {}, :batch_args => {:name => "getme"})
556
+ batch_api.get_object("koppel", {}, :batch_args => {:depends_on => "getme"})
574
557
  end
575
-
558
+
576
559
  me.should be_nil # gotcha! it's omitted because it's a successfully-executed dependency
577
560
  koppel["id"].should_not be_nil
578
561
  end
579
-
562
+
580
563
  it "properly handles dependencies that fail" do
581
- data, koppel = Koala::Facebook::GraphAPI.batch do
582
- @api.get_connections(@app_id, 'insights', {}, :batch_args => {:name => "getdata"})
583
- @api.get_object("koppel", {}, :batch_args => {:depends_on => "getdata"})
564
+ data, koppel = @api.batch do |batch_api|
565
+ batch_api.get_connections(@app_id, 'insights', {}, :batch_args => {:name => "getdata"})
566
+ batch_api.get_object("koppel", {}, :batch_args => {:depends_on => "getdata"})
584
567
  end
585
568
 
586
569
  data.should be_a(Koala::Facebook::APIError)
587
570
  koppel.should be_nil
588
571
  end
589
-
572
+
590
573
  it "throws an error for badly-constructed request relationships" do
591
- expect {
592
- Koala::Facebook::GraphAPI.batch do
593
- @api.get_connections("me", "friends", {:limit => 5})
594
- @api.get_objects("{result=i-dont-exist:$.data.*.id}")
574
+ expect {
575
+ @api.batch do |batch_api|
576
+ batch_api.get_connections("me", "friends", {:limit => 5})
577
+ batch_api.get_objects("{result=i-dont-exist:$.data.*.id}")
595
578
  end
596
579
  }.to raise_exception(Koala::Facebook::APIError)
597
580
  end
598
581
  end
599
582
  end
583
+
584
+ describe "new interface" do
585
+ it "includes a deprecation warning on GraphAPI" do
586
+ begin
587
+ Koala::Facebook::GraphAPI.batch do
588
+ end
589
+ rescue NoMethodError => @err
590
+ end
591
+
592
+ # verify the message points people to the wiki page
593
+ @err.should
594
+ @err.message.should =~ /https\:\/\/github.com\/arsduo\/koala\/wiki\/Batch-requests/
595
+ end
596
+
597
+ it "includes a deprecation warning on GraphAndRESTAPI" do
598
+ begin
599
+ Koala::Facebook::GraphAndRestAPI.batch do
600
+ end
601
+ rescue NoMethodError => @err
602
+ end
603
+
604
+ # verify the message points people to the wiki page
605
+ @err.should
606
+ @err.message.should =~ /https\:\/\/github.com\/arsduo\/koala\/wiki\/Batch-requests/
607
+ end
608
+ end
600
609
  end
@@ -35,47 +35,47 @@ describe "Koala::HTTPService" do
35
35
  end
36
36
  end
37
37
 
38
- describe "ca_file accessor" do
39
- it "should be added" do
40
- Bear.methods.collect {|m| m.to_sym}.should include(:ca_file)
41
- Bear.methods.collect {|m| m.to_sym}.should include(:ca_file=)
42
- end
43
- end
44
-
45
- describe "ca_path accessor" do
46
- it "should be added" do
47
- Bear.methods.collect {|m| m.to_sym}.should include(:ca_path)
48
- Bear.methods.collect {|m| m.to_sym}.should include(:ca_path=)
49
- end
50
- end
51
-
52
38
  describe "server" do
53
- describe "without options[:beta]" do
54
- it "should return the rest server if options[:rest_api]" do
39
+ describe "with no options" do
40
+ it "returns the REST server if options[:rest_api]" do
55
41
  Bear.server(:rest_api => true).should == Koala::Facebook::REST_SERVER
56
42
  end
57
43
 
58
- it "should return the rest server if !options[:rest_api]" do
44
+ it "returns the graph server if !options[:rest_api]" do
59
45
  Bear.server(:rest_api => false).should == Koala::Facebook::GRAPH_SERVER
60
46
  Bear.server({}).should == Koala::Facebook::GRAPH_SERVER
61
47
  end
62
48
  end
63
-
64
- describe "without options[:beta]" do
49
+
50
+ describe "with options[:beta]" do
65
51
  before :each do
66
52
  @options = {:beta => true}
67
53
  end
68
54
 
69
- it "should return the rest server if options[:rest_api]" do
55
+ it "returns the beta REST server if options[:rest_api]" do
56
+ server = Bear.server(@options.merge(:rest_api => true))
57
+ server.should =~ Regexp.new("beta.#{Koala::Facebook::REST_SERVER}")
58
+ end
59
+
60
+ it "returns the beta rest server if !options[:rest_api]" do
61
+ server = Bear.server(@options)
62
+ server.should =~ Regexp.new("beta.#{Koala::Facebook::GRAPH_SERVER}")
63
+ end
64
+ end
65
+
66
+ describe "with options[:video]" do
67
+ before :each do
68
+ @options = {:video => true}
69
+ end
70
+
71
+ it "should return the REST video server if options[:rest_api]" do
70
72
  server = Bear.server(@options.merge(:rest_api => true))
71
- server.should =~ Regexp.new(Koala::Facebook::REST_SERVER)
72
- server.should =~ /beta\./
73
+ server.should =~ Regexp.new(Koala::Facebook::REST_SERVER.gsub(/\.facebook/, "-video.facebook"))
73
74
  end
74
75
 
75
- it "should return the rest server if !options[:rest_api]" do
76
- server = Bear.server(:beta => true)
77
- server.should =~ Regexp.new(Koala::Facebook::GRAPH_SERVER)
78
- server.should =~ /beta\./
76
+ it "should return the graph video server if !options[:rest_api]" do
77
+ server = Bear.server(@options)
78
+ server.should =~ Regexp.new(Koala::Facebook::GRAPH_SERVER.gsub(/\.facebook/, "-video.facebook"))
79
79
  end
80
80
  end
81
81
  end
@@ -89,7 +89,7 @@ describe "Koala::HTTPService" do
89
89
  val = 'json_value'
90
90
  not_a_string = 'not_a_string'
91
91
  not_a_string.stub(:is_a?).and_return(false)
92
- not_a_string.should_receive(:to_json).and_return(val)
92
+ MultiJson.should_receive(:encode).with(not_a_string).and_return(val)
93
93
 
94
94
  string = "hi"
95
95