koala 1.2.0beta1 → 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.
@@ -13,6 +13,13 @@ describe "Koala::Facebook::TestUsers" do
13
13
  raise Exception, "Must supply OAuth app id, secret, app_access_token, and callback to run live subscription tests!"
14
14
  end
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
22
+ end
16
23
 
17
24
  describe "when initializing" do
18
25
  # basic initialization
@@ -83,14 +90,14 @@ describe "Koala::Facebook::TestUsers" do
83
90
  describe ".create" do
84
91
  it "should create a test user when not given installed" do
85
92
  result = @test_users.create(false)
86
- @temporary_object_id = result["id"]
93
+ @user1 = result["id"]
87
94
  result.should be_a(Hash)
88
95
  (result["id"] && result["access_token"] && result["login_url"]).should
89
96
  end
90
97
 
91
98
  it "should create a test user when not given installed, ignoring permissions" do
92
99
  result = @test_users.create(false, "read_stream")
93
- @temporary_object_id = result["id"]
100
+ @user1 = result["id"]
94
101
  result.should be_a(Hash)
95
102
  (result["id"] && result["access_token"] && result["login_url"]).should
96
103
  end
@@ -107,7 +114,7 @@ describe "Koala::Facebook::TestUsers" do
107
114
 
108
115
  it "should create a test user when given installed and a permission" do
109
116
  result = @test_users.create(true, "read_stream")
110
- @temporary_object_id = result["id"]
117
+ @user1 = result["id"]
111
118
  result.should be_a(Hash)
112
119
  (result["id"] && result["access_token"] && result["login_url"]).should
113
120
  end
@@ -131,11 +138,6 @@ describe "Koala::Facebook::TestUsers" do
131
138
  @user2 = @test_users.create(true, "read_stream,user_interests")
132
139
  end
133
140
 
134
- after :each do
135
- @test_users.delete(@user1) if @user1
136
- @test_users.delete(@user2) if @user2
137
- end
138
-
139
141
  it "should delete a user by id" do
140
142
  @test_users.delete(@user1['id']).should be_true
141
143
  @user1 = nil
@@ -163,24 +165,26 @@ describe "Koala::Facebook::TestUsers" do
163
165
  describe ".update" do
164
166
  before :each do
165
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)
166
170
  end
167
171
 
168
172
  it "makes a POST with the test user Graph API " do
169
- user = @test_users.create(true)
170
- @test_users.graph_api.should_receive(:graph_call).with(anything, anything, "post", anything)
171
- @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)
172
176
  end
173
177
 
174
178
  it "makes a request to the test user with the update params " do
175
- user = @test_users.create(true)
176
- @test_users.graph_api.should_receive(:graph_call).with(user["id"], @updates, anything, anything)
177
- @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)
178
182
  end
179
183
 
180
184
  it "works" do
181
- user = @test_users.create(true)
182
- @test_users.update(user, @updates)
183
- 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"])
184
188
  user_info["name"].should == @updates[:name]
185
189
  end
186
190
  end
@@ -191,11 +195,6 @@ describe "Koala::Facebook::TestUsers" do
191
195
  @user2 = @test_users.create(true, "read_stream,user_interests")
192
196
  end
193
197
 
194
- after :each do
195
- @test_users.delete(@user1)
196
- @test_users.delete(@user2)
197
- end
198
-
199
198
  it "should list test users" do
200
199
  result = @test_users.list
201
200
  result.should be_an(Array)
@@ -243,16 +242,6 @@ describe "Koala::Facebook::TestUsers" do
243
242
  end
244
243
 
245
244
  describe "tests that create users" do
246
- before :each do
247
- test_users = Koala::Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
248
- test_users.delete_all
249
- end
250
-
251
- after :each do
252
- test_users = Koala::Facebook::TestUsers.new({:app_access_token => @app_access_token, :app_id => @app_id})
253
- test_users.delete_all
254
- end
255
-
256
245
  it "should create a 5 person network" do
257
246
  size = 5
258
247
  @network = @test_users.create_network(size)
