paperclip 3.4.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +3 -0
- data/.gitignore +0 -6
- data/.hound.yml +1055 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +19 -12
- data/Appraisals +4 -11
- data/CONTRIBUTING.md +29 -13
- data/Gemfile +13 -4
- data/LICENSE +1 -3
- data/MIGRATING-ES.md +317 -0
- data/MIGRATING.md +375 -0
- data/NEWS +390 -71
- data/README.md +607 -152
- data/RELEASING.md +17 -0
- data/Rakefile +6 -8
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +34 -21
- data/features/migration.feature +0 -24
- data/features/rake_tasks.feature +2 -3
- data/features/step_definitions/attachment_steps.rb +44 -36
- data/features/step_definitions/html_steps.rb +2 -2
- data/features/step_definitions/rails_steps.rb +125 -26
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +1 -103
- data/features/support/env.rb +3 -2
- data/features/support/fakeweb.rb +4 -1
- data/features/support/file_helpers.rb +12 -2
- data/features/support/fixtures/gemfile.txt +1 -1
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +4 -11
- data/gemfiles/4.2.gemfile +17 -0
- data/gemfiles/5.0.gemfile +17 -0
- data/lib/generators/paperclip/paperclip_generator.rb +9 -3
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +2 -2
- data/lib/paperclip/attachment.rb +215 -82
- data/lib/paperclip/attachment_registry.rb +60 -0
- data/lib/paperclip/callbacks.rb +13 -1
- data/lib/paperclip/content_type_detector.rb +48 -24
- data/lib/paperclip/errors.rb +8 -1
- data/lib/paperclip/file_command_content_type_detector.rb +6 -8
- data/lib/paperclip/filename_cleaner.rb +15 -0
- data/lib/paperclip/geometry_detector_factory.rb +12 -5
- data/lib/paperclip/geometry_parser_factory.rb +1 -1
- data/lib/paperclip/glue.rb +1 -2
- data/lib/paperclip/has_attached_file.rb +115 -0
- data/lib/paperclip/helpers.rb +15 -20
- data/lib/paperclip/interpolations/plural_cache.rb +18 -0
- data/lib/paperclip/interpolations.rb +36 -14
- data/lib/paperclip/io_adapters/abstract_adapter.rb +42 -5
- data/lib/paperclip/io_adapters/attachment_adapter.rb +20 -9
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +22 -0
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +19 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +13 -7
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +16 -0
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +15 -16
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +11 -7
- data/lib/paperclip/io_adapters/uri_adapter.rb +43 -19
- data/lib/paperclip/locales/en.yml +1 -0
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +3 -6
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +7 -2
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
- data/lib/paperclip/matchers.rb +1 -1
- data/lib/paperclip/media_type_spoof_detector.rb +93 -0
- data/lib/paperclip/missing_attachment_styles.rb +11 -16
- data/lib/paperclip/processor.rb +15 -43
- data/lib/paperclip/processor_helpers.rb +50 -0
- data/lib/paperclip/rails_environment.rb +25 -0
- data/lib/paperclip/schema.rb +10 -8
- data/lib/paperclip/storage/filesystem.rb +20 -5
- data/lib/paperclip/storage/fog.rb +49 -23
- data/lib/paperclip/storage/s3.rb +153 -82
- data/lib/paperclip/style.rb +8 -3
- data/lib/paperclip/tempfile_factory.rb +6 -4
- data/lib/paperclip/thumbnail.rb +35 -19
- data/lib/paperclip/url_generator.rb +26 -14
- data/lib/paperclip/validators/attachment_content_type_validator.rb +15 -2
- data/lib/paperclip/validators/attachment_file_name_validator.rb +80 -0
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +29 -0
- data/lib/paperclip/validators/attachment_presence_validator.rb +12 -8
- data/lib/paperclip/validators/attachment_size_validator.rb +17 -10
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +31 -0
- data/lib/paperclip/validators.rb +31 -3
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +41 -55
- data/lib/tasks/paperclip.rake +56 -9
- data/paperclip.gemspec +18 -17
- data/shoulda_macros/paperclip.rb +13 -3
- data/spec/paperclip/attachment_definitions_spec.rb +13 -0
- data/spec/paperclip/attachment_processing_spec.rb +79 -0
- data/spec/paperclip/attachment_registry_spec.rb +158 -0
- data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +597 -389
- data/spec/paperclip/content_type_detector_spec.rb +48 -0
- data/spec/paperclip/file_command_content_type_detector_spec.rb +40 -0
- data/spec/paperclip/filename_cleaner_spec.rb +13 -0
- data/spec/paperclip/geometry_detector_spec.rb +39 -0
- data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
- data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +50 -52
- data/spec/paperclip/glue_spec.rb +44 -0
- data/spec/paperclip/has_attached_file_spec.rb +158 -0
- data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +179 -199
- data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +79 -46
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +160 -0
- data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +54 -25
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +89 -0
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +131 -0
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +138 -0
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
- data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
- data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +12 -9
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +64 -0
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +146 -0
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +220 -0
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +109 -0
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +120 -0
- data/spec/paperclip/meta_class_spec.rb +30 -0
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
- data/spec/paperclip/paperclip_spec.rb +192 -0
- data/spec/paperclip/plural_cache_spec.rb +37 -0
- data/spec/paperclip/processor_helpers_spec.rb +57 -0
- data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +7 -7
- data/spec/paperclip/rails_environment_spec.rb +33 -0
- data/spec/paperclip/rake_spec.rb +103 -0
- data/spec/paperclip/schema_spec.rb +248 -0
- data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
- data/spec/paperclip/storage/fog_spec.rb +566 -0
- data/spec/paperclip/storage/s3_live_spec.rb +188 -0
- data/spec/paperclip/storage/s3_spec.rb +1693 -0
- data/spec/paperclip/style_spec.rb +254 -0
- data/spec/paperclip/tempfile_factory_spec.rb +33 -0
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +186 -141
- data/spec/paperclip/url_generator_spec.rb +221 -0
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
- data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +20 -20
- data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +87 -59
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +52 -0
- data/spec/paperclip/validators_spec.rb +164 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/assertions.rb +82 -0
- data/spec/support/fake_model.rb +25 -0
- data/spec/support/fake_rails.rb +12 -0
- data/spec/support/fixtures/empty.html +1 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/matchers/accept.rb +5 -0
- data/spec/support/matchers/exist.rb +5 -0
- data/spec/support/matchers/have_column.rb +23 -0
- data/{test → spec}/support/mock_attachment.rb +2 -0
- data/{test → spec}/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +68 -0
- data/spec/support/reporting.rb +11 -0
- data/spec/support/test_data.rb +13 -0
- data/spec/support/version_helper.rb +9 -0
- metadata +395 -346
- data/Gemfile.lock +0 -200
- data/RUNNING_TESTS.md +0 -4
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/3.0.gemfile +0 -11
- data/gemfiles/3.1.gemfile +0 -11
- data/gemfiles/3.2.gemfile +0 -11
- data/lib/paperclip/attachment_options.rb +0 -9
- data/lib/paperclip/instance_methods.rb +0 -35
- data/test/attachment_options_test.rb +0 -27
- data/test/attachment_processing_test.rb +0 -29
- data/test/content_type_detector_test.rb +0 -40
- data/test/file_command_content_type_detector_test.rb +0 -25
- data/test/generator_test.rb +0 -80
- data/test/geometry_detector_test.rb +0 -24
- data/test/helper.rb +0 -199
- data/test/io_adapters/abstract_adapter_test.rb +0 -50
- data/test/io_adapters/file_adapter_test.rb +0 -100
- data/test/io_adapters/identity_adapter_test.rb +0 -8
- data/test/io_adapters/stringio_adapter_test.rb +0 -51
- data/test/io_adapters/uploaded_file_adapter_test.rb +0 -123
- data/test/io_adapters/uri_adapter_test.rb +0 -86
- data/test/matchers/have_attached_file_matcher_test.rb +0 -24
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -110
- data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -47
- data/test/matchers/validate_attachment_size_matcher_test.rb +0 -86
- data/test/meta_class_test.rb +0 -32
- data/test/paperclip_missing_attachment_styles_test.rb +0 -94
- data/test/paperclip_test.rb +0 -259
- data/test/schema_test.rb +0 -200
- data/test/storage/fog_test.rb +0 -453
- data/test/storage/s3_live_test.rb +0 -179
- data/test/storage/s3_test.rb +0 -1236
- data/test/style_test.rb +0 -213
- data/test/support/mock_model.rb +0 -2
- data/test/tempfile_factory_test.rb +0 -13
- data/test/url_generator_test.rb +0 -187
- data/test/validators/attachment_content_type_validator_test.rb +0 -292
- data/test/validators_test.rb +0 -25
- /data/{test → spec}/database.yml +0 -0
- /data/{test → spec/support}/fixtures/12k.png +0 -0
- /data/{test → spec/support}/fixtures/50x50.png +0 -0
- /data/{test → spec/support}/fixtures/5k.png +0 -0
- /data/{test → spec/support}/fixtures/animated +0 -0
- /data/{test → spec/support}/fixtures/animated.gif +0 -0
- /data/{test → spec/support}/fixtures/animated.unknown +0 -0
- /data/{test → spec/support}/fixtures/bad.png +0 -0
- /data/{test → spec/support}/fixtures/fog.yml +0 -0
- /data/{test → spec/support}/fixtures/rotated.jpg +0 -0
- /data/{test → spec/support}/fixtures/s3.yml +0 -0
- /data/{test → spec/support}/fixtures/spaced file.png +0 -0
- /data/{test → spec/support}/fixtures/text.txt +0 -0
- /data/{test → spec/support}/fixtures/twopage.pdf +0 -0
- /data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
- /data/{test → spec}/support/mock_interpolator.rb +0 -0
@@ -1,70 +1,38 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
class ThumbnailTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "A Paperclip Tempfile" do
|
6
|
-
setup do
|
7
|
-
@tempfile = Paperclip::Tempfile.new(["file", ".jpg"])
|
8
|
-
end
|
9
|
-
|
10
|
-
teardown { @tempfile.close }
|
11
|
-
|
12
|
-
should "have its path contain a real extension" do
|
13
|
-
assert_equal ".jpg", File.extname(@tempfile.path)
|
14
|
-
end
|
15
|
-
|
16
|
-
should "be a real Tempfile" do
|
17
|
-
assert @tempfile.is_a?(::Tempfile)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "Another Paperclip Tempfile" do
|
22
|
-
setup do
|
23
|
-
@tempfile = Paperclip::Tempfile.new("file")
|
24
|
-
end
|
25
|
-
|
26
|
-
teardown { @tempfile.close }
|
27
|
-
|
28
|
-
should "not have an extension if not given one" do
|
29
|
-
assert_equal "", File.extname(@tempfile.path)
|
30
|
-
end
|
31
|
-
|
32
|
-
should "still be a real Tempfile" do
|
33
|
-
assert @tempfile.is_a?(::Tempfile)
|
34
|
-
end
|
35
|
-
end
|
1
|
+
require 'spec_helper'
|
36
2
|
|
3
|
+
describe Paperclip::Thumbnail do
|
37
4
|
context "An image" do
|
38
|
-
|
5
|
+
before do
|
39
6
|
@file = File.new(fixture_file("5k.png"), 'rb')
|
40
7
|
end
|
41
8
|
|
42
|
-
|
9
|
+
after { @file.close }
|
43
10
|
|
44
11
|
[["600x600>", "434x66"],
|
45
12
|
["400x400>", "400x61"],
|
46
|
-
["32x32<", "434x66"]
|
13
|
+
["32x32<", "434x66"],
|
14
|
+
[nil, "434x66"]
|
47
15
|
].each do |args|
|
48
16
|
context "being thumbnailed with a geometry of #{args[0]}" do
|
49
|
-
|
50
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
17
|
+
before do
|
18
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: args[0])
|
51
19
|
end
|
52
20
|
|
53
|
-
|
21
|
+
it "starts with dimensions of 434x66" do
|
54
22
|
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
55
23
|
assert_equal "434x66", `#{cmd}`.chomp
|
56
24
|
end
|
57
25
|
|
58
|
-
|
59
|
-
assert_equal args[0], @thumb.target_geometry.to_s
|
26
|
+
it "reports the correct target geometry" do
|
27
|
+
assert_equal args[0].to_s, @thumb.target_geometry.to_s
|
60
28
|
end
|
61
29
|
|
62
30
|
context "when made" do
|
63
|
-
|
31
|
+
before do
|
64
32
|
@thumb_result = @thumb.make
|
65
33
|
end
|
66
34
|
|
67
|
-
|
35
|
+
it "is the size we expect it to be" do
|
68
36
|
cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
|
69
37
|
assert_equal args[1], `#{cmd}`.chomp
|
70
38
|
end
|
@@ -73,14 +41,14 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
73
41
|
end
|
74
42
|
|
75
43
|
context "being thumbnailed at 100x50 with cropping" do
|
76
|
-
|
77
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
44
|
+
before do
|
45
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
|
78
46
|
end
|
79
47
|
|
80
|
-
|
48
|
+
it "lets us know when a command isn't found versus a processing error" do
|
81
49
|
old_path = ENV['PATH']
|
82
50
|
begin
|
83
|
-
|
51
|
+
Terrapin::CommandLine.path = ''
|
84
52
|
Paperclip.options[:command_path] = ''
|
85
53
|
ENV['PATH'] = ''
|
86
54
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
@@ -93,28 +61,28 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
93
61
|
end
|
94
62
|
end
|
95
63
|
|
96
|
-
|
64
|
+
it "reports its correct current and target geometries" do
|
97
65
|
assert_equal "100x50#", @thumb.target_geometry.to_s
|
98
66
|
assert_equal "434x66", @thumb.current_geometry.to_s
|
99
67
|
end
|
100
68
|
|
101
|
-
|
69
|
+
it "reports its correct format" do
|
102
70
|
assert_nil @thumb.format
|
103
71
|
end
|
104
72
|
|
105
|
-
|
73
|
+
it "has whiny turned on by default" do
|
106
74
|
assert @thumb.whiny
|
107
75
|
end
|
108
76
|
|
109
|
-
|
77
|
+
it "has convert_options set to nil by default" do
|
110
78
|
assert_equal nil, @thumb.convert_options
|
111
79
|
end
|
112
80
|
|
113
|
-
|
81
|
+
it "has source_file_options set to nil by default" do
|
114
82
|
assert_equal nil, @thumb.source_file_options
|
115
83
|
end
|
116
84
|
|
117
|
-
|
85
|
+
it "sends the right command to convert when sent #make" do
|
118
86
|
@thumb.expects(:convert).with do |*arg|
|
119
87
|
arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' &&
|
120
88
|
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
@@ -122,34 +90,34 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
122
90
|
@thumb.make
|
123
91
|
end
|
124
92
|
|
125
|
-
|
93
|
+
it "creates the thumbnail when sent #make" do
|
126
94
|
dst = @thumb.make
|
127
95
|
assert_match /100x50/, `identify "#{dst.path}"`
|
128
96
|
end
|
129
97
|
end
|
130
98
|
|
131
|
-
|
99
|
+
it 'crops a EXIF-rotated image properly' do
|
132
100
|
file = File.new(fixture_file('rotated.jpg'))
|
133
|
-
thumb = Paperclip::Thumbnail.new(file, :
|
101
|
+
thumb = Paperclip::Thumbnail.new(file, geometry: "50x50#")
|
134
102
|
|
135
103
|
output_file = thumb.make
|
136
104
|
|
137
|
-
command =
|
138
|
-
assert_equal "50x50", command.run(:
|
105
|
+
command = Terrapin::CommandLine.new("identify", "-format %wx%h :file")
|
106
|
+
assert_equal "50x50", command.run(file: output_file.path).strip
|
139
107
|
end
|
140
108
|
|
141
109
|
context "being thumbnailed with source file options set" do
|
142
|
-
|
110
|
+
before do
|
143
111
|
@thumb = Paperclip::Thumbnail.new(@file,
|
144
|
-
:
|
145
|
-
:
|
112
|
+
geometry: "100x50#",
|
113
|
+
source_file_options: "-strip")
|
146
114
|
end
|
147
115
|
|
148
|
-
|
116
|
+
it "has source_file_options value set" do
|
149
117
|
assert_equal ["-strip"], @thumb.source_file_options
|
150
118
|
end
|
151
119
|
|
152
|
-
|
120
|
+
it "sends the right command to convert when sent #make" do
|
153
121
|
@thumb.expects(:convert).with do |*arg|
|
154
122
|
arg[0] == '-strip :source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' &&
|
155
123
|
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
@@ -157,19 +125,19 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
157
125
|
@thumb.make
|
158
126
|
end
|
159
127
|
|
160
|
-
|
128
|
+
it "creates the thumbnail when sent #make" do
|
161
129
|
dst = @thumb.make
|
162
130
|
assert_match /100x50/, `identify "#{dst.path}"`
|
163
131
|
end
|
164
132
|
|
165
133
|
context "redefined to have bad source_file_options setting" do
|
166
|
-
|
134
|
+
before do
|
167
135
|
@thumb = Paperclip::Thumbnail.new(@file,
|
168
|
-
:
|
169
|
-
:
|
136
|
+
geometry: "100x50#",
|
137
|
+
source_file_options: "-this-aint-no-option")
|
170
138
|
end
|
171
139
|
|
172
|
-
|
140
|
+
it "errors when trying to create the thumbnail" do
|
173
141
|
assert_raises(Paperclip::Error) do
|
174
142
|
silence_stream(STDERR) do
|
175
143
|
@thumb.make
|
@@ -180,17 +148,17 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
180
148
|
end
|
181
149
|
|
182
150
|
context "being thumbnailed with convert options set" do
|
183
|
-
|
151
|
+
before do
|
184
152
|
@thumb = Paperclip::Thumbnail.new(@file,
|
185
|
-
:
|
186
|
-
:
|
153
|
+
geometry: "100x50#",
|
154
|
+
convert_options: "-strip -depth 8")
|
187
155
|
end
|
188
156
|
|
189
|
-
|
157
|
+
it "has convert_options value set" do
|
190
158
|
assert_equal %w"-strip -depth 8", @thumb.convert_options
|
191
159
|
end
|
192
160
|
|
193
|
-
|
161
|
+
it "sends the right command to convert when sent #make" do
|
194
162
|
@thumb.expects(:convert).with do |*arg|
|
195
163
|
arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
|
196
164
|
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
@@ -198,30 +166,32 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
198
166
|
@thumb.make
|
199
167
|
end
|
200
168
|
|
201
|
-
|
169
|
+
it "creates the thumbnail when sent #make" do
|
202
170
|
dst = @thumb.make
|
203
171
|
assert_match /100x50/, `identify "#{dst.path}"`
|
204
172
|
end
|
205
173
|
|
206
174
|
context "redefined to have bad convert_options setting" do
|
207
|
-
|
175
|
+
before do
|
208
176
|
@thumb = Paperclip::Thumbnail.new(@file,
|
209
|
-
:
|
210
|
-
:
|
177
|
+
geometry: "100x50#",
|
178
|
+
convert_options: "-this-aint-no-option")
|
211
179
|
end
|
212
180
|
|
213
|
-
|
214
|
-
|
215
|
-
|
181
|
+
it "errors when trying to create the thumbnail" do
|
182
|
+
silence_stream(STDERR) do
|
183
|
+
expect {
|
216
184
|
@thumb.make
|
217
|
-
|
185
|
+
}.to raise_error(
|
186
|
+
Paperclip::Error, /unrecognized option `-this-aint-no-option'/
|
187
|
+
)
|
218
188
|
end
|
219
189
|
end
|
220
190
|
|
221
|
-
|
191
|
+
it "lets us know when a command isn't found versus a processing error" do
|
222
192
|
old_path = ENV['PATH']
|
223
193
|
begin
|
224
|
-
|
194
|
+
Terrapin::CommandLine.path = ''
|
225
195
|
Paperclip.options[:command_path] = ''
|
226
196
|
ENV['PATH'] = ''
|
227
197
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
@@ -237,20 +207,20 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
237
207
|
end
|
238
208
|
|
239
209
|
context "being thumbnailed with a blank geometry string" do
|
240
|
-
|
210
|
+
before do
|
241
211
|
@thumb = Paperclip::Thumbnail.new(@file,
|
242
|
-
:
|
243
|
-
:
|
212
|
+
geometry: "",
|
213
|
+
convert_options: "-gravity center -crop \"300x300+0-0\"")
|
244
214
|
end
|
245
215
|
|
246
|
-
|
216
|
+
it "does not get resized by default" do
|
247
217
|
assert !@thumb.transformation_command.include?("-resize")
|
248
218
|
end
|
249
219
|
end
|
250
220
|
|
251
221
|
context "being thumbnailed with default animated option (true)" do
|
252
|
-
|
253
|
-
thumb = Paperclip::Thumbnail.new(@file, :
|
222
|
+
it "calls identify to check for animated images when sent #make" do
|
223
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
|
254
224
|
thumb.expects(:identify).at_least_once.with do |*arg|
|
255
225
|
arg[0] == '-format %m :file' &&
|
256
226
|
arg[1][:file] == "#{File.expand_path(thumb.file.path)}[0]"
|
@@ -260,11 +230,11 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
260
230
|
end
|
261
231
|
|
262
232
|
context "passing a custom file geometry parser" do
|
263
|
-
|
264
|
-
|
233
|
+
after do
|
234
|
+
Object.send(:remove_const, :GeoParser) if Object.const_defined?(:GeoParser)
|
265
235
|
end
|
266
236
|
|
267
|
-
|
237
|
+
it "produces the appropriate transformation_command" do
|
268
238
|
GeoParser = Class.new do
|
269
239
|
def self.from_file(file)
|
270
240
|
new
|
@@ -275,7 +245,7 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
275
245
|
end
|
276
246
|
end
|
277
247
|
|
278
|
-
thumb = Paperclip::Thumbnail.new(@file, :
|
248
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: '50x50', file_geometry_parser: ::GeoParser)
|
279
249
|
|
280
250
|
transformation_command = thumb.transformation_command
|
281
251
|
|
@@ -291,11 +261,11 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
291
261
|
end
|
292
262
|
|
293
263
|
context "passing a custom geometry string parser" do
|
294
|
-
|
295
|
-
|
264
|
+
after do
|
265
|
+
Object.send(:remove_const, :GeoParser) if Object.const_defined?(:GeoParser)
|
296
266
|
end
|
297
267
|
|
298
|
-
|
268
|
+
it "produces the appropriate transformation_command" do
|
299
269
|
GeoParser = Class.new do
|
300
270
|
def self.parse(s)
|
301
271
|
new
|
@@ -306,7 +276,7 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
306
276
|
end
|
307
277
|
end
|
308
278
|
|
309
|
-
thumb = Paperclip::Thumbnail.new(@file, :
|
279
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: '50x50', string_geometry_parser: ::GeoParser)
|
310
280
|
|
311
281
|
transformation_command = thumb.transformation_command
|
312
282
|
|
@@ -317,32 +287,32 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
317
287
|
end
|
318
288
|
|
319
289
|
context "A multipage PDF" do
|
320
|
-
|
290
|
+
before do
|
321
291
|
@file = File.new(fixture_file("twopage.pdf"), 'rb')
|
322
292
|
end
|
323
293
|
|
324
|
-
|
294
|
+
after { @file.close }
|
325
295
|
|
326
|
-
|
296
|
+
it "starts with two pages with dimensions 612x792" do
|
327
297
|
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
328
298
|
assert_equal "612x792"*2, `#{cmd}`.chomp
|
329
299
|
end
|
330
300
|
|
331
301
|
context "being thumbnailed at 100x100 with cropping" do
|
332
|
-
|
333
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
302
|
+
before do
|
303
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "100x100#", format: :png)
|
334
304
|
end
|
335
305
|
|
336
|
-
|
306
|
+
it "reports its correct current and target geometries" do
|
337
307
|
assert_equal "100x100#", @thumb.target_geometry.to_s
|
338
308
|
assert_equal "612x792", @thumb.current_geometry.to_s
|
339
309
|
end
|
340
310
|
|
341
|
-
|
311
|
+
it "reports its correct format" do
|
342
312
|
assert_equal :png, @thumb.format
|
343
313
|
end
|
344
314
|
|
345
|
-
|
315
|
+
it "creates the thumbnail when sent #make" do
|
346
316
|
dst = @thumb.make
|
347
317
|
assert_match /100x100/, `identify "#{dst.path}"`
|
348
318
|
end
|
@@ -350,23 +320,23 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
350
320
|
end
|
351
321
|
|
352
322
|
context "An animated gif" do
|
353
|
-
|
323
|
+
before do
|
354
324
|
@file = File.new(fixture_file("animated.gif"), 'rb')
|
355
325
|
end
|
356
326
|
|
357
|
-
|
327
|
+
after { @file.close }
|
358
328
|
|
359
|
-
|
329
|
+
it "starts with 12 frames with size 100x100" do
|
360
330
|
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
361
331
|
assert_equal "100x100"*12, `#{cmd}`.chomp
|
362
332
|
end
|
363
333
|
|
364
334
|
context "with static output" do
|
365
|
-
|
366
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
335
|
+
before do
|
336
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :jpg)
|
367
337
|
end
|
368
338
|
|
369
|
-
|
339
|
+
it "creates the single frame thumbnail when sent #make" do
|
370
340
|
dst = @thumb.make
|
371
341
|
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
372
342
|
assert_equal "50x50", `#{cmd}`.chomp
|
@@ -374,87 +344,162 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
374
344
|
end
|
375
345
|
|
376
346
|
context "with animated output format" do
|
377
|
-
|
378
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
347
|
+
before do
|
348
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
|
379
349
|
end
|
380
350
|
|
381
|
-
|
351
|
+
it "creates the 12 frames thumbnail when sent #make" do
|
382
352
|
dst = @thumb.make
|
383
|
-
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
384
|
-
|
353
|
+
cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
|
354
|
+
frames = `#{cmd}`.chomp.split(',')
|
355
|
+
assert_equal 12, frames.size
|
356
|
+
assert_frame_dimensions (45..50), frames
|
385
357
|
end
|
386
358
|
|
387
|
-
|
359
|
+
it "uses the -coalesce option" do
|
388
360
|
assert_equal @thumb.transformation_command.first, "-coalesce"
|
389
361
|
end
|
362
|
+
|
363
|
+
it "uses the -layers 'optimize' option" do
|
364
|
+
assert_equal @thumb.transformation_command.last, '-layers "optimize"'
|
365
|
+
end
|
390
366
|
end
|
391
367
|
|
392
368
|
context "with omitted output format" do
|
393
|
-
|
394
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
369
|
+
before do
|
370
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50")
|
395
371
|
end
|
396
372
|
|
397
|
-
|
373
|
+
it "creates the 12 frames thumbnail when sent #make" do
|
398
374
|
dst = @thumb.make
|
399
|
-
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
400
|
-
|
375
|
+
cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
|
376
|
+
frames = `#{cmd}`.chomp.split(',')
|
377
|
+
assert_equal 12, frames.size
|
378
|
+
assert_frame_dimensions (45..50), frames
|
401
379
|
end
|
402
380
|
|
403
|
-
|
381
|
+
it "uses the -coalesce option" do
|
404
382
|
assert_equal @thumb.transformation_command.first, "-coalesce"
|
405
383
|
end
|
384
|
+
|
385
|
+
it "uses the -layers 'optimize' option" do
|
386
|
+
assert_equal @thumb.transformation_command.last, '-layers "optimize"'
|
387
|
+
end
|
406
388
|
end
|
407
389
|
|
408
390
|
context "with unidentified source format" do
|
409
|
-
|
391
|
+
before do
|
410
392
|
@unidentified_file = File.new(fixture_file("animated.unknown"), 'rb')
|
411
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
393
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "60x60")
|
412
394
|
end
|
413
395
|
|
414
|
-
|
396
|
+
it "creates the 12 frames thumbnail when sent #make" do
|
415
397
|
dst = @thumb.make
|
416
|
-
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
417
|
-
|
398
|
+
cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
|
399
|
+
frames = `#{cmd}`.chomp.split(',')
|
400
|
+
assert_equal 12, frames.size
|
401
|
+
assert_frame_dimensions (55..60), frames
|
418
402
|
end
|
419
403
|
|
420
|
-
|
404
|
+
it "uses the -coalesce option" do
|
421
405
|
assert_equal @thumb.transformation_command.first, "-coalesce"
|
422
406
|
end
|
407
|
+
|
408
|
+
it "uses the -layers 'optimize' option" do
|
409
|
+
assert_equal @thumb.transformation_command.last, '-layers "optimize"'
|
410
|
+
end
|
423
411
|
end
|
424
412
|
|
425
413
|
context "with no source format" do
|
426
|
-
|
414
|
+
before do
|
427
415
|
@unidentified_file = File.new(fixture_file("animated"), 'rb')
|
428
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
416
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "70x70")
|
429
417
|
end
|
430
418
|
|
431
|
-
|
419
|
+
it "creates the 12 frames thumbnail when sent #make" do
|
432
420
|
dst = @thumb.make
|
433
|
-
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
434
|
-
|
421
|
+
cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
|
422
|
+
frames = `#{cmd}`.chomp.split(',')
|
423
|
+
assert_equal 12, frames.size
|
424
|
+
assert_frame_dimensions (60..70), frames
|
435
425
|
end
|
436
426
|
|
437
|
-
|
427
|
+
it "uses the -coalesce option" do
|
438
428
|
assert_equal @thumb.transformation_command.first, "-coalesce"
|
439
429
|
end
|
430
|
+
|
431
|
+
it "uses the -layers 'optimize' option" do
|
432
|
+
assert_equal @thumb.transformation_command.last, '-layers "optimize"'
|
433
|
+
end
|
440
434
|
end
|
441
435
|
|
442
436
|
context "with animated option set to false" do
|
443
|
-
|
444
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
437
|
+
before do
|
438
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", animated: false)
|
445
439
|
end
|
446
440
|
|
447
|
-
|
441
|
+
it "outputs the gif format" do
|
448
442
|
dst = @thumb.make
|
449
443
|
cmd = %Q[identify "#{dst.path}"]
|
450
444
|
assert_match /GIF/, `#{cmd}`.chomp
|
451
445
|
end
|
452
446
|
|
453
|
-
|
447
|
+
it "creates the single frame thumbnail when sent #make" do
|
454
448
|
dst = @thumb.make
|
455
449
|
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
456
450
|
assert_equal "50x50", `#{cmd}`.chomp
|
457
451
|
end
|
458
452
|
end
|
453
|
+
|
454
|
+
context "with a specified frame_index" do
|
455
|
+
before do
|
456
|
+
@thumb = Paperclip::Thumbnail.new(
|
457
|
+
@file,
|
458
|
+
geometry: "50x50",
|
459
|
+
frame_index: 5,
|
460
|
+
format: :jpg,
|
461
|
+
)
|
462
|
+
end
|
463
|
+
|
464
|
+
it "creates the thumbnail from the frame index when sent #make" do
|
465
|
+
@thumb.make
|
466
|
+
assert_equal 5, @thumb.frame_index
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
context "with a specified frame_index out of bounds" do
|
471
|
+
before do
|
472
|
+
@thumb = Paperclip::Thumbnail.new(
|
473
|
+
@file,
|
474
|
+
geometry: "50x50",
|
475
|
+
frame_index: 20,
|
476
|
+
format: :jpg,
|
477
|
+
)
|
478
|
+
end
|
479
|
+
|
480
|
+
it "errors when trying to create the thumbnail" do
|
481
|
+
assert_raises(Paperclip::Error) do
|
482
|
+
silence_stream(STDERR) do
|
483
|
+
@thumb.make
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
context "with a really long file name" do
|
491
|
+
before do
|
492
|
+
tempfile = Tempfile.new("f")
|
493
|
+
tempfile_additional_chars = tempfile.path.split("/")[-1].length + 15
|
494
|
+
image_file = File.new(fixture_file("5k.png"), "rb")
|
495
|
+
@file = Tempfile.new("f" * (255 - tempfile_additional_chars))
|
496
|
+
@file.write(image_file.read)
|
497
|
+
@file.rewind
|
498
|
+
end
|
499
|
+
|
500
|
+
it "does not throw Errno::ENAMETOOLONG" do
|
501
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
|
502
|
+
expect { thumb.make }.to_not raise_error
|
503
|
+
end
|
459
504
|
end
|
460
505
|
end
|