koala 1.2.0 → 1.2.1

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.
@@ -30,21 +30,21 @@ describe "Koala::Facebook::OAuth" do
30
30
  end
31
31
 
32
32
  # initialization
33
- it "should properly initialize" do
33
+ it "properly initializes" do
34
34
  @oauth.should
35
35
  end
36
36
 
37
- it "should properly set attributes" do
37
+ it "properly sets attributes" do
38
38
  (@oauth.app_id == @app_id &&
39
39
  @oauth.app_secret == @secret &&
40
40
  @oauth.oauth_callback_url == @callback_url).should be_true
41
41
  end
42
42
 
43
- it "should properly initialize without a callback_url" do
43
+ it "properly initializes without a callback_url" do
44
44
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
45
45
  end
46
46
 
47
- it "should properly set attributes without a callback URL" do
47
+ it "properly sets attributes without a callback URL" do
48
48
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
49
49
  (@oauth.app_id == @app_id &&
50
50
  @oauth.app_secret == @secret &&
@@ -109,7 +109,7 @@ describe "Koala::Facebook::OAuth" do
109
109
  end
110
110
  end
111
111
 
112
- it "shouldn't parse invalid cookies" do
112
+ it "doesn't parse invalid cookies" do
113
113
  # make an invalid string by replacing some values
114
114
  bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
115
115
  result = @oauth.get_user_info_from_cookies(bad_cookie_hash)
@@ -118,37 +118,37 @@ describe "Koala::Facebook::OAuth" do
118
118
  end
119
119
 
120
120
  context "for unsigned cookies" do
121
- it "should properly parse valid cookies" do
121
+ it "properly parses valid cookies" do
122
122
  result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["valid_cookies"])
123
123
  result.should be_a(Hash)
124
124
  end
125
125
 
126
- it "should return all the cookie components from valid cookie string" do
126
+ it "returns all the cookie components from valid cookie string" do
127
127
  cookie_data = KoalaTest.oauth_test_data["valid_cookies"]
128
128
  parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
129
129
  number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
130
130
  parsing_results.length.should == number_of_components
131
131
  end
132
132
 
133
- it "should properly parse valid offline access cookies (e.g. no expiration)" do
133
+ it "properly parses valid offline access cookies (e.g. no expiration)" do
134
134
  result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["offline_access_cookies"])
135
135
  result["uid"].should
136
136
  end
137
137
 
138
- it "should return all the cookie components from offline access cookies" do
138
+ it "returns all the cookie components from offline access cookies" do
139
139
  cookie_data = KoalaTest.oauth_test_data["offline_access_cookies"]
140
140
  parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
141
141
  number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
142
142
  parsing_results.length.should == number_of_components
143
143
  end
144
144
 
145
- it "shouldn't parse expired cookies" do
145
+ it "doesn't parse expired cookies" do
146
146
  new_time = @time.to_i * 2
147
147
  @time.stub(:to_i).and_return(new_time)
148
148
  @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["valid_cookies"]).should be_nil
149
149
  end
150
150
 
151
- it "shouldn't parse invalid cookies" do
151
+ it "doesn't parse invalid cookies" do
152
152
  # make an invalid string by replacing some values
153
153
  bad_cookie_hash = KoalaTest.oauth_test_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
154
154
  result = @oauth.get_user_info_from_cookies(bad_cookie_hash)
@@ -158,22 +158,53 @@ describe "Koala::Facebook::OAuth" do
158
158
  end
159
159
 
160
160
  describe "get_user_from_cookies" do
161
- it "should use get_user_info_from_cookies to parse the cookies" do
162
- data = KoalaTest.oauth_test_data["valid_cookies"]
163
- @oauth.should_receive(:get_user_info_from_cookies).with(data).and_return({})
164
- @oauth.get_user_from_cookies(data)
165
- end
161
+ describe "for signed cookies" do
162
+ before :each do
163
+ # we don't actually want to make requests to Facebook to redeem the code
164
+ @cookie = KoalaTest.oauth_test_data["valid_signed_cookies"]
165
+ @oauth.stub(:get_access_token_info).and_return("access_token" => "my token")
166
+ end
166
167
 
