koala 1.2.1 → 1.3.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 (55) hide show
  1. data/.gitignore +3 -1
  2. data/.rspec +1 -0
  3. data/.travis.yml +4 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +28 -0
  6. data/Gemfile +14 -0
  7. data/Guardfile +6 -0
  8. data/koala.gemspec +3 -3
  9. data/lib/koala/api/batch_operation.rb +83 -0
  10. data/lib/koala/api/graph_api.rb +476 -0
  11. data/lib/koala/{graph_batch_api.rb → api/graph_batch_api.rb} +22 -17
  12. data/lib/koala/api/graph_collection.rb +107 -0
  13. data/lib/koala/api/legacy.rb +26 -0
  14. data/lib/koala/{rest_api.rb → api/rest_api.rb} +34 -13
  15. data/lib/koala/api.rb +93 -0
  16. data/lib/koala/http_service/multipart_request.rb +41 -0
  17. data/lib/koala/http_service/response.rb +18 -0
  18. data/lib/koala/http_service/uploadable_io.rb +187 -0
  19. data/lib/koala/http_service.rb +69 -20
  20. data/lib/koala/oauth.rb +170 -36
  21. data/lib/koala/realtime_updates.rb +89 -51
  22. data/lib/koala/test_users.rb +122 -32
  23. data/lib/koala/utils.rb +11 -4
  24. data/lib/koala/version.rb +1 -1
  25. data/lib/koala.rb +16 -96
  26. data/readme.md +9 -9
  27. data/spec/cases/api_spec.rb +19 -12
  28. data/spec/cases/error_spec.rb +10 -0
  29. data/spec/cases/graph_api_batch_spec.rb +100 -58
  30. data/spec/cases/graph_collection_spec.rb +23 -7
  31. data/spec/cases/http_service_spec.rb +5 -26
  32. data/spec/cases/koala_spec.rb +22 -4
  33. data/spec/cases/legacy_spec.rb +115 -0
  34. data/spec/cases/multipart_request_spec.rb +7 -7
  35. data/spec/cases/oauth_spec.rb +134 -48
  36. data/spec/cases/realtime_updates_spec.rb +154 -47
  37. data/spec/cases/test_users_spec.rb +276 -219
  38. data/spec/cases/uploadable_io_spec.rb +1 -1
  39. data/spec/cases/utils_spec.rb +29 -5
  40. data/spec/fixtures/mock_facebook_responses.yml +41 -30
  41. data/spec/spec_helper.rb +3 -0
  42. data/spec/support/custom_matchers.rb +28 -0
  43. data/spec/support/graph_api_shared_examples.rb +192 -14
  44. data/spec/support/koala_test.rb +10 -1
  45. data/spec/support/mock_http_service.rb +2 -2
  46. data/spec/support/rest_api_shared_examples.rb +5 -165
  47. metadata +75 -99
  48. data/lib/koala/batch_operation.rb +0 -74
  49. data/lib/koala/graph_api.rb +0 -270
  50. data/lib/koala/graph_collection.rb +0 -59
  51. data/lib/koala/multipart_request.rb +0 -35
  52. data/lib/koala/uploadable_io.rb +0 -181
  53. data/spec/cases/graph_and_rest_api_spec.rb +0 -22
  54. data/spec/cases/graph_api_spec.rb +0 -22
  55. data/spec/cases/rest_api_spec.rb +0 -22
@@ -1,271 +1,328 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Koala::Facebook::TestUsers" do
4
- context "with access token" do
5
- before :all do
6
- # get oauth data
7
- @app_id = KoalaTest.app_id
8
- @secret = KoalaTest.secret
9
- @app_access_token = KoalaTest.app_access_token
10
-
11
- # check OAuth data
12
- unless @app_id && @secret && @app_access_token
13
- raise Exception, "Must supply OAuth app id, secret, app_access_token, and callback to run live subscription tests!"
14
- end
4
+ before :all do
5
+ # get oauth data
6
+ @app_id = KoalaTest.app_id
7
+ @secret = KoalaTest.secret
8
+ @app_access_token = KoalaTest.app_access_token
9
+
10
+ @test_users = Koala::Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
11
+
12
+ # check OAuth data
13
+ unless @app_id && @secret && @app_access_token
14
+ raise Exception, "Must supply OAuth app id, secret, app_access_token, and callback to run live subscription tests!"
15
15
  end
