koala 0.9.0 → 0.10.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.
Files changed (37) hide show
  1. data/CHANGELOG +10 -0
  2. data/Manifest +2 -14
  3. data/Rakefile +2 -1
  4. data/koala.gemspec +7 -4
  5. data/lib/koala/test_users.rb +72 -0
  6. data/lib/koala.rb +15 -1
  7. data/readme.md +3 -2
  8. data/spec/facebook_data.yml +5 -5
  9. data/spec/koala/api_base_tests.rb +7 -0
  10. data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +1 -1
  11. data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +1 -1
  12. data/spec/koala/graph_api/graph_collection_tests.rb +2 -2
  13. data/spec/koala/live_testing_data_helper.rb +40 -12
  14. data/spec/koala/net_http_service_tests.rb +164 -159
  15. data/spec/koala/oauth/oauth_tests.rb +9 -11
  16. data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +5 -5
  17. data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +1 -1
  18. data/spec/koala/test_users/test_users_tests.rb +215 -0
  19. data/spec/koala_spec_helper.rb +21 -4
  20. data/spec/koala_spec_without_mocks.rb +1 -1
  21. data/spec/mock_facebook_responses.yml +49 -1
  22. data/spec/mock_http_service.rb +1 -0
  23. metadata +20 -19
  24. data/examples/oauth_playground/Capfile +0 -2
  25. data/examples/oauth_playground/LICENSE +0 -22
  26. data/examples/oauth_playground/Rakefile +0 -4
  27. data/examples/oauth_playground/config/deploy.rb +0 -39
  28. data/examples/oauth_playground/config/facebook.yml +0 -13
  29. data/examples/oauth_playground/config.ru +0 -27
  30. data/examples/oauth_playground/lib/load_facebook.rb +0 -3
  31. data/examples/oauth_playground/lib/oauth_playground.rb +0 -187
  32. data/examples/oauth_playground/readme.md +0 -8
  33. data/examples/oauth_playground/spec/oauth_playground_spec.rb +0 -35
  34. data/examples/oauth_playground/spec/spec_helper.rb +0 -36
  35. data/examples/oauth_playground/tmp/restart.txt +0 -0
  36. data/examples/oauth_playground/views/index.erb +0 -206
  37. data/examples/oauth_playground/views/layout.erb +0 -39
@@ -1,180 +1,185 @@
1
1
  require 'koala/http_services'
2
-
3
2
  class NetHTTPServiceTests < Test::Unit::TestCase
4
3
  module Bear
5
4
  include Koala::NetHTTPService
6
5
  end
7
-
8
- it "should define a make_request static module method" do
9
- Bear.respond_to?(:make_request).should be_true
10
- end
11
6
 
12
- describe "when making a request" do
13
- before(:each) do
14
- # Setup stubs for make_request to execute without exceptions
15
- @mock_http_response = stub('Net::HTTPResponse', :code => 1)
16
- @mock_body = stub('Net::HTTPResponse body')
17
- @http_request_result = [@mock_http_response, @mock_body]
18
-
19
- @http_yield_mock = mock('Net::HTTP start yielded object')
20
-
21
- @http_yield_mock.stub(:post).and_return(@http_request_result)
22
- @http_yield_mock.stub(:get).and_return(@http_request_result)
23
-
24
- @http_mock = stub('Net::HTTP object', 'use_ssl=' => true, 'verify_mode=' => true)
25
- @http_mock.stub(:start).and_yield(@http_yield_mock)
26
-
27
- Net::HTTP.stub(:new).and_return(@http_mock)
28
- end
29
-
30
- it "should use POST if verb is not GET" do
31
- @http_yield_mock.should_receive(:post).and_return(@mock_http_response)
32
- @http_mock.should_receive(:start).and_yield(@http_yield_mock)
33
-
34
- Bear.make_request('anything', {}, 'anything')
35
- end
36
-
37
- it "should use port 443" do
38
- Net::HTTP.should_receive(:new).with(anything, 443).and_return(@http_mock)
39
-
40
- Bear.make_request('anything', {}, 'anything')
41
- end
42
-
43
- it "should use SSL" do
44
- @http_mock.should_receive('use_ssl=').with(true)
45
-
46
- Bear.make_request('anything', {}, 'anything')
47
- end
48
-
49
- it "should use the graph server by default" do
50
- Net::HTTP.should_receive(:new).with(Koala::Facebook::GRAPH_SERVER, anything).and_return(@http_mock)
51
- Bear.make_request('anything', {}, 'anything')
52
- end
53
-
54
- it "should use the REST server if the :rest_api option is true" do
55
- Net::HTTP.should_receive(:new).with(Koala::Facebook::REST_SERVER, anything).and_return(@http_mock)
56
- Bear.make_request('anything', {}, 'anything', :rest_api => true)
57
- end
58
-
59
- it "should turn off vertificate validaiton warnings" do
60
- @http_mock.should_receive('verify_mode=').with(OpenSSL::SSL::VERIFY_NONE)
61
-
62
- Bear.make_request('anything', {}, 'anything')
63
- end
64
-
65
- it "should start an HTTP connection" do
66
- @http_mock.should_receive(:start).and_yield(@http_yield_mock)
67
- Bear.make_request('anything', {}, 'anything')
7
+ describe "NetHTTPService module holder class Bear" do
8
+ it "should define a make_request static module method" do
9
+ Bear.respond_to?(:make_request).should be_true
68
10
  end
