carrierwave_direct 0.0.13 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -1
  4. data/Changelog.md +130 -0
  5. data/Gemfile +1 -1
  6. data/README.md +82 -45
  7. data/carrierwave_direct.gemspec +3 -4
  8. data/gemfiles/3.2.gemfile +13 -0
  9. data/gemfiles/4.0.gemfile +13 -0
  10. data/gemfiles/4.1.gemfile +13 -0
  11. data/lib/carrierwave_direct/form_builder.rb +48 -11
  12. data/lib/carrierwave_direct/locale/nl.yml +9 -0
  13. data/lib/carrierwave_direct/mount.rb +16 -4
  14. data/lib/carrierwave_direct/orm/activerecord.rb +4 -4
  15. data/lib/carrierwave_direct/test/capybara_helpers.rb +7 -5
  16. data/lib/carrierwave_direct/uploader/configuration.rb +4 -2
  17. data/lib/carrierwave_direct/uploader/content_type.rb +28 -0
  18. data/lib/carrierwave_direct/uploader/direct_url.rb +15 -0
  19. data/lib/carrierwave_direct/uploader.rb +79 -68
  20. data/lib/carrierwave_direct/validations/active_model.rb +5 -4
  21. data/lib/carrierwave_direct/version.rb +1 -1
  22. data/lib/carrierwave_direct.rb +6 -8
  23. data/spec/action_view_extensions/form_helper_spec.rb +4 -5
  24. data/spec/data/sample_data.rb +41 -0
  25. data/spec/form_builder_spec.rb +139 -6
  26. data/spec/mount_spec.rb +13 -26
  27. data/spec/orm/activerecord_spec.rb +69 -19
  28. data/spec/spec_helper.rb +16 -2
  29. data/spec/support/form_builder_helpers.rb +1 -0
  30. data/spec/support/model_helpers.rb +7 -7
  31. data/spec/support/view_helpers.rb +12 -2
  32. data/spec/test/capybara_helpers_spec.rb +28 -26
  33. data/spec/test/helpers_spec.rb +9 -11
  34. data/spec/uploader/configuration_spec.rb +46 -0
  35. data/spec/uploader/content_type_spec.rb +40 -0
  36. data/spec/uploader/direct_url_spec.rb +26 -0
  37. data/spec/uploader_spec.rb +145 -184
  38. metadata +40 -39
@@ -1,87 +1,25 @@
1
1
  # encoding: utf-8
2
-
3
2
  require 'spec_helper'
3
+ require 'data/sample_data'
4
4
 
5
5
  describe CarrierWaveDirect::Uploader do
6
6
  include UploaderHelpers
7
7
  include ModelHelpers
8
8
 
9
- SAMPLE_DATA = {
10
- :path => "upload_dir/bliind.exe",
11
- :path_with_special_chars => "upload_dir/some file & blah.exe",
12
- :key => "some key",
13
- :guid => "guid",
14
- :store_dir => "store_dir",
15
- :extension_regexp => "(avi)",
16
- :url => "http://example.com/some_url",
17
- :expiration => 60,
18
- :min_file_size => 1024,
19
- :max_file_size => 10485760,
20
- :file_url => "http://anyurl.com/any_path/video_dir/filename.avi",
21
- :mounted_model_name => "Porno",
22
- :mounted_as => :video,
23
- :filename => "filename",
24
- :extension => ".avi",
25
- :version => :thumb,
26
- :s3_bucket_url => "https://s3-bucket.s3.amazonaws.com"
27
- }
28
-
29
- SAMPLE_DATA.merge!(
30
- :stored_filename_base => "#{sample(:guid)}/#{sample(:filename)}"
31
- )
32
-
33
- SAMPLE_DATA.merge!(
34
- :stored_filename => "#{sample(:stored_filename_base)}#{sample(:extension)}",
35
- :stored_version_filename => "#{sample(:stored_filename_base)}_#{sample(:version)}#{sample(:extension)}"
36
- )
37
-
38
- SAMPLE_DATA.merge!(
39
- :s3_key => "#{sample(:store_dir)}/#{sample(:stored_filename)}"
40
- )
41
-
42
- SAMPLE_DATA.merge!(
43
- :s3_file_url => "#{sample(:s3_bucket_url)}/#{sample(:s3_key)}"
44
- )
45
-
46
- SAMPLE_DATA.freeze
47
-
48
9
  let(:subject) { DirectUploader.new }