16
-
17
- after :each do
18
- # clean up any test users
19
- ((@network || []) + [@user1, @user2]).each do |u|
20
- puts "Unable to delete test user #{u.inspect}" if u && !(@test_users.delete(u) rescue false)
21
- end
16
+ end
17
+
18
+ after :each do
19
+ # clean up any test users
20
+ ((@network || []) + [@user1, @user2]).each do |u|
21
+ puts "Unable to delete test user #{u.inspect}" if u && !(@test_users.delete(u) rescue false)
22
22
  end
23
+ end
23
24
 
24
- describe "when initializing" do
25
- # basic initialization
26
- it "should initialize properly with an app_id and an app_access_token" do
27
- test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :app_access_token => @app_access_token)
28
- test_users.should be_a(Koala::Facebook::TestUsers)
29
- end
25
+ describe "when initializing" do
26
+ # basic initialization
27
+ it "initializes properly with an app_id and an app_access_token" do
28
+ test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :app_access_token => @app_access_token)
29
+ test_users.should be_a(Koala::Facebook::TestUsers)
30
+ end
30
31
 
31
- # init with secret / fetching the token
32
- it "should initialize properly with an app_id and a secret" do
33
- test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
34
- test_users.should be_a(Koala::Facebook::TestUsers)
35
- end
32
+ # init with secret / fetching the token
33
+ it "initializes properly with an app_id and a secret" do
34
+ test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
35
+ test_users.should be_a(Koala::Facebook::TestUsers)
36
+ end
37
+
38
+ it "uses the OAuth class to fetch a token when provided an app_id and a secret" do
39
+ oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
40
+ token = oauth.get_app_access_token
41
+ oauth.should_receive(:get_app_access_token).and_return(token)
42
+ Koala::Facebook::OAuth.should_receive(:new).with(@app_id, @secret).and_return(oauth)
43
+ test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
44
+ end
45
+
46
+ # attributes
47
+ it "allows read access to app_id, app_access_token, and secret" do
48
+ # in Ruby 1.9, .method returns symbols
49
+ Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should include(:app_id)
50
+ Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should_not include(:app_id=)
51
+ end
52
+
53
+ it "allows read access to app_access_token" do
54
+ # in Ruby 1.9, .method returns symbols
55
+ Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should include(:app_access_token)
56
+ Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should_not include(:app_access_token=)
57
+ end
58
+
59
+ it "allows read access to secret" do
60
+ # in Ruby 1.9, .method returns symbols
61
+ Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should include(:secret)
62
+ Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should_not include(:secret=)
63
+ end
64
+
65
+ it "allows read access to api" do
66
+ # in Ruby 1.9, .method returns symbols
67
+ Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should include(:api)
68
+ Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should_not include(:api=)
69
+ end
70
+
71
+ # old graph_api accessor
72
+ it "returns the api object when graph_api is called" do
73
+ test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
74
+ test_users.graph_api.should == test_users.api
75
+ end
36
76
 
37
- it "should use the OAuth class to fetch a token when provided an app_id and a secret" do
38
- oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
39
- token = oauth.get_app_access_token
40
- oauth.should_receive(:get_app_access_token).and_return(token)
41
- Koala::Facebook::OAuth.should_receive(:new).with(@app_id, @secret).and_return(oauth)
42
- test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
77
+ it "fire a deprecation warning when graph_api is called" do
78
+ test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
79
+ Koala::Utils.should_receive(:deprecate)
80
+ test_users.graph_api
81
+ end
82
+ end
83
+
84
+ describe "when used without network" do
85
+ # TEST USER MANAGEMENT
86
+
87
+ describe "#create" do
88
+ it "creates a test user when not given installed" do
89
+ result = @test_users.create(false)
90
+ @user1 = result["id"]
91
+ result.should be_a(Hash)
92
+ (result["id"] && result["access_token"] && result["login_url"]).should
43
93
  end
