koala 1.8.0 → 1.9.0rc1
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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile +5 -9
- data/changelog.md +22 -3
- data/koala.gemspec +0 -2
- data/lib/koala.rb +5 -0
- data/lib/koala/api.rb +12 -2
- data/lib/koala/api/graph_api.rb +4 -1
- data/lib/koala/version.rb +1 -1
- data/readme.md +17 -4
- data/spec/cases/api_spec.rb +81 -24
- data/spec/cases/error_spec.rb +16 -16
- data/spec/cases/graph_api_batch_spec.rb +103 -103
- data/spec/cases/graph_api_spec.rb +33 -10
- data/spec/cases/graph_collection_spec.rb +35 -35
- data/spec/cases/http_service_spec.rb +92 -92
- data/spec/cases/koala_spec.rb +9 -9
- data/spec/cases/legacy_spec.rb +22 -22
- data/spec/cases/multipart_request_spec.rb +20 -21
- data/spec/cases/oauth_spec.rb +125 -125
- data/spec/cases/realtime_updates_spec.rb +44 -44
- data/spec/cases/test_users_spec.rb +58 -58
- data/spec/cases/uploadable_io_spec.rb +36 -36
- data/spec/cases/utils_spec.rb +11 -11
- data/spec/spec_helper.rb +0 -19
- data/spec/support/custom_matchers.rb +3 -3
- data/spec/support/graph_api_shared_examples.rb +117 -114
- data/spec/support/koala_test.rb +3 -8
- data/spec/support/rest_api_shared_examples.rb +18 -19
- data/spec/support/uploadable_io_shared_examples.rb +10 -10
- metadata +20 -50
- data/spec/support/ordered_hash.rb +0 -201
@@ -33,83 +33,83 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
33
33
|
# basic initialization
|
34
34
|
it "initializes properly with an app_id and an app_access_token" do
|
35
35
|
updates = Koala::Facebook::RealtimeUpdates.new(:app_id => @app_id, :app_access_token => @app_access_token)
|
36
|
-
updates.
|
36
|
+
expect(updates).to be_a(Koala::Facebook::RealtimeUpdates)
|
37
37
|
end
|
38
38
|
|
39
39
|
# attributes
|
40
40
|
it "allows read access to app_id" do
|
41
41
|
# in Ruby 1.9, .method returns symbols
|
42
|
-
Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym).
|
43
|
-
Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym).
|
42
|
+
expect(Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym)).to include(:app_id)
|
43
|
+
expect(Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym)).not_to include(:app_id=)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "allows read access to app_access_token" do
|
47
47
|
# in Ruby 1.9, .method returns symbols
|
48
|
-
Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym).
|
49
|
-
Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym).
|
48
|
+
expect(Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym)).to include(:app_access_token)
|
49
|
+
expect(Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym)).not_to include(:app_access_token=)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "allows read access to secret" do
|
53
53
|
# in Ruby 1.9, .method returns symbols
|
54
|
-
Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym).
|
55
|
-
Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym).
|
54
|
+
expect(Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym)).to include(:secret)
|
55
|
+
expect(Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym)).not_to include(:secret=)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "allows read access to api" do
|
59
59
|
# in Ruby 1.9, .method returns symbols
|
60
|
-
Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym).
|
61
|
-
Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym).
|
60
|
+
expect(Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym)).to include(:api)
|
61
|
+
expect(Koala::Facebook::RealtimeUpdates.instance_methods.map(&:to_sym)).not_to include(:api=)
|
62
62
|
end
|
63
63
|
|
64
64
|
# old graph_api accessor
|
65
65
|
it "returns the api object when graph_api is called" do
|
66
66
|
updates = Koala::Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
67
|
-
updates.graph_api.
|
67
|
+
expect(updates.graph_api).to eq(updates.api)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "fire a deprecation warning when graph_api is called" do
|
71
71
|
updates = Koala::Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
72
|
-
Koala::Utils.
|
72
|
+
expect(Koala::Utils).to receive(:deprecate)
|
73
73
|
updates.graph_api
|
74
74
|
end
|
75
75
|
|
76
76
|
# init with secret / fetching the token
|
77
77
|
it "initializes properly with an app_id and a secret" do
|
78
78
|
updates = Koala::Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
79
|
-
updates.
|
79
|
+
expect(updates).to be_a(Koala::Facebook::RealtimeUpdates)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "fetches an app_token from Facebook when provided an app_id and a secret" do
|
83
83
|
updates = Koala::Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
84
|
-
updates.app_access_token.
|
84
|
+
expect(updates.app_access_token).not_to be_nil
|
85
85
|
end
|
86
86
|
|
87
87
|
it "uses the OAuth class to fetch a token when provided an app_id and a secret" do
|
88
88
|
oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
|
89
89
|
token = oauth.get_app_access_token
|
90
|
-
oauth.
|
91
|
-
Koala::Facebook::OAuth.
|
90
|
+
expect(oauth).to receive(:get_app_access_token).and_return(token)
|
91
|
+
expect(Koala::Facebook::OAuth).to receive(:new).with(@app_id, @secret).and_return(oauth)
|
92
92
|
updates = Koala::Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "sets up the with the app acces token" do
|
96
96
|
updates = Koala::Facebook::RealtimeUpdates.new(:app_id => @app_id, :app_access_token => @app_access_token)
|
97
|
-
updates.api.
|
98
|
-
updates.api.access_token.
|
97
|
+
expect(updates.api).to be_a(Koala::Facebook::API)
|
98
|
+
expect(updates.api.access_token).to eq(@app_access_token)
|
99
99
|
end
|
100
100
|
|
101
101
|
end
|
102
102
|
|
103
103
|
describe "#subscribe" do
|
104
104
|
it "makes a POST to the subscription path" do
|
105
|
-
@updates.api.
|
105
|
+
expect(@updates.api).to receive(:graph_call).with(@updates.subscription_path, anything, "post", anything)
|
106
106
|
@updates.subscribe("user", "name", @subscription_path, @verify_token)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "properly formats the subscription request" do
|
110
110
|
obj = "user"
|
111
111
|
fields = "name"
|
112
|
-
@updates.api.
|
112
|
+
expect(@updates.api).to receive(:graph_call).with(anything, hash_including(
|
113
113
|
:object => obj,
|
114
114
|
:fields => fields,
|
115
115
|
:callback_url => @subscription_path,
|
@@ -122,7 +122,7 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
122
122
|
# see https://github.com/arsduo/koala/issues/150
|
123
123
|
obj = "user"
|
124
124
|
fields = "name"
|
125
|
-
@updates.api.
|
125
|
+
expect(@updates.api).not_to receive(:graph_call).with(anything, hash_including(:verify_token => anything), anything, anything)
|
126
126
|
@updates.subscribe("user", "name", @subscription_path)
|
127
127
|
end
|
128
128
|
|
@@ -132,7 +132,7 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
132
132
|
|
133
133
|
it "accepts an options hash" do
|
134
134
|
options = {:a => 2, :b => "c"}
|
135
|
-
@updates.api.
|
135
|
+
expect(@updates.api).to receive(:graph_call).with(anything, anything, anything, hash_including(options))
|
136
136
|
@updates.subscribe("user", "name", @subscription_path, @verify_token, options)
|
137
137
|
end
|
138
138
|
|
@@ -157,19 +157,19 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
157
157
|
|
158
158
|
describe "#unsubscribe" do
|
159
159
|
it "makes a DELETE to the subscription path" do
|
160
|
-
@updates.api.
|
160
|
+
expect(@updates.api).to receive(:graph_call).with(@updates.subscription_path, anything, "delete", anything)
|
161
161
|
@updates.unsubscribe("user")
|
162
162
|
end
|
163
163
|
|
164
164
|
it "includes the object if provided" do
|
165
165
|
obj = "user"
|
166
|
-
@updates.api.
|
166
|
+
expect(@updates.api).to receive(:graph_call).with(anything, hash_including(:object => obj), anything, anything)
|
167
167
|
@updates.unsubscribe(obj)
|
168
168
|
end
|
169
169
|
|
170
170
|
it "accepts an options hash" do
|
171
171
|
options = {:a => 2, :b => "C"}
|
172
|
-
@updates.api.
|
172
|
+
expect(@updates.api).to receive(:graph_call).with(anything, anything, anything, hash_including(options))
|
173
173
|
@updates.unsubscribe("user", options)
|
174
174
|
end
|
175
175
|
|
@@ -190,26 +190,26 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
190
190
|
|
191
191
|
describe "#list_subscriptions" do
|
192
192
|
it "GETs the subscription path" do
|
193
|
-
@updates.api.
|
193
|
+
expect(@updates.api).to receive(:graph_call).with(@updates.subscription_path, anything, "get", anything)
|
194
194
|
@updates.list_subscriptions
|
195
195
|
end
|
196
196
|
|
197
197
|
it "accepts options" do
|
198
198
|
options = {:a => 3, :b => "D"}
|
199
|
-
@updates.api.
|
199
|
+
expect(@updates.api).to receive(:graph_call).with(anything, anything, anything, hash_including(options))
|
200
200
|
@updates.list_subscriptions(options)
|
201
201
|
end
|
202
202
|
|
203
203
|
describe "in practice" do
|
204
204
|
it "lists subscriptions properly" do
|
205
|
-
@updates.list_subscriptions.
|
205
|
+
expect(@updates.list_subscriptions).to be_a(Array)
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
210
|
describe "#subscription_path" do
|
211
211
|
it "returns the app_id/subscriptions" do
|
212
|
-
@updates.subscription_path.
|
212
|
+
expect(@updates.subscription_path).to eq("#{@app_id}/subscriptions")
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -222,23 +222,23 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
222
222
|
end
|
223
223
|
|
224
224
|
it "returns false if there is no X-Hub-Signature header" do
|
225
|
-
@updates.validate_update("", {}).
|
225
|
+
expect(@updates.validate_update("", {})).to be_falsey
|
226
226
|
end
|
227
227
|
|
228
228
|
it "returns false if the signature doesn't match the body" do
|
229
|
-
@updates.validate_update("", {"X-Hub-Signature" => "sha1=badsha1"}).
|
229
|
+
expect(@updates.validate_update("", {"X-Hub-Signature" => "sha1=badsha1"})).to be_falsey
|
230
230
|
end
|
231
231
|
|
232
232
|
it "results true if the signature matches the body with the secret" do
|
233
233
|
body = "BODY"
|
234
234
|
signature = OpenSSL::HMAC.hexdigest('sha1', @secret, body).chomp
|
235
|
-
@updates.validate_update(body, {"X-Hub-Signature" => "sha1=#{signature}"}).
|
235
|
+
expect(@updates.validate_update(body, {"X-Hub-Signature" => "sha1=#{signature}"})).to be_truthy
|
236
236
|
end
|
237
237
|
|
238
238
|
it "results true with alternate HTTP_X_HUB_SIGNATURE header" do
|
239
239
|
body = "BODY"
|
240
240
|
signature = OpenSSL::HMAC.hexdigest('sha1', @secret, body).chomp
|
241
|
-
@updates.validate_update(body, {"HTTP_X_HUB_SIGNATURE" => "sha1=#{signature}"}).
|
241
|
+
expect(@updates.validate_update(body, {"HTTP_X_HUB_SIGNATURE" => "sha1=#{signature}"})).to be_truthy
|
242
242
|
end
|
243
243
|
|
244
244
|
end
|
@@ -246,19 +246,19 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
246
246
|
describe ".meet_challenge" do
|
247
247
|
it "returns false if hub.mode isn't subscribe" do
|
248
248
|
params = {'hub.mode' => 'not subscribe'}
|
249
|
-
Koala::Facebook::RealtimeUpdates.meet_challenge(params).
|
249
|
+
expect(Koala::Facebook::RealtimeUpdates.meet_challenge(params)).to be_falsey
|
250
250
|
end
|
251
251
|
|
252
252
|
it "doesn't evaluate the block if hub.mode isn't subscribe" do
|
253
253
|
params = {'hub.mode' => 'not subscribe'}
|
254
254
|
block_evaluated = false
|
255
255
|
Koala::Facebook::RealtimeUpdates.meet_challenge(params){|token| block_evaluated = true}
|
256
|
-
block_evaluated.
|
256
|
+
expect(block_evaluated).to be_falsey
|
257
257
|
end
|
258
258
|
|
259
259
|
it "returns false if not given a verify_token or block" do
|
260
260
|
params = {'hub.mode' => 'subscribe'}
|
261
|
-
Koala::Facebook::RealtimeUpdates.meet_challenge(params).
|
261
|
+
expect(Koala::Facebook::RealtimeUpdates.meet_challenge(params)).to be_falsey
|
262
262
|
end
|
263
263
|
|
264
264
|
describe "and mode is 'subscribe'" do
|
@@ -273,12 +273,12 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
273
273
|
end
|
274
274
|
|
275
275
|
it "returns false if the given verify token doesn't match" do
|
276
|
-
Koala::Facebook::RealtimeUpdates.meet_challenge(@params, @token + '1').
|
276
|
+
expect(Koala::Facebook::RealtimeUpdates.meet_challenge(@params, @token + '1')).to be_falsey
|
277
277
|
end
|
278
278
|
|
279
279
|
it "returns the challenge if the given verify token matches" do
|
280
280
|
@params['hub.challenge'] = 'challenge val'
|
281
|
-
Koala::Facebook::RealtimeUpdates.meet_challenge(@params, @token).
|
281
|
+
expect(Koala::Facebook::RealtimeUpdates.meet_challenge(@params, @token)).to eq(@params['hub.challenge'])
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
@@ -289,27 +289,27 @@ describe "Koala::Facebook::RealtimeUpdates" do
|
|
289
289
|
|
290
290
|
it "gives the block the token as a parameter" do
|
291
291
|
Koala::Facebook::RealtimeUpdates.meet_challenge(@params) do |token|
|
292
|
-
token.
|
292
|
+
expect(token).to eq(@token)
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
296
|
it "returns false if the given block return false" do
|
297
|
-
Koala::Facebook::RealtimeUpdates.meet_challenge(@params) do |token|
|
297
|
+
expect(Koala::Facebook::RealtimeUpdates.meet_challenge(@params) do |token|
|
298
298
|
false
|
299
|
-
end.
|
299
|
+
end).to be_falsey
|
300
300
|
end
|
301
301
|
|
302
302
|
it "returns false if the given block returns nil" do
|
303
|
-
Koala::Facebook::RealtimeUpdates.meet_challenge(@params) do |token|
|
303
|
+
expect(Koala::Facebook::RealtimeUpdates.meet_challenge(@params) do |token|
|
304
304
|
nil
|
305
|
-
end.
|
305
|
+
end).to be_falsey
|
306
306
|
end
|
307
307
|
|
308
308
|
it "returns the challenge if the given block returns true" do
|
309
309
|
@params['hub.challenge'] = 'challenge val'
|
310
|
-
Koala::Facebook::RealtimeUpdates.meet_challenge(@params) do |token|
|
310
|
+
expect(Koala::Facebook::RealtimeUpdates.meet_challenge(@params) do |token|
|
311
311
|
true
|
312
|
-
end.
|
312
|
+
end).to be_truthy
|
313
313
|
end
|
314
314
|
end
|
315
315
|
end
|
@@ -31,57 +31,57 @@ describe "Koala::Facebook::TestUsers" do
|
|
31
31
|
# basic initialization
|
32
32
|
it "initializes properly with an app_id and an app_access_token" do
|
33
33
|
test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :app_access_token => @app_access_token)
|
34
|
-
test_users.
|
34
|
+
expect(test_users).to be_a(Koala::Facebook::TestUsers)
|
35
35
|
end
|
36
36
|
|
37
37
|
# init with secret / fetching the token
|
38
38
|
it "initializes properly with an app_id and a secret" do
|
39
39
|
test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
|
40
|
-
test_users.
|
40
|
+
expect(test_users).to be_a(Koala::Facebook::TestUsers)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "uses the OAuth class to fetch a token when provided an app_id and a secret" do
|
44
44
|
oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
|
45
45
|
token = oauth.get_app_access_token
|
46
|
-
oauth.
|
47
|
-
Koala::Facebook::OAuth.
|
46
|
+
expect(oauth).to receive(:get_app_access_token).and_return(token)
|
47
|
+
expect(Koala::Facebook::OAuth).to receive(:new).with(@app_id, @secret).and_return(oauth)
|
48
48
|
test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
|
49
49
|
end
|
50
50
|
|
51
51
|
# attributes
|
52
52
|
it "allows read access to app_id, app_access_token, and secret" do
|
53
53
|
# in Ruby 1.9, .method returns symbols
|
54
|
-
Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).
|
55
|
-
Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).
|
54
|
+
expect(Koala::Facebook::TestUsers.instance_methods.map(&:to_sym)).to include(:app_id)
|
55
|
+
expect(Koala::Facebook::TestUsers.instance_methods.map(&:to_sym)).not_to include(:app_id=)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "allows read access to app_access_token" do
|
59
59
|
# in Ruby 1.9, .method returns symbols
|
60
|
-
Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).
|
61
|
-
Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).
|
60
|
+
expect(Koala::Facebook::TestUsers.instance_methods.map(&:to_sym)).to include(:app_access_token)
|
61
|
+
expect(Koala::Facebook::TestUsers.instance_methods.map(&:to_sym)).not_to include(:app_access_token=)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "allows read access to secret" do
|
65
65
|
# in Ruby 1.9, .method returns symbols
|
66
|
-
Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).
|
67
|
-
Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).
|
66
|
+
expect(Koala::Facebook::TestUsers.instance_methods.map(&:to_sym)).to include(:secret)
|
67
|
+
expect(Koala::Facebook::TestUsers.instance_methods.map(&:to_sym)).not_to include(:secret=)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "allows read access to api" do
|
71
71
|
# in Ruby 1.9, .method returns symbols
|
72
|
-
Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).
|
73
|
-
Koala::Facebook::TestUsers.instance_methods.map(&:to_sym).
|
72
|
+
expect(Koala::Facebook::TestUsers.instance_methods.map(&:to_sym)).to include(:api)
|
73
|
+
expect(Koala::Facebook::TestUsers.instance_methods.map(&:to_sym)).not_to include(:api=)
|
74
74
|
end
|
75
75
|
|
76
76
|
# old graph_api accessor
|
77
77
|
it "returns the api object when graph_api is called" do
|
78
78
|
test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
|
79
|
-
test_users.graph_api.
|
79
|
+
expect(test_users.graph_api).to eq(test_users.api)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "fire a deprecation warning when graph_api is called" do
|
83
83
|
test_users = Koala::Facebook::TestUsers.new(:app_id => @app_id, :secret => @secret)
|
84
|
-
Koala::Utils.
|
84
|
+
expect(Koala::Utils).to receive(:deprecate)
|
85
85
|
test_users.graph_api
|
86
86
|
end
|
87
87
|
end
|
@@ -93,43 +93,43 @@ describe "Koala::Facebook::TestUsers" do
|
|
93
93
|
it "creates a test user when not given installed" do
|
94
94
|
result = @test_users.create(false)
|
95
95
|
@user1 = result["id"]
|
96
|
-
result.
|
97
|
-
(result["id"] && result["access_token"] && result["login_url"]).
|
96
|
+
expect(result).to be_a(Hash)
|
97
|
+
expect(result["id"] && result["access_token"] && result["login_url"]).to be_truthy
|
98
98
|
end
|
99
99
|
|
100
100
|
it "creates a test user when not given installed, ignoring permissions" do
|
101
101
|
result = @test_users.create(false, "read_stream")
|
102
102
|
@user1 = result["id"]
|
103
|
-
result.
|
104
|
-
(result["id"] && result["access_token"] && result["login_url"]).
|
103
|
+
expect(result).to be_a(Hash)
|
104
|
+
expect(result["id"] && result["access_token"] && result["login_url"]).to be_truthy
|
105
105
|
end
|
106
106
|
|
107
107
|
it "accepts permissions as a string" do
|
108
|
-
@test_users.graph_api.
|
108
|
+
expect(@test_users.graph_api).to receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything, anything)
|
109
109
|
result = @test_users.create(true, "read_stream,publish_stream")
|
110
110
|
end
|
111
111
|
|
112
112
|
it "accepts permissions as an array" do
|
113
|
-
@test_users.graph_api.
|
113
|
+
expect(@test_users.graph_api).to receive(:graph_call).with(anything, hash_including("permissions" => "read_stream,publish_stream"), anything, anything)
|
114
114
|
result = @test_users.create(true, ["read_stream", "publish_stream"])
|
115
115
|
end
|
116
116
|
|
117
117
|
it "creates a test user when given installed and a permission" do
|
118
118
|
result = @test_users.create(true, "read_stream")
|
119
119
|
@user1 = result["id"]
|
120
|
-
result.
|
121
|
-
(result["id"] && result["access_token"] && result["login_url"]).
|
120
|
+
expect(result).to be_a(Hash)
|
121
|
+
expect(result["id"] && result["access_token"] && result["login_url"]).to be_truthy
|
122
122
|
end
|
123
123
|
|
124
124
|
it "lets you specify other graph arguments, like uid and access token" do
|
125
125
|
args = {:uid => "some test user ID", :owner_access_token => "some owner access token"}
|
126
|
-
@test_users.graph_api.
|
126
|
+
expect(@test_users.graph_api).to receive(:graph_call).with(anything, hash_including(args), anything, anything)
|
127
127
|
@test_users.create(true, nil, args)
|
128
128
|
end
|
129
129
|
|
130
130
|
it "lets you specify http options that get passed through to the graph call" do
|
131
131
|
options = {:some_http_option => true}
|
132
|
-
@test_users.graph_api.
|
132
|
+
expect(@test_users.graph_api).to receive(:graph_call).with(anything, anything, anything, options)
|
133
133
|
@test_users.create(true, nil, {}, options)
|
134
134
|
end
|
135
135
|
end
|
@@ -142,16 +142,16 @@ describe "Koala::Facebook::TestUsers" do
|
|
142
142
|
|
143
143
|
it "lists test users" do
|
144
144
|
result = @test_users.list
|
145
|
-
result.
|
145
|
+
expect(result).to be_an(Array)
|
146
146
|
first_user, second_user = result[0], result[1]
|
147
|
-
(first_user["id"] && first_user["access_token"] && first_user["login_url"]).
|
148
|
-
(second_user["id"] && second_user["access_token"] && second_user["login_url"]).
|
147
|
+
expect(first_user["id"] && first_user["access_token"] && first_user["login_url"]).to be_truthy
|
148
|
+
expect(second_user["id"] && second_user["access_token"] && second_user["login_url"]).to be_truthy
|
149
149
|
end
|
150
150
|
|
151
151
|
it "accepts http options" do
|
152
152
|
@stubbed = true
|
153
153
|
options = {:some_http_option => true}
|
154
|
-
@test_users.api.
|
154
|
+
expect(@test_users.api).to receive(:graph_call).with(anything, anything, anything, options)
|
155
155
|
@test_users.list(options)
|
156
156
|
end
|
157
157
|
end
|
@@ -163,24 +163,24 @@ describe "Koala::Facebook::TestUsers" do
|
|
163
163
|
end
|
164
164
|
|
165
165
|
it "deletes a user by id" do
|
166
|
-
@test_users.delete(@user1['id']).
|
166
|
+
expect(@test_users.delete(@user1['id'])).to be_truthy
|
167
167
|
@user1 = nil
|
168
168
|
end
|
169
169
|
|
170
170
|
it "deletes a user by hash" do
|
171
|
-
@test_users.delete(@user2).
|
171
|
+
expect(@test_users.delete(@user2)).to be_truthy
|
172
172
|
@user2 = nil
|
173
173
|
end
|
174
174
|
|
175
175
|
it "does not delete users when provided a false ID" do
|
176
|
-
|
176
|
+
expect { @test_users.delete("#{@user1['id']}1") }.to raise_exception(Koala::Facebook::APIError)
|
177
177
|
end
|
178
178
|
|
179
179
|
it "lets you specify http options that get passed through to the graph call" do
|
180
180
|
options = {:some_http_option => true}
|
181
181
|
# technically this goes through delete_object, but this makes it less brittle
|
182
182
|
@stubbed = true
|
183
|
-
@test_users.graph_api.
|
183
|
+
expect(@test_users.graph_api).to receive(:graph_call).with(anything, anything, anything, options)
|
184
184
|
@test_users.delete("user", options)
|
185
185
|
end
|
186
186
|
end
|
@@ -188,24 +188,24 @@ describe "Koala::Facebook::TestUsers" do
|
|
188
188
|
describe "#delete_all" do
|
189
189
|
it "deletes the batch API to deleten all users found by the list commnand" do
|
190
190
|
array = 200.times.collect { {"id" => rand}}
|
191
|
-
@test_users.
|
191
|
+
expect(@test_users).to receive(:list).and_return(array, [])
|
192
192
|
batch_api = double("batch API")
|
193
193
|
allow(@test_users.api).to receive(:batch).and_yield(batch_api)
|
194
|
-
array.each {|item| batch_api.
|
194
|
+
array.each {|item| expect(batch_api).to receive(:delete_object).with(item["id"]) }
|
195
195
|
@test_users.delete_all
|
196
196
|
end
|
197
197
|
|
198
198
|
it "accepts http options that get passed to both list and the batch call" do
|
199
199
|
options = {:some_http_option => true}
|
200
|
-
@test_users.
|
201
|
-
@test_users.api.
|
200
|
+
expect(@test_users).to receive(:list).with(options).and_return([{"id" => rand}], [])
|
201
|
+
expect(@test_users.api).to receive(:batch).with(options)
|
202
202
|
@test_users.delete_all(options)
|
203
203
|
end
|
204
204
|
|
205
205
|
it "breaks if Facebook sends back the same list twice" do
|
206
206
|
list = [{"id" => rand}]
|
207
207
|
allow(@test_users).to receive(:list).and_return(list)
|
208
|
-
@test_users.api.
|
208
|
+
expect(@test_users.api).to receive(:batch).once
|
209
209
|
@test_users.delete_all
|
210
210
|
end
|
211
211
|
|
@@ -213,7 +213,7 @@ describe "Koala::Facebook::TestUsers" do
|
|
213
213
|
list1 = [{"id" => 123}]
|
214
214
|
list2 = [{"id" => 123, "name" => "foo"}]
|
215
215
|
allow(@test_users).to receive(:list).twice.and_return(list1, list2)
|
216
|
-
@test_users.api.
|
216
|
+
expect(@test_users.api).to receive(:batch).once
|
217
217
|
@test_users.delete_all
|
218
218
|
end
|
219
219
|
end
|
@@ -227,20 +227,20 @@ describe "Koala::Facebook::TestUsers" do
|
|
227
227
|
|
228
228
|
it "makes a POST with the test user Graph API " do
|
229
229
|
@user1 = @test_users2.create(true)
|
230
|
-
@test_users2.graph_api.
|
230
|
+
expect(@test_users2.graph_api).to receive(:graph_call).with(anything, anything, "post", anything)
|
231
231
|
@test_users2.update(@user1, @updates)
|
232
232
|
end
|
233
233
|
|
234
234
|
it "makes a request to the test user with the update params " do
|
235
235
|
@user1 = @test_users2.create(true)
|
236
|
-
@test_users2.graph_api.
|
236
|
+
expect(@test_users2.graph_api).to receive(:graph_call).with(@user1["id"], @updates, anything, anything)
|
237
237
|
@test_users2.update(@user1, @updates)
|
238
238
|
end
|
239
239
|
|
240
240
|
it "accepts an options hash" do
|
241
241
|
options = {:some_http_option => true}
|
242
242
|
@stubbed = true
|
243
|
-
@test_users2.graph_api.
|
243
|
+
expect(@test_users2.graph_api).to receive(:graph_call).with(anything, anything, anything, options)
|
244
244
|
@test_users2.update("foo", @updates, options)
|
245
245
|
end
|
246
246
|
|
@@ -248,7 +248,7 @@ describe "Koala::Facebook::TestUsers" do
|
|
248
248
|
@user1 = @test_users.create(true)
|
249
249
|
@test_users.update(@user1, @updates)
|
250
250
|
user_info = Koala::Facebook::API.new(@user1["access_token"]).get_object(@user1["id"])
|
251
|
-
user_info["name"].
|
251
|
+
expect(user_info["name"]).to eq(@updates[:name])
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
@@ -260,7 +260,7 @@ describe "Koala::Facebook::TestUsers" do
|
|
260
260
|
|
261
261
|
it "makes two users into friends with string hashes" do
|
262
262
|
result = @test_users.befriend(@user1, @user2)
|
263
|
-
result.
|
263
|
+
expect(result).to be_truthy
|
264
264
|
end
|
265
265
|
|
266
266
|
it "makes two users into friends with symbol hashes" do
|
@@ -270,18 +270,18 @@ describe "Koala::Facebook::TestUsers" do
|
|
270
270
|
@user2.each_pair {|k, v| new_user_2[k.to_sym] = v}
|
271
271
|
|
272
272
|
result = @test_users.befriend(new_user_1, new_user_2)
|
273
|
-
result.
|
273
|
+
expect(result).to be_truthy
|
274
274
|
end
|
275
275
|
|
276
276
|
it "does not accept user IDs anymore" do
|
277
|
-
|
277
|
+
expect { @test_users.befriend(@user1["id"], @user2["id"]) }.to raise_exception
|
278
278
|
end
|
279
279
|
|
280
280
|
it "accepts http options passed to both calls" do
|
281
281
|
options = {:some_http_option => true}
|
282
282
|
# should come twice, once for each user
|
283
283
|
@stubbed = true
|
284
|
-
Koala.http_service.
|
284
|
+
expect(Koala.http_service).to receive(:make_request).with(anything, anything, anything, options).twice.and_return(Koala::HTTPService::Response.new(200, "{}", {}))
|
285
285
|
@test_users.befriend(@user1, @user2, options)
|
286
286
|
end
|
287
287
|
end
|
@@ -289,7 +289,7 @@ describe "Koala::Facebook::TestUsers" do
|
|
289
289
|
|
290
290
|
describe "#test_user_accounts_path" do
|
291
291
|
it "returns the app_id/accounts/test-users" do
|
292
|
-
@test_users.test_user_accounts_path.
|
292
|
+
expect(@test_users.test_user_accounts_path).to eq("/#{@app_id}/accounts/test-users")
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
@@ -299,12 +299,12 @@ describe "Koala::Facebook::TestUsers" do
|
|
299
299
|
|
300
300
|
if KoalaTest.mock_interface?
|
301
301
|
id_counter = 999999900
|
302
|
-
@test_users.
|
302
|
+
allow(@test_users).to receive(:create).and_return do
|
303
303
|
id_counter += 1
|
304
304
|
{"id" => id_counter, "access_token" => @token, "login_url" => "https://www.facebook.com/platform/test_account.."}
|
305
305
|
end
|
306
|
-
@test_users.
|
307
|
-
@test_users.
|
306
|
+
allow(@test_users).to receive(:befriend).and_return(true)
|
307
|
+
allow(@test_users).to receive(:delete).and_return(true)
|
308
308
|
end
|
309
309
|
end
|
310
310
|
|
@@ -312,15 +312,15 @@ describe "Koala::Facebook::TestUsers" do
|
|
312
312
|
it "creates a 5 person network" do
|
313
313
|
size = 5
|
314
314
|
@network = @test_users.create_network(size)
|
315
|
-
@network.
|
316
|
-
@network.size.
|
315
|
+
expect(@network).to be_a(Array)
|
316
|
+
expect(@network.size).to eq(size)
|
317
317
|
end
|
318
318
|
end
|
319
319
|
|
320
320
|
it "has no built-in network size limit" do
|
321
321
|
times = 100
|
322
|
-
@test_users.
|
323
|
-
@test_users.
|
322
|
+
expect(@test_users).to receive(:create).exactly(times).times
|
323
|
+
allow(@test_users).to receive(:befriend)
|
324
324
|
@test_users.create_network(times)
|
325
325
|
end
|
326
326
|
|
@@ -328,17 +328,17 @@ describe "Koala::Facebook::TestUsers" do
|
|
328
328
|
perms = ["read_stream", "offline_access"]
|
329
329
|
installed = false
|
330
330
|
count = 25
|
331
|
-
@test_users.
|
332
|
-
@test_users.
|
331
|
+
expect(@test_users).to receive(:create).exactly(count).times.with(installed, perms, anything)
|
332
|
+
allow(@test_users).to receive(:befriend)
|
333
333
|
@test_users.create_network(count, installed, perms)
|
334
334
|
end
|
335
335
|
|
336
336
|
it "accepts http options that are passed to both the create and befriend calls" do
|
337
337
|
count = 25
|
338
338
|
options = {:some_http_option => true}
|
339
|
-
@test_users.
|
339
|
+
expect(@test_users).to receive(:create).exactly(count).times.with(anything, anything, options).and_return({})
|
340
340
|
# there are more befriends than creates, but we don't need to do the extra work to calculate out the exact #
|
341
|
-
@test_users.
|
341
|
+
expect(@test_users).to receive(:befriend).at_least(count).times.with(anything, anything, options)
|
342
342
|
@test_users.create_network(count, true, "", options)
|
343
343
|
end
|
344
344
|
end # when creating network
|