69
-
70
- describe "via POST" do
71
- it "should use Net::HTTP to make a POST request" do
72
- @http_yield_mock.should_receive(:post).and_return(@http_request_result)
73
-
74
- Bear.make_request('anything', {}, 'post')
11
+
12
+ describe "when making a request" do
13
+ before(:each) do
14
+ # Setup stubs for make_request to execute without exceptions
15
+ @mock_http_response = stub('Net::HTTPResponse', :code => 1)
16
+ @mock_body = stub('Net::HTTPResponse body')
17
+ @http_request_result = [@mock_http_response, @mock_body]
18
+
19
+ # to_ary is called in Ruby 1.9 to provide backwards compatibility
20
+ # with the response, body = http.get() syntax we use
21
+ @mock_http_response.stub!(:to_ary).and_return(@http_request_result)
22
+
23
+ @http_yield_mock = mock('Net::HTTP start yielded object')
24
+
25
+ @http_yield_mock.stub(:post).and_return(@http_request_result)
26
+ @http_yield_mock.stub(:get).and_return(@http_request_result)
27
+
28
+ @http_mock = stub('Net::HTTP object', 'use_ssl=' => true, 'verify_mode=' => true)
29
+ @http_mock.stub(:start).and_yield(@http_yield_mock)
30
+
31
+ Net::HTTP.stub(:new).and_return(@http_mock)
75
32
  end
76
-
77
- it "should go to the specified path adding a / if it doesn't exist" do
78
- path = mock('Path')
79
- @http_yield_mock.should_receive(:post).with(path, anything).and_return(@http_request_result)
80
-
81
- Bear.make_request(path, {}, 'post')
33
+
34
+ it "should use POST if verb is not GET" do
35
+ @http_yield_mock.should_receive(:post).and_return(@mock_http_response)
36
+ @http_mock.should_receive(:start).and_yield(@http_yield_mock)
37
+
38
+ Bear.make_request('anything', {}, 'anything')
82
39
  end
83
-
84
- it "should use encoded parameters" do
85
- args = {}
86
- params = mock('Encoded parameters')
87
- Bear.should_receive(:encode_params).with(args).and_return(params)
88
-
89
- @http_yield_mock.should_receive(:post).with(anything, params).and_return(@http_request_result)
90
-
91
- Bear.make_request('anything', args, 'post')
40
+
41
+ it "should use port 443" do
42
+ Net::HTTP.should_receive(:new).with(anything, 443).and_return(@http_mock)
43
+
44
+ Bear.make_request('anything', {}, 'anything')
92
45
  end
93
- end
94
-
95
- describe "via GET" do
96
- it "should use Net::HTTP to make a GET request" do
97
- @http_yield_mock.should_receive(:get).and_return(@http_request_result)
98
-
99
- Bear.make_request('anything', {}, 'get')
46
+
47
+ it "should use SSL" do
48
+ @http_mock.should_receive('use_ssl=').with(true)
49
+
50
+ Bear.make_request('anything', {}, 'anything')
100
51
  end