49
- let(:mounted_model) { mock(sample(:mounted_model_name)) }
10
+ let(:mounted_model) { double(sample(:mounted_model_name), video_identifier: sample(:stored_filename)) }
50
11
  let(:mounted_subject) { DirectUploader.new(mounted_model, sample(:mounted_as)) }
51
12
  let(:direct_subject) { DirectUploader.new }
52
13
 
53
- describe ".upload_expiration" do
54
- it "should be 10 hours" do
55
- subject.class.upload_expiration.should == 36000
56
- end
57
- end
58
-
59
- describe ".min_file_size" do
60
- it "should be 1 byte" do
61
- subject.class.min_file_size.should == 1
62
- end
63
- end
64
-
65
- describe ".max_file_size" do
66
- it "should be 5 MB" do
67
- subject.class.max_file_size.should == 5242880
68
- end
69
- end
70
-
71
- describe ".use_action_status" do
72
- it "should be false" do
73
- subject.class.use_action_status.should be_false
74
- end
75
- end
76
14
 
77
15
  DirectUploader.fog_credentials.keys.each do |key|
78
16
  describe "##{key}" do
79
17
  it "should return the #{key.to_s.capitalize}" do
80
- subject.send(key).should == DirectUploader.fog_credentials[key]
18
+ expect(subject.send(key)).to eq subject.class.fog_credentials[key]
81
19
  end
82
20
 
83
21
  it "should not be nil" do
84
- subject.send(key).should_not be_nil
22
+ expect(subject.send(key)).to_not be_nil
85
23
  end
86
24
  end
87
25
  end
@@ -93,13 +31,13 @@ describe CarrierWaveDirect::Uploader do
93
31
  before { subject.key = sample(:key) }
94
32
 
95
33
  it "should set the key" do
96
- subject.key.should == sample(:key)
34
+ expect(subject.key).to eq sample(:key)
97
35
  end
98
36
 
99
37
  context "the versions keys" do
100
38
  it "should == this subject's key" do
101
39
  subject.versions.each do |name, version_subject|
102
- version_subject.key.should == subject.key
40
+ expect(version_subject.key).to eq subject.key
103
41
  end
104
42
  end
105
43
  end
@@ -112,39 +50,40 @@ describe CarrierWaveDirect::Uploader do
112
50
  end
113
51
 
114
52
  it "should return '*/\#\{guid\}/${filename}'" do
115
- mounted_subject.key.should =~ /#{GUID_REGEXP}\/\$\{filename\}$/
53
+ expect(mounted_subject.key).to match /#{GUID_REGEXP}\/\$\{filename\}$/
116
54
  end
117
55
 
118
56
  context "and #store_dir returns '#{sample(:store_dir)}'" do
119
57
  before do
120
- mounted_subject.stub(:store_dir).and_return(sample(:store_dir))
58
+ allow(mounted_subject).to receive(:store_dir).and_return(sample(:store_dir))
121
59
  end
122
60
 
123
61
  it "should return '#{sample(:store_dir)}/\#\{guid\}/${filename}'" do
124
- mounted_subject.key.should =~ /^#{sample(:store_dir)}\/#{GUID_REGEXP}\/\$\{filename\}$/
62
+ expect(mounted_subject.key).to match /^#{sample(:store_dir)}\/#{GUID_REGEXP}\/\$\{filename\}$/
125
63
  end
126
64
  end
127
65
 
128
66
  context "and the uploaders url is #default_url" do
129
67
  it "should return '*/\#\{guid\}/${filename}'" do
