koala 0.9.0 → 1.0.0.beta

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.
Files changed (46) hide show
  1. data/CHANGELOG +33 -7
  2. data/Manifest +6 -14
  3. data/Rakefile +4 -3
  4. data/koala.gemspec +13 -8
  5. data/lib/koala/graph_api.rb +16 -3
  6. data/lib/koala/http_services.rb +100 -16
  7. data/lib/koala/rest_api.rb +73 -6
  8. data/lib/koala/test_users.rb +72 -0
  9. data/lib/koala.rb +101 -71
  10. data/readme.md +14 -13
  11. data/spec/facebook_data.yml +14 -8
  12. data/spec/koala/api_base_tests.rb +7 -0
  13. data/spec/koala/assets/beach.jpg +0 -0
  14. data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +5 -1
  15. data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +9 -4
  16. data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +10 -61
  17. data/spec/koala/graph_api/graph_api_tests.rb +86 -0
  18. data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +130 -126
  19. data/spec/koala/graph_api/graph_collection_tests.rb +2 -2
  20. data/spec/koala/live_testing_data_helper.rb +40 -12
  21. data/spec/koala/net_http_service_tests.rb +401 -152
  22. data/spec/koala/oauth/oauth_tests.rb +41 -72
  23. data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +7 -76
  24. data/spec/koala/rest_api/rest_api_tests.rb +118 -0
  25. data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +6 -4
  26. data/spec/koala/test_users/test_users_tests.rb +208 -0
  27. data/spec/koala/typhoeus_service_tests.rb +156 -0
  28. data/spec/koala_spec_helper.rb +43 -4
  29. data/spec/koala_spec_without_mocks.rb +4 -4
  30. data/spec/mock_facebook_responses.yml +69 -3
  31. data/spec/mock_http_service.rb +16 -1
  32. metadata +49 -23
  33. data/examples/oauth_playground/Capfile +0 -2
  34. data/examples/oauth_playground/LICENSE +0 -22
  35. data/examples/oauth_playground/Rakefile +0 -4
  36. data/examples/oauth_playground/config/deploy.rb +0 -39
  37. data/examples/oauth_playground/config/facebook.yml +0 -13
  38. data/examples/oauth_playground/config.ru +0 -27
  39. data/examples/oauth_playground/lib/load_facebook.rb +0 -3
  40. data/examples/oauth_playground/lib/oauth_playground.rb +0 -187
  41. data/examples/oauth_playground/readme.md +0 -8
  42. data/examples/oauth_playground/spec/oauth_playground_spec.rb +0 -35
  43. data/examples/oauth_playground/spec/spec_helper.rb +0 -36
  44. data/examples/oauth_playground/tmp/restart.txt +0 -0
  45. data/examples/oauth_playground/views/index.erb +0 -206
  46. data/examples/oauth_playground/views/layout.erb +0 -39
@@ -1,14 +1,3 @@
1
- # stub the Time class to always return a time for which the valid cookie is still valid
2
- class Time
3
- def self.now
4
- self
5
- end
6
-
7
- def self.to_i
8
- 1273363199
9
- end
10
- end
11
-
12
1
  class FacebookOAuthTests < Test::Unit::TestCase
13
2
  describe "Koala OAuth tests" do
14
3
  before :each do
@@ -27,6 +16,10 @@ class FacebookOAuthTests < Test::Unit::TestCase
27
16
  @request_secret = @oauth_data["request_secret"] || @secret
28
17
  @signed_request = @oauth_data["signed_request"]
29
18
  @signed_request_result = @oauth_data["signed_request_result"]
19
+ # for signed requests (http://developers.facebook.com/docs/authentication/canvas/encryption_proposal)
20
+ @signed_params_secret = @oauth_data["signed_params_secret"] || @secret
21
+ @signed_params = @oauth_data["signed_params"]
22
+ @signed_params_result = @oauth_data["signed_params_result"]
30
23
 
31
24
  # this should expanded to cover all variables
32
25
  raise Exception, "Must supply app data to run FacebookOAuthTests!" unless @app_id && @secret && @callback_url &&
@@ -34,6 +27,10 @@ class FacebookOAuthTests < Test::Unit::TestCase
34
27
  @raw_offline_access_token_string
35
28
 
