carrierwave-rails3 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +527 -0
- data/lib/carrierwave.rb +103 -0
- data/lib/carrierwave/compatibility/paperclip.rb +95 -0
- data/lib/carrierwave/core_ext/file.rb +11 -0
- data/lib/carrierwave/mount.rb +359 -0
- data/lib/carrierwave/orm/activerecord.rb +75 -0
- data/lib/carrierwave/orm/datamapper.rb +27 -0
- data/lib/carrierwave/orm/mongoid.rb +23 -0
- data/lib/carrierwave/orm/mongomapper.rb +27 -0
- data/lib/carrierwave/orm/sequel.rb +45 -0
- data/lib/carrierwave/processing/image_science.rb +116 -0
- data/lib/carrierwave/processing/mini_magick.rb +261 -0
- data/lib/carrierwave/processing/rmagick.rb +278 -0
- data/lib/carrierwave/sanitized_file.rb +273 -0
- data/lib/carrierwave/storage/abstract.rb +30 -0
- data/lib/carrierwave/storage/cloud_files.rb +169 -0
- data/lib/carrierwave/storage/file.rb +48 -0
- data/lib/carrierwave/storage/grid_fs.rb +104 -0
- data/lib/carrierwave/storage/right_s3.rb +3 -0
- data/lib/carrierwave/storage/s3.rb +206 -0
- data/lib/carrierwave/test/matchers.rb +164 -0
- data/lib/carrierwave/uploader.rb +44 -0
- data/lib/carrierwave/uploader/cache.rb +146 -0
- data/lib/carrierwave/uploader/callbacks.rb +41 -0
- data/lib/carrierwave/uploader/configuration.rb +134 -0
- data/lib/carrierwave/uploader/default_url.rb +19 -0
- data/lib/carrierwave/uploader/download.rb +60 -0
- data/lib/carrierwave/uploader/extension_whitelist.rb +38 -0
- data/lib/carrierwave/uploader/mountable.rb +39 -0
- data/lib/carrierwave/uploader/processing.rb +84 -0
- data/lib/carrierwave/uploader/proxy.rb +62 -0
- data/lib/carrierwave/uploader/remove.rb +23 -0
- data/lib/carrierwave/uploader/store.rb +90 -0
- data/lib/carrierwave/uploader/url.rb +33 -0
- data/lib/carrierwave/uploader/versions.rb +147 -0
- data/lib/generators/templates/uploader.rb +47 -0
- data/lib/generators/uploader_generator.rb +13 -0
- data/spec/compatibility/paperclip_spec.rb +52 -0
- data/spec/mount_spec.rb +538 -0
- data/spec/orm/activerecord_spec.rb +271 -0
- data/spec/orm/datamapper_spec.rb +168 -0
- data/spec/orm/mongoid_spec.rb +202 -0
- data/spec/orm/mongomapper_spec.rb +202 -0
- data/spec/orm/sequel_spec.rb +183 -0
- data/spec/processing/image_science_spec.rb +56 -0
- data/spec/processing/mini_magick_spec.rb +76 -0
- data/spec/processing/rmagick_spec.rb +75 -0
- data/spec/sanitized_file_spec.rb +623 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/storage/cloudfiles_spec.rb +78 -0
- data/spec/storage/grid_fs_spec.rb +86 -0
- data/spec/storage/s3_spec.rb +118 -0
- data/spec/uploader/cache_spec.rb +209 -0
- data/spec/uploader/callback_spec.rb +24 -0
- data/spec/uploader/configuration_spec.rb +105 -0
- data/spec/uploader/default_url_spec.rb +85 -0
- data/spec/uploader/download_spec.rb +75 -0
- data/spec/uploader/extension_whitelist_spec.rb +44 -0
- data/spec/uploader/mountable_spec.rb +33 -0
- data/spec/uploader/paths_spec.rb +22 -0
- data/spec/uploader/processing_spec.rb +73 -0
- data/spec/uploader/proxy_spec.rb +54 -0
- data/spec/uploader/remove_spec.rb +70 -0
- data/spec/uploader/store_spec.rb +264 -0
- data/spec/uploader/url_spec.rb +102 -0
- data/spec/uploader/versions_spec.rb +298 -0
- metadata +128 -0
@@ -0,0 +1,54 @@
|
|
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 '#blank?' do
|
17
|
+
it "should be true when nothing has been done" do
|
18
|
+
@uploader.should be_blank
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not be true when the file is empty" do
|
22
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
|
23
|
+
@uploader.should be_blank
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not be true when a file has been cached" do
|
27
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
28
|
+
@uploader.should_not be_blank
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#read' do
|
33
|
+
it "should be nil by default" do
|
34
|
+
@uploader.read.should be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should read the contents of a cached file" do
|
38
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
39
|
+
@uploader.read.should == "this is stuff"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#size' do
|
44
|
+
it "should be zero by default" do
|
45
|
+
@uploader.size.should == 0
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should get the size of a cached file" do
|
49
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
50
|
+
@uploader.size.should == 13
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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
|
@@ -0,0 +1,264 @@
|
|
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
|
@@ -0,0 +1,102 @@
|
|
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
|