carrierwave 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of carrierwave might be problematic. Click here for more details.

Files changed (92) hide show
  1. data/README.rdoc +33 -15
  2. data/lib/carrierwave.rb +0 -1
  3. data/lib/carrierwave/compatibility/paperclip.rb +2 -2
  4. data/lib/carrierwave/orm/activerecord.rb +9 -5
  5. data/lib/carrierwave/orm/datamapper.rb +10 -0
  6. data/lib/carrierwave/processing/mini_magick.rb +1 -1
  7. data/lib/carrierwave/processing/rmagick.rb +4 -4
  8. data/lib/carrierwave/sanitized_file.rb +2 -2
  9. data/lib/carrierwave/storage/cloud_files.rb +11 -12
  10. data/lib/carrierwave/storage/grid_fs.rb +37 -26
  11. data/lib/carrierwave/storage/right_s3.rb +1 -168
  12. data/lib/carrierwave/storage/s3.rb +73 -66
  13. data/lib/carrierwave/test/matchers.rb +57 -21
  14. data/lib/carrierwave/uploader/configuration.rb +8 -5
  15. data/lib/carrierwave/uploader/processing.rb +1 -0
  16. data/lib/carrierwave/uploader/url.rb +2 -2
  17. data/lib/carrierwave/uploader/versions.rb +10 -0
  18. metadata +31 -279
  19. data/Generators +0 -4
  20. data/History.txt +0 -125
  21. data/Manifest.txt +0 -111
  22. data/Rakefile +0 -39
  23. data/carrierwave.gemspec +0 -85
  24. data/cucumber.yml +0 -2
  25. data/features/caching.feature +0 -28
  26. data/features/download.feature +0 -20
  27. data/features/file_storage.feature +0 -37
  28. data/features/file_storage_overridden_filename.feature +0 -38
  29. data/features/file_storage_overridden_store_dir.feature +0 -38
  30. data/features/file_storage_reversing_processor.feature +0 -43
  31. data/features/fixtures/bork.txt +0 -1
  32. data/features/fixtures/monkey.txt +0 -1
  33. data/features/grid_fs_storage.feature +0 -32
  34. data/features/mount_activerecord.feature +0 -46
  35. data/features/mount_datamapper.feature +0 -46
  36. data/features/step_definitions/activerecord_steps.rb +0 -22
  37. data/features/step_definitions/caching_steps.rb +0 -14
  38. data/features/step_definitions/datamapper_steps.rb +0 -29
  39. data/features/step_definitions/download_steps.rb +0 -4
  40. data/features/step_definitions/file_steps.rb +0 -53
  41. data/features/step_definitions/general_steps.rb +0 -85
  42. data/features/step_definitions/mount_steps.rb +0 -19
  43. data/features/step_definitions/store_steps.rb +0 -18
  44. data/features/support/activerecord.rb +0 -30
  45. data/features/support/datamapper.rb +0 -7
  46. data/features/support/env.rb +0 -22
  47. data/features/versions_basics.feature +0 -50
  48. data/features/versions_nested_versions.feature +0 -70
  49. data/features/versions_overridden_filename.feature +0 -51
  50. data/features/versions_overriden_store_dir.feature +0 -41
  51. data/lib/carrierwave/orm/mongomapper.rb +0 -27
  52. data/merb_generators/uploader_generator.rb +0 -22
  53. data/rails_generators/uploader/USAGE +0 -2
  54. data/rails_generators/uploader/templates/uploader.rb +0 -47
  55. data/rails_generators/uploader/uploader_generator.rb +0 -21
  56. data/script/console +0 -10
  57. data/script/destroy +0 -14
  58. data/script/generate +0 -14
  59. data/spec/compatibility/paperclip_spec.rb +0 -52
  60. data/spec/fixtures/bork.txt +0 -1
  61. data/spec/fixtures/landscape.jpg +0 -0
  62. data/spec/fixtures/portrait.jpg +0 -0
  63. data/spec/fixtures/test.jpeg +0 -1
  64. data/spec/fixtures/test.jpg +0 -1
  65. data/spec/mount_spec.rb +0 -538
  66. data/spec/orm/activerecord_spec.rb +0 -271
  67. data/spec/orm/datamapper_spec.rb +0 -168
  68. data/spec/orm/mongoid_spec.rb +0 -202
  69. data/spec/orm/mongomapper_spec.rb +0 -202
  70. data/spec/orm/sequel_spec.rb +0 -183
  71. data/spec/processing/image_science_spec.rb +0 -56
  72. data/spec/processing/mini_magick_spec.rb +0 -76
  73. data/spec/processing/rmagick_spec.rb +0 -75
  74. data/spec/sanitized_file_spec.rb +0 -623
  75. data/spec/spec_helper.rb +0 -92
  76. data/spec/storage/cloudfiles_spec.rb +0 -78
  77. data/spec/storage/grid_fs_spec.rb +0 -83
  78. data/spec/storage/right_s3_spec.rb +0 -83
  79. data/spec/storage/s3_spec.rb +0 -95
  80. data/spec/uploader/cache_spec.rb +0 -209
  81. data/spec/uploader/configuration_spec.rb +0 -105
  82. data/spec/uploader/default_url_spec.rb +0 -85
  83. data/spec/uploader/download_spec.rb +0 -75
  84. data/spec/uploader/extension_whitelist_spec.rb +0 -44
  85. data/spec/uploader/mountable_spec.rb +0 -33
  86. data/spec/uploader/paths_spec.rb +0 -22
  87. data/spec/uploader/processing_spec.rb +0 -73
  88. data/spec/uploader/proxy_spec.rb +0 -54
  89. data/spec/uploader/remove_spec.rb +0 -70
  90. data/spec/uploader/store_spec.rb +0 -264
  91. data/spec/uploader/url_spec.rb +0 -102
  92. data/spec/uploader/versions_spec.rb +0 -298
