carrierwave 0.4.1 → 0.4.2
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/History.txt +8 -1
- data/Manifest.txt +10 -0
- data/README.rdoc +64 -2
- data/Rakefile +3 -1
- data/lib/carrierwave.rb +3 -1
- data/lib/carrierwave/orm/datamapper.rb +2 -2
- data/lib/carrierwave/orm/mongoid.rb +23 -0
- data/lib/carrierwave/processing/mini_magick.rb +269 -0
- data/lib/carrierwave/storage/right_s3.rb +183 -0
- data/lib/carrierwave/uploader/configuration.rb +7 -2
- data/lib/carrierwave/uploader/processing.rb +4 -2
- data/spec/fixtures/landscape.jpg +0 -0
- data/spec/fixtures/portrait.jpg +0 -0
- data/spec/orm/datamapper_spec.rb +54 -47
- data/spec/orm/mongoid_spec.rb +204 -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 +68 -0
- data/spec/storage/right_s3_spec.rb +75 -0
- data/spec/storage/s3_spec.rb +1 -1
- data/spec/uploader/processing_spec.rb +11 -0
- data/spec/uploader/store_spec.rb +21 -0
- metadata +33 -3
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe CarrierWave::ImageScience do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@klass = Class.new do
|
9
|
+
include CarrierWave::ImageScience
|
10
|
+
end
|
11
|
+
@instance = @klass.new
|
12
|
+
FileUtils.cp(file_path('landscape.jpg'), file_path('landscape_copy.jpg'))
|
13
|
+
@instance.stub(:current_path).and_return(file_path('landscape_copy.jpg'))
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
FileUtils.rm(file_path('landscape_copy.jpg'))
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#resize_to_fill' do
|
21
|
+
it "should resize the image to exactly the given dimensions" do
|
22
|
+
@instance.resize_to_fill(200, 200)
|
23
|
+
@instance.should have_dimensions(200, 200)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
27
|
+
@instance.resize_to_fill(1000, 1000)
|
28
|
+
@instance.should have_dimensions(1000, 1000)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#resize_to_fit' do
|
33
|
+
it "should resize the image to fit within the given dimensions" do
|
34
|
+
@instance.resize_to_fit(200, 200)
|
35
|
+
@instance.should have_dimensions(200, 150)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
39
|
+
@instance.resize_to_fit(1000, 1000)
|
40
|
+
@instance.should have_dimensions(1000, 750)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#resize_to_limit' do
|
45
|
+
it "should resize the image to fit within the given dimensions" do
|
46
|
+
@instance.resize_to_limit(200, 200)
|
47
|
+
@instance.should have_dimensions(200, 150)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should not scale up the image if it smaller than the given dimensions" do
|
51
|
+
@instance.resize_to_limit(1000, 1000)
|
52
|
+
@instance.should have_dimensions(640, 480)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe CarrierWave::MiniMagick do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@klass = Class.new do
|
9
|
+
include CarrierWave::MiniMagick
|
10
|
+
end
|
11
|
+
@instance = @klass.new
|
12
|
+
FileUtils.cp(file_path('landscape.jpg'), file_path('landscape_copy.jpg'))
|
13
|
+
@instance.stub(:current_path).and_return(file_path('landscape_copy.jpg'))
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
FileUtils.rm(file_path('landscape_copy.jpg'))
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#convert" do
|
21
|
+
it "should convert from one format to another" do
|
22
|
+
@instance.convert('png')
|
23
|
+
img = ::MiniMagick::Image.from_file(@instance.current_path)
|
24
|
+
img['format'].should =~ /PNG/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#resize_to_fill' do
|
29
|
+
it "should resize the image to exactly the given dimensions" do
|
30
|
+
@instance.resize_to_fill(200, 200)
|
31
|
+
@instance.should have_dimensions(200, 200)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
35
|
+
@instance.resize_to_fill(1000, 1000)
|
36
|
+
@instance.should have_dimensions(1000, 1000)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#resize_and_pad' do
|
41
|
+
it "should resize the image to exactly the given dimensions" do
|
42
|
+
@instance.resize_and_pad(200, 200)
|
43
|
+
@instance.should have_dimensions(200, 200)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
47
|
+
@instance.resize_and_pad(1000, 1000)
|
48
|
+
@instance.should have_dimensions(1000, 1000)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#resize_to_fit' do
|
53
|
+
it "should resize the image to fit within the given dimensions" do
|
54
|
+
@instance.resize_to_fit(200, 200)
|
55
|
+
@instance.should have_dimensions(200, 150)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
59
|
+
@instance.resize_to_fit(1000, 1000)
|
60
|
+
@instance.should have_dimensions(1000, 750)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#resize_to_limit' do
|
65
|
+
it "should resize the image to fit within the given dimensions" do
|
66
|
+
@instance.resize_to_limit(200, 200)
|
67
|
+
@instance.should have_dimensions(200, 150)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not scale up the image if it smaller than the given dimensions" do
|
71
|
+
@instance.resize_to_limit(1000, 1000)
|
72
|
+
@instance.should have_dimensions(640, 480)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe CarrierWave::RMagick do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@klass = Class.new do
|
9
|
+
include CarrierWave::RMagick
|
10
|
+
end
|
11
|
+
@instance = @klass.new
|
12
|
+
FileUtils.cp(file_path('landscape.jpg'), file_path('landscape_copy.jpg'))
|
13
|
+
@instance.stub(:current_path).and_return(file_path('landscape_copy.jpg'))
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
FileUtils.rm(file_path('landscape_copy.jpg'))
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#resize_to_fill' do
|
21
|
+
it "should resize the image to exactly the given dimensions" do
|
22
|
+
@instance.resize_to_fill(200, 200)
|
23
|
+
@instance.should have_dimensions(200, 200)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
27
|
+
@instance.resize_to_fill(1000, 1000)
|
28
|
+
@instance.should have_dimensions(1000, 1000)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#resize_and_pad' do
|
33
|
+
it "should resize the image to exactly the given dimensions" do
|
34
|
+
@instance.resize_and_pad(200, 200)
|
35
|
+
@instance.should have_dimensions(200, 200)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
39
|
+
@instance.resize_and_pad(1000, 1000)
|
40
|
+
@instance.should have_dimensions(1000, 1000)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#resize_to_fit' do
|
45
|
+
it "should resize the image to fit within the given dimensions" do
|
46
|
+
@instance.resize_to_fit(200, 200)
|
47
|
+
@instance.should have_dimensions(200, 150)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
51
|
+
@instance.resize_to_fit(1000, 1000)
|
52
|
+
@instance.should have_dimensions(1000, 750)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#resize_to_limit' do
|
57
|
+
it "should resize the image to fit within the given dimensions" do
|
58
|
+
@instance.resize_to_limit(200, 200)
|
59
|
+
@instance.should have_dimensions(200, 150)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not scale up the image if it smaller than the given dimensions" do
|
63
|
+
@instance.resize_to_limit(1000, 1000)
|
64
|
+
@instance.should have_dimensions(640, 480)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
require 'right_aws'
|
5
|
+
|
6
|
+
if ENV['S3_SPEC']
|
7
|
+
describe CarrierWave::Storage::RightS3 do
|
8
|
+
before do
|
9
|
+
@bucket = ENV['CARRIERWAVE_TEST_BUCKET']
|
10
|
+
@uploader = mock('an uploader')
|
11
|
+
@uploader.stub!(:s3_access_key_id).and_return(ENV["S3_ACCESS_KEY_ID"])
|
12
|
+
@uploader.stub!(:s3_secret_access_key).and_return(ENV["S3_SECRET_ACCESS_KEY"])
|
13
|
+
@uploader.stub!(:s3_bucket).and_return(@bucket)
|
14
|
+
@uploader.stub!(:s3_access_policy).and_return('public-read')
|
15
|
+
@uploader.stub!(:s3_cnamed).and_return(false)
|
16
|
+
|
17
|
+
@storage = CarrierWave::Storage::RightS3.new(@uploader)
|
18
|
+
@file = CarrierWave::SanitizedFile.new(file_path('test.jpg'))
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
@storage.connection.delete(@bucket, 'uploads/bar.txt')
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#store!' do
|
26
|
+
before do
|
27
|
+
@uploader.stub!(:store_path).and_return('uploads/bar.txt')
|
28
|
+
@s3_file = @storage.store!(@file)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should upload the file to s3" do
|
32
|
+
@storage.connection.get_object(@bucket, 'uploads/bar.txt').should == 'this is stuff'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have a path" do
|
36
|
+
@s3_file.path.should == 'uploads/bar.txt'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have an Amazon URL" do
|
40
|
+
@s3_file.url.should == "http://#{@bucket}.s3.amazonaws.com/uploads/bar.txt"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be deletable" do
|
44
|
+
@s3_file.delete
|
45
|
+
lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#retrieve!' do
|
50
|
+
before do
|
51
|
+
@storage.connection.put(@bucket, "uploads/bar.txt", "A test, 1234", {'a-amz-acl' => 'public-read'})
|
52
|
+
@uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
53
|
+
@s3_file = @storage.retrieve!('bar.txt')
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should retrieve the file contents from s3" do
|
57
|
+
@s3_file.read.chomp.should == "A test, 1234"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have a path" do
|
61
|
+
@s3_file.path.should == 'uploads/bar.txt'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should have an Amazon URL" do
|
65
|
+
@s3_file.url.should == "http://#{@bucket}.s3.amazonaws.com/uploads/bar.txt"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be deletable" do
|
69
|
+
@s3_file.delete
|
70
|
+
lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/spec/storage/s3_spec.rb
CHANGED
@@ -9,7 +9,7 @@ if ENV['S3_SPEC']
|
|
9
9
|
@uploader = mock('an uploader')
|
10
10
|
@uploader.stub!(:s3_access_key_id).and_return(ENV["S3_ACCESS_KEY_ID"])
|
11
11
|
@uploader.stub!(:s3_secret_access_key).and_return(ENV["S3_SECRET_ACCESS_KEY"])
|
12
|
-
@uploader.stub!(:s3_bucket).and_return('
|
12
|
+
@uploader.stub!(:s3_bucket).and_return(ENV['CARRIERWAVE_TEST_BUCKET'])
|
13
13
|
@uploader.stub!(:s3_access).and_return(:public_read)
|
14
14
|
@uploader.stub!(:s3_cnamed).and_return(false)
|
15
15
|
|
@@ -46,6 +46,17 @@ describe CarrierWave::Uploader do
|
|
46
46
|
@uploader.should_receive(:format).with('png')
|
47
47
|
@uploader.process!
|
48
48
|
end
|
49
|
+
|
50
|
+
context "with 'enable_processing' set to false" do
|
51
|
+
it "should not do any processing" do
|
52
|
+
@uploader_class.enable_processing = false
|
53
|
+
@uploader_class.process :sepiatone, :desaturate, :invert
|
54
|
+
@uploader.should_not_receive(:sepiatone)
|
55
|
+
@uploader.should_not_receive(:desaturate)
|
56
|
+
@uploader.should_not_receive(:invert)
|
57
|
+
@uploader.process!
|
58
|
+
end
|
59
|
+
end
|
49
60
|
end
|
50
61
|
|
51
62
|
describe '#cache!' do
|
data/spec/uploader/store_spec.rb
CHANGED
@@ -147,6 +147,27 @@ describe CarrierWave::Uploader do
|
|
147
147
|
@uploader.file.should == @stored_file
|
148
148
|
end
|
149
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
|
150
171
|
|
151
172
|
describe 'with an overridden, reversing, filename' do
|
152
173
|
before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-26 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -112,6 +112,16 @@ dependencies:
|
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: 2.10.0
|
114
114
|
version:
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: mini_magick
|
117
|
+
type: :development
|
118
|
+
version_requirement:
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 1.2.5
|
124
|
+
version:
|
115
125
|
- !ruby/object:Gem::Dependency
|
116
126
|
name: mongo_mapper
|
117
127
|
type: :development
|
@@ -120,7 +130,17 @@ dependencies:
|
|
120
130
|
requirements:
|
121
131
|
- - ">="
|
122
132
|
- !ruby/object:Gem::Version
|
123
|
-
version: 0.5.
|
133
|
+
version: 0.5.8
|
134
|
+
version:
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: mongoid
|
137
|
+
type: :development
|
138
|
+
version_requirement:
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 0.5.11
|
124
144
|
version:
|
125
145
|
- !ruby/object:Gem::Dependency
|
126
146
|
name: aws-s3
|
@@ -198,14 +218,17 @@ files:
|
|
198
218
|
- lib/carrierwave/mount.rb
|
199
219
|
- lib/carrierwave/orm/activerecord.rb
|
200
220
|
- lib/carrierwave/orm/datamapper.rb
|
221
|
+
- lib/carrierwave/orm/mongoid.rb
|
201
222
|
- lib/carrierwave/orm/mongomapper.rb
|
202
223
|
- lib/carrierwave/orm/sequel.rb
|
203
224
|
- lib/carrierwave/processing/image_science.rb
|
225
|
+
- lib/carrierwave/processing/mini_magick.rb
|
204
226
|
- lib/carrierwave/processing/rmagick.rb
|
205
227
|
- lib/carrierwave/sanitized_file.rb
|
206
228
|
- lib/carrierwave/storage/abstract.rb
|
207
229
|
- lib/carrierwave/storage/file.rb
|
208
230
|
- lib/carrierwave/storage/grid_fs.rb
|
231
|
+
- lib/carrierwave/storage/right_s3.rb
|
209
232
|
- lib/carrierwave/storage/s3.rb
|
210
233
|
- lib/carrierwave/test/matchers.rb
|
211
234
|
- lib/carrierwave/uploader.rb
|
@@ -230,16 +253,23 @@ files:
|
|
230
253
|
- script/generate
|
231
254
|
- spec/compatibility/paperclip_spec.rb
|
232
255
|
- spec/fixtures/bork.txt
|
256
|
+
- spec/fixtures/landscape.jpg
|
257
|
+
- spec/fixtures/portrait.jpg
|
233
258
|
- spec/fixtures/test.jpeg
|
234
259
|
- spec/fixtures/test.jpg
|
235
260
|
- spec/mount_spec.rb
|
236
261
|
- spec/orm/activerecord_spec.rb
|
237
262
|
- spec/orm/datamapper_spec.rb
|
263
|
+
- spec/orm/mongoid_spec.rb
|
238
264
|
- spec/orm/mongomapper_spec.rb
|
239
265
|
- spec/orm/sequel_spec.rb
|
266
|
+
- spec/processing/image_science_spec.rb
|
267
|
+
- spec/processing/mini_magick_spec.rb
|
268
|
+
- spec/processing/rmagick_spec.rb
|
240
269
|
- spec/sanitized_file_spec.rb
|
241
270
|
- spec/spec_helper.rb
|
242
271
|
- spec/storage/grid_fs_spec.rb
|
272
|
+
- spec/storage/right_s3_spec.rb
|
243
273
|
- spec/storage/s3_spec.rb
|
244
274
|
- spec/uploader/cache_spec.rb
|
245
275
|
- spec/uploader/configuration_spec.rb
|