130
- mounted_subject.stub(:url).and_return(sample(:s3_file_url))
131
- mounted_subject.stub(:present?).and_return(false)
132
- mounted_subject.key.should =~ /#{GUID_REGEXP}\/\$\{filename\}$/
68
+ allow(mounted_subject).to receive(:url).and_return(sample(:s3_file_url))
69
+ allow(mounted_subject).to receive(:present?).and_return(false)
70
+ expect(mounted_subject.key).to match /#{GUID_REGEXP}\/\$\{filename\}$/
133
71
  end
134
72
  end
135
73
 
136
74
  context "but the uploaders url is '#{sample(:s3_file_url)}'" do
137
75
  before do
138
- mounted_subject.stub(:url).and_return(sample(:s3_file_url))
139
- mounted_subject.stub(:present?).and_return(true)
76
+ allow(mounted_subject).to receive(:store_dir).and_return(sample(:store_dir))
77
+ allow(mounted_subject).to receive(:url).and_return(sample(:s3_file_url))
78
+ allow(mounted_subject).to receive(:present?).and_return(true)
140
79
  end
141
80
 
142
81
  it "should return '#{sample(:s3_key)}'" do
143
- mounted_subject.key.should == sample(:s3_key)
82
+ expect(mounted_subject.key).to eq sample(:s3_key)
144
83
  end
145
84
 
146
85
  it "should set the key explicitly in order to update the version keys" do
147
- mounted_subject.should_receive("key=").with(sample(:s3_key))
86
+ expect(mounted_subject).to receive("key=").with(sample(:s3_key))
148
87
  mounted_subject.key
149
88
  end
150
89
  end
@@ -154,34 +93,35 @@ describe CarrierWaveDirect::Uploader do
154
93
  before { subject.key = sample(:key) }
155
94
 
156
95
  it "should return '#{sample(:key)}'" do
157
- subject.key.should == sample(:key)
96
+ expect(subject.key).to eq sample(:key)
158
97
  end
159
98
  end
160
99
  end
161
100
 
162
101
  describe "#url_scheme_white_list" do
163
102
  it "should return nil" do
164
- subject.url_scheme_white_list.should be_nil
103
+ expect(subject.url_scheme_white_list).to be_nil
165
104
  end
166
105
  end
167
106
 
168
107
  describe "#key_regexp" do
169
108
  it "should return a regexp" do
170
- subject.key_regexp.should be_a(Regexp)
109
+ expect(subject.key_regexp).to be_a(Regexp)
171
110
  end
172
111
 
173
112
  context "where #store_dir returns '#{sample(:store_dir)}'" do
174
113
  before do
175
- subject.stub(:store_dir).and_return(sample(:store_dir))
114
+ allow(subject).to receive(:store_dir).and_return(sample(:store_dir))
115
+ allow(subject).to receive(:cache_dir).and_return(sample(:cache_dir))
176
116
  end
177
117
 
178
118
  context "and #extension_regexp returns '#{sample(:extension_regexp)}'" do
179
119
  before do
180
- subject.stub(:extension_regexp).and_return(sample(:extension_regexp))
120
+ allow(subject).to receive(:extension_regexp).and_return(sample(:extension_regexp))
181
121
  end
182
122
 
