koala 1.8.0 → 1.9.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.
- 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/api/graph_api.rb +4 -1
- data/lib/koala/api.rb +12 -2
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +5 -0
- 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 +19 -49
- data/spec/support/ordered_hash.rb +0 -201
|
@@ -16,7 +16,7 @@ describe "Koala::UploadableIO" do
|
|
|
16
16
|
:tempfile => tempfile,
|
|
17
17
|
:original_filename => "bar"
|
|
18
18
|
)
|
|
19
|
-
tempfile.
|
|
19
|
+
allow(tempfile).to receive(:respond_to?).with(:path).and_return(true)
|
|
20
20
|
|
|
21
21
|
[tempfile, uploaded_file]
|
|
22
22
|
end
|
|
@@ -39,15 +39,15 @@ describe "Koala::UploadableIO" do
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "returns an UploadIO with the same file path" do
|
|
42
|
-
Koala::UploadableIO.new(*@koala_io_params).io_or_path.
|
|
42
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@path)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "returns an UploadIO with the same content type" do
|
|
46
|
-
Koala::UploadableIO.new(*@koala_io_params).content_type.
|
|
46
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(@stub_type)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "returns an UploadIO with the file's name" do
|
|
50
|
-
Koala::UploadableIO.new(*@koala_io_params).filename.
|
|
50
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@path))
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
@@ -68,16 +68,16 @@ describe "Koala::UploadableIO" do
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "returns an UploadIO with the same io" do
|
|
71
|
-
Koala::UploadableIO.new(*@koala_io_params).io_or_path.
|
|
71
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@koala_io_params[0])
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it "returns an UploadableIO with the same content_type" do
|
|
75
75
|
content_stub = @koala_io_params[1] = double('Content Type')
|
|
76
|
-
Koala::UploadableIO.new(*@koala_io_params).content_type.
|
|
76
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
it "returns an UploadableIO with the right filename" do
|
|
80
|
-
Koala::UploadableIO.new(*@koala_io_params).filename.
|
|
80
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@file.path))
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
|
|
@@ -100,16 +100,16 @@ describe "Koala::UploadableIO" do
|
|
|
100
100
|
|
|
101
101
|
it "returns an UploadIO with the same io" do
|
|
102
102
|
#Problem comparing Tempfile in Ruby 1.8, REE and Rubinius mode 1.8
|
|
103
|
-
Koala::UploadableIO.new(*@koala_io_params).io_or_path.path.
|
|
103
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path.path).to eq(@koala_io_params[0].path)
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
it "returns an UploadableIO with the same content_type" do
|
|
107
107
|
content_stub = @koala_io_params[1] = double('Content Type')
|
|
108
|
-
Koala::UploadableIO.new(*@koala_io_params).content_type.
|
|
108
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
it "returns an UploadableIO with the right filename" do
|
|
112
|
-
Koala::UploadableIO.new(*@koala_io_params).filename.
|
|
112
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@file.path))
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
|
|
@@ -130,18 +130,18 @@ describe "Koala::UploadableIO" do
|
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
it "returns an UploadableIO with the same io" do
|
|
133
|
-
Koala::UploadableIO.new(*@koala_io_params).io_or_path.
|
|
133
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@koala_io_params[0])
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
it "returns an UploadableIO with the same content_type" do
|
|
137
137
|
content_stub = @koala_io_params[1] = double('Content Type')
|
|
138
|
-
Koala::UploadableIO.new(*@koala_io_params).content_type.
|
|
138
|
+
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
|
139
139
|
end
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
describe "and no content type" do
|
|
143
143
|
it "raises an exception" do
|
|
144
|
-
|
|
144
|
+
expect { Koala::UploadableIO.new(*@koala_io_params) }.to raise_exception(Koala::KoalaError)
|
|
145
145
|
end
|
|
146
146
|
end
|
|
147
147
|
end
|
|
@@ -153,18 +153,18 @@ describe "Koala::UploadableIO" do
|
|
|
153
153
|
|
|
154
154
|
it "gets the path from the tempfile associated with the UploadedFile" do
|
|
155
155
|
expected_path = double('Tempfile')
|
|
156
|
-
@tempfile.
|
|
157
|
-
Koala::UploadableIO.new(@uploaded_file).io_or_path.
|
|
156
|
+
expect(@tempfile).to receive(:path).and_return(expected_path)
|
|
157
|
+
expect(Koala::UploadableIO.new(@uploaded_file).io_or_path).to eq(expected_path)
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
it "gets the content type via the content_type method" do
|
|
161
161
|
expected_content_type = double('Content Type')
|
|
162
|
-
@uploaded_file.
|
|
163
|
-
Koala::UploadableIO.new(@uploaded_file).content_type.
|
|
162
|
+
expect(@uploaded_file).to receive(:content_type).and_return(expected_content_type)
|
|
163
|
+
expect(Koala::UploadableIO.new(@uploaded_file).content_type).to eq(expected_content_type)
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
it "gets the filename from the UploadedFile" do
|
|
167
|
-
Koala::UploadableIO.new(@uploaded_file).filename.
|
|
167
|
+
expect(Koala::UploadableIO.new(@uploaded_file).filename).to eq(@uploaded_file.original_filename)
|
|
168
168
|
end
|
|
169
169
|
end
|
|
170
170
|
|
|
@@ -178,7 +178,7 @@ describe "Koala::UploadableIO" do
|
|
|
178
178
|
@file_hash[:tempfile] = expected_file
|
|
179
179
|
|
|
180
180
|
uploadable = Koala::UploadableIO.new(@file_hash)
|
|
181
|
-
uploadable.io_or_path.
|
|
181
|
+
expect(uploadable.io_or_path).to eq(expected_file)
|
|
182
182
|
end
|
|
183
183
|
|
|
184
184
|
it "gets the content type from the :type key" do
|
|
@@ -186,12 +186,12 @@ describe "Koala::UploadableIO" do
|
|
|
186
186
|
@file_hash[:type] = expected_content_type
|
|
187
187
|
|
|
188
188
|
uploadable = Koala::UploadableIO.new(@file_hash)
|
|
189
|
-
uploadable.content_type.
|
|
189
|
+
expect(uploadable.content_type).to eq(expected_content_type)
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
it "gets the content type from the :type key" do
|
|
193
193
|
uploadable = Koala::UploadableIO.new(@file_hash)
|
|
194
|
-
uploadable.filename.
|
|
194
|
+
expect(uploadable.filename).to eq(@file_hash[:filename])
|
|
195
195
|
end
|
|
196
196
|
end
|
|
197
197
|
|
|
@@ -199,12 +199,12 @@ describe "Koala::UploadableIO" do
|
|
|
199
199
|
# what that means is tested below
|
|
200
200
|
it "should accept a file object alone" do
|
|
201
201
|
params = [BEACH_BALL_PATH]
|
|
202
|
-
|
|
202
|
+
expect { Koala::UploadableIO.new(*params) }.not_to raise_exception
|
|
203
203
|
end
|
|
204
204
|
|
|
205
205
|
it "should accept a file path alone" do
|
|
206
206
|
params = [BEACH_BALL_PATH]
|
|
207
|
-
|
|
207
|
+
expect { Koala::UploadableIO.new(*params) }.not_to raise_exception
|
|
208
208
|
end
|
|
209
209
|
end
|
|
210
210
|
end
|
|
@@ -212,20 +212,20 @@ describe "Koala::UploadableIO" do
|
|
|
212
212
|
describe "getting an UploadableIO" do
|
|
213
213
|
before(:each) do
|
|
214
214
|
@upload_io = double("UploadIO")
|
|
215
|
-
UploadIO.
|
|
215
|
+
allow(UploadIO).to receive(:new).with(anything, anything, anything).and_return(@upload_io)
|
|
216
216
|
end
|
|
217
217
|
|
|
218
218
|
context "if no filename was provided" do
|
|
219
219
|
it "should call the constructor with the content type, file name, and a dummy file name" do
|
|
220
|
-
UploadIO.
|
|
221
|
-
Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type").to_upload_io.
|
|
220
|
+
expect(UploadIO).to receive(:new).with(BEACH_BALL_PATH, "content/type", anything).and_return(@upload_io)
|
|
221
|
+
expect(Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type").to_upload_io).to eq(@upload_io)
|
|
222
222
|
end
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
context "if a filename was provided" do
|
|
226
226
|
it "should call the constructor with the content type, file name, and the filename" do
|
|
227
227
|
filename = "file"
|
|
228
|
-
UploadIO.
|
|
228
|
+
expect(UploadIO).to receive(:new).with(BEACH_BALL_PATH, "content/type", filename).and_return(@upload_io)
|
|
229
229
|
Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type", filename).to_upload_io
|
|
230
230
|
end
|
|
231
231
|
end
|
|
@@ -234,33 +234,33 @@ describe "Koala::UploadableIO" do
|
|
|
234
234
|
describe "getting a file" do
|
|
235
235
|
it "returns the File if initialized with a file" do
|
|
236
236
|
f = File.new(BEACH_BALL_PATH)
|
|
237
|
-
Koala::UploadableIO.new(f).to_file.
|
|
237
|
+
expect(Koala::UploadableIO.new(f).to_file).to eq(f)
|
|
238
238
|
end
|
|
239
239
|
|
|
240
240
|
it "should open up and return a file corresponding to the path if io_or_path is a path" do
|
|
241
241
|
result = double("File")
|
|
242
|
-
File.
|
|
243
|
-
Koala::UploadableIO.new(BEACH_BALL_PATH).to_file.
|
|
242
|
+
expect(File).to receive(:open).with(BEACH_BALL_PATH).and_return(result)
|
|
243
|
+
expect(Koala::UploadableIO.new(BEACH_BALL_PATH).to_file).to eq(result)
|
|
244
244
|
end
|
|
245
245
|
end
|
|
246
246
|
|
|
247
247
|
describe ".binary_content?" do
|
|
248
248
|
it "returns true for Rails 3 file uploads" do
|
|
249
|
-
Koala::UploadableIO.binary_content?(rails_3_mocks.last).
|
|
249
|
+
expect(Koala::UploadableIO.binary_content?(rails_3_mocks.last)).to be_truthy
|
|
250
250
|
end
|
|
251
251
|
|
|
252
252
|
it "returns true for Sinatra file uploads" do
|
|
253
|
-
Koala::UploadableIO.binary_content?(rails_3_mocks.last).
|
|
253
|
+
expect(Koala::UploadableIO.binary_content?(rails_3_mocks.last)).to be_truthy
|
|
254
254
|
end
|
|
255
255
|
|
|
256
256
|
it "returns true for File objects" do
|
|
257
|
-
Koala::UploadableIO.binary_content?(File.open(BEACH_BALL_PATH)).
|
|
257
|
+
expect(Koala::UploadableIO.binary_content?(File.open(BEACH_BALL_PATH))).to be_truthy
|
|
258
258
|
end
|
|
259
259
|
|
|
260
260
|
it "returns false for everything else" do
|
|
261
|
-
Koala::UploadableIO.binary_content?(StringIO.new).
|
|
262
|
-
Koala::UploadableIO.binary_content?(BEACH_BALL_PATH).
|
|
263
|
-
Koala::UploadableIO.binary_content?(nil).
|
|
261
|
+
expect(Koala::UploadableIO.binary_content?(StringIO.new)).to be_falsey
|
|
262
|
+
expect(Koala::UploadableIO.binary_content?(BEACH_BALL_PATH)).to be_falsey
|
|
263
|
+
expect(Koala::UploadableIO.binary_content?(nil)).to be_falsey
|
|
264
264
|
end
|
|
265
265
|
end
|
|
266
266
|
end # describe UploadableIO
|
data/spec/cases/utils_spec.rb
CHANGED
|
@@ -4,29 +4,29 @@ describe Koala::Utils do
|
|
|
4
4
|
describe ".deprecate" do
|
|
5
5
|
before :each do
|
|
6
6
|
# unstub deprecate so we can test it
|
|
7
|
-
|
|
7
|
+
allow(Koala::Utils).to receive(:deprecate).and_call_original
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it "has a deprecation prefix that includes the words Koala and deprecation" do
|
|
11
|
-
Koala::Utils::DEPRECATION_PREFIX.
|
|
12
|
-
Koala::Utils::DEPRECATION_PREFIX.
|
|
11
|
+
expect(Koala::Utils::DEPRECATION_PREFIX).to match(/koala/i)
|
|
12
|
+
expect(Koala::Utils::DEPRECATION_PREFIX).to match(/deprecation/i)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "prints a warning with Kernel.warn" do
|
|
16
16
|
message = Time.now.to_s + rand.to_s
|
|
17
|
-
Kernel.
|
|
17
|
+
expect(Kernel).to receive(:warn)
|
|
18
18
|
Koala::Utils.deprecate(message)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "prints the deprecation prefix and the warning" do
|
|
22
22
|
message = Time.now.to_s + rand.to_s
|
|
23
|
-
Kernel.
|
|
23
|
+
expect(Kernel).to receive(:warn).with(Koala::Utils::DEPRECATION_PREFIX + message)
|
|
24
24
|
Koala::Utils.deprecate(message)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "only prints each unique message once" do
|
|
28
28
|
message = Time.now.to_s + rand.to_s
|
|
29
|
-
Kernel.
|
|
29
|
+
expect(Kernel).to receive(:warn).once
|
|
30
30
|
Koala::Utils.deprecate(message)
|
|
31
31
|
Koala::Utils.deprecate(message)
|
|
32
32
|
end
|
|
@@ -34,20 +34,20 @@ describe Koala::Utils do
|
|
|
34
34
|
|
|
35
35
|
describe ".logger" do
|
|
36
36
|
it "has an accessor for logger" do
|
|
37
|
-
Koala::Utils.methods.map(&:to_sym).
|
|
38
|
-
Koala::Utils.methods.map(&:to_sym).
|
|
37
|
+
expect(Koala::Utils.methods.map(&:to_sym)).to include(:logger)
|
|
38
|
+
expect(Koala::Utils.methods.map(&:to_sym)).to include(:logger=)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "defaults to the standard ruby logger with level set to ERROR" do |variable|
|
|
42
|
-
Koala::Utils.logger.
|
|
43
|
-
Koala::Utils.logger.level.
|
|
42
|
+
expect(Koala::Utils.logger).to be_kind_of(Logger)
|
|
43
|
+
expect(Koala::Utils.logger.level).to eq(Logger::ERROR)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
logger_methods = [:debug, :info, :warn, :error, :fatal]
|
|
47
47
|
|
|
48
48
|
logger_methods.each do |logger_method|
|
|
49
49
|
it "should delegate #{logger_method} to the attached logger" do
|
|
50
|
-
Koala::Utils.logger.
|
|
50
|
+
expect(Koala::Utils.logger).to receive(logger_method)
|
|
51
51
|
Koala::Utils.send(logger_method, "Test #{logger_method} message")
|
|
52
52
|
end
|
|
53
53
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
if RUBY_VERSION == '1.9.2' && RUBY_PATCHLEVEL < 290 && RUBY_ENGINE != "macruby"
|
|
2
|
-
# In Ruby 1.9.2 versions before patchlevel 290, the default Psych
|
|
3
|
-
# parser has an issue with YAML merge keys, which
|
|
4
|
-
# fixtures/mock_facebook_responses.yml relies heavily on.
|
|
5
|
-
#
|
|
6
|
-
# Anyone using an earlier version will see missing mock response
|
|
7
|
-
# errors when running the test suite similar to this:
|
|
8
|
-
#
|
|
9
|
-
# RuntimeError:
|
|
10
|
-
# Missing a mock response for graph_api: /me/videos: source=[FILE]: post: with_token
|
|
11
|
-
# API PATH: /me/videos?source=[FILE]&format=json&access_token=*
|
|
12
|
-
#
|
|
13
|
-
# For now, it seems the best fix is to just downgrade to the old syck YAML parser
|
|
14
|
-
# for these troubled versions.
|
|
15
|
-
#
|
|
16
|
-
# See https://github.com/tenderlove/psych/issues/8 for more details
|
|
17
|
-
YAML::ENGINE.yamler = 'syck'
|
|
18
|
-
end
|
|
19
|
-
|
|
20
1
|
# load the library
|
|
21
2
|
require 'koala'
|
|
22
3
|
|
|
@@ -7,14 +7,14 @@ RSpec::Matchers.define :match_url do |url|
|
|
|
7
7
|
original_query_hash = query_to_params(original_query_string)
|
|
8
8
|
|
|
9
9
|
# the base URLs need to match
|
|
10
|
-
base.
|
|
10
|
+
expect(base).to eq(original_base)
|
|
11
11
|
|
|
12
12
|
# the number of parameters should match (avoid one being a subset of the other)
|
|
13
|
-
query_hash.values.length.
|
|
13
|
+
expect(query_hash.values.length).to eq(original_query_hash.values.length)
|
|
14
14
|
|
|
15
15
|
# and ensure all the keys and values match
|
|
16
16
|
query_hash.each_pair do |key, value|
|
|
17
|
-
original_query_hash[key].
|
|
17
|
+
expect(original_query_hash[key]).to eq(value)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|