167
- it "should use return a string if the cookies are valid" do
168
- result = @oauth.get_user_from_cookies(KoalaTest.oauth_test_data["valid_cookies"])
169
- result.should be_a(String)
168
+ it "uses get_user_info_from_cookies to parse the cookies" do
169
+ @oauth.should_receive(:get_user_info_from_cookies).with(@cookie).and_return({})
170
+ @oauth.get_user_from_cookies(@cookie)
171
+ end
172
+
173
+ it "uses return the token string if the cookies are valid" do
174
+ result = @oauth.get_user_from_cookies(@cookie)
175
+ result.should == "2905623" # the user who generated the original test cookie
176
+ end
177
+
178
+ it "returns nil if the cookies are invalid" do
179
+ # make an invalid string by replacing some values
180
+ bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
181
+ result = @oauth.get_user_from_cookies(bad_cookie_hash)
182
+ result.should be_nil
183
+ end
170
184
  end
185
+
186
+ describe "for unsigned cookies" do
187
+ before :each do
188
+ # we don't actually want to make requests to Facebook to redeem the code
189
+ @cookie = KoalaTest.oauth_test_data["valid_cookies"]
190
+ end
191
+
192
+ it "uses get_user_info_from_cookies to parse the cookies" do
193
+ @oauth.should_receive(:get_user_info_from_cookies).with(@cookie).and_return({})
194
+ @oauth.get_user_from_cookies(@cookie)
195
+ end
196
+
197
+ it "uses return a string if the cookies are valid" do
198
+ result = @oauth.get_user_from_cookies(@cookie)
199
+ result.should == "2905623" # the user who generated the original test cookie
200
+ end
171
201
 
172
- it "should return nil if the cookies are invalid" do
173
- # make an invalid string by replacing some values
174
- bad_cookie_hash = KoalaTest.oauth_test_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
175
- result = @oauth.get_user_from_cookies(bad_cookie_hash)
176
- result.should be_nil
202
+ it "returns nil if the cookies are invalid" do
203
+ # make an invalid string by replacing some values
204
+ bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
205
+ result = @oauth.get_user_from_cookies(bad_cookie_hash)
206
+ result.should be_nil
207
+ end
177
208
  end
178
209
  end
179
210
  end
@@ -184,42 +215,42 @@ describe "Koala::Facebook::OAuth" do
184
215
 
185
216
  describe "for OAuth codes" do
186
217
  # url_for_oauth_code
187
- it "should generate a properly formatted OAuth code URL with the default values" do
218
+ it "generates a properly formatted OAuth code URL with the default values" do
188
219
  url = @oauth.url_for_oauth_code
189
220
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}"
190
221
  end
191
222
 
192
- it "should generate a properly formatted OAuth code URL when a callback is given" do
223
+ it "generates a properly formatted OAuth code URL when a callback is given" do
193
224
  callback = "foo.com"
194
225
  url = @oauth.url_for_oauth_code(:callback => callback)
195
226
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}"
196
227
  end
197
228
 
198
- it "should generate a properly formatted OAuth code URL when permissions are requested as a string" do
229
+ it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
199
230
  permissions = "publish_stream,read_stream"
200
231
  url = @oauth.url_for_oauth_code(:permissions => permissions)
201
232
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}&scope=#{permissions}"
202
233
  end
203
234
 
204
- it "should generate a properly formatted OAuth code URL when permissions are requested as a string" do
235
+ it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
205
236
  permissions = ["publish_stream", "read_stream"]
206
237
  url = @oauth.url_for_oauth_code(:permissions => permissions)
207
238
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}&scope=#{permissions.join(",")}"
208
239
  end
209
240
 