36
29
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret, @callback_url)
30
+
31
+ @time = Time.now
32
+ Time.stub!(:now).and_return(@time)
33
+ @time.stub!(:to_i).and_return(1273363199)
37
34
  end
38
35
 
39
36
  # initialization
@@ -298,6 +295,11 @@ class FacebookOAuthTests < Test::Unit::TestCase
298
295
  # it should return nil for each of the invalid ones
299
296
  result.each_with_index {|r, index| index > 0 ? r.should(be_a(Hash)) : r.should(be_nil)}
300
297
  end
298
+
299
+ it "should throw an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
300
+ @oauth.should_receive(:fetch_token_string).and_return("")
301
+ lambda { @oauth.get_token_info_from_session_keys(@oauth_data["multiple_session_keys"]) }.should raise_error(Koala::Facebook::APIError)
302
+ end
301
303
  end
302
304
 
303
305
  describe "with get_tokens_from_session_keys" do
@@ -358,81 +360,48 @@ class FacebookOAuthTests < Test::Unit::TestCase
358
360
  @oauth = Koala::Facebook::OAuth.new(@app_id, @request_secret || @app_secret)
359
361
  end
360
362
 
361
- it "should break the request into the encoded signature and the payload" do
362
- @signed_request.should_receive(:split).with(".").and_return(["", ""])
363
- @oauth.parse_signed_request(@signed_request)
363
+ # the signed request code comes directly from Facebook
364
+ # so we only need to test at a high level that it works
365
+ # signed params refers to http://developers.facebook.com/docs/authentication/canvas
366
+ # signed request refers to http://developers.facebook.com/docs/authentication/canvas/encryption_proposal
367
+ it "should throw an error if the algorithm is unsupported" do
368
+ JSON.stub!(:parse).and_return("algorithm" => "my fun algorithm")
369
+ lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
364
370
  end
365
371
 
366
- it "should base64 URL decode the signed request" do
367
- sig = ""
368
- @signed_request.should_receive(:split).with(".").and_return([sig, "1"])
369
- @oauth.should_receive(:base64_url_decode).with(sig).and_return("4")
370
- @oauth.parse_signed_request(@signed_request)
372
+ it "should throw an error if the signature is invalid" do
373
+ OpenSSL::HMAC.stub!(:hexdigest).and_return("i'm an invalid signature")
374
+ lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
371
375
  end
372
376
 
373
- it "should base64 URL decode the signed request" do
374
- sig = @signed_request.split(".")[0]
375
- @oauth.should_receive(:base64_url_decode).with(sig).and_return(nil)
376
- @oauth.parse_signed_request(@signed_request)
377
- end
378
-
379
- it "should get the sha64 encoded payload using proper arguments from OpenSSL::HMAC" do
380
- payload = ""
381
- @signed_request.should_receive(:split).with(".").and_return(["1", payload])
382
- OpenSSL::HMAC.should_receive(:digest).with("sha256", @request_secret, payload)
383
- @oauth.parse_signed_request(@signed_request)
377
+ describe "for signed params" do
378
+ it "should work" do
379
+ @oauth.parse_signed_request(@signed_request).should == @signed_request_result
380
+ end
384
381
  end
385
382
 
386
- it "should compare the encoded payload with the signature" do
387
- sig = "2"
388
- @oauth.should_receive(:base64_url_decode).and_return(sig)
389
- encoded_payload = "1"
390
- OpenSSL::HMAC.should_receive(:digest).with(anything, anything, anything).and_return(encoded_payload)
391
- encoded_payload.should_receive(:==).with(sig)
392
- @oauth.parse_signed_request(@signed_request)
393
- end
394
-
395
- describe "if the encoded payload matches the signature" do
396
- before :each do
397
- # set it up so the sig will match the encoded payload
398
- raw_sig = ""
399
- @sig = "2"
400
- @payload = "1"
401
- @signed_request.should_receive(:split).and_return([raw_sig, @payload])
402
- @oauth.should_receive(:base64_url_decode).with(raw_sig).and_return(@sig)
403
- OpenSSL::HMAC.should_receive(:digest).with(anything, anything, anything).and_return(@sig.dup)
383
+ describe "for signed requests" do
384
+ it "should work" do
385
+ @oauth = Koala::Facebook::OAuth.new(@app_id, @signed_params_secret || @app_secret)
386
+ @oauth.parse_signed_request(@signed_params).should == @signed_params_result
404
387
  end
405
388
 
406
- it "should base64_url_decode the payload" do
407
- @oauth.should_receive(:base64_url_decode).with(@payload).ordered.and_return("{}")
408
- @oauth.parse_signed_request(@signed_request)
389
+ it "should throw an error if the params are too old" do
390
+ @time.stub!(:to_i).and_return(1287601988 + 4000)
391
+ @oauth = Koala::Facebook::OAuth.new(@app_id, @signed_params_secret || @app_secret)
392
+
393
+ lambda { @oauth.parse_signed_request(@signed_params) }.should raise_error
409
394
  end
410
395
 
411
- it "should JSON decode the payload" do
412
- result = "{}"
413
- @oauth.should_receive(:base64_url_decode).with(@payload).and_return(result)
414
- JSON.should_receive(:parse).with(result)
415
- @oauth.parse_signed_request(@signed_request)
416
- end
417
- end
418
-
419
- describe "if the encoded payload does not match the signature" do
420
- before :each do
421
- sig = ""
422
- @signed_request.should_receive(:split).and_return([sig, ""])
423
- OpenSSL::HMAC.should_receive(:digest).with(anything, anything, anything).and_return("hi")
396
+ it "should let you specify the max age for a request" do
397
+ @time.stub!(:to_i).and_return(1287601988 + 4000)
398
+ @oauth = Koala::Facebook::OAuth.new(@app_id, @signed_params_secret || @app_secret)
399
+
400
+ lambda { @oauth.parse_signed_request(@signed_params, 4001) }.should_not raise_error
424
401
  end
425
402
 
426
- it "should return nil" do
427
- @oauth.parse_signed_request(@signed_request).should be_nil
428
- end
429
403
  end
430
404
 
431
- describe "run against data" do
432
- it "should work" do
433
- @oauth.parse_signed_request(@signed_request).should == @signed_request_result
434
- end
435
- end
436
405
  end
437
406
 
438
407
  end # describe
@@ -1,82 +1,12 @@
1
1
  shared_examples_for "Koala RestAPI without an access token" do
2
- # REST_CALL
3
- describe "when making a rest request" do
4
- it "should use the proper path" do
5
- method = stub('methodName')
6
- @api.should_receive(:api).with(
7
- "method/#{method}",
8
- anything,
9
- anything,
10
- anything
11
- )
12
-
13
- @api.rest_call(method)
14
- end
15
-
16
- it "should always use the rest api" do
17
- @api.should_receive(:api).with(
18
- anything,
19
- anything,
20
- anything,
21
- :rest_api => true
22
- )
23
-
24
- @api.rest_call('anything')
25
- end
26
-
27
- it "should take an optional hash of arguments" do
28
- args = {:arg1 => 'arg1'}
29
-
30
- @api.should_receive(:api).with(
31
- anything,
32
- hash_including(args),
33
- anything,
34
- anything
35
- )
36
-
37
- @api.rest_call('anything', args)
38
- end
39
-
40
- it "should always ask for JSON" do
41
- @api.should_receive(:api).with(
42
- anything,
43
- hash_including('format' => 'json'),
44
- anything,
45
- anything
46
- )
47
-
48
- @api.rest_call('anything')
49
- end
50
- end
51
-
52
2
  # FQL_QUERY
53
3
  describe "when making a FQL request" do
54
- it "should call fql.query method" do
55
- @api.should_receive(:rest_call).with(
56
- "fql.query",
57
- anything
58
- ).and_return(Koala::Response.new(200, "2", {}))
59
-
60
- @api.fql_query stub('query string')
61
- end
62
-
63
- it "should pass a query argument" do
64
- query = stub('query string')
65
-
66
- @api.should_receive(:rest_call).with(
67
- anything,
68
- hash_including("query" => query)
69
- )
70
-
71
- @api.fql_query(query)
72
- end
73
-
74
4
  it "should be able to access public information via FQL" do
75
5
  @result = @api.fql_query("select first_name from user where uid = 216743")
76
6
  @result.size.should == 1
77
7
  @result.first["first_name"].should == "Chris"
78
8
  end
79
-
9
+
80
10
  it "should not be able to access protected information via FQL" do
81
11
  lambda { @api.fql_query("select read_stream from permissions where uid = 216743") }.should raise_error(Koala::Facebook::APIError)