@@ -1,70 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- describe CarrierWave::Uploader do
6
-
7
- before do
8
- @uploader_class = Class.new(CarrierWave::Uploader::Base)
9
- @uploader = @uploader_class.new
10
- end
11
-
12
- after do
13
- FileUtils.rm_rf(public_path)
14
- end
15
-
16
- describe '#remove!' do
17
- before do
18
- @file = File.open(file_path('test.jpg'))
19
-
20
- @stored_file = mock('a stored file')
21
- @stored_file.stub!(:path).and_return('/path/to/somewhere')
22
- @stored_file.stub!(:url).and_return('http://www.example.com')
23
- @stored_file.stub!(:identifier).and_return('this-is-me')
24
- @stored_file.stub!(:delete)
25
-
26
- @storage = mock('a storage engine')
27
- @storage.stub!(:store!).and_return(@stored_file)
28
-
29
- @uploader_class.storage.stub!(:new).and_return(@storage)
30
- @uploader.store!(@file)
31
- end
32
-
33
- it "should reset the current path" do
34
- @uploader.remove!
35
- @uploader.current_path.should be_nil
36
- end
37
-
38
- it "should not be cached" do
39
- @uploader.remove!
40
- @uploader.should_not be_cached
41
- end
42
-
43
- it "should reset the url" do
44
- @uploader.cache!(@file)
45
- @uploader.remove!
46
- @uploader.url.should be_nil
47
- end
48
-
49
- it "should reset the identifier" do
50
- @uploader.remove!
51
- @uploader.identifier.should be_nil
52
- end
53
-
54
- it "should delete the file" do
55
- @stored_file.should_receive(:delete)
56
- @uploader.remove!
57
- end
58
-
59
- it "should reset the cache_name" do
60
- @uploader.cache!(@file)
61
- @uploader.remove!
62
- @uploader.cache_name.should be_nil
63
- end
64
-
65
- it "should do nothing when trying to remove an empty file" do
66
- running { @uploader.remove! }.should_not raise_error
67
- end
68
- end
69
-
70
- end
@@ -1,264 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- describe CarrierWave::Uploader do
6
-
7
- before do
8
- @uploader_class = Class.new(CarrierWave::Uploader::Base)
9
- @uploader = @uploader_class.new
10
- end
11
-
12
- after do
13
- FileUtils.rm_rf(public_path)
14
- end
15
-
16
- describe '#store_dir' do
17
- it "should default to the config option" do
18
- @uploader.store_dir.should == 'uploads'
19
- end
20
- end
21
-
22
- describe '#filename' do
23
- it "should default to nil" do
24
- @uploader.filename.should be_nil
25
- end
26
- end
27
-
28
- describe '#store!' do
29
- before do
30
- @file = File.open(file_path('test.jpg'))
31
-
32
- @stored_file = mock('a stored file')
33
- @stored_file.stub!(:path).and_return('/path/to/somewhere')
34
- @stored_file.stub!(:url).and_return('http://www.example.com')
35
-
36
- @storage = mock('a storage engine')
37
- @storage.stub!(:store!).and_return(@stored_file)
38
- @storage.stub!(:identifier).and_return('this-is-me')
39
-
40
- @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
41
- end
42
-
43
- it "should set the current path" do
44
- @uploader.store!(@file)
45
- @uploader.current_path.should == '/path/to/somewhere'
46
- end
47
-
48
- it "should not be cached" do
49
- @uploader.store!(@file)
50
- @uploader.should_not be_cached
51
- end
52
-
53
- it "should set the url" do
54
- @uploader.store!(@file)
55
- @uploader.url.should == 'http://www.example.com'
56
- end
57
-
58
- it "should set the identifier" do
59
- @uploader.store!(@file)
60
- @uploader.identifier.should == 'this-is-me'
61
- end
62
-
63
- it "should, if a file is given as argument, cache that file" do
64
- @uploader.should_receive(:cache!).with(@file)
65
- @uploader.store!(@file)
66
- end
67
-
68
- it "should use a previously cached file if no argument is given" do
69
- @uploader.cache!(File.open(file_path('test.jpg')))
70
- @uploader.should_not_receive(:cache!)
71
- @uploader.store!
72
- end
73
-
74
- it "should instruct the storage engine to store the file" do
75
- @uploader.cache!(@file)
76
- @storage.should_receive(:store!).with(@uploader.file).and_return(:monkey)
77
- @uploader.store!
78
- end
79
-
80
- it "should reset the cache_name" do
81
- @uploader.cache!(@file)
82
- @uploader.store!
83
- @uploader.cache_name.should be_nil
84
- end
85
-
86
- it "should cache the result given by the storage engine" do
87
- @uploader.store!(@file)
88
- @uploader.file.should == @stored_file
89
- end
90
-
91
- it "should do nothing when trying to store an empty file" do
92
- @uploader.store!(nil)
93
- end
94
-
95
- it "should not re-store a retrieved file" do
96
- @stored_file = mock('a stored file')
97
- @storage.stub!(:retrieve!).and_return(@stored_file)
98
-
99
- @uploader_class.storage.should_not_receive(:store!)
100
- @uploader.retrieve_from_store!('monkey.txt')
101
- @uploader.store!
102
- end
103
- end
104
-
105
- describe '#retrieve_from_store!' do
106
- before do
107
- @stored_file = mock('a stored file')
108
- @stored_file.stub!(:path).and_return('/path/to/somewhere')
109
- @stored_file.stub!(:url).and_return('http://www.example.com')
110
-
111
- @storage = mock('a storage engine')
112
- @storage.stub!(:retrieve!).and_return(@stored_file)
113
- @storage.stub!(:identifier).and_return('this-is-me')
114
-
115
- @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
116
- end
117
-
118
- it "should set the current path" do
119
- @uploader.retrieve_from_store!('monkey.txt')
120
- @uploader.current_path.should == '/path/to/somewhere'
121
- end
122
-
123
- it "should not be cached" do
124
- @uploader.retrieve_from_store!('monkey.txt')
125
- @uploader.should_not be_cached
126
- end
127
-
128
- it "should set the url" do
129
- @uploader.retrieve_from_store!('monkey.txt')
130
- @uploader.url.should == 'http://www.example.com'
131
- end
132
-
133
- it "should set the identifier" do
134
- @uploader.retrieve_from_store!('monkey.txt')
135
- @uploader.identifier.should == 'this-is-me'
136
- end
137
-
138
- it "should instruct the storage engine to retrieve the file and store the result" do
139
- @storage.should_receive(:retrieve!).with('monkey.txt').and_return(@stored_file)
140
- @uploader.retrieve_from_store!('monkey.txt')
141
- @uploader.file.should == @stored_file
142
- end
143
-
144
- it "should overwrite a file that has already been cached" do
145
- @uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
146
- @uploader.retrieve_from_store!('bork.txt')
147
- @uploader.file.should == @stored_file
148
- end
149
- end
150
-
151
- describe 'with an overridden filename' do
152
- before do
153
- @uploader_class.class_eval do
154
- def filename; "foo.jpg"; end
155
- end
156
- end
157
-
158
- it "should create new files if there is a file" do
159
- @file = File.open(file_path('test.jpg'))
160
- @uploader.store!(@file)
161
- @path = ::File.expand_path(@uploader.store_path, @uploader.root)
162
- File.exist?(@path).should be_true
163
- end
164
-
165
- it "should not create new files if there is no file" do
166
- @uploader.store!(nil)
167
- @path = ::File.expand_path(@uploader.store_path, @uploader.root)
168
- File.exist?(@path).should be_false
169
- end
170
- end
171
-
172
- describe 'without a store dir' do
173
- before do
174
- @uploader_class.class_eval do
175
- def store_dir; nil; end
176
- end
177
- end
178
-
179
- it "should create a new file with a valid path and url" do
180
- @file = File.open(file_path('test.jpg'))
181
- @uploader.store!(@file)
182
- @path = ::File.expand_path(@uploader.store_path, @uploader.root)
183
- File.exist?(@path).should be_true
184
- @uploader.url.should == '/test.jpg'
185
- end
186
- end
187
-
188
- describe 'with an overridden, reversing, filename' do
189
- before do
190
- @uploader_class.class_eval do
191
- def filename
192
- super.reverse unless super.blank?
193
- end
194
- end
195
- end
196
-
197
- describe '#store!' do
198
- before do
199
- @file = File.open(file_path('test.jpg'))
200
-
201
- @stored_file = mock('a stored file')
202
- @stored_file.stub!(:path).and_return('/path/to/somewhere')
203
- @stored_file.stub!(:url).and_return('http://www.example.com')
204
-
205
- @storage = mock('a storage engine')
206
- @storage.stub!(:store!).and_return(@stored_file)
207
-
208
- @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
209
- end
210
-
211
- it "should set the current path" do
212
- @uploader.store!(@file)
213
- @uploader.current_path.should == '/path/to/somewhere'
214
- end
215
-
216
- it "should set the url" do
217
- @uploader.store!(@file)
218
- @uploader.url.should == 'http://www.example.com'
219
- end
220
-
221
- it "should, if a file is given as argument, reverse the filename" do
222
- @uploader.store!(@file)
223
- @uploader.filename.should == 'gpj.tset'
224
- end
225
-
226
- end
227
-
228
- describe '#retrieve_from_store!' do
229
- before do
230
- @stored_file = mock('a stored file')
231
- @stored_file.stub!(:path).and_return('/path/to/somewhere')
232
- @stored_file.stub!(:url).and_return('http://www.example.com')
233
-
234
- @storage = mock('a storage engine')
235
- @storage.stub!(:retrieve!).and_return(@stored_file)
236
-
237
- @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
238
- end
239
-
240
- it "should set the current path" do
241
- @uploader.retrieve_from_store!('monkey.txt')
242
- @uploader.current_path.should == '/path/to/somewhere'
243
- end
244
-
245
- it "should set the url" do
246
- @uploader.retrieve_from_store!('monkey.txt')
247
- @uploader.url.should == 'http://www.example.com'
248
- end
249
-
250
- it "should pass the identifier to the storage engine" do
251
- @storage.should_receive(:retrieve!).with('monkey.txt').and_return(@stored_file)
252
- @uploader.retrieve_from_store!('monkey.txt')
253
- @uploader.file.should == @stored_file
254
- end
255
-
256
- it "should not set the filename" do
257
- @uploader.retrieve_from_store!('monkey.txt')
258
- @uploader.filename.should be_nil
259
- end
260
- end
261
-
262
- end
263
-
264
- end
@@ -1,102 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- describe CarrierWave::Uploader do
6
-
7
- before do
8
- @uploader_class = Class.new(CarrierWave::Uploader::Base)
9
- @uploader = @uploader_class.new
10
- end
11
-
12
- after do
13
- FileUtils.rm_rf(public_path)
14
- end
15
-
16
- describe '#url' do
17
- before do
18
- CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
19
- end
20
-
21
- it "should default to nil" do
22
- @uploader.url.should be_nil
23
- end
24
-
25
- it "should raise ArgumentError when version doesn't exist" do
26
- lambda { @uploader.url(:thumb) }.should raise_error(ArgumentError)
27
- end
28
-
29
- it "should not raise ArgumentError when versions version exists" do
30
- @uploader_class.version(:thumb)
31
- lambda { @uploader.url(:thumb) }.should_not raise_error(ArgumentError)
32
- end
33
-
34
- it "should get the directory relative to public, prepending a slash" do
35
- @uploader.cache!(File.open(file_path('test.jpg')))
36
- @uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
37
- end
38
-
39
- it "should get the directory relative to public for a specific version" do
40
- @uploader_class.version(:thumb)
41
- @uploader.cache!(File.open(file_path('test.jpg')))
42
- @uploader.url(:thumb).should == '/uploads/tmp/20071201-1234-345-2255/thumb_test.jpg'
43
- end
44
-
45
- it "should get the directory relative to public for a nested version" do
46
- @uploader_class.version(:thumb) do
47
- version(:mini)
48
- end
49
- @uploader.cache!(File.open(file_path('test.jpg')))
50
- @uploader.url(:thumb, :mini).should == '/uploads/tmp/20071201-1234-345-2255/thumb_mini_test.jpg'
51
- end
52
-
53
- it "should return file#url if available" do
54
- @uploader.cache!(File.open(file_path('test.jpg')))
55
- @uploader.file.stub!(:url).and_return('http://www.example.com/someurl.jpg')
56
- @uploader.url.should == 'http://www.example.com/someurl.jpg'
57
- end
58
-
59
- it "should get the directory relative to public, if file#url is blank" do
60
- @uploader.cache!(File.open(file_path('test.jpg')))
61
- @uploader.file.stub!(:url).and_return('')
62
- @uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
63
- end
64
- end
65
-
66
- describe '#to_json' do
67
- before do
68
- CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
69
- end
70
-
71
- it "should return a hash with a blank URL" do
72
- JSON.parse(@uploader.to_json)['url'].should be_nil
73
- end
74
-
75
- it "should return a hash including a cached URL" do
76
- @uploader.cache!(File.open(file_path('test.jpg')))
77
- JSON.parse(@uploader.to_json)['url'].should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
78
- end
79
- end
80
-
81
- describe '#to_s' do
82
- before do
83
- CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
84
- end
85
-
86
- it "should default to nil" do
87
- @uploader.to_s.should be_nil
88
- end
89
-
90
- it "should get the directory relative to public, prepending a slash" do
91
- @uploader.cache!(File.open(file_path('test.jpg')))
92
- @uploader.to_s.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
93
- end
94
-
95
- it "should return file#url if available" do
96
- @uploader.cache!(File.open(file_path('test.jpg')))
97
- @uploader.file.stub!(:url).and_return('http://www.example.com/someurl.jpg')
98
- @uploader.to_s.should == 'http://www.example.com/someurl.jpg'
99
- end
100
- end
101
-
102
- end
@@ -1,298 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- describe CarrierWave::Uploader do
6
-
7
- before do
8
- @uploader_class = Class.new(CarrierWave::Uploader::Base)
9
- @uploader = @uploader_class.new
10
- end
11
-
12
- after do
13
- FileUtils.rm_rf(public_path)
14
- end
15
-
16
- describe '.version' do
17
- it "should add it to .versions" do
18
- @uploader_class.version :thumb
19
- @uploader_class.versions[:thumb].should be_a(Class)
20
- @uploader_class.versions[:thumb].ancestors.should include(@uploader_class)
21
- end
22
-
23
- it "should add an accessor which returns the version" do
24
- @uploader_class.version :thumb
25
- @uploader.thumb.should be_a(@uploader_class)
26
- end
27
-
28
- it "should add it to #versions which returns the version" do
29
- @uploader_class.version :thumb
30
- @uploader.versions[:thumb].should be_a(@uploader_class)
31
- end
32
-
33
- it "should set the version name" do
34
- @uploader_class.version :thumb
35
- @uploader.version_name.should == nil
36
- @uploader.thumb.version_name.should == :thumb
37
- end
38
-
39
- it "should set the version names on the class" do
40
- @uploader_class.version :thumb
41
- @uploader.class.version_names.should == []
42
- @uploader.thumb.class.version_names.should == [:thumb]
43
- end
44
-
45
- it "should remember mount options" do
46
- model = mock('a model')
47
- @uploader_class.version :thumb
48
- @uploader = @uploader_class.new(model, :gazelle)
49
-
50
- @uploader.thumb.model.should == model
51
- @uploader.thumb.mounted_as.should == :gazelle
52
- end
53
-
54
- it "should apply any overrides given in a block" do
55
- @uploader_class.version :thumb do
56
- def store_dir
57
- public_path('monkey/apache')
58
- end
59
- end
60
- @uploader.store_dir.should == 'uploads'
61
- @uploader.thumb.store_dir.should == public_path('monkey/apache')
62
- end
63
-
64
- it "should reopen the same class when called multiple times" do
65
- @uploader_class.version :thumb do
66
- def self.monkey
67
- "monkey"
68
- end
69
- end
70
- @uploader_class.version :thumb do
71
- def self.llama
72
- "llama"
73
- end
74
- end
75
- @uploader_class.version(:thumb).monkey.should == "monkey"
76
- @uploader_class.version(:thumb).llama.should == "llama"
77
- end
78
-
79
- describe 'with nested versions' do
80
- before do
81
- @uploader_class.version :thumb do
82
- version :mini
83
- version :micro
84
- end
85
- end
86
-
87
- it "should add an array of version names" do
88
- @uploader.class.version_names.should == []
89
- @uploader.thumb.class.version_names.should == [:thumb]
90
- @uploader.thumb.mini.class.version_names.should == [:thumb, :mini]
91
- @uploader.thumb.micro.class.version_names.should == [:thumb, :micro]
92
- end
93
-
94
- it "should set the version name for the instances" do
95
- @uploader.version_name.should be_nil
96
- @uploader.thumb.version_name.should == :thumb
97
- @uploader.thumb.mini.version_name.should == :thumb_mini
98
- @uploader.thumb.micro.version_name.should == :thumb_micro
99
- end
100
-
101
- end
102
-
103
- end
104
-
105
- describe 'with a version' do
106
- before do
107
- @uploader_class.version(:thumb)
108
- end
109
-
110
- describe '#cache!' do
111
-
112
- before do
113
- CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
114
- end
115
-
116
- it "should set store_path with versions" do
117
- @uploader.cache!(File.open(file_path('test.jpg')))
118
- @uploader.store_path.should == 'uploads/test.jpg'
119
- @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
120
- @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
121
- end
122
-
123
- it "should move it to the tmp dir with the filename prefixed" do
124
- @uploader.cache!(File.open(file_path('test.jpg')))
125
- @uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
126
- @uploader.thumb.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/thumb_test.jpg')
127
- @uploader.file.exists?.should be_true
128
- @uploader.thumb.file.exists?.should be_true
129
- end
130
- end
131
-
132
- describe '#retrieve_from_cache!' do
133
- it "should set the path to the tmp dir" do
134
- @uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpg')
135
- @uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
136
- @uploader.thumb.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/thumb_test.jpg')
137
- end
138
-
139
- it "should set store_path with versions" do
140
- @uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpg')
141
- @uploader.store_path.should == 'uploads/test.jpg'
142
- @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
143
- @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
144
- end
145
- end
146
-
147
- describe '#store!' do
148
- before do
149
- @uploader_class.storage = mock_storage('base')
150
- @uploader_class.version(:thumb).storage = mock_storage('thumb')
151
-
152
- @file = File.open(file_path('test.jpg'))
153
-
154
- @base_stored_file = mock('a stored file')
155
- @base_stored_file.stub!(:path).and_return('/path/to/somewhere')
156
- @base_stored_file.stub!(:url).and_return('http://www.example.com')
157
-
158
- @thumb_stored_file = mock('a thumb version of a stored file')
159
- @thumb_stored_file.stub!(:path).and_return('/path/to/somewhere/thumb')
160
- @thumb_stored_file.stub!(:url).and_return('http://www.example.com/thumb')
161
-
162
- @storage = mock('a storage engine')
163
- @storage.stub!(:store!).and_return(@base_stored_file)
164
-
165
- @thumb_storage = mock('a storage engine for thumbnails')
166
- @thumb_storage.stub!(:store!).and_return(@thumb_stored_file)
167
-
168
- @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
169
- @uploader_class.version(:thumb).storage.stub!(:new).with(@uploader.thumb).and_return(@thumb_storage)
170
- end
171
-
172
- it "should set the current path for the version" do
173
- @uploader.store!(@file)
174
- @uploader.current_path.should == '/path/to/somewhere'
175
- @uploader.thumb.current_path.should == '/path/to/somewhere/thumb'
176
- end
177
-
178
- it "should set the url" do
179
- @uploader.store!(@file)
180
- @uploader.url.should == 'http://www.example.com'
181
- @uploader.thumb.url.should == 'http://www.example.com/thumb'
182
- end
183
-
184
- it "should, if a file is given as argument, set the store_path" do
185
- @uploader.store!(@file)
186
- @uploader.store_path.should == 'uploads/test.jpg'
187
- @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
188
- @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
189
- end
190
-
191
- it "should instruct the storage engine to store the file and its version" do
192
- @uploader.cache!(@file)
193
- @storage.should_receive(:store!).with(@uploader.file).and_return(:monkey)
194
- @thumb_storage.should_receive(:store!).with(@uploader.thumb.file).and_return(:gorilla)
195
- @uploader.store!
196
- end
197
-
198
- end
199
-
200
- describe '#remove!' do
201
- before do
202
- @uploader_class.storage = mock_storage('base')
203
- @uploader_class.version(:thumb).storage = mock_storage('thumb')
204
-
205
- @file = File.open(file_path('test.jpg'))
206
-
207
- @base_stored_file = mock('a stored file')
208
- @thumb_stored_file = mock('a thumb version of a stored file')
209
-
210
- @storage = mock('a storage engine')
211
- @storage.stub!(:store!).and_return(@base_stored_file)
212
-
213
- @thumb_storage = mock('a storage engine for thumbnails')
214
- @thumb_storage.stub!(:store!).and_return(@thumb_stored_file)
215
-
216
- @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
217
- @uploader_class.version(:thumb).storage.stub!(:new).with(@uploader.thumb).and_return(@thumb_storage)
218
-
219
- @base_stored_file.stub!(:delete)
220
- @thumb_stored_file.stub!(:delete)
221
-
222
- @uploader.store!(@file)
223
- end
224
-
225
- it "should reset the current path for the version" do
226
- @uploader.remove!
227
- @uploader.current_path.should be_nil
228
- @uploader.thumb.current_path.should be_nil
229
- end
230
-
231
- it "should reset the url" do
232
- @uploader.remove!
233
- @uploader.url.should be_nil
234
- @uploader.thumb.url.should be_nil
235
- end
236
-
237
- it "should delete all the files" do
238
- @base_stored_file.should_receive(:delete)
239
- @thumb_stored_file.should_receive(:delete)
240
- @uploader.remove!
241
- end
242
-
243
- end
244
-
245
-
246
- describe '#retrieve_from_store!' do
247
- before do
248
- @uploader_class.storage = mock_storage('base')
249
- @uploader_class.version(:thumb).storage = mock_storage('thumb')
250
-
251
- @file = File.open(file_path('test.jpg'))
252
-
253
- @base_stored_file = mock('a stored file')
254
- @base_stored_file.stub!(:path).and_return('/path/to/somewhere')
255
- @base_stored_file.stub!(:url).and_return('http://www.example.com')
256
-
257
- @thumb_stored_file = mock('a thumb version of a stored file')
258
- @thumb_stored_file.stub!(:path).and_return('/path/to/somewhere/thumb')
259
- @thumb_stored_file.stub!(:url).and_return('http://www.example.com/thumb')
260
-
261
- @storage = mock('a storage engine')
262
- @storage.stub!(:retrieve!).and_return(@base_stored_file)
263
-
264
- @thumb_storage = mock('a storage engine for thumbnails')
265
- @thumb_storage.stub!(:retrieve!).and_return(@thumb_stored_file)
266
-
267
- @uploader_class.storage.stub!(:new).with(@uploader).and_return(@storage)
268
- @uploader_class.version(:thumb).storage.stub!(:new).with(@uploader.thumb).and_return(@thumb_storage)
269
- end
270
-
271
- it "should set the current path" do
272
- @uploader.retrieve_from_store!('monkey.txt')
273
- @uploader.current_path.should == '/path/to/somewhere'
274
- @uploader.thumb.current_path.should == '/path/to/somewhere/thumb'
275
- end
276
-
277
- it "should set the url" do
278
- @uploader.retrieve_from_store!('monkey.txt')
279
- @uploader.url.should == 'http://www.example.com'
280
- @uploader.thumb.url.should == 'http://www.example.com/thumb'
281
- end
282
-
283
- it "should pass the identifier to the storage engine" do
284
- @storage.should_receive(:retrieve!).with('monkey.txt').and_return(@base_stored_file)
285
- @thumb_storage.should_receive(:retrieve!).with('monkey.txt').and_return(@thumb_stored_file)
286
- @uploader.retrieve_from_store!('monkey.txt')
287
- @uploader.file.should == @base_stored_file
288
- @uploader.thumb.file.should == @thumb_stored_file
289
- end
290
-
291
- it "should not set the filename" do
292
- @uploader.retrieve_from_store!('monkey.txt')
293
- @uploader.filename.should be_nil
294
- end
295
- end
296
- end
297
-
298
- end