210
- it "should generate a properly formatted OAuth code URL when both permissions and callback are provided" do
241
+ it "generates a properly formatted OAuth code URL when both permissions and callback are provided" do
211
242
  permissions = "publish_stream,read_stream"
212
243
  callback = "foo.com"
213
244
  url = @oauth.url_for_oauth_code(:callback => callback, :permissions => permissions)
214
245
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}&scope=#{permissions}"
215
246
  end
216
247
 
217
- it "should generate a properly formatted OAuth code URL when a display is given as a string" do
248
+ it "generates a properly formatted OAuth code URL when a display is given as a string" do
218
249
  url = @oauth.url_for_oauth_code(:display => "page")
219
250
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}&display=page"
220
251
  end
221
252
 
222
- it "should raise an exception if no callback is given in initialization or the call" do
253
+ it "raises an exception if no callback is given in initialization or the call" do
223
254
  oauth2 = Koala::Facebook::OAuth.new(@app_id, @secret)
224
255
  lambda { oauth2.url_for_oauth_code }.should raise_error(ArgumentError)
225
256
  end
@@ -232,12 +263,12 @@ describe "Koala::Facebook::OAuth" do
232
263
  end
233
264
 
234
265
  # url_for_access_token
235
- it "should generate a properly formatted OAuth token URL when provided a code" do
266
+ it "generates a properly formatted OAuth token URL when provided a code" do
236
267
  url = @oauth.url_for_access_token(@code)
237
268
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{@callback_url}&client_secret=#{@secret}&code=#{@code}"
238
269
  end
239
270
 
240
- it "should generate a properly formatted OAuth token URL when provided a callback" do
271
+ it "generates a properly formatted OAuth token URL when provided a callback" do
241
272
  callback = "foo.com"
242
273
  url = @oauth.url_for_access_token(@code, :callback => callback)
243
274
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{callback}&client_secret=#{@secret}&code=#{@code}"
@@ -264,16 +295,17 @@ describe "Koala::Facebook::OAuth" do
264
295
  end
265
296
 
266
297
  if KoalaTest.code
267
- it "should properly get and parse an access token token results into a hash" do
298
+ it "properly gets and parses an access token token results into a hash" do
268
299
  result = @oauth.get_access_token_info(@code)
269
300
  result.should be_a(Hash)
270
301
  end
271
302
 
272
- it "should properly include the access token results" do
303
+ it "properly includes the access token results" do
273
304
  result = @oauth.get_access_token_info(@code)
274
305
  result["access_token"].should
275
306
  end
276
- it "should raise an error when get_access_token is called with a bad code" do
307
+
308
+ it "raises an error when get_access_token is called with a bad code" do
277
309
  lambda { @oauth.get_access_token_info("foo") }.should raise_error(Koala::Facebook::APIError)
278
310
  end
279
311
  end
@@ -281,7 +313,7 @@ describe "Koala::Facebook::OAuth" do
281
313
 
282
314
  describe ".get_access_token" do
283
315
  # TODO refactor these to be proper tests with stubs and tests against real data
284
- it "should pass on any options provided to make_request" do
316
+ it "passes on any options provided to make_request" do
285
317
  options = {:a => 2}
286
318
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
287
319
  @oauth.get_access_token(@code, options)
@@ -310,17 +342,17 @@ describe "Koala::Facebook::OAuth" do
310
342
  end
311
343
 
312
344
  describe "get_app_access_token_info" do
313
- it "should properly get and parse an app's access token as a hash" do
345
+ it "properly gets and parses an app's access token as a hash" do
314
346
  result = @oauth.get_app_access_token_info
315
347
  result.should be_a(Hash)
316
348
  end
317
349
 
318
- it "should include the access token" do
350
+ it "includes the access token" do
319
351
  result = @oauth.get_app_access_token_info
320
352
  result["access_token"].should
321
353
  end
322
354
 
323
- it "should pass on any options provided to make_request" do
355
+ it "passes on any options provided to make_request" do
324
356
  options = {:a => 2}