101
-
102
- it "should use the correct path, including arguments" do
103
- path = mock('Path')
104
- params = mock('Encoded parameters')
105
- args = {}
106
-
107
- Bear.should_receive(:encode_params).with(args).and_return(params)
108
- @http_yield_mock.should_receive(:get).with("#{path}?#{params}").and_return(@http_request_result)
109
-
110
- Bear.make_request(path, args, 'get')
52
+
53
+ it "should use the graph server by default" do
54
+ Net::HTTP.should_receive(:new).with(Koala::Facebook::GRAPH_SERVER, anything).and_return(@http_mock)
55
+ Bear.make_request('anything', {}, 'anything')
111
56
  end
112
- end
113
-
114
- describe "the returned value" do
115
- before(:each) do
116
- @response = Bear.make_request('anything', {}, 'anything')
57
+
58
+ it "should use the REST server if the :rest_api option is true" do
59
+ Net::HTTP.should_receive(:new).with(Koala::Facebook::REST_SERVER, anything).and_return(@http_mock)
60
+ Bear.make_request('anything', {}, 'anything', :rest_api => true)
61
+ end
62
+
63
+ it "should turn off vertificate validaiton warnings" do
64
+ @http_mock.should_receive('verify_mode=').with(OpenSSL::SSL::VERIFY_NONE)
65
+
66
+ Bear.make_request('anything', {}, 'anything')
67
+ end
68
+
69
+ it "should start an HTTP connection" do
70
+ @http_mock.should_receive(:start).and_yield(@http_yield_mock)
71
+ Bear.make_request('anything', {}, 'anything')
117
72
  end
118
-
119
- it "should return a Koala::Response object" do
120
- @response.class.should == Koala::Response
73
+
74
+ describe "via POST" do
75
+ it "should use Net::HTTP to make a POST request" do
76
+ @http_yield_mock.should_receive(:post).and_return(@http_request_result)
77
+
78
+ Bear.make_request('anything', {}, 'post')
79
+ end
80
+
81
+ it "should go to the specified path adding a / if it doesn't exist" do
82
+ path = mock('Path')
83
+ @http_yield_mock.should_receive(:post).with(path, anything).and_return(@http_request_result)
84
+
85
+ Bear.make_request(path, {}, 'post')
86
+ end
87
+
88
+ it "should use encoded parameters" do
89
+ args = {}
90
+ params = mock('Encoded parameters')
91
+ Bear.should_receive(:encode_params).with(args).and_return(params)
92
+
93
+ @http_yield_mock.should_receive(:post).with(anything, params).and_return(@http_request_result)
94
+
95
+ Bear.make_request('anything', args, 'post')
96
+ end
121
97
  end
122
-
123
- it "should return a Koala::Response with the right status" do
124
- @response.status.should == @mock_http_response.code
98
+
99
+ describe "via GET" do
100
+ it "should use Net::HTTP to make a GET request" do
101
+ @http_yield_mock.should_receive(:get).and_return(@http_request_result)
102
+
103
+ Bear.make_request('anything', {}, 'get')
104
+ end
105
+
106
+ it "should use the correct path, including arguments" do
107
+ path = mock('Path')
108
+ params = mock('Encoded parameters')
109
+ args = {}
110
+
111
+ Bear.should_receive(:encode_params).with(args).and_return(params)
112
+ @http_yield_mock.should_receive(:get).with("#{path}?#{params}").and_return(@http_request_result)
113
+
114
+ Bear.make_request(path, args, 'get')
115
+ end
125
116
  end
126
-
127
- it "should reutrn a Koala::Response with the right body" do
128
- @response.body.should == @mock_body
117
+
118
+ describe "the returned value" do
119
+ before(:each) do
120
+ @response = Bear.make_request('anything', {}, 'anything')
121
+ end
122
+
123
+ it "should return a Koala::Response object" do
124
+ @response.class.should == Koala::Response
125
+ end
126
+
127
+ it "should return a Koala::Response with the right status" do
128
+ @response.status.should == @mock_http_response.code
129
+ end
130
+
131
+ it "should reutrn a Koala::Response with the right body" do
132
+ @response.body.should == @mock_body
133
+ end
134
+
135
+ it "should return a Koala::Response with the Net::HTTPResponse object as headers" do
136
+ @response.headers.should == @mock_http_response
137
+ end
138
+ end # describe return value
139
+ end # describe when making a request
140
+
141
+ describe "when encoding parameters" do
142
+ it "should return an empty string if param_hash evaluates to false" do
143
+ Bear.encode_params(nil).should == ''
129
144
  end
