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.
- data/.gitignore +3 -1
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/.yardopts +3 -0
- data/CHANGELOG +28 -0
- data/Gemfile +14 -0
- data/Guardfile +6 -0
- data/koala.gemspec +3 -3
- data/lib/koala/api/batch_operation.rb +83 -0
- data/lib/koala/api/graph_api.rb +476 -0
- data/lib/koala/{graph_batch_api.rb → api/graph_batch_api.rb} +22 -17
- data/lib/koala/api/graph_collection.rb +107 -0
- data/lib/koala/api/legacy.rb +26 -0
- data/lib/koala/{rest_api.rb → api/rest_api.rb} +34 -13
- data/lib/koala/api.rb +93 -0
- data/lib/koala/http_service/multipart_request.rb +41 -0
- data/lib/koala/http_service/response.rb +18 -0
- data/lib/koala/http_service/uploadable_io.rb +187 -0
- data/lib/koala/http_service.rb +69 -20
- data/lib/koala/oauth.rb +170 -36
- data/lib/koala/realtime_updates.rb +89 -51
- data/lib/koala/test_users.rb +122 -32
- data/lib/koala/utils.rb +11 -4
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +16 -96
- data/readme.md +9 -9
- data/spec/cases/api_spec.rb +19 -12
- data/spec/cases/error_spec.rb +10 -0
- data/spec/cases/graph_api_batch_spec.rb +100 -58
- data/spec/cases/graph_collection_spec.rb +23 -7
- data/spec/cases/http_service_spec.rb +5 -26
- data/spec/cases/koala_spec.rb +22 -4
- data/spec/cases/legacy_spec.rb +115 -0
- data/spec/cases/multipart_request_spec.rb +7 -7
- data/spec/cases/oauth_spec.rb +134 -48
- data/spec/cases/realtime_updates_spec.rb +154 -47
- data/spec/cases/test_users_spec.rb +276 -219
- data/spec/cases/uploadable_io_spec.rb +1 -1
- data/spec/cases/utils_spec.rb +29 -5
- data/spec/fixtures/mock_facebook_responses.yml +41 -30
- data/spec/spec_helper.rb +3 -0
- data/spec/support/custom_matchers.rb +28 -0
- data/spec/support/graph_api_shared_examples.rb +192 -14
- data/spec/support/koala_test.rb +10 -1
- data/spec/support/mock_http_service.rb +2 -2
- data/spec/support/rest_api_shared_examples.rb +5 -165
- metadata +75 -99
- data/lib/koala/batch_operation.rb +0 -74
- data/lib/koala/graph_api.rb +0 -270
- data/lib/koala/graph_collection.rb +0 -59
- data/lib/koala/multipart_request.rb +0 -35
- data/lib/koala/uploadable_io.rb +0 -181
- data/spec/cases/graph_and_rest_api_spec.rb +0 -22
- data/spec/cases/graph_api_spec.rb +0 -22
- 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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 "
|
|
53
|
-
|
|
54
|
-
|
|
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 "
|
|
59
|
-
|
|
60
|
-
|
|
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 "
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
test_users
|
|
73
|
-
test_users.
|
|
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 "
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
test_users.
|
|
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 "
|
|
131
|
+
|
|
132
|
+
describe "#list" do
|
|
84
133
|
before :each do
|
|
85
|
-
@
|
|
134
|
+
@user1 = @test_users.create(true, "read_stream")
|
|
135
|
+
@user2 = @test_users.create(true, "read_stream,user_interests")
|
|
86
136
|
end
|
|
87
137
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
279
|
+
describe "when creating a network of friends" do
|
|
280
|
+
before :each do
|
|
281
|
+
@network = []
|
|
227
282
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
@test_users
|
|
231
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
270
|
-
|
|
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 "
|
|
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
|
data/spec/cases/utils_spec.rb
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Koala::Utils do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|