325
357
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
326
358
  @oauth.get_app_access_token_info(options)
@@ -328,18 +360,18 @@ describe "Koala::Facebook::OAuth" do
328
360
  end
329
361
 
330
362
  describe "get_app_acess_token" do
331
- it "should use get_access_token_info to get and parse an access token token results" do
363
+ it "uses get_access_token_info to get and parse an access token token results" do
332
364
  result = @oauth.get_app_access_token
333
365
  result.should be_a(String)
334
366
  end
335
367
 
336
- it "should return the access token as a string" do
368
+ it "returns the access token as a string" do
337
369
  result = @oauth.get_app_access_token
338
370
  original = @oauth.get_app_access_token_info
339
371
  result.should == original["access_token"]
340
372
  end
341
373
 
342
- it "should pass on any options provided to make_request" do
374
+ it "passes on any options provided to make_request" do
343
375
  options = {:a => 2}
344
376
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
345
377
  @oauth.get_app_access_token(options)
@@ -352,13 +384,13 @@ describe "Koala::Facebook::OAuth" do
352
384
  # since these are pretty fundamental and pretty testable, we want to test them
353
385
 
354
386
  # parse_access_token
355
- it "should properly parse access token results" do
387
+ it "properly parses access token results" do
356
388
  result = @oauth.send(:parse_access_token, @raw_token_string)
357
389
  has_both_parts = result["access_token"] && result["expires"]
358
390
  has_both_parts.should
359
391
  end
360
392
 
361
- it "should properly parse offline access token results" do
393
+ it "properly parses offline access token results" do
362
394
  result = @oauth.send(:parse_access_token, @raw_offline_access_token_string)
363
395
  has_both_parts = result["access_token"] && !result["expires"]
364
396
  has_both_parts.should
@@ -368,7 +400,7 @@ describe "Koala::Facebook::OAuth" do
368
400
  # somewhat duplicative with the tests for get_access_token and get_app_access_token
369
401
  # but no harm in thoroughness
370
402
  if KoalaTest.code
371
- it "should fetch a proper token string from Facebook when given a code" do
403
+ it "fetches a proper token string from Facebook when given a code" do
372
404
  result = @oauth.send(:fetch_token_string, :code => @code, :redirect_uri => @callback_url)
373
405
  result.should =~ /^access_token/
374
406
  end
@@ -376,7 +408,7 @@ describe "Koala::Facebook::OAuth" do
376
408
  it "fetch_token_string code test will not be run since the code field in facebook_data.yml is blank."
377
409
  end
378
410
 
379
- it "should fetch a proper token string from Facebook when asked for the app token" do
411
+ it "fetches a proper token string from Facebook when asked for the app token" do
380
412
  result = @oauth.send(:fetch_token_string, {:type => 'client_cred'}, true)
381
413
  result.should =~ /^access_token/
382
414
  end
@@ -386,41 +418,41 @@ describe "Koala::Facebook::OAuth" do
386
418
  describe "for exchanging session keys" do
387
419
  if KoalaTest.session_key
388
420
  describe "with get_token_info_from_session_keys" do
389
- it "should get an array of session keys from Facebook when passed a single key" do
421
+ it "gets an array of session keys from Facebook when passed a single key" do
390
422
  result = @oauth.get_tokens_from_session_keys([KoalaTest.session_key])
391
423
  result.should be_an(Array)
392
424
  result.length.should == 1
393
425
  end
394
426
 
395
- it "should get an array of session keys from Facebook when passed multiple keys" do
427
+ it "gets an array of session keys from Facebook when passed multiple keys" do
396
428
  result = @oauth.get_tokens_from_session_keys(@multiple_session_keys)
397
429
  result.should be_an(Array)
398
430
  result.length.should == 2
399
431
  end
400
432
 
401
- it "should return the original hashes" do
433
+ it "returns the original hashes" do
402
434
  result = @oauth.get_token_info_from_session_keys(@multiple_session_keys)