183
- it "should return /\\A#{sample(:store_dir)}\\/#{GUID_REGEXP}\\/.+\\.#{sample(:extension_regexp)}\\z/" do
184
- subject.key_regexp.should == /\A#{sample(:store_dir)}\/#{GUID_REGEXP}\/.+\.(?i)#{sample(:extension_regexp)}(?-i)\z/
123
+ it "should return /\\A(#{sample(:store_dir)}|#{sample(:cache_dir)})\\/#{GUID_REGEXP}\\/.+\\.#{sample(:extension_regexp)}\\z/" do
124
+ expect(subject.key_regexp).to eq /\A(#{sample(:store_dir)}|#{sample(:cache_dir)})\/#{GUID_REGEXP}\/.+\.(?i)#{sample(:extension_regexp)}(?-i)\z/
185
125
  end
186
126
  end
187
127
  end
@@ -190,17 +130,17 @@ describe CarrierWaveDirect::Uploader do
190
130
  describe "#extension_regexp" do
191
131
  shared_examples_for "a globally allowed file extension" do
192
132
  it "should return '\\w+'" do
193
- subject.extension_regexp.should == "\\w+"
133
+ expect(subject.extension_regexp).to eq "\\w+"
194
134
  end
195
135
  end
196
136
 
197
137
  it "should return a string" do
198
- subject.extension_regexp.should be_a(String)
138
+ expect(subject.extension_regexp).to be_a(String)
199
139
  end
200
140
 
201
141
  context "where #extension_white_list returns nil" do
202
142
  before do
203
- subject.stub(:extension_white_list).and_return(nil)
143
+ allow(subject).to receive(:extension_white_list).and_return(nil)
204
144
  end
205
145
 
206
146
  it_should_behave_like "a globally allowed file extension"
@@ -208,7 +148,7 @@ describe CarrierWaveDirect::Uploader do
208
148
 
209
149
  context "where #extension_white_list returns []" do
210
150
  before do
211
- subject.stub(:extension_white_list).and_return([])
151
+ allow(subject).to receive(:extension_white_list).and_return([])
212
152
  end
213
153
 
214
154
  it_should_behave_like "a globally allowed file extension"
@@ -217,11 +157,11 @@ describe CarrierWaveDirect::Uploader do
217
157
  context "where #extension_white_list returns ['exe', 'bmp']" do
218
158
 
219
159
  before do
220
- subject.stub(:extension_white_list).and_return(%w{exe bmp})
160
+ allow(subject).to receive(:extension_white_list).and_return(%w{exe bmp})
221
161
  end
222
162
 
223
163
  it "should return '(exe|bmp)'" do
224
- subject.extension_regexp.should == "(exe|bmp)"
164
+ expect(subject.extension_regexp).to eq "(exe|bmp)"
225
165
  end
226
166
  end
227
167
  end
@@ -230,7 +170,7 @@ describe CarrierWaveDirect::Uploader do
230
170
  context "a key has not been set" do
231
171
 
232
172
  it "should return false" do
233
- subject.should_not have_key
173
+ expect(subject).to_not have_key
234
174
  end
235
175
  end
236
176
 
@@ -238,7 +178,7 @@ describe CarrierWaveDirect::Uploader do
238
178
  before { subject.key }
239
179
 
240
180
  it "should return false" do
241
- subject.should_not have_key
181
+ expect(subject).to_not have_key
242
182
  end
243
183
  end
244
184
 
@@ -246,47 +186,14 @@ describe CarrierWaveDirect::Uploader do
246
186
  before { subject.key = sample_key }
247
187
 
248
188
  it "should return true" do
249
- subject.should have_key
250
- end
251
- end
252
- end
253
-
254
- describe "#direct_fog_url" do
255
- it "should return the result from CarrierWave::Storage::Fog::File#public_url" do
256
- subject.direct_fog_url.should == CarrierWave::Storage::Fog::File.new(
257
- subject, nil, nil
258
- ).public_url
259
- end
260
-
261
- context ":with_path => true" do
262
-
263
- context "#key is set to '#{sample(:path_with_special_chars)}'" do
264
- before { subject.key = sample(:path_with_special_chars) }
265
-
266
- it "should return the full url with '/#{URI.escape(sample(:path_with_special_chars))}' as the path" do
267
- direct_fog_url = CarrierWave::Storage::Fog::File.new(
268
- subject, nil, nil
269
- ).public_url
270
- subject.direct_fog_url(:with_path => true).should == direct_fog_url + "#{URI.escape(sample(:path_with_special_chars))}"
271
- end
272
- end
273
-
274
- context "#key is set to '#{sample(:path)}'" do
275
- before { subject.key = sample(:path) }
276
-
277
- it "should return the full url with '/#{sample(:path)}' as the path" do
278
- direct_fog_url = CarrierWave::Storage::Fog::File.new(
279
- subject, nil, nil
280
- ).public_url
281
- subject.direct_fog_url(:with_path => true).should == direct_fog_url + "#{sample(:path)}"
282
- end
189
+ expect(subject).to have_key
283
190
  end
284
191
  end
285
192
  end
286
193
 
287
194
  describe "#persisted?" do
288
195
  it "should return false" do
289
- subject.should_not be_persisted
196
+ expect(subject).to_not be_persisted
290
197
  end
291
198
  end
292
199
 
@@ -295,7 +202,7 @@ describe CarrierWaveDirect::Uploader do
295
202
  before { mounted_subject.key = sample(:s3_key) }
296
203
 
297
204
  it "should return '#{sample(:stored_filename)}'" do
298
- mounted_subject.filename.should == sample(:stored_filename)
205
+ expect(mounted_subject.filename).to eq sample(:stored_filename)
299
206
  end
300
207
  end
301
208
 
@@ -303,7 +210,7 @@ describe CarrierWaveDirect::Uploader do
303
210
  before { subject.key = sample(:key) }
304
211
 
305
212
  it "should return '#{sample(:key)}'" do
306
- subject.filename.should == sample(:key)
213
+ expect(subject.filename).to eq sample(:key)
307
214
  end
308
215
  end
309
216
 
@@ -311,51 +218,51 @@ describe CarrierWaveDirect::Uploader do
311
218
  context "but the model's remote #{sample(:mounted_as)} url is: '#{sample(:file_url)}'" do
312
219
 
313
220
  before do
314
- mounted_subject.model.stub(
221
+ allow(mounted_subject.model).to receive(
315
222
  "remote_#{mounted_subject.mounted_as}_url"
316
223
  ).and_return(sample(:file_url))
317
224
  end
318
225
 
319
226
  it "should set the key to contain '#{File.basename(sample(:file_url))}'" do
320
227
  mounted_subject.filename
321
- mounted_subject.key.should =~ /#{Regexp.escape(File.basename(sample(:file_url)))}$/
228
+ expect(mounted_subject.key).to match /#{Regexp.escape(File.basename(sample(:file_url)))}$/
322
229
  end
323
230
 
324
231
  it "should return a filename based off the key and remote url" do
325
232
  filename = mounted_subject.filename
326
- mounted_subject.key.should =~ /#{Regexp.escape(filename)}$/
233
+ expect(mounted_subject.key).to match /#{Regexp.escape(filename)}$/
327
234
  end
328
235
 
329
236
  # this ensures that the version subject keys are updated
330
237
  # see spec for key= for more details
331
238
  it "should set the key explicitly" do
332
- mounted_subject.should_receive(:key=)
239
+ expect(mounted_subject).to receive(:key=)
333
240
  mounted_subject.filename
334
241
  end
335
242
  end
336
243
 
337
- context "and the model's remote #{sample(:mounted_as)} url has whitespace in it" do
244
+ context "and the model's remote #{sample(:mounted_as)} url has special characters in it" do
338
245
  before do
339
- mounted_model.stub(
246
+ allow(mounted_model).to receive(
340
247
  "remote_#{mounted_subject.mounted_as}_url"
341
- ).and_return("http://anyurl.com/any_path/video_dir/filename 2.avi")
248
+ ).and_return("http://anyurl.com/any_path/video_dir/filename ()+[]2.avi")
342
249
  end
343
250
 
344
- it "should be sanitized (whitespace replaced with _)" do
251
+ it "should be sanitized (special characters replaced with _)" do
345
252
  mounted_subject.filename
346
- mounted_subject.key.should =~ /filename_2.avi$/
253
+ expect(mounted_subject.key).to match /filename___\+__2.avi$/
347
254
  end
348
255
  end
349
256
 
350
257
  context "and the model's remote #{sample(:mounted_as)} url is blank" do
351
258
  before do
352
- mounted_model.stub(
259
+ allow(mounted_model).to receive(
353
260
  "remote_#{mounted_subject.mounted_as}_url"
354
261
  ).and_return nil
355
262
  end
356
263
 
357
264
  it "should return nil" do
358
- mounted_subject.filename.should be_nil
265
+ expect(mounted_subject.filename).to be_nil
359
266
  end
360
267
  end
361
268
  end
@@ -363,23 +270,52 @@ describe CarrierWaveDirect::Uploader do
363
270
 
364
271
  describe "#acl" do
365
272
  it "should return the correct s3 access policy" do
366
- subject.acl.should == (subject.fog_public ? 'public-read' : 'private')
273
+ expect(subject.acl).to eq (subject.fog_public ? 'public-read' : 'private')
367
274
  end
368
275
  end
369
276
 
370
277
  # http://aws.amazon.com/articles/1434?_encoding=UTF8
371
278
  describe "#policy" do
372
- def decoded_policy(options = {})
279
+
280
+
281
+ def decoded_policy(options = {}, &block)
373
282
  instance = options.delete(:subject) || subject
374
- JSON.parse(Base64.decode64(instance.policy(options)))
283
+ JSON.parse(Base64.decode64(instance.policy(options, &block)))
284
+ end
285
+
286
+ context "policy is given a block" do
287
+ it "should yield the options to the block" do
288
+ number = 0
289
+ subject.policy do |conditions|
290
+ number+=1
291
+ end
292
+ expect(number).to eq 1
293
+ end
294
+ it "should include new options in the conditions" do
295
+ policy = subject.policy do |conditions|
296
+ conditions << {"x-aws-storage-class" => "STANDARD"}
297
+ end
298
+ decoded = JSON.parse(Base64.decode64(policy))
299
+ expect(decoded['conditions'].last['x-aws-storage-class']).to eq "STANDARD"
300
+ end
375
301
  end
376
302
 
377
303
  it "should return Base64-encoded JSON" do
378
- decoded_policy.should be_a(Hash)
304
+ expect(decoded_policy).to be_a(Hash)
379
305
  end
380
306
 
381
307
  it "should not contain any new lines" do
382
- subject.policy.should_not include("\n")
308
+ expect(subject.policy).to_not include("\n")
309
+ end
310
+
311
+ it "should be cached" do
312
+ Timecop.freeze(Time.now) do
313
+ @policy_now = subject.policy
314
+ end
315
+ Timecop.freeze(1.second.from_now) do
316
+ @policy_later = subject.policy
317
+ end
318
+ expect(@policy_later).to eql @policy_now
383
319
  end
384
320
 
385
321
  context "expiration" do
@@ -387,29 +323,30 @@ describe CarrierWaveDirect::Uploader do
387
323
  decoded_policy(options)["expiration"]
388
324
  end
389
325
 
326
+ # JSON times have no seconds, so accept upto one second inaccuracy
390
327
  def have_expiration(expires_in = DirectUploader.upload_expiration)
391
- eql(
392
- Time.parse(
393
- JSON.parse({
394
- "expiry" => Time.now + expires_in
395
- }.to_json)["expiry"]
396
- )
397
- )
328
+ be_within(1.second).of (Time.now + expires_in)
329
+ end
330
+
331
+ it "should be valid ISO8601 and not use default Time#to_json" do
332
+ Time.any_instance.stub(:to_json) { '"Invalid time"' } # JSON gem
333
+ Time.any_instance.stub(:as_json) { '"Invalid time"' } # Active Support
334
+ expect { Time.iso8601(expiration) }.to_not raise_error
398
335
  end
399
336
 
400
337
  it "should be #{DirectUploader.upload_expiration / 3600} hours from now" do
401
338
  Timecop.freeze(Time.now) do
402
- Time.parse(expiration).should have_expiration
339
+ expect(Time.parse(expiration)).to have_expiration
403
340
  end
404
341
  end
405
342
 
406
343
  it "should be encoded as a utc time" do
407
- Time.parse(expiration).should be_utc
344
+ expect(Time.parse(expiration)).to be_utc
408
345
  end
409
346
 
410
347
  it "should be #{sample(:expiration) / 60 } minutes from now when passing {:expiration => #{sample(:expiration)}}" do
411
348
  Timecop.freeze(Time.now) do
412
- Time.parse(expiration(:expiration => sample(:expiration))).should have_expiration(sample(:expiration))
349
+ expect(Time.parse(expiration(:expiration => sample(:expiration)))).to have_expiration(sample(:expiration))
413
350
  end
414
351
  end
415
352
  end
@@ -424,40 +361,49 @@ describe CarrierWaveDirect::Uploader do
424
361
  end
425
362
 
426
363
  context "should include" do
427
- # Rails form builder conditions
428
- it "'utf8'" do
429
- conditions.should have_condition(:utf8)
364
+ it "'utf8' if enforce_ut8 is set" do
365
+ expect(conditions(enforce_utf8: true)).to have_condition(:utf8)
366
+ end
367
+
368
+ it "'utf8' if enforce_ut8 is set" do
369
+ expect(conditions).to_not have_condition(:utf8)
430
370
  end
431
371
 
432
372
  # S3 conditions
433
373
  it "'key'" do
434
- mounted_subject.stub(:key).and_return(sample(:s3_key))
435
- conditions(
374
+ allow(mounted_subject).to receive(:key).and_return(sample(:s3_key))
375
+ expect(conditions(
436
376
  :subject => mounted_subject
437
- ).should have_condition(:key, sample(:s3_key))
377
+ )).to have_condition(:key, sample(:s3_key))
438
378
  end
439
379
 
440
380
  it "'key' without FILENAME_WILDCARD" do
441
- conditions(
381
+ expect(conditions(
442
382
  :subject => mounted_subject
443
- ).should have_condition(:key, mounted_subject.key.sub("${filename}", ""))
383
+ )).to have_condition(:key, mounted_subject.key.sub("${filename}", ""))
444
384
  end
445
385
 
446
386
  it "'bucket'" do
447
- conditions.should have_condition("bucket" => subject.fog_directory)
387
+ expect(conditions).to have_condition("bucket" => subject.fog_directory)
448
388
  end
449
389
 
450
390
  it "'acl'" do
451
- conditions.should have_condition("acl" => subject.acl)
391
+ expect(conditions).to have_condition("acl" => subject.acl)
452
392
  end
453
393
 
454
394
  it "'success_action_redirect'" do
455
395
  subject.success_action_redirect = "http://example.com/some_url"
456
- conditions.should have_condition("success_action_redirect" => "http://example.com/some_url")
396
+ expect(conditions).to have_condition("success_action_redirect" => "http://example.com/some_url")
457
397
  end
458
398
 
459
- it "'content-type' only if enabled" do
460
- conditions.should have_condition('Content-Type') if subject.class.will_include_content_type
399
+ it "does not have 'content-type' when will_include_content_type is false" do
400
+ allow(subject.class).to receive(:will_include_content_type).and_return(false)
401
+ expect(conditions).to_not have_condition('Content-Type')
402
+ end
403
+
404
+ it "has 'content-type' when will_include_content_type is true" do
405
+ allow(subject.class).to receive(:will_include_content_type).and_return(true)
406
+ expect(conditions).to have_condition('Content-Type')
461
407
  end
462
408
 
463
409
  context 'when use_action_status is true' do
@@ -471,12 +417,12 @@ describe CarrierWaveDirect::Uploader do
471
417
 
472
418
  it "'success_action_status'" do
473
419
  subject.success_action_status = '200'
474
- conditions.should have_condition("success_action_status" => "200")
420
+ expect(conditions).to have_condition("success_action_status" => "200")
475
421
  end
476
422
 
477
423
  it "does not have 'success_action_redirect'" do
478
424
  subject.success_action_redirect = "http://example.com/some_url"
479
- conditions.should_not have_condition("success_action_redirect" => "http://example.com/some_url")
425
+ expect(conditions).to_not have_condition("success_action_redirect" => "http://example.com/some_url")
480
426
  end
481
427
  end
482
428
 
@@ -490,53 +436,68 @@ describe CarrierWaveDirect::Uploader do
490
436
  end
491
437
 
492
438
  it "#{DirectUploader.min_file_size} bytes" do
493
- conditions.should have_content_length_range
439
+ expect(conditions).to have_content_length_range
494
440
  end
495
441
 
496
442
  it "#{DirectUploader.max_file_size} bytes" do
497
- conditions.should have_content_length_range
443
+ expect(conditions).to have_content_length_range
498
444
  end
499
445
 
500
446
  it "#{sample(:min_file_size)} bytes when passing {:min_file_size => #{sample(:min_file_size)}}" do
501
- conditions(
447
+ expect(conditions(
502
448
  :min_file_size => sample(:min_file_size)
503
- ).should have_content_length_range(:min_file_size => sample(:min_file_size))
449
+ )).to have_content_length_range(:min_file_size => sample(:min_file_size))
504
450
  end
505
451
 
506
452
  it "#{sample(:max_file_size)} bytes when passing {:max_file_size => #{sample(:max_file_size)}}" do
507
- conditions(
453
+ expect(conditions(
508
454
  :max_file_size => sample(:max_file_size)
509
- ).should have_content_length_range(:max_file_size => sample(:max_file_size))
455
+ )).to have_content_length_range(:max_file_size => sample(:max_file_size))
510
456
  end
511
457
  end
512
458
  end
513
459
  end
514
460
  end
515
461
 
462
+ describe "clear_policy!" do
463
+ it "should reset the cached policy string" do
464
+ Timecop.freeze(Time.now) do
465
+ @policy_now = subject.policy
466
+ end
467
+ subject.clear_policy!
468
+
469
+ Timecop.freeze(1.second.from_now) do
470
+ @policy_after_reset = subject.policy
471
+ end
472
+ expect(@policy_after_reset).not_to eql @policy_now
473
+ end
474
+ end
475
+
516
476
  describe "#signature" do
517
477
  it "should not contain any new lines" do
518
- subject.signature.should_not include("\n")
478
+ expect(subject.signature).to_not include("\n")
519
479
  end
520
480
 
521
481
  it "should return a base64 encoded 'sha1' hash of the secret key and policy document" do
522
- Base64.decode64(subject.signature).should == OpenSSL::HMAC.digest(
523
- OpenSSL::Digest::Digest.new('sha1'),
482
+ expect(Base64.decode64(subject.signature)).to eq OpenSSL::HMAC.digest(
483
+ OpenSSL::Digest.new('sha1'),
524
484
  subject.aws_secret_access_key, subject.policy
525
485
  )
526
486
  end
527
487
  end
528
488
 
489
+
529
490
  # note that 'video' is hardcoded into the MountedClass support file
530
491
  # so changing the sample will cause the tests to fail
531
492
  context "a class has a '#{sample(:mounted_as)}' mounted" do
532
493
  describe "#{sample(:mounted_as).to_s.capitalize}Uploader" do
533
494
  describe "##{sample(:mounted_as)}" do
534
495
  it "should be defined" do
535
- direct_subject.should be_respond_to(sample(:mounted_as))
496
+ expect(direct_subject).to be_respond_to(sample(:mounted_as))
536
497
  end
537
498
 
538
499
  it "should return itself" do
539
- direct_subject.send(sample(:mounted_as)).should == direct_subject
500
+ expect(direct_subject.send(sample(:mounted_as))).to eq direct_subject
540
501
  end
541
502
  end
542
503
 
@@ -556,11 +517,11 @@ describe CarrierWaveDirect::Uploader do
556
517
  let(:store_path) { video_subject.send(sample(:version)).store_path }
557
518
 
558
519
  it "should be like '#{sample(:stored_version_filename)}'" do
559
- store_path.should =~ /#{sample(:stored_version_filename)}$/
520
+ expect(store_path).to match /#{sample(:stored_version_filename)}$/
560
521
  end
561
522
 
562
523
  it "should not be like '#{sample(:version)}_#{sample(:stored_filename_base)}'" do
563
- store_path.should_not =~ /#{sample(:version)}_#{sample(:stored_filename_base)}/
524
+ expect(store_path).to_not match /#{sample(:version)}_#{sample(:stored_filename_base)}/
564
525
  end
565
526
  end
566
527
  end