@@ -261,10 +250,11 @@ describe "Koala::Facebook::TestUsers" do
261
250
  end
262
251
  end
263
252
 
264
- it "should limit to a 50 person network" do
265
- @test_users.should_receive(:create).exactly(50).times
253
+ it "has no built-in network size limit" do
254
+ times = 100
255
+ @test_users.should_receive(:create).exactly(times).times
266
256
  @test_users.stub!(:befriend)
267
- @network = @test_users.create_network(51)
257
+ @network = @test_users.create_network(times)
268
258
  end
269
259
 
270
260
  it "should pass on the installed and permissions parameters to create" do
@@ -86,6 +86,34 @@ describe "Koala::UploadableIO" do
86
86
  end
87
87
  end
88
88
 
89
+ describe "when given an IO object" do
90
+ before(:each) do
91
+ @io = StringIO.open("abcdefgh")
92
+ @koala_io_params = [@io]
93
+ end
94
+
95
+ describe "and a content type" do
96
+ before :each do
97
+ @koala_io_params.concat(["image/jpg"])
98
+ end
99
+
100
+ it "returns an UploadableIO with the same io" do
101
+ Koala::UploadableIO.new(*@koala_io_params).io_or_path.should == @koala_io_params[0]
102
+ end
103
+
104
+ it "returns an UploadableIO with the same content_type" do
105
+ content_stub = @koala_io_params[1] = stub('Content Type')
106
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
107
+ end
108
+ end
109
+
110
+ describe "and no content type" do
111
+ it "raises an exception" do
112
+ lambda { Koala::UploadableIO.new(*@koala_io_params) }.should raise_exception(Koala::KoalaError)
113
+ end
114
+ end
115
+ end
116
+
89
117
  describe "when given a Rails 3 ActionDispatch::Http::UploadedFile" do
90
118
  before(:each) do
91
119
  @tempfile, @uploaded_file = rails_3_mocks
@@ -30,11 +30,12 @@ oauth_test_data:
30
30
  # note: the tests stub the time class so these default cookies are always valid (if you're using the default app)
31
31
  # if not you may want to remove the stubbing to test expiration
32
32
  fbs_119908831367602: '"access_token=119908831367602|2.LKE7ksSPOx0V_8mHPr2NHQ__.3600.1273363200-2905623|CMpi0AYbn03Oukzv94AUha2qbO4.&expires=1273363200&secret=lT_9zm5r5IbJ6Aa5O54nFw__&session_key=2.LKE7ksSPOx0V_8mHPr2NHQ__.3600.1273363200-2905623&sig=9515e93113921f9476a4efbdd4a3c746&uid=2905623"'
33
- expired_cookies:
34
- fbs_119908831367602: '"access_token=119908831367602|2.xv9mi6QSOpr474s4n2X_pw__.3600.1273287600-2905623|yVt5WH_S6J5p3gFa5_5lBzckhws.&expires=1273287600&secret=V_E79ovQnXqxGctFuC_n5A__&session_key=2.xv9mi6QSOpr474s4n2X_pw__.3600.1273287600-2905623&sig=eeef60838c0c800258d89b7e6ddddddb&uid=2905623"'
35
33
  offline_access_cookies:
36
34
  # note: I've revoked the offline access for security reasons, so you can't make calls against this :)
37
35
  fbs_119908831367602: '"access_token=119908831367602|08170230801eb225068e7a70-2905623|Q3LDCYYF8CX9cstxnZLsxiR0nwg.&expires=0&secret=78abaee300b392e275072a9f2727d436&session_key=08170230801eb225068e7a70-2905623&sig=423b8aa4b6fa1f9a571955f8e929d567&uid=2905623"'
36
+ valid_signed_cookies:
37
+ "fbsr_119908831367602": "f1--LHwjHVCxfs97hRHL-4cF-0jNxZRc6MGzo1qHLb0.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiIyLkFRQm90a0pBWlhVY1l3RkMuMzYwMC4xMzE0ODEzNjAwLjEtMjkwNTYyM3x4V2xya0d0UmJIZlpIclRnVWwxQmxJcVhRbjQiLCJpc3N1ZWRfYXQiOjEzMTQ4MDY2NTUsInVzZXJfaWQiOiIyOTA1NjIzIn0"
38
+
38
39
 