403
435
  result[0].should be_a(Hash)
404
436
  end
405
437
 
406
- it "should properly handle invalid session keys" do
438
+ it "properly handles invalid session keys" do
407
439
  result = @oauth.get_token_info_from_session_keys(["foo", "bar"])
408
440
  #it should return nil for each of the invalid ones
409
441
  result.each {|r| r.should be_nil}
410
442
  end
411
443
 
412
- it "should properly handle a mix of valid and invalid session keys" do
444
+ it "properly handles a mix of valid and invalid session keys" do
413
445
  result = @oauth.get_token_info_from_session_keys(["foo"].concat(@multiple_session_keys))
414
446
  # it should return nil for each of the invalid ones
415
447
  result.each_with_index {|r, index| index > 0 ? r.should(be_a(Hash)) : r.should(be_nil)}
416
448
  end
417
449
 
418
- it "should throw an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
450
+ it "throws an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
419
451
  @oauth.should_receive(:fetch_token_string).and_return("")
420
452
  lambda { @oauth.get_token_info_from_session_keys(@multiple_session_keys) }.should raise_error(Koala::Facebook::APIError)
421
453
  end
422
454
 
423
- it "should pass on any options provided to make_request" do
455
+ it "passes on any options provided to make_request" do
424
456
  options = {:a => 2}
425
457
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
426
458
  @oauth.get_token_info_from_session_keys([], options)
@@ -428,31 +460,31 @@ describe "Koala::Facebook::OAuth" do
428
460
  end
429
461
 
430
462
  describe "with get_tokens_from_session_keys" do
431
- it "should call get_token_info_from_session_keys" do
463
+ it "calls get_token_info_from_session_keys" do
432
464
  args = @multiple_session_keys
433
465
  @oauth.should_receive(:get_token_info_from_session_keys).with(args, anything).and_return([])
434
466
  @oauth.get_tokens_from_session_keys(args)
435
467
  end
436
468
 
437
- it "should return an array of strings" do
469
+ it "returns an array of strings" do
438
470
  args = @multiple_session_keys
439
471
  result = @oauth.get_tokens_from_session_keys(args)
440
472
  result.each {|r| r.should be_a(String) }
441
473
  end
442
474
 
443
- it "should properly handle invalid session keys" do
475
+ it "properly handles invalid session keys" do
444
476
  result = @oauth.get_tokens_from_session_keys(["foo", "bar"])
445
477
  # it should return nil for each of the invalid ones
446
478
  result.each {|r| r.should be_nil}
447
479
  end
448
480
 
449
- it "should properly handle a mix of valid and invalid session keys" do
481
+ it "properly handles a mix of valid and invalid session keys" do
450
482
  result = @oauth.get_tokens_from_session_keys(["foo"].concat(@multiple_session_keys))
451
483
  # it should return nil for each of the invalid ones
452
484
  result.each_with_index {|r, index| index > 0 ? r.should(be_a(String)) : r.should(be_nil)}
453
485
  end
454
486
 
455
- it "should pass on any options provided to make_request" do
487
+ it "passes on any options provided to make_request" do
456
488
  options = {:a => 2}
457
489
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
458
490
  @oauth.get_tokens_from_session_keys([], options)
@@ -460,29 +492,29 @@ describe "Koala::Facebook::OAuth" do
460
492
  end
461
493
 
462
494
  describe "get_token_from_session_key" do
463
- it "should call get_tokens_from_session_keys when the get_token_from_session_key is called" do
495
+ it "calls get_tokens_from_session_keys when the get_token_from_session_key is called" do
464
496
  key = KoalaTest.session_key
465
497
  @oauth.should_receive(:get_tokens_from_session_keys).with([key], anything).and_return([])
466
498
  @oauth.get_token_from_session_key(key)
467
499
  end
468
500
 