44
94
 
45
- # attributes
46
- it "should allow read access to app_id, app_access_token, and secret" do
47
- # in Ruby 1.9, .method returns symbols
48
- Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should include(:app_id)
49
- Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should_not include(:app_id=)
95
+ it "creates a test user when not given installed, ignoring permissions" do
96
+ result = @test_users.create(false, "read_stream")
97
+ @user1 = result["id"]
98
+ result.should be_a(Hash)
99
+ (result["id"] && result["access_token"] && result["login_url"]).should
50
100
  end
51
101
 
52
- it "should allow read access to app_access_token" do
53
- # in Ruby 1.9, .method returns symbols
54
- Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should include(:app_access_token)
55
- Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should_not include(:app_access_token=)
102
+ it "accepts permissions as a string" do
103
+ @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything, anything)
104
+ result = @test_users.create(true, "read_stream,publish_stream")
56
105
  end
57
106
 
58
- it "should allow read access to secret" do
59
- # in Ruby 1.9, .method returns symbols
60
- Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should include(:secret)
61
- Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should_not include(:secret=)
107
+ it "accepts permissions as an array" do
108
+ @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything, anything)
109
+ result = @test_users.create(true, ["read_stream", "publish_stream"])
62
110
  end
63
111
 
64
- it "should allow read access to api" do
65
- # in Ruby 1.9, .method returns symbols
66
- Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should include(:api)
67
- Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).should_not include(:api=)
112
+ it "creates a test user when given installed and a permission" do
113
+ result = @test_users.create(true, "read_stream")
114
+ @user1 = result["id"]
115
+ result.should be_a(Hash)
116
+ (result["id"] && result["access_token"] && result["login_url"]).should
68
117
  end
69
118
 
70
- # old graph_api accessor
71
- it "returns the api object when graph_api is called" do
72
- test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
73
- test_users.graph_api.should == test_users.api
119
+ it "lets you specify other graph arguments, like uid and access token" do
120
+ args = {:uid => "some test user ID", :owner_access_token => "some owner access token"}
121
+ @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including(args), anything, anything)
122
+ @test_users.create(true, nil, args)
74
123
  end
75
124
 
76
- it "fire a deprecation warning when graph_api is called" do
77
- test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
78
- Koala::Utils.should_receive(:deprecate)
79
- test_users.graph_api
125
+ it "lets you specify http options that get passed through to the graph call" do
126
+ options = {:some_http_option => true}
127
+ @test_users.graph_api.should_receive(:graph_call).with(anything, anything, anything, options)
128
+ @test_users.create(true, nil, {}, options)
80
129
  end
81
130
  end
82
-
83
- describe "when used without network" do
131
+
132
+ describe "#list" do
84
133
  before :each do
85
- @test_users = Koala::Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
134
+ @user1 = @test_users.create(true, "read_stream")
135
+ @user2 = @test_users.create(true, "read_stream,user_interests")
86
136
  end
87
137
 
88
- # TEST USER MANAGEMENT
89
-
90
- describe ".create" do
91
- it "should create a test user when not given installed" do
92
- result = @test_users.create(false)
93
- @user1 = result["id"]
94
- result.should be_a(Hash)
95
- (result["id"] && result["access_token"] && result["login_url"]).should
96
- end
97
-
98
- it "should create a test user when not given installed, ignoring permissions" do
99
- result = @test_users.create(false, "read_stream")
100
- @user1 = result["id"]
101
- result.should be_a(Hash)
102
- (result["id"] && result["access_token"] && result["login_url"]).should
103
- end
104
-
105
- it "should accept permissions as a string" do
106
- @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything, anything)
107
- result = @test_users.create(true, "read_stream,publish_stream")
108
- end
109
-
110
- it "should accept permissions as an array" do
111
- @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything, anything)
112
- result = @test_users.create(true, ["read_stream", "publish_stream"])
113
- end
114
-
115
- it "should create a test user when given installed and a permission" do
116
- result = @test_users.create(true, "read_stream")
117
- @user1 = result["id"]
118
- result.should be_a(Hash)
119
- (result["id"] && result["access_token"] && result["login_url"]).should
120
- end
121
-
122
- it "lets you specify other graph arguments, like uid and access token" do
123
- args = {:uid => "some test user ID", :owner_access_token => "some owner access token"}
124
- @test_users.graph_api.should_receive(:graph_call).with(anything, hash_including(args), anything, anything)
125
- @test_users.create(true, nil, args)
126
- end
127
-
128
- it "lets you specify http options that get passed through to the graph call" do
129
- options = {:some_http_option => true}
130
- @test_users.graph_api.should_receive(:graph_call).with(anything, anything, anything, options)
131
- @test_users.create(true, nil, {}, options)
132
- end
138
+ it "lists test users" do
139
+ result = @test_users.list
140
+ result.should be_an(Array)
141
+ first_user, second_user = result[0], result[1]
142
+ (first_user["id"] && first_user["access_token"] && first_user["login_url"]).should
143
+ (second_user["id"] && second_user["access_token"] && second_user["login_url"]).should
133
144
  end
145
+
146
+ it "accepts http options" do
147
+ options = {:some_http_option => true}
148
+ @test_users.api.should_receive(:graph_call).with(anything, anything, anything, options)
149
+ @test_users.list(options)
150
+ end
151
+ end
134
152
 
135
- describe ".delete" do
136
- before :each do
137
- @user1 = @test_users.create(true, "read_stream")
138
- @user2 = @test_users.create(true, "read_stream,user_interests")
139
- end
140
-
141
- it "should delete a user by id" do
142
- @test_users.delete(@user1['id']).should be_true
143
- @user1 = nil
144
- end
145
-
146
- it "should delete a user by hash" do
147
- @test_users.delete(@user2).should be_true
148
- @user2 = nil
149
- end
153
+ describe "#delete" do
154
+ before :each do
155
+ @user1 = @test_users.create(true, "read_stream")
156
+ @user2 = @test_users.create(true, "read_stream,user_interests")
157
+ end
150
158
 
151
- it "should not delete users when provided a false ID" do
152
- lambda { @test_users.delete("#{@user1['id']}1") }.should raise_exception(Koala::Facebook::APIError)
153
- end
159
+ it "deletes a user by id" do
160
+ @test_users.delete(@user1['id']).should be_true
161
+ @user1 = nil
154
162
  end
155
163
 
156
- describe ".delete_all" do
157
- it "should delete all users found by the list commnand" do
158
- array = [1, 2, 3]
159
- @test_users.should_receive(:list).and_return(array)
160
- array.each {|i| @test_users.should_receive(:delete).with(i) }
161
- @test_users.delete_all
162
- end
164
+ it "deletes a user by hash" do
165
+ @test_users.delete(@user2).should be_true
166
+ @user2 = nil
163
167
  end
164
168
 
165
- describe ".update" do
166
- before :each do
167
- @updates = {:name => "Foo Baz"}
168
- # we stub out :graph_call, but still need to be able to delete the users
169
- @test_users2 = Koala::Facebook::TestUsers.new(:app_id => @test_users.app_id, :app_access_token => @test_users.app_access_token)
170
- end
169
+ it "does not delete users when provided a false ID" do
170
+ lambda { @test_users.delete("#{@user1['id']}1") }.should raise_exception(Koala::Facebook::APIError)
171
+ end
172
+
173
+ it "lets you specify http options that get passed through to the graph call" do
174
+ options = {:some_http_option => true}
175
+ # technically this goes through delete_object, but this makes it less brittle
176
+ @test_users.graph_api.should_receive(:graph_call).with(anything, anything, anything, options)
177
+ @test_users.delete("user", options)
178
+ end
179
+ end
171
180
 