130
-
131
- it "should return a Koala::Response with the Net::HTTPResponse object as headers" do
132
- @response.headers.should == @mock_http_response
145
+
146
+ it "should convert values to JSON if the value is not a String" do
147
+ val = 'json_value'
148
+ not_a_string = 'not_a_string'
149
+ not_a_string.stub(:class).and_return('NotAString')
150
+ not_a_string.should_receive(:to_json).and_return(val)
151
+
152
+ string = "hi"
153
+
154
+ args = {
155
+ not_a_string => not_a_string,
156
+ string => string
157
+ }
158
+
159
+ result = Bear.encode_params(args)
160
+ result.split('&').find do |key_and_val|
161
+ key_and_val.match("#{not_a_string}=#{val}")
162
+ end.should be_true
133
163
  end
134
- end # describe return value
135
- end # describe when making a request
136
-
137
- describe "when encoding parameters" do
138
- it "should return an empty string if param_hash evaluates to false" do
139
- Bear.encode_params(nil).should == ''
140
- end
141
-
142
- it "should convert values to JSON if the value is not a String" do
143
- val = 'json_value'
144
- not_a_string = 'not_a_string'
145
- not_a_string.stub(:class).and_return('NotAString')
146
- not_a_string.should_receive(:to_json).and_return(val)
147
-
148
- string = "hi"
149
-
150
- args = {
151
- not_a_string => not_a_string,
152
- string => string
153
- }
154
-
155
- result = Bear.encode_params(args)
156
- result.split('&').find do |key_and_val|
157
- key_and_val.match("#{not_a_string}=#{val}")
158
- end.should be_true
159
- end
160
-
161
- it "should escape all values" do
162
- args = Hash[*(1..4).map {|i| [i.to_s, "Value #{i}($"]}.flatten]
163
-
164
- result = Bear.encode_params(args)
165
- result.split('&').each do |key_val|
166
- key, val = key_val.split('=')
167
- val.should == CGI.escape(args[key])
164
+
165
+ it "should escape all values" do
166
+ args = Hash[*(1..4).map {|i| [i.to_s, "Value #{i}($"]}.flatten]
167
+
168
+ result = Bear.encode_params(args)
169
+ result.split('&').each do |key_val|
170
+ key, val = key_val.split('=')
171
+ val.should == CGI.escape(args[key])
172
+ end
168
173
  end
169
- end
170
-
171
- it "should convert all keys to Strings" do
172
- args = Hash[*(1..4).map {|i| [i, "val#{i}"]}.flatten]
173
-
174
- result = Bear.encode_params(args)
175
- result.split('&').each do |key_val|
176
- key, val = key_val.split('=')
177
- key.should == args.find{|key_val_arr| key_val_arr.last == val}.first.to_s
174
+
175
+ it "should convert all keys to Strings" do
176
+ args = Hash[*(1..4).map {|i| [i, "val#{i}"]}.flatten]
177
+
178
+ result = Bear.encode_params(args)
179
+ result.split('&').each do |key_val|
180
+ key, val = key_val.split('=')
181
+ key.should == args.find{|key_val_arr| key_val_arr.last == val}.first.to_s
182
+ end
178
183
  end
179
184
  end
180
185
  end
@@ -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
@@ -34,6 +23,10 @@ class FacebookOAuthTests < Test::Unit::TestCase
34
23
  @raw_offline_access_token_string
35
24
 
36
25
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret, @callback_url)
26
+
27
+ time = Time.now
28
+ Time.stub!(:now).and_return(time)
29
+ time.stub!(:to_i).and_return(1273363199)
37
30
  end
38
31
 
39
32
  # initialization
@@ -298,6 +291,11 @@ class FacebookOAuthTests < Test::Unit::TestCase
298
291
  # it should return nil for each of the invalid ones