469
- it "should get back the access token string from get_token_from_session_key" do
501
+ it "gets back the access token string from get_token_from_session_key" do
470
502
  result = @oauth.get_token_from_session_key(KoalaTest.session_key)
471
503
  result.should be_a(String)
472
504
  end
473
505
 
474
- it "should be the first value in the array" do
506
+ it "returns the first value in the array" do
475
507
  result = @oauth.get_token_from_session_key(KoalaTest.session_key)
476
508
  array = @oauth.get_tokens_from_session_keys([KoalaTest.session_key])
477
509
  result.should == array[0]
478
510
  end
479
511
 
480
- it "should properly handle an invalid session key" do
512
+ it "properly handles an invalid session key" do
481
513
  result = @oauth.get_token_from_session_key("foo")
482
514
  result.should be_nil
483
515
  end
484
516
 
485
- it "should pass on any options provided to make_request" do
517
+ it "passes on any options provided to make_request" do
486
518
  options = {:a => 2}
487
519
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
488
520
  @oauth.get_token_from_session_key("", options)
@@ -496,15 +528,21 @@ describe "Koala::Facebook::OAuth" do
496
528
  describe "for parsing signed requests" do
497
529
  # the signed request code is ported directly from Facebook
498
530
  # so we only need to test at a high level that it works
499
- it "should throw an error if the algorithm is unsupported" do
531
+ it "throws an error if the algorithm is unsupported" do
500
532
  MultiJson.stub(:decode).and_return("algorithm" => "my fun algorithm")
501
533
  lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
502
534
  end
503
535
 
504
- it "should throw an error if the signature is invalid" do
536
+ it "throws an error if the signature is invalid" do
505
537
  OpenSSL::HMAC.stub!(:hexdigest).and_return("i'm an invalid signature")
506
538
  lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
507
539
  end
540
+
541
+ it "throws an error if the signature string is empty" do
542
+ # this occasionally happens due to Facebook error
543
+ lambda { @oauth.parse_signed_request("") }.should raise_error
544
+ lambda { @oauth.parse_signed_request("abc-def") }.should raise_error
545
+ end
508
546
 
509
547
  it "properly parses requests" do
510
548
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret || @app_secret)
@@ -512,4 +550,4 @@ describe "Koala::Facebook::OAuth" do
512
550
  end
513
551
  end
514
552
 
515
- end # describe
553
+ end # describe
@@ -19,23 +19,4 @@ describe "Koala::Facebook::RestAPI" do
19
19
  api = Koala::Facebook::RestAPI.new("token")
20
20
  end
21
21
  end
22
-
23
- context "without an access token" do
24
- before :each do
25
- @api = Koala::Facebook::API.new
26
- end
27
-
28
- it_should_behave_like "Koala RestAPI"
29
- it_should_behave_like "Koala RestAPI without an access token"
30
- end
31
-
32
- context "with an access token" do
33
- before :each do
34
- @api = Koala::Facebook::API.new(@token)
35
- end
36
-
37
- it_should_behave_like "Koala RestAPI"
38
- it_should_behave_like "Koala RestAPI with an access token"
39
- end
40
-
41
22
  end
@@ -17,7 +17,7 @@ describe "Koala::Facebook::TestUsers" do
17
17
  after :each do
18
18
  # clean up any test users
19
19
  ((@network || []) + [@user1, @user2]).each do |u|
20
- puts "Unable to delete test user #{u.inspect}" if u && (!@test_users.delete(u) rescue false)
20
+ puts "Unable to delete test user #{u.inspect}" if u && !(@test_users.delete(u) rescue false)
21
21
  end
22
22
  end
23
23
 
@@ -90,14 +90,14 @@ describe "Koala::Facebook::TestUsers" do
90
90
  describe ".create" do
91
91
  it "should create a test user when not given installed" do
92
92
  result = @test_users.create(false)
93
- @temporary_object_id = result["id"]
93
+ @user1 = result["id"]
94
94
  result.should be_a(Hash)
95
95
  (result["id"] && result["access_token"] && result["login_url"]).should