172
- it "makes a POST with the test user Graph API " do
173
- @user1 = @test_users2.create(true)
174
- @test_users2.graph_api.should_receive(:graph_call).with(anything, anything, "post", anything)
175
- @test_users2.update(@user1, @updates)
176
- end
181
+ describe "#delete_all" do
182
+ it "deletes the batch API to deleten all users found by the list commnand" do
183
+ array = 200.times.collect { {"id" => rand}}
184
+ @test_users.should_receive(:list).and_return(array, [])
185
+ batch_api = stub("batch API")
186
+ @test_users.api.should_receive(:batch).and_yield(batch_api).any_number_of_times
187
+ array.each {|item| batch_api.should_receive(:delete_object).with(item["id"]) }
188
+ @test_users.delete_all
189
+ end
190
+
191
+ it "accepts http options that get passed to both list and the batch call" do
192
+ options = {:some_http_option => true}
193
+ @test_users.should_receive(:list).with(options).and_return([{"id" => rand}], [])
194
+ @test_users.api.should_receive(:batch).with(options)
195
+ @test_users.delete_all(options)
196
+ end
197
+
198
+ it "breaks if Facebook sends back the same list twice" do
199
+ list = [{"id" => rand}]
200
+ @test_users.should_receive(:list).any_number_of_times.and_return(list)
201
+ @test_users.api.should_receive(:batch).once
202
+ @test_users.delete_all
203
+ end
204
+ end
177
205
 
178
- it "makes a request to the test user with the update params " do
179
- @user1 = @test_users2.create(true)
180
- @test_users2.graph_api.should_receive(:graph_call).with(@user1["id"], @updates, anything, anything)
181
- @test_users2.update(@user1, @updates)
182
- end
206
+ describe "#update" do
207
+ before :each do
208
+ @updates = {:name => "Foo Baz"}
209
+ # we stub out :graph_call, but still need to be able to delete the users
210
+ @test_users2 = Koala::Facebook::TestUsers.new(:app_id => @test_users.app_id, :app_access_token => @test_users.app_access_token)
211
+ end
183
212
 
184
- it "works" do
185
- @user1 = @test_users.create(true)
186
- @test_users.update(@user1, @updates)
187
- user_info = Koala::Facebook::API.new(@user1["access_token"]).get_object(@user1["id"])
188
- user_info["name"].should == @updates[:name]
189
- end
213
+ it "makes a POST with the test user Graph API " do
214
+ @user1 = @test_users2.create(true)
215
+ @test_users2.graph_api.should_receive(:graph_call).with(anything, anything, "post", anything)
216
+ @test_users2.update(@user1, @updates)
190
217
  end
191
218
 
192
- describe "with existing users" do
193
- before :each do
194
- @user1 = @test_users.create(true, "read_stream")
195
- @user2 = @test_users.create(true, "read_stream,user_interests")
196
- end
219
+ it "makes a request to the test user with the update params " do
220
+ @user1 = @test_users2.create(true)
221
+ @test_users2.graph_api.should_receive(:graph_call).with(@user1["id"], @updates, anything, anything)
222
+ @test_users2.update(@user1, @updates)
223
+ end
224
+
225
+ it "accepts an options hash" do
226
+ options = {:some_http_option => true}
227
+ @test_users2.graph_api.should_receive(:graph_call).with(anything, anything, anything, options)
228
+ @test_users2.update("foo", @updates, options)
229
+ end
197
230
 
198
- it "should list test users" do
199
- result = @test_users.list
200
- result.should be_an(Array)
201
- first_user, second_user = result[0], result[1]
202
- (first_user["id"] && first_user["access_token"] && first_user["login_url"]).should
203
- (second_user["id"] && second_user["access_token"] && second_user["login_url"]).should
204
- end
231
+ it "works" do
232
+ @user1 = @test_users.create(true)
233
+ @test_users.update(@user1, @updates)
234
+ user_info = Koala::Facebook::API.new(@user1["access_token"]).get_object(@user1["id"])
235
+ user_info["name"].should == @updates[:name]
236
+ end
237
+ end
238
+
239
+ describe "#befriend" do
240
+ before :each do
241
+ @user1 = @test_users.create(true, "read_stream")
242
+ @user2 = @test_users.create(true, "read_stream,user_interests")
243
+ end
244
+
245
+ it "makes two users into friends with string hashes" do
246
+ result = @test_users.befriend(@user1, @user2)
247
+ result.should be_true
248
+ end
205
249
 