39
40
  # These values from the OAuth Playground (see above) will work out of the box
40
41
  # You can update this to live data if desired
@@ -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
 
@@ -87,10 +91,10 @@ graph_api:
87
91
  with_token: '[{"headers":[{"name":"Location","value":"http://google.com"}]}]'
88
92
  batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me"},{"method" => "get", "relative_url" => "me/friends"}]) %>:
89
93
  post:
90
- with_token: '[{"body":"{\"id\":\"123\"}"}, {"body":"{\"data\":[]}"}]'
94
+ with_token: '[{"body":"{\"id\":\"123\"}"}, {"body":"{\"data\":[],\"paging\":{}}"}]'
91
95
  batch=<%= MultiJson.encode([{"method"=>"get", "relative_url"=>"me"}, {"method"=>"get", "relative_url"=>"#{OAUTH_DATA["app_id"]}/insights?access_token=#{CGI.escape APP_ACCESS_TOKEN}"}]) %>:
92
96
  post:
93
- with_token: '[{"body":"{\"id\":\"123\"}"}, {"body":"{\"data\":[]}"}]'
97
+ with_token: '[{"body":"{\"id\":\"123\"}"}, {"body":"{\"data\":[],\"paging\":{}}"}]'
94
98
  batch=<%= MultiJson.encode([{"method"=>"get", "relative_url"=>"#{OAUTH_DATA["app_id"]}/insights"}, {"method"=>"get", "relative_url"=>"koppel?access_token=#{CGI.escape APP_ACCESS_TOKEN}"}]) %>:
95
99
  post:
96
100
  with_token: '[{"body": "{\"error\":{\"type\":\"AnError\", \"message\":\"An error occurred!.\"}}"},{"body":"{\"id\":\"123\"}"}]'
@@ -113,7 +117,7 @@ graph_api:
113
117
  with_token: '[null,{"body":"{}"}]'
114
118
  batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me/friends?limit=5", "name" => "get-friends", "omit_response_on_success" => false}, {"method" => "get", "relative_url" => "?ids=#{CGI.escape "{result=get-friends:$.data.*.id}"}"}]) %>:
115
119
  post:
116
- with_token: '[{"body":"{\"data\":[]}"},{"body":"{}"}]'
120
+ with_token: '[{"body":"{\"data\":[],\"paging\":{}}"},{"body":"{}"}]'
117
121
  batch=<%= MultiJson.encode([{"method" => "get", "relative_url" => "me/friends?limit=5"}, {"method" => "get", "relative_url" => "?ids=#{CGI.escape "{result=i-dont-exist:$.data.*.id}"}"}]) %>:
118
122
  post:
119
123
  with_token: '{"error":190,"error_description":"Error validating access token."}'
@@ -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]:
@@ -211,7 +224,7 @@ graph_api:
211
224
  no_args:
212
225
  get:
213
226
  <<: *token_required
214
- with_token: '{"data": [{}]}'
227
+ with_token: '{"data": [{}], "paging": {}}'
215
228
 
216
229
  /lukeshepard/picture:
217
230
  type=large:
@@ -261,7 +274,7 @@ graph_api:
261
274
  get:
262
275
  with_token: '{"data": [{"id": "507731521_100412693339488"}], "paging": {"previous": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000", "next": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000"}}'
263
276
  no_token: '{"data": [{"id": "507731521_100412693339488"}], "paging": {"previous": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000", "next": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000"}}'
264
- "limit=25&q=facebook&until=2010-09-23T21:17:33+0000":
277
+ "limit=25&q=facebook&until=<%= TEST_DATA['search_time'] %>":
265
278
  get:
266
279
  with_token: '{"data": [{"id": "507731521_100412693339488"}], "paging": {"previous": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000", "next": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000"}}'
267
280
  no_token: '{"data": [{"id": "507731521_100412693339488"}], "paging": {"previous": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000", "next": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000"}}'