299
292
  result.each_with_index {|r, index| index > 0 ? r.should(be_a(Hash)) : r.should(be_nil)}
300
293
  end
294
+
295
+ it "should throw an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
296
+ @oauth.should_receive(:fetch_token_string).and_return("")
297
+ lambda { @oauth.get_token_info_from_session_keys(@oauth_data["multiple_session_keys"]) }.should raise_error(Koala::Facebook::APIError)
298
+ end
301
299
  end
302
300
 
303
301
  describe "with get_tokens_from_session_keys" do
@@ -83,12 +83,12 @@ shared_examples_for "Koala RestAPI without an access token" do
83
83
  end
84
84
  end
85
85
 
86
- class FacebookRestAPINoAccessTokenTest < Test::Unit::TestCase
87
- before :each do
88
- @api = Koala::Facebook::RestAPI.new
89
- end
90
-
86
+ class FacebookRestAPINoAccessTokenTest < Test::Unit::TestCase
91
87
  describe "Koala RestAPI without an access token" do
88
+ before :each do
89
+ @api = Koala::Facebook::RestAPI.new
90
+ end
91
+
92
92
  it_should_behave_like "Koala RestAPI without an access token"
93
93
  end
94
94
  end
@@ -26,7 +26,7 @@ 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"
29
+ include LiveTestingDataHelper
30
30
  it_should_behave_like "Koala RestAPI with an access token"
31
31
 
32
32
  before :each do
@@ -0,0 +1,215 @@
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 2 person network" do
183
+ @network = @test_users.create_network(2)
184
+ @network.should be_a(Array)
185
+ @network.size.should == 2
186
+ end
187
+
188
+ it "should create a 50 person network" do
189
+ puts "\nStarting 50-person network test (this may take several minutes)..."
190
+ @network = @test_users.create_network(50)
191
+ @network.should be_a(Array)
192
+ @network.size.should == 50
193
+ puts "done!"
194
+ end
195
+ end
196
+
197
+ it "should limit to a 50 person network" do
198
+ @test_users.should_receive(:create).exactly(50).times
199
+ @test_users.stub!(:befriend)
200
+ @network = @test_users.create_network(51)
201
+ end
202
+
203
+ it "should pass on the installed and permissions parameters to create" do
204
+ perms = ["read_stream", "offline_access"]
205
+ installed = false
206
+ count = 25
207
+ @test_users.should_receive(:create).exactly(count).times.with(installed, perms)
208
+ @test_users.stub!(:befriend)
209
+ @network = @test_users.create_network(count, installed, perms)
210
+ end
211
+
212
+ end # when creating network
213
+
214
+ end # describe Koala TestUsers
215
+ end # class
@@ -1,6 +1,18 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'spec/test/unit'
1
+ if defined?(RUBY_VERSION) && RUBY_VERSION =~ /1\.9/
2
+ require 'test/unit'
3
+ require 'rspec'
4
+
5
+ Rspec.configure do |c|
6
+ c.mock_with :rspec
7
+ end
8
+
9
+ else
10
+ # Ruby 1.8.x
11
+ require 'test/unit'
12
+ require 'rubygems'
13
+
14
+ require 'spec/test/unit'
15
+ end
4
16
 
5
17
  # load the libraries
6
18
  require 'koala'
@@ -28,4 +40,9 @@ require 'koala/oauth/oauth_tests'
28
40
  require 'koala/realtime_updates/realtime_updates_tests'
29
41
 
30
42
  # Services tests
31
- require 'koala/net_http_service_tests'
43
+ require 'koala/net_http_service_tests'
44
+
45
+ # Test users tests
46
+ require 'koala/test_users/test_users_tests'
47
+
48
+
@@ -15,5 +15,5 @@ unless $testing_data["oauth_token"]
15
15
  end
16
16
 
17
17
  unless $testing_data["oauth_test_data"] && $testing_data["oauth_test_data"]["code"] && $testing_data["oauth_test_data"]["secret"]
18
- puts "Cookie tests will fail until you store valid data for the cookie hash, app_id, and app secret in facebook_data.yml"
18
+ puts "OAuth code tests will fail until you store valid data for the user's OAuth code and the app secret in facebook_data.yml"
19
19
  end