206
- it "should make two users into friends with string hashes" do
207
- result = @test_users.befriend(@user1, @user2)
208
- result.should be_true
209
- end
250
+ it "makes two users into friends with symbol hashes" do
251
+ new_user_1 = {}
252
+ @user1.each_pair {|k, v| new_user_1[k.to_sym] = v}
253
+ new_user_2 = {}
254
+ @user2.each_pair {|k, v| new_user_2[k.to_sym] = v}
210
255
 
211
- it "should make two users into friends with symbol hashes" do
212
- new_user_1 = {}
213
- @user1.each_pair {|k, v| new_user_1[k.to_sym] = v}
214
- new_user_2 = {}
215
- @user2.each_pair {|k, v| new_user_2[k.to_sym] = v}
256
+ result = @test_users.befriend(new_user_1, new_user_2)
257
+ result.should be_true
258
+ end
216
259
 
217
- result = @test_users.befriend(new_user_1, new_user_2)
218
- result.should be_true
219
- end
260
+ it "does not accept user IDs anymore" do
261
+ lambda { @test_users.befriend(@user1["id"], @user2["id"]) }.should raise_exception
262
+ end
263
+
264
+ it "accepts http options passed to both calls" do
265
+ options = {:some_http_option => true}
266
+ # should come twice, once for each user
267
+ Koala.http_service.should_receive(:make_request).with(anything, anything, anything, options).twice.and_return(Koala::HTTPService::Response.new(200, "{}", {}))
268
+ @test_users.befriend(@user1, @user2, options)
269
+ end
270
+ end
271
+ end # when used without network
220
272
 
221
- it "should not accept user IDs anymore" do
222
- lambda { @test_users.befriend(@user1["id"], @user2["id"]) }.should raise_exception
223
- end
224
- end # with existing users
273
+ describe "#test_user_accounts_path" do
274
+ it "returns the app_id/accounts/test-users" do
275
+ @test_users.test_user_accounts_path.should == "/#{@app_id}/accounts/test-users"
276
+ end
277
+ end
225
278
 
226
- end # when used without network
279
+ describe "when creating a network of friends" do
280
+ before :each do
281
+ @network = []
227
282
 
228
- describe "when creating a network of friends" do
229
- before :each do
230
- @test_users = Koala::Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
231
- @network = []
232
-
233
- if KoalaTest.mock_interface?
234
- id_counter = 999999900
235
- @test_users.stub!(:create).and_return do
236
- id_counter += 1
237
- {"id" => id_counter, "access_token" => @token, "login_url" => "https://www.facebook.com/platform/test_account.."}
238
- end
239
- @test_users.stub!(:befriend).and_return(true)
240
- @test_users.stub!(:delete).and_return(true)
283
+ if KoalaTest.mock_interface?
284
+ id_counter = 999999900
285
+ @test_users.stub!(:create).and_return do
286
+ id_counter += 1
287
+ {"id" => id_counter, "access_token" => @token, "login_url" => "https://www.facebook.com/platform/test_account.."}
241
288
  end
289
+ @test_users.stub!(:befriend).and_return(true)
290
+ @test_users.stub!(:delete).and_return(true)
242
291
  end
292
+ end
243
293
 
244
- describe "tests that create users" do
245
- it "should create a 5 person network" do
246
- size = 5
247
- @network = @test_users.create_network(size)
248
- @network.should be_a(Array)
249
- @network.size.should == size
250
- end
294
+ describe "tests that create users" do
295
+ it "creates a 5 person network" do
296
+ size = 5
297
+ @network = @test_users.create_network(size)
298
+ @network.should be_a(Array)
299
+ @network.size.should == size
251
300
  end
301
+ end
252
302
 
253
- it "has no built-in network size limit" do
254
- times = 100
255
- @test_users.should_receive(:create).exactly(times).times
256
- @test_users.stub!(:befriend)
257
- @network = @test_users.create_network(times)
258
- end
303
+ it "has no built-in network size limit" do
304
+ times = 100
305
+ @test_users.should_receive(:create).exactly(times).times
306
+ @test_users.stub!(:befriend)
307
+ @test_users.create_network(times)
308
+ end
259
309
 
260
- it "should pass on the installed and permissions parameters to create" do
261
- perms = ["read_stream", "offline_access"]
262
- installed = false
263
- count = 25
264
- @test_users.should_receive(:create).exactly(count).times.with(installed, perms)
265
- @test_users.stub!(:befriend)
266
- @network = @test_users.create_network(count, installed, perms)
267
- end
310
+ it "passes on the installed and permissions parameters to create" do
311
+ perms = ["read_stream", "offline_access"]
312
+ installed = false
313
+ count = 25
314
+ @test_users.should_receive(:create).exactly(count).times.with(installed, perms, anything)
315
+ @test_users.stub!(:befriend)
316
+ @test_users.create_network(count, installed, perms)
317
+ end
268
318
 
269
- end # when creating network
270
- end
319
+ it "accepts http options that are passed to both the create and befriend calls" do
320
+ count = 25
321
+ options = {:some_http_option => true}
322
+ @test_users.should_receive(:create).exactly(count).times.with(anything, anything, options).and_return({})
323
+ # there are more befriends than creates, but we don't need to do the extra work to calculate out the exact #
324
+ @test_users.should_receive(:befriend).at_least(count).times.with(anything, anything, options)
325
+ @test_users.create_network(count, true, "", options)
326
+ end
327
+ end # when creating network
271
328
  end # describe Koala TestUsers
@@ -212,7 +212,7 @@ describe "Koala::UploadableIO" do
212
212
  end
213
213
  end
214
214
 
215
- describe "#binary_content?" do
215
+ describe ".binary_content?" do
216
216
  it "returns true for Rails 3 file uploads" do
217
217
  Koala::UploadableIO.binary_content?(rails_3_mocks.last).should be_true
218
218
  end
@@ -1,10 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Koala::Utils do
4
- it "has a deprecate method" do
5
- Koala::Utils.should respond_to(:deprecate)
6
- end
4
+ describe ".deprecate" do
5
+ before :each do
6
+ # unstub deprecate so we can test it
7
+ Koala::Utils.unstub(:deprecate)
8
+ end
9
+
10
+ it "has a deprecation prefix that includes the words Koala and deprecation" do
11
+ Koala::Utils::DEPRECATION_PREFIX.should =~ /koala/i
12
+ Koala::Utils::DEPRECATION_PREFIX.should =~ /deprecation/i
13
+ end
14
+
15
+ it "prints a warning with Kernel.warn" do
16
+ message = Time.now.to_s + rand.to_s
17
+ Kernel.should_receive(:warn)
18
+ Koala::Utils.deprecate(message)
19
+ end
7
20
 
8
- # AFAIK there's no way to test that (Kernel.)warn receives the text
9
- # Kernel.should_receive(:warn) doesn't seem to work, even though the text gets printed
21
+ it "prints the deprecation prefix and the warning" do
22
+ message = Time.now.to_s + rand.to_s
23
+ Kernel.should_receive(:warn).with(Koala::Utils::DEPRECATION_PREFIX + message)
24
+ Koala::Utils.deprecate(message)
25
+ end
26
+
27
+ it "only prints each unique message once" do
28
+ message = Time.now.to_s + rand.to_s
29
+ Kernel.should_receive(:warn).once
30
+ Koala::Utils.deprecate(message)
31
+ Koala::Utils.deprecate(message)
32
+ end
33
+ end
10
34
  end