82
12
  end
@@ -84,11 +14,12 @@ shared_examples_for "Koala RestAPI without an access token" do
84
14
  end
85
15
 
86
16
  class FacebookRestAPINoAccessTokenTest < Test::Unit::TestCase
87
- before :each do
88
- @api = Koala::Facebook::RestAPI.new
89
- end
90
-
91
17
  describe "Koala RestAPI without an access token" do
92
- it_should_behave_like "Koala RestAPI without an access token"
18
+ before :each do
19
+ @api = Koala::Facebook::RestAPI.new
20
+ end
21
+
22
+ it_should_behave_like "Koala RestAPI"
23
+ it_should_behave_like "Koala RestAPI without an access token"
93
24
  end
94
25
  end
@@ -0,0 +1,118 @@
1
+ shared_examples_for "Koala RestAPI" do
2
+ # REST_CALL
3
+ describe "when making a rest request" do
4
+ it "should use the proper path" do
5
+ method = stub('methodName')
6
+ @api.should_receive(:api).with(
7
+ "method/#{method}",
8
+ anything,
9
+ anything,
10
+ anything
11
+ )
12
+
13
+ @api.rest_call(method)
14
+ end
15
+
16
+ it "should always use the rest api" do
17
+ @api.should_receive(:api).with(
18
+ anything,
19
+ anything,
20
+ anything,
21
+ hash_including(:rest_api => true)
22
+ )
23
+
24
+ @api.rest_call('anything')
25
+ end
26
+
27
+ it "should set the read_only option to true if the method is listed in the read-only list" do
28
+ method = Koala::Facebook::RestAPI::READ_ONLY_METHODS.first
29
+
30
+ @api.should_receive(:api).with(
31
+ anything,
32
+ anything,
33
+ anything,
34
+ hash_including(:read_only => true)
35
+ )
36
+
37
+ @api.rest_call(method)
38
+ end
39
+
40
+ it "should set the read_only option to false if the method is not inthe read-only list" do
41
+ method = "I'm not a read-only method"
42
+
43
+ @api.should_receive(:api).with(
44
+ anything,
45
+ anything,
46
+ anything,
47
+ hash_including(:read_only => false)
48
+ )
49
+
50
+ @api.rest_call(method)
51
+ end
52
+
53
+
54
+ it "should take an optional hash of arguments" do
55
+ args = {:arg1 => 'arg1'}
56
+
57
+ @api.should_receive(:api).with(
58
+ anything,
59
+ hash_including(args),
60
+ anything,
61
+ anything
62
+ )
63
+
64
+ @api.rest_call('anything', args)
65
+ end
66
+
67
+ it "should always ask for JSON" do
68
+ @api.should_receive(:api).with(
69
+ anything,
70
+ hash_including('format' => 'json'),
71
+ anything,
72
+ anything
73
+ )
74
+
75
+ @api.rest_call('anything')
76
+ end
77
+
78
+ it "should pass any options provided to the API" do
79
+ options = {:a => 2}
80
+
81
+ @api.should_receive(:api).with(
82
+ anything,
83
+ hash_including('format' => 'json'),
84
+ anything,
85
+ hash_including(options)
86
+ )
87
+
88
+ @api.rest_call('anything', {}, options)
89
+ end
90
+
91
+ it "should throw an APIError if the result hash has an error key" do
92
+ Koala.stub(:make_request).and_return(Koala::Response.new(500, {"error_code" => "An error occurred!"}, {}))
93
+ lambda { @api.rest_call("koppel", {}) }.should raise_exception(Koala::Facebook::APIError)
94
+ end
95
+
96
+ describe "when making a FQL request" do
97
+ it "should call fql.query method" do
98
+ @api.should_receive(:rest_call).with(
99
+ "fql.query",
100
+ anything
101
+ ).and_return(Koala::Response.new(200, "2", {}))
102
+
103
+ @api.fql_query stub('query string')
104
+ end
105
+
106
+ it "should pass a query argument" do
107
+ query = stub('query string')
108
+
109
+ @api.should_receive(:rest_call).with(
110
+ anything,
111
+ hash_including("query" => query)
112
+ )
113
+
114
+ @api.fql_query(query)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -8,7 +8,7 @@ shared_examples_for "Koala RestAPI with an access token" do
8
8
 
9
9
  it "should be able to access protected information via FQL" do
10
10
  # Tests agains the permissions fql table
11
-
11
+
12
12
  # get the current user's ID
13
13
  # we're sneakily using the Graph API, which should be okay since it has its own tests
14
14
  g = Koala::Facebook::GraphAPI.new(@token)
@@ -26,11 +26,13 @@ end
26
26
 
27
27
  class FacebookRestAPIWithAccessTokenTests < Test::Unit::TestCase
28
28
  describe "Koala RestAPI with an access token" do
29
- it_should_behave_like "live testing examples"
30
- it_should_behave_like "Koala RestAPI with an access token"
31
-
29
+ include LiveTestingDataHelper
30
+
32
31
  before :each do
33
32
  @api = Koala::Facebook::RestAPI.new(@token)
34
33
  end
34
+
35
+ it_should_behave_like "Koala RestAPI"
36
+ it_should_behave_like "Koala RestAPI with an access token"
35
37
  end
36
38
  end
@@ -0,0 +1,208 @@
1
+ class TestUsersTests < Test::Unit::TestCase
2
+ include Koala
3
+
4
+ describe "Koala TestUsers with access token" do
5
+ include LiveTestingDataHelper
6
+
7
+ before :all do
8
+ # get oauth data
9
+ @oauth_data = $testing_data["oauth_test_data"]
10
+ @app_id = @oauth_data["app_id"]
11
+ @secret = @oauth_data["secret"]
12
+ @app_access_token = @oauth_data["app_access_token"]
13
+
14
+ # check OAuth data
15
+ unless @app_id && @secret && @app_access_token
16
+ raise Exception, "Must supply OAuth app id, secret, app_access_token, and callback to run live subscription tests!"
17
+ end
18
+
19
+ @is_mock = defined?(Koala::IS_MOCK) && Koala::IS_MOCK
20
+ end
21
+
22
+ describe "when initializing" do
23
+ # basic initialization
24
+ it "should initialize properly with an app_id and an app_access_token" do
25
+ test_users = Facebook::TestUsers.new(:app_id => @app_id, :app_access_token => @app_access_token)
26
+ test_users.should be_a(Facebook::TestUsers)
27
+ end
28
+
29
+ # init with secret / fetching the token
30
+ it "should initialize properly with an app_id and a secret" do
31
+ test_users = Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
32
+ test_users.should be_a(Facebook::TestUsers)
33
+ end
34
+
35
+ it "should use the OAuth class to fetch a token when provided an app_id and a secret" do
36
+ oauth = Facebook::OAuth.new(@app_id, @secret)
37
+ token = oauth.get_app_access_token
38
+ oauth.should_receive(:get_app_access_token).and_return(token)
39
+ Facebook::OAuth.should_receive(:new).with(@app_id, @secret).and_return(oauth)
40
+ test_users = Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
41
+ end
42
+ end
43
+
44
+ describe "when used without network" do
45
+ before :each do
46
+ @test_users = Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
47
+ end
48
+
49
+ # TEST USER MANAGEMENT
50
+ it "should create a test user when not given installed" do
51
+ result = @test_users.create(false)
52
+ @temporary_object_id = result["id"]
53
+ result.should be_a(Hash)
54
+ (result["id"] && result["access_token"] && result["login_url"]).should
55
+ end
56
+
57
+ it "should create a test user when not given installed, ignoring permissions" do
58
+ result = @test_users.create(false, "read_stream")
59
+ @temporary_object_id = result["id"]
60
+ result.should be_a(Hash)
61
+ (result["id"] && result["access_token"] && result["login_url"]).should
62
+ end
63
+
64
+ it "should accept permissions as a string" do
65
+ @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything)
66
+ result = @test_users.create(true, "read_stream,publish_stream")
67
+ end
68
+
69
+ it "should accept permissions as an array" do
70
+ @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything)
71
+ result = @test_users.create(true, ["read_stream", "publish_stream"])
72
+ end
73
+
74
+ it "should create a test user when given installed and a permission" do
75
+ result = @test_users.create(true, "read_stream")
76
+ @temporary_object_id = result["id"]
77
+ result.should be_a(Hash)
78
+ (result["id"] && result["access_token"] && result["login_url"]).should
79
+ end
80
+
81
+ describe "with a user to delete" do
82
+ before :each do
83
+ @user1 = @test_users.create(true, "read_stream")
84
+ @user2 = @test_users.create(true, "read_stream,user_interests")
85
+ end
86
+
87
+ after :each do
88
+ print "\nCleaning up test users..."
89
+ @test_users.delete(@user1) if @user1
90
+ @test_users.delete(@user2) if @user2
91
+ puts "done."
92
+ end
93
+
94
+ it "should delete a user by id" do
95
+ @test_users.delete(@user1['id']).should be_true
96
+ @user1 = nil
97
+ end
98
+
99
+ it "should delete a user by hash" do
100
+ @test_users.delete(@user2).should be_true
101
+ @user2 = nil
102
+ end
103
+
104
+ it "should not delete users when provided a false ID" do
105
+ lambda { @test_users.delete("#{@user1['id']}1") }.should raise_exception(Koala::Facebook::APIError)
106
+ end
107
+ end
108
+
109
+ describe "with delete_all" do
110
+ it "should delete all users found by the list commnand" do
111
+ array = [1, 2, 3]
112
+ @test_users.should_receive(:list).and_return(array)
113
+ array.each {|i| @test_users.should_receive(:delete).with(i) }
114
+ @test_users.delete_all
115
+ end
116
+ end
117
+
118
+ describe "with existing users" do
119
+ before :each do
120
+ @user1 = @test_users.create(true, "read_stream")
121
+ @user2 = @test_users.create(true, "read_stream,user_interests")
122
+ end
123
+
124
+ after :each do
125
+ @test_users.delete(@user1)
126
+ @test_users.delete(@user2)
127
+ end
128
+
129
+ it "should list test users" do
130
+ result = @test_users.list
131
+ result.should be_an(Array)
132
+ first_user, second_user = result[0], result[1]
133
+ (first_user["id"] && first_user["access_token"] && first_user["login_url"]).should
134
+ (second_user["id"] && second_user["access_token"] && second_user["login_url"]).should
135
+ end
136
+
137
+ it "should make two users into friends by id" do
138
+ result = @test_users.befriend(@user1['id'], @user2['id'])
139
+ result.should be_true
140
+ end
141
+
142
+ it "should make two users into friends by hash" do
143
+ result = @test_users.befriend(@user1, @user2)
144
+ result.should be_true
145
+ end
146
+
147
+ end # with existing users
148
+
149
+ end # when used without network
150
+
151
+ describe "when creating a network of friends" do
152
+ before :each do
153
+ @test_users = Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
154
+ @network = []
155
+
156
+ if @is_mock
157
+ id_counter = 999999900
158
+ @test_users.stub!(:create).and_return do
159
+ id_counter += 1
160
+ {"id" => id_counter, "access_token" => "119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.", "login_url" => "https://www.facebook.com/platform/test_account.."}
161
+ end
162
+ @test_users.stub!(:befriend).and_return(true)
163
+ @test_users.stub!(:delete).and_return(true)
164
+ end
165
+ end
166
+
167
+ describe "tests that create users" do
168
+ before :each do
169
+ print "\nCleaning up test user network..."
170
+ test_users = Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
171
+ test_users.delete_all
172
+ puts "done!"
173
+ end
174
+
175
+ after :each do
176
+ print "\nCleaning up test user network..."
177
+ test_users = Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
178
+ test_users.delete_all
179
+ puts "done!"
180
+ end
181
+
182
+ it "should create a 5 person network" do
183
+ size = 5
184
+ @network = @test_users.create_network(size)
185
+ @network.should be_a(Array)
186
+ @network.size.should == size
187
+ end
188
+ end
189
+
190
+ it "should limit to a 50 person network" do
191
+ @test_users.should_receive(:create).exactly(50).times
192
+ @test_users.stub!(:befriend)
193
+ @network = @test_users.create_network(51)
194
+ end
195
+
196
+ it "should pass on the installed and permissions parameters to create" do
197
+ perms = ["read_stream", "offline_access"]
198
+ installed = false
199
+ count = 25
200
+ @test_users.should_receive(:create).exactly(count).times.with(installed, perms)
201
+ @test_users.stub!(:befriend)
202
+ @network = @test_users.create_network(count, installed, perms)
203
+ end
204
+
205
+ end # when creating network
206
+
207
+ end # describe Koala TestUsers
208
+ end # class