96
96
  end
97
97
 
98
98
  it "should create a test user when not given installed, ignoring permissions" do
99
99
  result = @test_users.create(false, "read_stream")
100
- @temporary_object_id = result["id"]
100
+ @user1 = result["id"]
101
101
  result.should be_a(Hash)
102
102
  (result["id"] && result["access_token"] && result["login_url"]).should
103
103
  end
@@ -114,7 +114,7 @@ describe "Koala::Facebook::TestUsers" do
114
114
 
115
115
  it "should create a test user when given installed and a permission" do
116
116
  result = @test_users.create(true, "read_stream")
117
- @temporary_object_id = result["id"]
117
+ @user1 = result["id"]
118
118
  result.should be_a(Hash)
119
119
  (result["id"] && result["access_token"] && result["login_url"]).should
120
120
  end
@@ -165,24 +165,26 @@ describe "Koala::Facebook::TestUsers" do
165
165
  describe ".update" do
166
166
  before :each do
167
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)
168
170
  end
169
171
 
170
172
  it "makes a POST with the test user Graph API " do
171
- user = @test_users.create(true)
172
- @test_users.graph_api.should_receive(:graph_call).with(anything, anything, "post", anything)
173
- @test_users.update(user, @updates)
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)
174
176
  end
175
177
 
176
178
  it "makes a request to the test user with the update params " do
177
- user = @test_users.create(true)
178
- @test_users.graph_api.should_receive(:graph_call).with(user["id"], @updates, anything, anything)
179
- @test_users.update(user, @updates)
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)
180
182
  end
181
183
 
182
184
  it "works" do
183
- user = @test_users.create(true)
184
- @test_users.update(user, @updates)
185
- user_info = Koala::Facebook::API.new(user["access_token"]).get_object(user["id"])
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"])
186
188
  user_info["name"].should == @updates[:name]
187
189
  end
188
190
  end
@@ -33,6 +33,10 @@ rest_api:
33
33
  get:
34
34
  with_token: '[{"name":"query1", "fql_result_set":[{"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"first_name":"Alex"}]}]'
35
35
  no_token: '[{"name":"query1", "fql_result_set":[{"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"first_name":"Alex"}]}]'
36
+ /method/admin.setAppProperties:
37
+ 'properties={"desktop":0}':
38
+ post:
39
+ with_token: 'true'
36
40
 
37
41
 
38
42
 
@@ -148,6 +152,12 @@ graph_api:
148
152
  message=Hello, world, from the test suite, testing comments!:
149
153
  post:
150
154
  with_token: '{"id": "MOCK_FEED_ITEM"}'
155
+ message=Hello, world, from the test suite, testing comments again!:
156
+ post:
157
+ with_token: '{"id": "MOCK_FEED_ITEM"}'
158
+ message=Hello, world, from the test suite, testing liking!:
159
+ post:
160
+ with_token: '{"id": "MOCK_FEED_ITEM"}'
151
161
  message=the cats are asleep:
152
162
  post:
153
163
  with_token: '{"id": "FEED_ITEM_CATS"}'
@@ -160,6 +170,9 @@ graph_api:
160
170
  link=http://oauth.twoalex.com/&message=Hello, world, from the test suite again!&name=OAuth Playground:
161
171
  post:
162
172
  with_token: '{"id": "FEED_ITEM_CONTEXT"}'
173
+ link=http://oauth.twoalex.com/&message=body&name=It's a big question&picture=http://oauth.twoalex.com//images/logo.png&properties=<%= {"name"=>"Link1'", "text"=>"Left", "href"=>"http://oauth.twoalex.com/"}.to_s %>=<%= {"name"=>"other", "text"=>"Straight ahead"}.to_s %>&type=link:
174
+ post:
175
+ with_token: '{"id": "FEED_ITEM_CONTEXT"}'
163
176
 
164
177
  /me/photos:
165
178
  source=[FILE]: