dsturnbull-carrierwave 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/Generators +4 -0
  2. data/History.txt +118 -0
  3. data/Manifest.txt +107 -0
  4. data/README.rdoc +502 -0
  5. data/Rakefile +38 -0
  6. data/cucumber.yml +2 -0
  7. data/features/caching.feature +28 -0
  8. data/features/download.feature +20 -0
  9. data/features/file_storage.feature +37 -0
  10. data/features/file_storage_overridden_filename.feature +38 -0
  11. data/features/file_storage_overridden_store_dir.feature +38 -0
  12. data/features/file_storage_reversing_processor.feature +43 -0
  13. data/features/fixtures/bork.txt +1 -0
  14. data/features/fixtures/monkey.txt +1 -0
  15. data/features/grid_fs_storage.feature +32 -0
  16. data/features/mount_activerecord.feature +46 -0
  17. data/features/mount_datamapper.feature +46 -0
  18. data/features/step_definitions/activerecord_steps.rb +22 -0
  19. data/features/step_definitions/caching_steps.rb +14 -0
  20. data/features/step_definitions/datamapper_steps.rb +29 -0
  21. data/features/step_definitions/download_steps.rb +4 -0
  22. data/features/step_definitions/file_steps.rb +53 -0
  23. data/features/step_definitions/general_steps.rb +85 -0
  24. data/features/step_definitions/mount_steps.rb +19 -0
  25. data/features/step_definitions/store_steps.rb +18 -0
  26. data/features/support/activerecord.rb +30 -0
  27. data/features/support/datamapper.rb +7 -0
  28. data/features/support/env.rb +22 -0
  29. data/features/versions_basics.feature +50 -0
  30. data/features/versions_nested_versions.feature +70 -0
  31. data/features/versions_overridden_filename.feature +51 -0
  32. data/features/versions_overriden_store_dir.feature +41 -0
  33. data/lib/carrierwave/compatibility/paperclip.rb +95 -0
  34. data/lib/carrierwave/core_ext/blank.rb +46 -0
  35. data/lib/carrierwave/core_ext/inheritable_attributes.rb +104 -0
  36. data/lib/carrierwave/core_ext/module_setup.rb +51 -0
  37. data/lib/carrierwave/mount.rb +359 -0
  38. data/lib/carrierwave/orm/activerecord.rb +73 -0
  39. data/lib/carrierwave/orm/datamapper.rb +27 -0
  40. data/lib/carrierwave/orm/mongoid.rb +23 -0
  41. data/lib/carrierwave/orm/mongomapper.rb +27 -0
  42. data/lib/carrierwave/orm/sequel.rb +45 -0
  43. data/lib/carrierwave/processing/image_science.rb +101 -0
  44. data/lib/carrierwave/processing/mini_magick.rb +269 -0
  45. data/lib/carrierwave/processing/rmagick.rb +282 -0
  46. data/lib/carrierwave/sanitized_file.rb +268 -0
  47. data/lib/carrierwave/storage/abstract.rb +30 -0
  48. data/lib/carrierwave/storage/file.rb +48 -0
  49. data/lib/carrierwave/storage/grid_fs.rb +96 -0
  50. data/lib/carrierwave/storage/right_s3.rb +170 -0
  51. data/lib/carrierwave/storage/s3.rb +199 -0
  52. data/lib/carrierwave/test/matchers.rb +128 -0
  53. data/lib/carrierwave/uploader/cache.rb +145 -0
  54. data/lib/carrierwave/uploader/callbacks.rb +42 -0
  55. data/lib/carrierwave/uploader/configuration.rb +122 -0
  56. data/lib/carrierwave/uploader/default_url.rb +19 -0
  57. data/lib/carrierwave/uploader/download.rb +59 -0
  58. data/lib/carrierwave/uploader/extension_whitelist.rb +37 -0
  59. data/lib/carrierwave/uploader/mountable.rb +39 -0
  60. data/lib/carrierwave/uploader/processing.rb +83 -0
  61. data/lib/carrierwave/uploader/proxy.rb +62 -0
  62. data/lib/carrierwave/uploader/remove.rb +22 -0
  63. data/lib/carrierwave/uploader/store.rb +89 -0
  64. data/lib/carrierwave/uploader/url.rb +24 -0
  65. data/lib/carrierwave/uploader/versions.rb +146 -0
  66. data/lib/carrierwave/uploader.rb +44 -0
  67. data/lib/carrierwave.rb +96 -0
  68. data/merb_generators/uploader_generator.rb +22 -0
  69. data/rails_generators/uploader/USAGE +2 -0
  70. data/rails_generators/uploader/templates/uploader.rb +47 -0
  71. data/rails_generators/uploader/uploader_generator.rb +21 -0
  72. data/script/console +10 -0
  73. data/script/destroy +14 -0
  74. data/script/generate +14 -0
  75. data/spec/compatibility/paperclip_spec.rb +52 -0
  76. data/spec/fixtures/bork.txt +1 -0
  77. data/spec/fixtures/landscape.jpg +0 -0
  78. data/spec/fixtures/portrait.jpg +0 -0
  79. data/spec/fixtures/test.jpeg +1 -0
  80. data/spec/fixtures/test.jpg +1 -0
  81. data/spec/mount_spec.rb +538 -0
  82. data/spec/orm/activerecord_spec.rb +271 -0
  83. data/spec/orm/datamapper_spec.rb +168 -0
  84. data/spec/orm/mongoid_spec.rb +206 -0
  85. data/spec/orm/mongomapper_spec.rb +202 -0
  86. data/spec/orm/sequel_spec.rb +183 -0
  87. data/spec/processing/image_science_spec.rb +56 -0
  88. data/spec/processing/mini_magick_spec.rb +76 -0
  89. data/spec/processing/rmagick_spec.rb +75 -0
  90. data/spec/sanitized_file_spec.rb +601 -0
  91. data/spec/spec_helper.rb +99 -0
  92. data/spec/storage/grid_fs_spec.rb +82 -0
  93. data/spec/storage/right_s3_spec.rb +75 -0
  94. data/spec/storage/s3_spec.rb +95 -0
  95. data/spec/uploader/cache_spec.rb +209 -0
  96. data/spec/uploader/configuration_spec.rb +105 -0
  97. data/spec/uploader/default_url_spec.rb +85 -0
  98. data/spec/uploader/download_spec.rb +75 -0
  99. data/spec/uploader/extension_whitelist_spec.rb +44 -0
  100. data/spec/uploader/mountable_spec.rb +33 -0
  101. data/spec/uploader/paths_spec.rb +22 -0
  102. data/spec/uploader/processing_spec.rb +73 -0
  103. data/spec/uploader/proxy_spec.rb +54 -0
  104. data/spec/uploader/remove_spec.rb +70 -0
  105. data/spec/uploader/store_spec.rb +248 -0
  106. data/spec/uploader/url_spec.rb +87 -0
  107. data/spec/uploader/versions_spec.rb +298 -0
  108. metadata +351 -0
