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.
- data/README.rdoc +33 -15
- data/lib/carrierwave.rb +0 -1
- data/lib/carrierwave/compatibility/paperclip.rb +2 -2
- data/lib/carrierwave/orm/activerecord.rb +9 -5
- data/lib/carrierwave/orm/datamapper.rb +10 -0
- data/lib/carrierwave/processing/mini_magick.rb +1 -1
- data/lib/carrierwave/processing/rmagick.rb +4 -4
- data/lib/carrierwave/sanitized_file.rb +2 -2
- data/lib/carrierwave/storage/cloud_files.rb +11 -12
- data/lib/carrierwave/storage/grid_fs.rb +37 -26
- data/lib/carrierwave/storage/right_s3.rb +1 -168
- data/lib/carrierwave/storage/s3.rb +73 -66
- data/lib/carrierwave/test/matchers.rb +57 -21
- data/lib/carrierwave/uploader/configuration.rb +8 -5
- data/lib/carrierwave/uploader/processing.rb +1 -0
- data/lib/carrierwave/uploader/url.rb +2 -2
- data/lib/carrierwave/uploader/versions.rb +10 -0
- metadata +31 -279
- data/Generators +0 -4
- data/History.txt +0 -125
- data/Manifest.txt +0 -111
- data/Rakefile +0 -39
- data/carrierwave.gemspec +0 -85
- data/cucumber.yml +0 -2
- data/features/caching.feature +0 -28
- data/features/download.feature +0 -20
- data/features/file_storage.feature +0 -37
- data/features/file_storage_overridden_filename.feature +0 -38
- data/features/file_storage_overridden_store_dir.feature +0 -38
- data/features/file_storage_reversing_processor.feature +0 -43
- data/features/fixtures/bork.txt +0 -1
- data/features/fixtures/monkey.txt +0 -1
- data/features/grid_fs_storage.feature +0 -32
- data/features/mount_activerecord.feature +0 -46
- data/features/mount_datamapper.feature +0 -46
- data/features/step_definitions/activerecord_steps.rb +0 -22
- data/features/step_definitions/caching_steps.rb +0 -14
- data/features/step_definitions/datamapper_steps.rb +0 -29
- data/features/step_definitions/download_steps.rb +0 -4
- data/features/step_definitions/file_steps.rb +0 -53
- data/features/step_definitions/general_steps.rb +0 -85
- data/features/step_definitions/mount_steps.rb +0 -19
- data/features/step_definitions/store_steps.rb +0 -18
- data/features/support/activerecord.rb +0 -30
- data/features/support/datamapper.rb +0 -7
- data/features/support/env.rb +0 -22
- data/features/versions_basics.feature +0 -50
- data/features/versions_nested_versions.feature +0 -70
- data/features/versions_overridden_filename.feature +0 -51
- data/features/versions_overriden_store_dir.feature +0 -41
- data/lib/carrierwave/orm/mongomapper.rb +0 -27
- data/merb_generators/uploader_generator.rb +0 -22
- data/rails_generators/uploader/USAGE +0 -2
- data/rails_generators/uploader/templates/uploader.rb +0 -47
- data/rails_generators/uploader/uploader_generator.rb +0 -21
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/compatibility/paperclip_spec.rb +0 -52
- data/spec/fixtures/bork.txt +0 -1
- data/spec/fixtures/landscape.jpg +0 -0
- data/spec/fixtures/portrait.jpg +0 -0
- data/spec/fixtures/test.jpeg +0 -1
- data/spec/fixtures/test.jpg +0 -1
- data/spec/mount_spec.rb +0 -538
- data/spec/orm/activerecord_spec.rb +0 -271
- data/spec/orm/datamapper_spec.rb +0 -168
- data/spec/orm/mongoid_spec.rb +0 -202
- data/spec/orm/mongomapper_spec.rb +0 -202
- data/spec/orm/sequel_spec.rb +0 -183
- data/spec/processing/image_science_spec.rb +0 -56
- data/spec/processing/mini_magick_spec.rb +0 -76
- data/spec/processing/rmagick_spec.rb +0 -75
- data/spec/sanitized_file_spec.rb +0 -623
- data/spec/spec_helper.rb +0 -92
- data/spec/storage/cloudfiles_spec.rb +0 -78
- data/spec/storage/grid_fs_spec.rb +0 -83
- data/spec/storage/right_s3_spec.rb +0 -83
- data/spec/storage/s3_spec.rb +0 -95
- data/spec/uploader/cache_spec.rb +0 -209
- data/spec/uploader/configuration_spec.rb +0 -105
- data/spec/uploader/default_url_spec.rb +0 -85
- data/spec/uploader/download_spec.rb +0 -75
- data/spec/uploader/extension_whitelist_spec.rb +0 -44
- data/spec/uploader/mountable_spec.rb +0 -33
- data/spec/uploader/paths_spec.rb +0 -22
- data/spec/uploader/processing_spec.rb +0 -73
- data/spec/uploader/proxy_spec.rb +0 -54
- data/spec/uploader/remove_spec.rb +0 -70
- data/spec/uploader/store_spec.rb +0 -264
- data/spec/uploader/url_spec.rb +0 -102
- data/spec/uploader/versions_spec.rb +0 -298
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/carrierwave.rb'}"
|
9
|
-
puts "Loading carrierwave gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
-
|
5
|
-
require 'carrierwave/orm/activerecord'
|
6
|
-
|
7
|
-
module Rails
|
8
|
-
def self.root
|
9
|
-
File.expand_path(File.join('..'), File.dirname(__FILE__))
|
10
|
-
end
|
11
|
-
def self.env
|
12
|
-
"test"
|
13
|
-
end
|
14
|
-
end unless defined?(Rails)
|
15
|
-
|
16
|
-
describe CarrierWave::Compatibility::Paperclip do
|
17
|
-
|
18
|
-
before do
|
19
|
-
@uploader_class = Class.new(CarrierWave::Uploader::Base) do
|
20
|
-
include CarrierWave::Compatibility::Paperclip
|
21
|
-
end
|
22
|
-
@model = mock('a model')
|
23
|
-
@model.stub!(:id).and_return(23)
|
24
|
-
@uploader = @uploader_class.new(@model, :monkey)
|
25
|
-
end
|
26
|
-
|
27
|
-
after do
|
28
|
-
FileUtils.rm_rf(public_path)
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#store_path' do
|
32
|
-
it "should mimics paperclip default" do
|
33
|
-
@uploader.store_path("monkey.png").should == CarrierWave::Uploader::Base.root + "/system/monkeys/23/original/monkey.png"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should interpolate the root path" do
|
37
|
-
@uploader.stub!(:paperclip_path).and_return(":rails_root/foo/bar")
|
38
|
-
@uploader.store_path("monkey.png").should == Rails.root + "/foo/bar"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should interpolate the attachment" do
|
42
|
-
@uploader.stub!(:paperclip_path).and_return("/foo/:attachment/bar")
|
43
|
-
@uploader.store_path("monkey.png").should == "/foo/monkeys/bar"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should interpolate the id" do
|
47
|
-
@uploader.stub!(:paperclip_path).and_return("/foo/:id/bar")
|
48
|
-
@uploader.store_path("monkey.png").should == "/foo/23/bar"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
data/spec/fixtures/bork.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
bork bork bork Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
data/spec/fixtures/landscape.jpg
DELETED
Binary file
|
data/spec/fixtures/portrait.jpg
DELETED
Binary file
|
data/spec/fixtures/test.jpeg
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
this is stuff
|
data/spec/fixtures/test.jpg
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
this is stuff
|
data/spec/mount_spec.rb
DELETED
@@ -1,538 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
-
|
5
|
-
describe CarrierWave::Mount do
|
6
|
-
|
7
|
-
after do
|
8
|
-
FileUtils.rm_rf(public_path)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '.mount_uploader' do
|
12
|
-
|
13
|
-
before do
|
14
|
-
@class = Class.new
|
15
|
-
@class.send(:extend, CarrierWave::Mount)
|
16
|
-
|
17
|
-
@uploader = Class.new(CarrierWave::Uploader::Base)
|
18
|
-
|
19
|
-
@class.mount_uploader(:image, @uploader)
|
20
|
-
@instance = @class.new
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should maintain the ability to super" do
|
24
|
-
@class.class_eval do
|
25
|
-
def image_uploader
|
26
|
-
super
|
27
|
-
end
|
28
|
-
|
29
|
-
def image=(val)
|
30
|
-
super
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
@instance.image = stub_file('test.jpg')
|
35
|
-
@instance.image.should be_an_instance_of(@uploader)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should inherit uploaders to subclasses" do
|
39
|
-
@subclass = Class.new(@class)
|
40
|
-
@subclass_instance = @subclass.new
|
41
|
-
@subclass_instance.image = stub_file('test.jpg')
|
42
|
-
@subclass_instance.image.should be_an_instance_of(@uploader)
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#image' do
|
46
|
-
|
47
|
-
it "should return a blank uploader when nothing has been assigned" do
|
48
|
-
@instance.should_receive(:read_uploader).with(:image).twice.and_return(nil)
|
49
|
-
@instance.image.should be_an_instance_of(@uploader)
|
50
|
-
@instance.image.should be_blank
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should return a blank uploader when an empty string has been assigned" do
|
54
|
-
@instance.should_receive(:read_uploader).with(:image).twice.and_return('')
|
55
|
-
@instance.image.should be_an_instance_of(@uploader)
|
56
|
-
@instance.image.should be_blank
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should retrieve a file from the storage if a value is stored in the database" do
|
60
|
-
@instance.should_receive(:read_uploader).with(:image).at_least(:once).and_return('test.jpg')
|
61
|
-
@instance.image.should be_an_instance_of(@uploader)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should set the path to the store dir" do
|
65
|
-
@instance.should_receive(:read_uploader).with(:image).at_least(:once).and_return('test.jpg')
|
66
|
-
@instance.image.current_path.should == public_path('uploads/test.jpg')
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#image=' do
|
72
|
-
|
73
|
-
it "should cache a file" do
|
74
|
-
@instance.image = stub_file('test.jpg')
|
75
|
-
@instance.image.should be_an_instance_of(@uploader)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should copy a file into into the cache directory" do
|
79
|
-
@instance.image = stub_file('test.jpg')
|
80
|
-
@instance.image.current_path.should =~ /^#{public_path('uploads/tmp')}/
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should do nothing when nil is assigned" do
|
84
|
-
@instance.should_not_receive(:write_uploader)
|
85
|
-
@instance.image = nil
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should do nothing when an empty string is assigned" do
|
89
|
-
@instance.should_not_receive(:write_uploader)
|
90
|
-
@instance.image = stub_file('test.jpg')
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should fail silently if the image fails an integrity check" do
|
94
|
-
@uploader.class_eval do
|
95
|
-
def extension_white_list
|
96
|
-
%(txt)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
@instance.image = stub_file('test.jpg')
|
100
|
-
@instance.image.should be_blank
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should fail silently if the image fails to be processed" do
|
104
|
-
@uploader.class_eval do
|
105
|
-
process :monkey
|
106
|
-
def monkey
|
107
|
-
raise CarrierWave::ProcessingError, "Ohh noez!"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
@instance.image = stub_file('test.jpg')
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '#image?' do
|
116
|
-
|
117
|
-
it "should be false when nothing has been assigned" do
|
118
|
-
@instance.should_receive(:read_uploader).with(:image).and_return(nil)
|
119
|
-
@instance.image?.should be_false
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should be false when an empty string has been assigned" do
|
123
|
-
@instance.should_receive(:read_uploader).with(:image).and_return('')
|
124
|
-
@instance.image?.should be_false
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should be true when a file has been cached" do
|
128
|
-
@instance.image = stub_file('test.jpg')
|
129
|
-
@instance.image?.should be_true
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
describe '#image_url' do
|
135
|
-
|
136
|
-
it "should return nil when nothing has been assigned" do
|
137
|
-
@instance.should_receive(:read_uploader).with(:image).and_return(nil)
|
138
|
-
@instance.image_url.should be_nil
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should return nil when an empty string has been assigned" do
|
142
|
-
@instance.should_receive(:read_uploader).with(:image).and_return('')
|
143
|
-
@instance.image_url.should be_nil
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should get the url from a retrieved file" do
|
147
|
-
@instance.should_receive(:read_uploader).at_least(:once).with(:image).and_return('test.jpg')
|
148
|
-
@instance.image_url.should == '/uploads/test.jpg'
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should get the url from a cached file" do
|
152
|
-
@instance.image = stub_file('test.jpg')
|
153
|
-
@instance.image_url.should =~ %r{uploads/tmp/[\d\-]+/test.jpg}
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should get the url from a cached file's version" do
|
157
|
-
@uploader.version(:thumb)
|
158
|
-
@instance.image = stub_file('test.jpg')
|
159
|
-
@instance.image_url(:thumb).should =~ %r{uploads/tmp/[\d\-]+/thumb_test.jpg}
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
describe '#image_cache' do
|
165
|
-
|
166
|
-
before do
|
167
|
-
@instance.stub!(:write_uploader)
|
168
|
-
@instance.stub!(:read_uploader).and_return(nil)
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should return nil when nothing has been assigned" do
|
172
|
-
@instance.image_cache.should be_nil
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should be nil when a file has been stored" do
|
176
|
-
@instance.image = stub_file('test.jpg')
|
177
|
-
@instance.image.store!
|
178
|
-
@instance.image_cache.should be_nil
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should be the cache name when a file has been cached" do
|
182
|
-
@instance.image = stub_file('test.jpg')
|
183
|
-
@instance.image_cache.should =~ %r(^[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}/test\.jpg$)
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|
187
|
-
|
188
|
-
describe '#image_cache=' do
|
189
|
-
|
190
|
-
before do
|
191
|
-
@instance.stub!(:write_uploader)
|
192
|
-
@instance.stub!(:read_uploader).and_return(nil)
|
193
|
-
CarrierWave::SanitizedFile.new(file_path('test.jpg')).copy_to(public_path('uploads/tmp/19990512-1202-123-1234/test.jpg'))
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should do nothing when nil is assigned" do
|
197
|
-
@instance.image_cache = nil
|
198
|
-
@instance.image.should be_blank
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should do nothing when an empty string is assigned" do
|
202
|
-
@instance.image_cache = ''
|
203
|
-
@instance.image.should be_blank
|
204
|
-
end
|
205
|
-
|
206
|
-
it "retrieve from cache when a cache name is assigned" do
|
207
|
-
@instance.image_cache = '19990512-1202-123-1234/test.jpg'
|
208
|
-
@instance.image.current_path.should == public_path('uploads/tmp/19990512-1202-123-1234/test.jpg')
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should not write over a previously assigned file" do
|
212
|
-
@instance.image = stub_file('test.jpg')
|
213
|
-
@instance.image_cache = '19990512-1202-123-1234/monkey.jpg'
|
214
|
-
@instance.image.current_path.should =~ /test.jpg$/
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
describe '#remote_image_url' do
|
219
|
-
before do
|
220
|
-
response = mock('HTTP Response')
|
221
|
-
response.stub!(:body).and_return('Response Body')
|
222
|
-
Net::HTTP.stub!(:get_response).and_return(response)
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should return nil" do
|
226
|
-
@instance.remote_image_url.should be_nil
|
227
|
-
end
|
228
|
-
|
229
|
-
it "should return previously cached URL" do
|
230
|
-
@instance.remote_image_url = 'http://www.example.com/funky/monkey.png'
|
231
|
-
@instance.remote_image_url.should == 'http://www.example.com/funky/monkey.png'
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe '#remote_image_url=' do
|
236
|
-
before do
|
237
|
-
response = mock('HTTP Response')
|
238
|
-
response.stub!(:body).and_return('Response Body')
|
239
|
-
Net::HTTP.stub!(:get_response).and_return(response)
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should do nothing when nil is assigned" do
|
243
|
-
@instance.remote_image_url = nil
|
244
|
-
@instance.image.should be_blank
|
245
|
-
end
|
246
|
-
|
247
|
-
it "should do nothing when an empty string is assigned" do
|
248
|
-
@instance.remote_image_url = ''
|
249
|
-
@instance.image.should be_blank
|
250
|
-
end
|
251
|
-
|
252
|
-
it "retrieve from cache when a cache name is assigned" do
|
253
|
-
@instance.remote_image_url = 'http://www.example.com/funky/monkey.png'
|
254
|
-
@instance.image.current_path.should =~ /monkey.png$/
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should not write over a previously assigned file" do
|
258
|
-
@instance.image = stub_file('test.jpg')
|
259
|
-
@instance.remote_image_url = '19990512-1202-123-1234/monkey.jpg'
|
260
|
-
@instance.image.current_path.should =~ /test.jpg$/
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe '#store_image!' do
|
265
|
-
|
266
|
-
before do
|
267
|
-
@instance.stub!(:write_uploader)
|
268
|
-
@instance.stub!(:read_uploader).and_return(nil)
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should do nothing when no file has been uploaded" do
|
272
|
-
@instance.store_image!
|
273
|
-
@instance.image.should be_blank
|
274
|
-
end
|
275
|
-
|
276
|
-
it "store an assigned file" do
|
277
|
-
@instance.image = stub_file('test.jpg')
|
278
|
-
@instance.store_image!
|
279
|
-
@instance.image.current_path.should == public_path('uploads/test.jpg')
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should remove an uploaded file when remove_image? returns true" do
|
283
|
-
@instance.image = stub_file('test.jpg')
|
284
|
-
path = @instance.image.current_path
|
285
|
-
@instance.remove_image = true
|
286
|
-
@instance.store_image!
|
287
|
-
@instance.image.should be_blank
|
288
|
-
File.exist?(path).should be_false
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
describe '#remove_image!' do
|
293
|
-
|
294
|
-
before do
|
295
|
-
@instance.stub!(:write_uploader)
|
296
|
-
@instance.stub!(:read_uploader).and_return(nil)
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should do nothing when no file has been uploaded" do
|
300
|
-
@instance.remove_image!
|
301
|
-
@instance.image.should be_blank
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should remove an uploaded file" do
|
305
|
-
@instance.image = stub_file('test.jpg')
|
306
|
-
path = @instance.image.current_path
|
307
|
-
@instance.remove_image!
|
308
|
-
@instance.image.should be_blank
|
309
|
-
File.exist?(path).should be_false
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
describe '#remove_image' do
|
314
|
-
|
315
|
-
it "should store a value" do
|
316
|
-
@instance.remove_image = true
|
317
|
-
@instance.remove_image.should be_true
|
318
|
-
end
|
319
|
-
|
320
|
-
end
|
321
|
-
|
322
|
-
describe '#remove_image?' do
|
323
|
-
|
324
|
-
it "should be true when the value is truthy" do
|
325
|
-
@instance.remove_image = true
|
326
|
-
@instance.remove_image?.should be_true
|
327
|
-
end
|
328
|
-
|
329
|
-
it "should be false when the value is falsey" do
|
330
|
-
@instance.remove_image = false
|
331
|
-
@instance.remove_image?.should be_false
|
332
|
-
end
|
333
|
-
|
334
|
-
it "should be false when the value is ''" do
|
335
|
-
@instance.remove_image = ''
|
336
|
-
@instance.remove_image?.should be_false
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should be false when the value is '0'" do
|
340
|
-
@instance.remove_image = '0'
|
341
|
-
@instance.remove_image?.should be_false
|
342
|
-
end
|
343
|
-
|
344
|
-
it "should be false when the value is 'false'" do
|
345
|
-
@instance.remove_image = 'false'
|
346
|
-
@instance.remove_image?.should be_false
|
347
|
-
end
|
348
|
-
|
349
|
-
end
|
350
|
-
|
351
|
-
describe '#image_integrity_error' do
|
352
|
-
|
353
|
-
it "should be nil by default" do
|
354
|
-
@instance.image_integrity_error.should be_nil
|
355
|
-
end
|
356
|
-
|
357
|
-
it "should be nil after a file is cached" do
|
358
|
-
@instance.image = stub_file('test.jpg')
|
359
|
-
@instance.image_integrity_error.should be_nil
|
360
|
-
end
|
361
|
-
|
362
|
-
it "should be an error instance after an integrity check has failed" do
|
363
|
-
@uploader.class_eval do
|
364
|
-
def extension_white_list
|
365
|
-
%(txt)
|
366
|
-
end
|
367
|
-
end
|
368
|
-
@instance.image = stub_file('test.jpg')
|
369
|
-
@instance.image_integrity_error.should be_an_instance_of(CarrierWave::IntegrityError)
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
describe '#image_processing_error' do
|
374
|
-
|
375
|
-
it "should be nil by default" do
|
376
|
-
@instance.image_processing_error.should be_nil
|
377
|
-
end
|
378
|
-
|
379
|
-
it "should be nil after a file is cached" do
|
380
|
-
@instance.image = stub_file('test.jpg')
|
381
|
-
@instance.image_processing_error.should be_nil
|
382
|
-
end
|
383
|
-
|
384
|
-
it "should be an error instance after an integrity check has failed" do
|
385
|
-
@uploader.class_eval do
|
386
|
-
process :monkey
|
387
|
-
def monkey
|
388
|
-
raise CarrierWave::ProcessingError, "Ohh noez!"
|
389
|
-
end
|
390
|
-
end
|
391
|
-
@instance.image = stub_file('test.jpg')
|
392
|
-
@instance.image_processing_error.should be_an_instance_of(CarrierWave::ProcessingError)
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
describe '#write_image_identifier' do
|
397
|
-
it "should write to the column" do
|
398
|
-
@instance.should_receive(:write_uploader).with(:image, "test.jpg")
|
399
|
-
@instance.image = stub_file('test.jpg')
|
400
|
-
@instance.write_image_identifier
|
401
|
-
end
|
402
|
-
|
403
|
-
it "should remove from the column when remove_image is true" do
|
404
|
-
@instance.image = stub_file('test.jpg')
|
405
|
-
@instance.store_image!
|
406
|
-
@instance.remove_image = true
|
407
|
-
@instance.should_receive(:write_uploader).with(:image, "")
|
408
|
-
@instance.write_image_identifier
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
end
|
413
|
-
|
414
|
-
describe '#mount_uploader with a block' do
|
415
|
-
|
416
|
-
before do
|
417
|
-
@class = Class.new
|
418
|
-
@class.send(:extend, CarrierWave::Mount)
|
419
|
-
@class.mount_uploader(:image) do
|
420
|
-
def monkey
|
421
|
-
'blah'
|
422
|
-
end
|
423
|
-
end
|
424
|
-
@instance = @class.new
|
425
|
-
end
|
426
|
-
|
427
|
-
describe '#image' do
|
428
|
-
|
429
|
-
before do
|
430
|
-
@instance.stub!(:read_uploader).and_return('test.jpg')
|
431
|
-
end
|
432
|
-
|
433
|
-
it "should return an instance of a subclass of CarrierWave::Uploader::Base" do
|
434
|
-
@instance.image.should be_a(CarrierWave::Uploader::Base)
|
435
|
-
end
|
436
|
-
|
437
|
-
it "should set the path to the store dir" do
|
438
|
-
@instance.image.current_path.should == public_path('uploads/test.jpg')
|
439
|
-
end
|
440
|
-
|
441
|
-
it "should apply any custom modifications" do
|
442
|
-
@instance.image.monkey.should == "blah"
|
443
|
-
end
|
444
|
-
|
445
|
-
end
|
446
|
-
|
447
|
-
end
|
448
|
-
|
449
|
-
describe '#mount_uploader with :ignore_integrity_errors => false' do
|
450
|
-
|
451
|
-
before do
|
452
|
-
@class = Class.new
|
453
|
-
@class.send(:extend, CarrierWave::Mount)
|
454
|
-
|
455
|
-
@uploader = Class.new(CarrierWave::Uploader::Base)
|
456
|
-
|
457
|
-
@class.mount_uploader(:image, @uploader, :ignore_integrity_errors => false)
|
458
|
-
@instance = @class.new
|
459
|
-
end
|
460
|
-
|
461
|
-
it "should raise an error if the image fails an integrity check" do
|
462
|
-
@uploader.class_eval do
|
463
|
-
def extension_white_list
|
464
|
-
%(txt)
|
465
|
-
end
|
466
|
-
end
|
467
|
-
running {
|
468
|
-
@instance.image = stub_file('test.jpg')
|
469
|
-
}.should raise_error(CarrierWave::IntegrityError)
|
470
|
-
end
|
471
|
-
|
472
|
-
end
|
473
|
-
|
474
|
-
describe '#mount_uploader with :ignore_processing_errors => false' do
|
475
|
-
|
476
|
-
before do
|
477
|
-
@class = Class.new
|
478
|
-
@class.send(:extend, CarrierWave::Mount)
|
479
|
-
|
480
|
-
@uploader = Class.new(CarrierWave::Uploader::Base)
|
481
|
-
|
482
|
-
@class.mount_uploader(:image, @uploader, :ignore_processing_errors => false)
|
483
|
-
@instance = @class.new
|
484
|
-
end
|
485
|
-
|
486
|
-
it "should raise an error if the image fails to be processed" do
|
487
|
-
@uploader.class_eval do
|
488
|
-
process :monkey
|
489
|
-
def monkey
|
490
|
-
raise CarrierWave::ProcessingError, "Ohh noez!"
|
491
|
-
end
|
492
|
-
end
|
493
|
-
running {
|
494
|
-
@instance.image = stub_file('test.jpg')
|
495
|
-
}.should raise_error(CarrierWave::ProcessingError)
|
496
|
-
end
|
497
|
-
|
498
|
-
end
|
499
|
-
|
500
|
-
describe '#mount_uploader with :mount_on => :monkey' do
|
501
|
-
|
502
|
-
|
503
|
-
before do
|
504
|
-
@class = Class.new
|
505
|
-
@class.send(:extend, CarrierWave::Mount)
|
506
|
-
|
507
|
-
@uploader = Class.new(CarrierWave::Uploader::Base)
|
508
|
-
|
509
|
-
@class.mount_uploader(:image, @uploader, :mount_on => :monkey)
|
510
|
-
@instance = @class.new
|
511
|
-
end
|
512
|
-
|
513
|
-
describe '#image' do
|
514
|
-
it "should retrieve a file from the storage if a value is stored in the database" do
|
515
|
-
@instance.should_receive(:read_uploader).at_least(:once).with(:monkey).twice.and_return('test.jpg')
|
516
|
-
@instance.image.should be_an_instance_of(@uploader)
|
517
|
-
@instance.image.current_path.should == public_path('uploads/test.jpg')
|
518
|
-
end
|
519
|
-
end
|
520
|
-
|
521
|
-
describe '#write_image_identifier' do
|
522
|
-
it "should write to the given column" do
|
523
|
-
@instance.should_receive(:write_uploader).with(:monkey, "test.jpg")
|
524
|
-
@instance.image = stub_file('test.jpg')
|
525
|
-
@instance.write_image_identifier
|
526
|
-
end
|
527
|
-
|
528
|
-
it "should remove from the given column when remove_image is true" do
|
529
|
-
@instance.image = stub_file('test.jpg')
|
530
|
-
@instance.store_image!
|
531
|
-
@instance.remove_image = true
|
532
|
-
@instance.should_receive(:write_uploader).with(:monkey, "")
|
533
|
-
@instance.write_image_identifier
|
534
|
-
end
|
535
|
-
end
|
536
|
-
end
|
537
|
-
|
538
|
-
end
|