@@ -0,0 +1,601 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
+
5
+ describe CarrierWave::SanitizedFile do
6
+
7
+ before do
8
+ unless File.exists?(file_path('llama.jpg'))
9
+ FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg'))
10
+ end
11
+ end
12
+
13
+ after(:all) do
14
+ if File.exists?(file_path('llama.jpg'))
15
+ FileUtils.rm(file_path('llama.jpg'))
16
+ end
17
+ FileUtils.rm_rf(public_path)
18
+ end
19
+
20
+ describe '#empty?' do
21
+
22
+ it "should be empty for nil" do
23
+ @sanitized_file = CarrierWave::SanitizedFile.new(nil)
24
+ @sanitized_file.should be_empty
25
+ end
26
+
27
+ it "should be empty for an empty string" do
28
+ @sanitized_file = CarrierWave::SanitizedFile.new("")
29
+ @sanitized_file.should be_empty
30
+ end
31
+
32
+ it "should be empty for an empty StringIO" do
33
+ @sanitized_file = CarrierWave::SanitizedFile.new(StringIO.new(""))
34
+ @sanitized_file.should be_empty
35
+ end
36
+
37
+ it "should be empty for a file with a zero size" do
38
+ empty_file = mock('emptyfile')
39
+ empty_file.should_receive(:size).at_least(:once).and_return(0)
40
+ @sanitized_file = CarrierWave::SanitizedFile.new(empty_file)
41
+ @sanitized_file.should be_empty
42
+ end
43
+
44
+ end
45
+
46
+ describe '#original_filename' do
47
+ it "should default to the original_filename" do
48
+ file = mock('file', :original_filename => 'llama.jpg')
49
+ sanitized_file = CarrierWave::SanitizedFile.new(file)
50
+ sanitized_file.original_filename.should == "llama.jpg"
51
+ end
52
+
53
+ it "should defer to the base name of the path if original_filename is unavailable" do
54
+ file = mock('file', :path => '/path/to/test.jpg')
55
+ sanitized_file = CarrierWave::SanitizedFile.new(file)
56
+ sanitized_file.original_filename.should == "test.jpg"
57
+ end
58
+
59
+ it "should be nil otherwise" do
60
+ file = mock('file')
61
+ sanitized_file = CarrierWave::SanitizedFile.new(file)
62
+ sanitized_file.original_filename.should be_nil
63
+ end
64
+ end
65
+
66
+ describe '#basename' do
67
+ it "should return the basename for complicated extensions" do
68
+ @sanitized_file = CarrierWave::SanitizedFile.new(file_path('complex.filename.tar.gz'))
69
+ @sanitized_file.basename.should == "complex.filename"
70
+ end
71
+
72
+ it "should be the filename if the file has no extension" do
73
+ @sanitized_file = CarrierWave::SanitizedFile.new(file_path('complex'))
74
+ @sanitized_file.basename.should == "complex"
75
+ end
76
+ end
77
+
78
+ describe '#extension' do
79
+ it "should return the extension for complicated extensions" do
80
+ @sanitized_file = CarrierWave::SanitizedFile.new(file_path('complex.filename.tar.gz'))
81
+ @sanitized_file.extension.should == "tar.gz"
82
+ end
83
+
84
+ it "should return the extension for real-world user file names" do
85
+ @sanitized_file = CarrierWave::SanitizedFile.new(file_path('Photo on 2009-12-01 at 11.12.jpg'))
86
+ @sanitized_file.extension.should == "jpg"
87
+ end
88
+
89
+ it "should return the extension for basic filenames" do
90
+ @sanitized_file = CarrierWave::SanitizedFile.new(file_path('something.png'))
91
+ @sanitized_file.extension.should == "png"
92
+ end
93
+
94
+ it "should be an empty string if the file has no extension" do
95
+ @sanitized_file = CarrierWave::SanitizedFile.new(file_path('complex'))
96
+ @sanitized_file.extension.should == ""
97
+ end
98
+ end
99
+
100
+ describe '#filename' do
101
+
102
+ before do
103
+ @sanitized_file = CarrierWave::SanitizedFile.new(nil)
104
+ end
105
+
106
+ it "should default to the original filename if it is valid" do
107
+ @sanitized_file.should_receive(:original_filename).at_least(:once).and_return("llama.jpg")
108
+ @sanitized_file.filename.should == "llama.jpg"
109
+ end
110
+
111
+ it "should remove slashes from the filename" do
112
+ @sanitized_file.should_receive(:original_filename).at_least(:once).and_return("../../very_tricky/foo.bar")
113
+ @sanitized_file.filename.should_not =~ /[\\\/]/
114
+ end
115
+
116
+ it "should remove the path prefix on Windows" do
117
+ @sanitized_file.should_receive(:original_filename).at_least(:once).and_return('c:\temp\foo.txt')
118
+ @sanitized_file.filename.should == "foo.txt"
119
+ end
120
+ end
121
+
122
+ shared_examples_for "all valid sanitized files" do
123
+
124
+ describe '#empty?' do
125
+ it "should not be empty" do
126
+ @sanitized_file.should_not be_empty
127
+ end
128
+ end
129
+
130
+ describe '#original_filename' do
131
+ it "should return the original filename" do
132
+ @sanitized_file.original_filename.should == "llama.jpg"
133
+ end
134
+ end
135
+
136
+ describe '#filename' do
137
+ it "should return the filename" do
138
+ @sanitized_file.filename.should == "llama.jpg"
139
+ end
140
+ end
141
+
142
+ describe '#basename' do
143
+ it "should return the basename" do
144
+ @sanitized_file.basename.should == "llama"
145
+ end
146
+ end
147
+
148
+ describe '#extension' do
149
+ it "should return the extension" do
150
+ @sanitized_file.extension.should == "jpg"
151
+ end
152
+ end
153
+
154
+ describe "#read" do
155
+ it "should return the contents of the file" do
156
+ @sanitized_file.read.should == "this is stuff"
157
+ end
158
+ end
159
+
160
+ describe "#size" do
161
+ it "should return the size of the file" do
162
+ @sanitized_file.size.should == 13
163
+ end
164
+ end
165
+
166
+ describe '#move_to' do
167
+
168
+ after do
169
+ FileUtils.rm(file_path('gurr.png'))
170
+ end
171
+
172
+ it "should be moved to the correct location" do
173
+ @sanitized_file.move_to(file_path('gurr.png'))
174
+
175
+ File.exists?( file_path('gurr.png') ).should be_true
176
+ end
177
+
178
+ it "should have changed its path when moved" do
179
+ @sanitized_file.move_to(file_path('gurr.png'))
180
+ @sanitized_file.path.should == file_path('gurr.png')
181
+ end
182
+
183
+ it "should have changed its filename when moved" do
184
+ @sanitized_file.move_to(file_path('gurr.png'))
185
+ @sanitized_file.filename.should == 'gurr.png'
186
+ end
187
+
188
+ it "should have changed its basename when moved" do
189
+ @sanitized_file.move_to(file_path('gurr.png'))
190
+ @sanitized_file.basename.should == 'gurr'
191
+ end
192
+
193
+ it "should have changed its extension when moved" do
194
+ @sanitized_file.move_to(file_path('gurr.png'))
195
+ @sanitized_file.extension.should == 'png'
196
+ end
197
+
198
+ it "should set the right permissions" do
199
+ @sanitized_file.move_to(file_path('gurr.png'), 0755)
200
+ @sanitized_file.should have_permissions(0755)
201
+ end
202
+
203
+ end
204
+
205
+ describe '#copy_to' do
206
+
207
+ after do
208
+ FileUtils.rm(file_path('gurr.png'))
209
+ end
210
+
211
+ it "should be copied to the correct location" do
212
+ @sanitized_file.copy_to(file_path('gurr.png'))
213
+
214
+ File.exists?( file_path('gurr.png') ).should be_true
215
+
216
+ file_path('gurr.png').should be_identical_to(file_path('llama.jpg'))
217
+ end
218
+
219
+ it "should not have changed its path when copied" do
220
+ running { @sanitized_file.copy_to(file_path('gurr.png')) }.should_not change(@sanitized_file, :path)
221
+ end
222
+
223
+ it "should not have changed its filename when copied" do
224
+ running { @sanitized_file.copy_to(file_path('gurr.png')) }.should_not change(@sanitized_file, :filename)
225
+ end
226
+
227
+ it "should return an object of the same class when copied" do
228
+ new_file = @sanitized_file.copy_to(file_path('gurr.png'))
229
+ new_file.should be_an_instance_of(@sanitized_file.class)
230
+ end
231
+
232
+ it "should adjust the path of the object that is returned when copied" do
233
+ new_file = @sanitized_file.copy_to(file_path('gurr.png'))
234
+ new_file.path.should == file_path('gurr.png')
235
+ end
236
+
237
+ it "should adjust the filename of the object that is returned when copied" do
238
+ new_file = @sanitized_file.copy_to(file_path('gurr.png'))
239
+ new_file.filename.should == 'gurr.png'
240
+ end
241
+
242
+ it "should adjust the basename of the object that is returned when copied" do
243
+ new_file = @sanitized_file.copy_to(file_path('gurr.png'))
244
+ new_file.basename.should == 'gurr'
245
+ end
246
+
247
+ it "should adjust the extension of the object that is returned when copied" do
248
+ new_file = @sanitized_file.copy_to(file_path('gurr.png'))
249
+ new_file.extension.should == 'png'
250
+ end
251
+
252
+ it "should set the right permissions" do
253
+ new_file = @sanitized_file.copy_to(file_path('gurr.png'), 0755)
254
+ new_file.should have_permissions(0755)
255
+ end
256
+
257
+ end
258
+
259
+ end
260
+
261
+ shared_examples_for "all valid sanitized files that are stored on disk" do
262
+ describe '#move_to' do
263
+ it "should not raise an error when moved to its own location" do
264
+ running { @sanitized_file.move_to(@sanitized_file.path) }.should_not raise_error
265
+ end
266
+
267
+ it "should remove the original file" do
268
+ original_path = @sanitized_file.path
269
+ @sanitized_file.move_to(public_path('blah.txt'))
270
+ File.exist?(original_path).should be_false
271
+ end
272
+ end
273
+
274
+ describe '#copy_to' do
275
+ it "should return a new instance when copied to its own location" do
276
+ running {
277
+ new_file = @sanitized_file.copy_to(@sanitized_file.path)
278
+ new_file.should be_an_instance_of(@sanitized_file.class)
279
+ }.should_not raise_error
280
+ end
281
+
282
+ it "should not remove the original file" do
283
+ new_file = @sanitized_file.copy_to(public_path('blah.txt'))
284
+ File.exist?(@sanitized_file.path).should be_true
285
+ File.exist?(new_file.path).should be_true
286
+ end
287
+ end
288
+
289
+ describe '#exists?' do
290
+ it "should be true" do
291
+ @sanitized_file.exists?.should be_true
292
+ end
293
+ end
294
+
295
+ describe '#delete' do
296
+ it "should remove it from the filesystem" do
297
+ File.exists?(@sanitized_file.path).should be_true
298
+ @sanitized_file.delete
299
+ File.exists?(@sanitized_file.path).should be_false
300
+ end
301
+ end
302
+ end
303
+
304
+ describe "with a valid Hash" do
305
+ before do
306
+ @hash = {
307
+ "tempfile" => stub_merb_tempfile('llama.jpg'),
308
+ "filename" => "llama.jpg",
309
+ "content_type" => 'image/jpeg'
310
+ }
311
+ @sanitized_file = CarrierWave::SanitizedFile.new(@hash)
312
+ end
313
+
314
+ it_should_behave_like "all valid sanitized files"
315
+
316
+ it_should_behave_like "all valid sanitized files that are stored on disk"
317
+
318
+ describe '#path' do
319
+ it "should return the path of the tempfile" do
320
+ @sanitized_file.path.should_not be_nil
321
+ @sanitized_file.path.should == @hash["tempfile"].path
322
+ end
323
+ end
324
+
325
+ describe '#is_path?' do
326
+ it "should be false" do
327
+ @sanitized_file.is_path?.should be_false
328
+ end
329
+ end
330
+
331
+ end
332
+
333
+ describe "with a valid Tempfile" do
334
+ before do
335
+ @tempfile = stub_tempfile('llama.jpg', 'image/jpeg')
336
+ @sanitized_file = CarrierWave::SanitizedFile.new(@tempfile)
337
+ end
338
+
339
+ it_should_behave_like "all valid sanitized files"
340
+
341
+ it_should_behave_like "all valid sanitized files that are stored on disk"
342
+
343
+ describe '#is_path?' do
344
+ it "should be false" do
345
+ @sanitized_file.is_path?.should be_false
346
+ end
347
+ end
348
+
349
+ describe '#path' do
350
+ it "should return the path of the tempfile" do
351
+ @sanitized_file.path.should_not be_nil
352
+ @sanitized_file.path.should == @tempfile.path
353
+ end
354
+ end
355
+
356
+ end
357
+
358
+ describe "with a valid StringIO" do
359
+ before do
360
+ @sanitized_file = CarrierWave::SanitizedFile.new(stub_stringio('llama.jpg', 'image/jpeg'))
361
+ end
362
+
363
+ it_should_behave_like "all valid sanitized files"
364
+
365
+ describe '#exists?' do
366
+ it "should be false" do
367
+ @sanitized_file.exists?.should be_false
368
+ end
369
+ end
370
+
371
+ describe '#is_path?' do
372
+ it "should be false" do
373
+ @sanitized_file.is_path?.should be_false
374
+ end
375
+ end
376
+
377
+ describe '#path' do
378
+ it "should be nil" do
379
+ @sanitized_file.path.should be_nil
380
+ end
381
+ end
382
+
383
+ describe '#delete' do
384
+ it "should not raise an error" do
385
+ running { @sanitized_file.delete }.should_not raise_error
386
+ end
387
+ end
388
+
389
+ end
390
+
391
+ describe "with a valid File object" do
392
+ before do
393
+ FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg'))
394
+ @sanitized_file = CarrierWave::SanitizedFile.new(stub_file('llama.jpg', 'image/jpeg'))
395
+ @sanitized_file.should_not be_empty
396
+ end
397
+
398
+ it_should_behave_like "all valid sanitized files"
399
+
400
+ it_should_behave_like "all valid sanitized files that are stored on disk"
401
+
402
+ describe '#is_path?' do
403
+ it "should be false" do
404
+ @sanitized_file.is_path?.should be_false
405
+ end
406
+ end
407
+
408
+ describe '#path' do
409
+ it "should return the path of the file" do
410
+ @sanitized_file.path.should_not be_nil
411
+ @sanitized_file.path.should == file_path('llama.jpg')
412
+ end
413
+ end
414
+
415
+ end
416
+
417
+ describe "with a valid path" do
418
+ before do
419
+ FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg'))
420
+ @sanitized_file = CarrierWave::SanitizedFile.new(file_path('llama.jpg'))
421
+ @sanitized_file.should_not be_empty
422
+ end
423
+
424
+ it_should_behave_like "all valid sanitized files"
425
+
426
+ it_should_behave_like "all valid sanitized files that are stored on disk"
427
+
428
+ describe '#is_path?' do
429
+ it "should be true" do
430
+ @sanitized_file.is_path?.should be_true
431
+ end
432
+ end
433
+
434
+ describe '#path' do
435
+ it "should return the path of the file" do
436
+ @sanitized_file.path.should_not be_nil
437
+ @sanitized_file.path.should == file_path('llama.jpg')
438
+ end
439
+ end
440
+
441
+ end
442
+
443
+ describe "with a valid Pathname" do
444
+ before do
445
+ FileUtils.copy_file(file_path('test.jpg'), file_path('llama.jpg'))
446
+ @sanitized_file = CarrierWave::SanitizedFile.new(Pathname.new(file_path('llama.jpg')))
447
+ @sanitized_file.should_not be_empty
448
+ end
449
+
450
+ it_should_behave_like "all valid sanitized files"
451
+
452
+ it_should_behave_like "all valid sanitized files that are stored on disk"
453
+
454
+ describe '#is_path?' do
455
+ it "should be true" do
456
+ @sanitized_file.is_path?.should be_true
457
+ end
458
+ end
459
+
460
+ describe '#path' do
461
+ it "should return the path of the file" do
462
+ @sanitized_file.path.should_not be_nil
463
+ @sanitized_file.path.should == file_path('llama.jpg')
464
+ end
465
+ end
466
+
467
+ end
468
+
469
+ describe "that is empty" do
470
+ before do
471
+ @empty = CarrierWave::SanitizedFile.new(nil)
472
+ end
473
+
474
+ describe '#empty?' do
475
+ it "should be true" do
476
+ @empty.should be_empty
477
+ end
478
+ end
479
+
480
+ describe '#exists?' do
481
+ it "should be false" do
482
+ @empty.exists?.should be_false
483
+ end
484
+ end
485
+
486
+ describe '#is_path?' do
487
+ it "should be false" do
488
+ @empty.is_path?.should be_false
489
+ end
490
+ end
491
+
492
+ describe '#size' do
493
+ it "should be zero" do
494
+ @empty.size.should be_zero
495
+ end
496
+ end
497
+
498
+ describe '#path' do
499
+ it "should be nil" do
500
+ @empty.path.should be_nil
501
+ end
502
+ end
503
+
504
+ describe '#original_filename' do
505
+ it "should be nil" do
506
+ @empty.original_filename.should be_nil
507
+ end
508
+ end
509
+
510
+ describe '#filename' do
511
+ it "should be nil" do
512
+ @empty.filename.should be_nil
513
+ end
514
+ end
515
+
516
+ describe '#basename' do
517
+ it "should be nil" do
518
+ @empty.basename.should be_nil
519
+ end
520
+ end
521
+
522
+ describe '#extension' do
523
+ it "should be nil" do
524
+ @empty.extension.should be_nil
525
+ end
526
+ end
527
+
528
+ describe '#delete' do
529
+ it "should not raise an error" do
530
+ running { @empty.delete }.should_not raise_error
531
+ end
532
+ end
533
+ end
534
+
535
+ describe "that is an empty string" do
536
+ before do
537
+ @empty = CarrierWave::SanitizedFile.new("")
538
+ end
539
+
540
+ describe '#empty?' do
541
+ it "should be true" do
542
+ @empty.should be_empty
543
+ end
544
+ end
545
+
546
+ describe '#exists?' do
547
+ it "should be false" do
548
+ @empty.exists?.should be_false
549
+ end
550
+ end
551
+
552
+ describe '#is_path?' do
553
+ it "should be false" do
554
+ @empty.is_path?.should be_false
555
+ end
556
+ end
557
+
558
+ describe '#size' do
559
+ it "should be zero" do
560
+ @empty.size.should be_zero
561
+ end
562
+ end
563
+
564
+ describe '#path' do
565
+ it "should be nil" do
566
+ @empty.path.should be_nil
567
+ end
568
+ end
569
+
570
+ describe '#original_filename' do
571
+ it "should be nil" do
572
+ @empty.original_filename.should be_nil
573
+ end
574
+ end
575
+
576
+ describe '#filename' do
577
+ it "should be nil" do
578
+ @empty.filename.should be_nil
579
+ end
580
+ end
581
+
582
+ describe '#basename' do
583
+ it "should be nil" do
584
+ @empty.basename.should be_nil
585
+ end
586
+ end
587
+
588
+ describe '#extension' do
589
+ it "should be nil" do
590
+ @empty.extension.should be_nil
591
+ end
592
+ end
593
+
594
+ describe '#delete' do
595
+ it "should not raise an error" do
596
+ running { @empty.delete }.should_not raise_error
597
+ end
598
+ end
599
+ end
600
+
601
+ end
@@ -0,0 +1,99 @@
1
+ # encoding: utf-8
2
+
3
+ $TESTING=true
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+
6
+ require 'rubygems'
7
+
8
+ if ENV["AS"]
9
+ puts "--> using ActiveSupport"
10
+ require 'activesupport'
11
+ elsif ENV["EXTLIB"]
12
+ puts "--> using Extlib"
13
+ require 'extlib'
14
+ end
15
+
16
+ require 'tempfile'
17
+ #require 'ruby-debug'
18
+ require 'spec'
19
+ require 'spec/autorun'
20
+
21
+ require 'carrierwave'
22
+ require 'timecop'
23
+ require 'time'
24
+
25
+ require 'logger'
26
+
27
+ alias :running :lambda
28
+
29
+ def file_path( *paths )
30
+ File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
31
+ end
32
+
33
+ def public_path( *paths )
34
+ File.expand_path(File.join(File.dirname(__FILE__), 'public', *paths))
35
+ end
36
+
37
+ CarrierWave.root = public_path
38
+
39
+ module CarrierWave
40
+ module Test
41
+ module MockStorage
42
+ def mock_storage(kind)
43
+ storage = mock("storage for #{kind} uploader")
44
+ storage.stub!(:setup!)
45
+ storage
46
+ end
47
+ end
48
+
49
+ module MockFiles
50
+ def stub_merb_tempfile(filename)
51
+ raise "#{path} file does not exist" unless File.exist?(file_path(filename))
52
+
53
+ t = Tempfile.new(filename)
54
+ FileUtils.copy_file(file_path(filename), t.path)
55
+
56
+ return t
57
+ end
58
+
59
+ def stub_tempfile(filename, mime_type=nil, fake_name=nil)
60
+ raise "#{path} file does not exist" unless File.exist?(file_path(filename))
61
+
62
+ t = Tempfile.new(filename)
63
+ FileUtils.copy_file(file_path(filename), t.path)
64
+
65
+ # This is stupid, but for some reason rspec won't play nice...
66
+ eval <<-EOF
67
+ def t.original_filename; '#{fake_name || filename}'; end
68
+ def t.content_type; '#{mime_type}'; end
69
+ def t.local_path; path; end
70
+ EOF
71
+
72
+ return t
73
+ end
74
+
75
+ def stub_stringio(filename, mime_type=nil, fake_name=nil)
76
+ if filename
77
+ t = StringIO.new( IO.read( file_path( filename ) ) )
78
+ else
79
+ t = StringIO.new
80
+ end
81
+ t.stub!(:local_path).and_return("")
82
+ t.stub!(:original_filename).and_return(filename || fake_name)
83
+ t.stub!(:content_type).and_return(mime_type)
84
+ return t
85
+ end
86
+
87
+ def stub_file(filename, mime_type=nil, fake_name=nil)
88
+ f = File.open(file_path(filename))
89
+ return f
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ Spec::Runner.configure do |config|
96
+ config.include CarrierWave::Test::Matchers
97
+ config.include CarrierWave::Test::MockFiles
98
+ config.include CarrierWave::Test::MockStorage
99
+ end