paperclip 3.5.4 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.gitignore +0 -6
- data/.hound.yml +1055 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +17 -20
- data/Appraisals +4 -16
- data/CONTRIBUTING.md +29 -13
- data/Gemfile +11 -3
- data/LICENSE +1 -3
- data/NEWS +241 -49
- data/README.md +471 -166
- data/RELEASING.md +17 -0
- data/Rakefile +6 -8
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +27 -8
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +36 -28
- data/features/step_definitions/html_steps.rb +2 -2
- data/features/step_definitions/rails_steps.rb +68 -37
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/step_definitions/web_steps.rb +1 -103
- data/features/support/env.rb +3 -2
- data/features/support/file_helpers.rb +2 -2
- data/features/support/fixtures/gemfile.txt +1 -1
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +2 -25
- 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 +151 -46
- data/lib/paperclip/attachment_registry.rb +3 -2
- data/lib/paperclip/callbacks.rb +13 -1
- data/lib/paperclip/content_type_detector.rb +26 -22
- data/lib/paperclip/errors.rb +8 -1
- data/lib/paperclip/file_command_content_type_detector.rb +6 -8
- data/lib/paperclip/geometry_detector_factory.rb +5 -3
- data/lib/paperclip/geometry_parser_factory.rb +1 -1
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +17 -1
- data/lib/paperclip/helpers.rb +15 -11
- data/lib/paperclip/interpolations/plural_cache.rb +6 -5
- data/lib/paperclip/interpolations.rb +26 -13
- data/lib/paperclip/io_adapters/abstract_adapter.rb +32 -4
- data/lib/paperclip/io_adapters/attachment_adapter.rb +13 -8
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +11 -16
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
- data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +7 -7
- 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 +10 -6
- data/lib/paperclip/io_adapters/uri_adapter.rb +41 -19
- data/lib/paperclip/locales/en.yml +1 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +2 -1
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +2 -1
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
- data/lib/paperclip/media_type_spoof_detector.rb +90 -0
- data/lib/paperclip/processor.rb +5 -41
- data/lib/paperclip/processor_helpers.rb +50 -0
- data/lib/paperclip/rails_environment.rb +25 -0
- data/lib/paperclip/schema.rb +9 -7
- data/lib/paperclip/storage/filesystem.rb +14 -3
- data/lib/paperclip/storage/fog.rb +37 -19
- data/lib/paperclip/storage/s3.rb +129 -69
- data/lib/paperclip/style.rb +8 -2
- data/lib/paperclip/tempfile_factory.rb +5 -1
- data/lib/paperclip/thumbnail.rb +30 -18
- data/lib/paperclip/url_generator.rb +26 -14
- data/lib/paperclip/validators/attachment_content_type_validator.rb +4 -0
- 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 +4 -0
- data/lib/paperclip/validators/attachment_size_validator.rb +5 -3
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +27 -0
- data/lib/paperclip/validators.rb +11 -4
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +30 -11
- data/lib/tasks/paperclip.rake +34 -5
- data/paperclip.gemspec +21 -16
- data/shoulda_macros/paperclip.rb +0 -1
- data/spec/paperclip/attachment_definitions_spec.rb +13 -0
- data/{test/attachment_processing_test.rb → spec/paperclip/attachment_processing_spec.rb} +17 -20
- data/spec/paperclip/attachment_registry_spec.rb +158 -0
- data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +502 -407
- data/{test/content_type_detector_test.rb → spec/paperclip/content_type_detector_spec.rb} +17 -20
- data/spec/paperclip/file_command_content_type_detector_spec.rb +40 -0
- data/spec/paperclip/filename_cleaner_spec.rb +14 -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} +137 -128
- data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +70 -46
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +132 -0
- data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +33 -32
- 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/{test/io_adapters/file_adapter_test.rb → spec/paperclip/io_adapters/file_adapter_spec.rb} +38 -42
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +121 -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/{test/io_adapters/stringio_adapter_test.rb → spec/paperclip/io_adapters/stringio_adapter_spec.rb} +21 -18
- data/{test/io_adapters/uploaded_file_adapter_test.rb → spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb} +46 -46
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +172 -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 +94 -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/{test/rake_test.rb → spec/paperclip/rake_spec.rb} +15 -15
- 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 +255 -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} +153 -134
- data/spec/paperclip/url_generator_spec.rb +222 -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} +77 -64
- 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 +47 -0
- data/spec/support/assertions.rb +82 -0
- data/spec/support/conditional_filter_helper.rb +5 -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 +348 -225
- 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/gemfiles/4.0.gemfile +0 -11
- data/test/attachment_definitions_test.rb +0 -12
- data/test/attachment_registry_test.rb +0 -88
- data/test/file_command_content_type_detector_test.rb +0 -27
- data/test/filename_cleaner_test.rb +0 -14
- data/test/generator_test.rb +0 -84
- data/test/geometry_detector_test.rb +0 -24
- data/test/has_attached_file_test.rb +0 -125
- data/test/helper.rb +0 -232
- data/test/io_adapters/abstract_adapter_test.rb +0 -58
- data/test/io_adapters/data_uri_adapter_test.rb +0 -74
- data/test/io_adapters/empty_string_adapter_test.rb +0 -18
- data/test/io_adapters/http_url_proxy_adapter_test.rb +0 -102
- data/test/io_adapters/identity_adapter_test.rb +0 -8
- data/test/io_adapters/uri_adapter_test.rb +0 -102
- 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 -69
- 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 -90
- data/test/paperclip_test.rb +0 -217
- data/test/plural_cache_test.rb +0 -36
- data/test/schema_test.rb +0 -200
- data/test/storage/fog_test.rb +0 -473
- data/test/storage/s3_live_test.rb +0 -179
- data/test/storage/s3_test.rb +0 -1356
- data/test/style_test.rb +0 -213
- data/test/support/mock_model.rb +0 -2
- data/test/tempfile_factory_test.rb +0 -17
- data/test/url_generator_test.rb +0 -187
- data/test/validators/attachment_content_type_validator_test.rb +0 -324
- data/test/validators_test.rb +0 -61
- /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,19 +166,19 @@ 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
|
-
|
181
|
+
it "errors when trying to create the thumbnail" do
|
214
182
|
assert_raises(Paperclip::Error) do
|
215
183
|
silence_stream(STDERR) do
|
216
184
|
@thumb.make
|
@@ -218,10 +186,10 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
218
186
|
end
|
219
187
|
end
|
220
188
|
|
221
|
-
|
189
|
+
it "lets us know when a command isn't found versus a processing error" do
|
222
190
|
old_path = ENV['PATH']
|
223
191
|
begin
|
224
|
-
|
192
|
+
Terrapin::CommandLine.path = ''
|
225
193
|
Paperclip.options[:command_path] = ''
|
226
194
|
ENV['PATH'] = ''
|
227
195
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
@@ -237,20 +205,20 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
237
205
|
end
|
238
206
|
|
239
207
|
context "being thumbnailed with a blank geometry string" do
|
240
|
-
|
208
|
+
before do
|
241
209
|
@thumb = Paperclip::Thumbnail.new(@file,
|
242
|
-
:
|
243
|
-
:
|
210
|
+
geometry: "",
|
211
|
+
convert_options: "-gravity center -crop \"300x300+0-0\"")
|
244
212
|
end
|
245
213
|
|
246
|
-
|
214
|
+
it "does not get resized by default" do
|
247
215
|
assert !@thumb.transformation_command.include?("-resize")
|
248
216
|
end
|
249
217
|
end
|
250
218
|
|
251
219
|
context "being thumbnailed with default animated option (true)" do
|
252
|
-
|
253
|
-
thumb = Paperclip::Thumbnail.new(@file, :
|
220
|
+
it "calls identify to check for animated images when sent #make" do
|
221
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
|
254
222
|
thumb.expects(:identify).at_least_once.with do |*arg|
|
255
223
|
arg[0] == '-format %m :file' &&
|
256
224
|
arg[1][:file] == "#{File.expand_path(thumb.file.path)}[0]"
|
@@ -260,11 +228,11 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
260
228
|
end
|
261
229
|
|
262
230
|
context "passing a custom file geometry parser" do
|
263
|
-
|
264
|
-
|
231
|
+
after do
|
232
|
+
Object.send(:remove_const, :GeoParser) if Object.const_defined?(:GeoParser)
|
265
233
|
end
|
266
234
|
|
267
|
-
|
235
|
+
it "produces the appropriate transformation_command" do
|
268
236
|
GeoParser = Class.new do
|
269
237
|
def self.from_file(file)
|
270
238
|
new
|
@@ -275,7 +243,7 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
275
243
|
end
|
276
244
|
end
|
277
245
|
|
278
|
-
thumb = Paperclip::Thumbnail.new(@file, :
|
246
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: '50x50', file_geometry_parser: ::GeoParser)
|
279
247
|
|
280
248
|
transformation_command = thumb.transformation_command
|
281
249
|
|
@@ -291,11 +259,11 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
291
259
|
end
|
292
260
|
|
293
261
|
context "passing a custom geometry string parser" do
|
294
|
-
|
295
|
-
|
262
|
+
after do
|
263
|
+
Object.send(:remove_const, :GeoParser) if Object.const_defined?(:GeoParser)
|
296
264
|
end
|
297
265
|
|
298
|
-
|
266
|
+
it "produces the appropriate transformation_command" do
|
299
267
|
GeoParser = Class.new do
|
300
268
|
def self.parse(s)
|
301
269
|
new
|
@@ -306,7 +274,7 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
306
274
|
end
|
307
275
|
end
|
308
276
|
|
309
|
-
thumb = Paperclip::Thumbnail.new(@file, :
|
277
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: '50x50', string_geometry_parser: ::GeoParser)
|
310
278
|
|
311
279
|
transformation_command = thumb.transformation_command
|
312
280
|
|
@@ -317,32 +285,32 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
317
285
|
end
|
318
286
|
|
319
287
|
context "A multipage PDF" do
|
320
|
-
|
288
|
+
before do
|
321
289
|
@file = File.new(fixture_file("twopage.pdf"), 'rb')
|
322
290
|
end
|
323
291
|
|
324
|
-
|
292
|
+
after { @file.close }
|
325
293
|
|
326
|
-
|
294
|
+
it "starts with two pages with dimensions 612x792" do
|
327
295
|
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
328
296
|
assert_equal "612x792"*2, `#{cmd}`.chomp
|
329
297
|
end
|
330
298
|
|
331
299
|
context "being thumbnailed at 100x100 with cropping" do
|
332
|
-
|
333
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
300
|
+
before do
|
301
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "100x100#", format: :png)
|
334
302
|
end
|
335
303
|
|
336
|
-
|
304
|
+
it "reports its correct current and target geometries" do
|
337
305
|
assert_equal "100x100#", @thumb.target_geometry.to_s
|
338
306
|
assert_equal "612x792", @thumb.current_geometry.to_s
|
339
307
|
end
|
340
308
|
|
341
|
-
|
309
|
+
it "reports its correct format" do
|
342
310
|
assert_equal :png, @thumb.format
|
343
311
|
end
|
344
312
|
|
345
|
-
|
313
|
+
it "creates the thumbnail when sent #make" do
|
346
314
|
dst = @thumb.make
|
347
315
|
assert_match /100x100/, `identify "#{dst.path}"`
|
348
316
|
end
|
@@ -350,23 +318,23 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
350
318
|
end
|
351
319
|
|
352
320
|
context "An animated gif" do
|
353
|
-
|
321
|
+
before do
|
354
322
|
@file = File.new(fixture_file("animated.gif"), 'rb')
|
355
323
|
end
|
356
324
|
|
357
|
-
|
325
|
+
after { @file.close }
|
358
326
|
|
359
|
-
|
327
|
+
it "starts with 12 frames with size 100x100" do
|
360
328
|
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
361
329
|
assert_equal "100x100"*12, `#{cmd}`.chomp
|
362
330
|
end
|
363
331
|
|
364
332
|
context "with static output" do
|
365
|
-
|
366
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
333
|
+
before do
|
334
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :jpg)
|
367
335
|
end
|
368
336
|
|
369
|
-
|
337
|
+
it "creates the single frame thumbnail when sent #make" do
|
370
338
|
dst = @thumb.make
|
371
339
|
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
372
340
|
assert_equal "50x50", `#{cmd}`.chomp
|
@@ -374,11 +342,11 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
374
342
|
end
|
375
343
|
|
376
344
|
context "with animated output format" do
|
377
|
-
|
378
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
345
|
+
before do
|
346
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
|
379
347
|
end
|
380
348
|
|
381
|
-
|
349
|
+
it "creates the 12 frames thumbnail when sent #make" do
|
382
350
|
dst = @thumb.make
|
383
351
|
cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
|
384
352
|
frames = `#{cmd}`.chomp.split(',')
|
@@ -386,21 +354,21 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
386
354
|
assert_frame_dimensions (45..50), frames
|
387
355
|
end
|
388
356
|
|
389
|
-
|
357
|
+
it "uses the -coalesce option" do
|
390
358
|
assert_equal @thumb.transformation_command.first, "-coalesce"
|
391
359
|
end
|
392
360
|
|
393
|
-
|
361
|
+
it "uses the -layers 'optimize' option" do
|
394
362
|
assert_equal @thumb.transformation_command.last, '-layers "optimize"'
|
395
363
|
end
|
396
364
|
end
|
397
365
|
|
398
366
|
context "with omitted output format" do
|
399
|
-
|
400
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
367
|
+
before do
|
368
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50")
|
401
369
|
end
|
402
370
|
|
403
|
-
|
371
|
+
it "creates the 12 frames thumbnail when sent #make" do
|
404
372
|
dst = @thumb.make
|
405
373
|
cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
|
406
374
|
frames = `#{cmd}`.chomp.split(',')
|
@@ -408,22 +376,22 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
408
376
|
assert_frame_dimensions (45..50), frames
|
409
377
|
end
|
410
378
|
|
411
|
-
|
379
|
+
it "uses the -coalesce option" do
|
412
380
|
assert_equal @thumb.transformation_command.first, "-coalesce"
|
413
381
|
end
|
414
382
|
|
415
|
-
|
383
|
+
it "uses the -layers 'optimize' option" do
|
416
384
|
assert_equal @thumb.transformation_command.last, '-layers "optimize"'
|
417
385
|
end
|
418
386
|
end
|
419
387
|
|
420
388
|
context "with unidentified source format" do
|
421
|
-
|
389
|
+
before do
|
422
390
|
@unidentified_file = File.new(fixture_file("animated.unknown"), 'rb')
|
423
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
391
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "60x60")
|
424
392
|
end
|
425
393
|
|
426
|
-
|
394
|
+
it "creates the 12 frames thumbnail when sent #make" do
|
427
395
|
dst = @thumb.make
|
428
396
|
cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
|
429
397
|
frames = `#{cmd}`.chomp.split(',')
|
@@ -431,22 +399,22 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
431
399
|
assert_frame_dimensions (55..60), frames
|
432
400
|
end
|
433
401
|
|
434
|
-
|
402
|
+
it "uses the -coalesce option" do
|
435
403
|
assert_equal @thumb.transformation_command.first, "-coalesce"
|
436
404
|
end
|
437
405
|
|
438
|
-
|
406
|
+
it "uses the -layers 'optimize' option" do
|
439
407
|
assert_equal @thumb.transformation_command.last, '-layers "optimize"'
|
440
408
|
end
|
441
409
|
end
|
442
410
|
|
443
411
|
context "with no source format" do
|
444
|
-
|
412
|
+
before do
|
445
413
|
@unidentified_file = File.new(fixture_file("animated"), 'rb')
|
446
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
414
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "70x70")
|
447
415
|
end
|
448
416
|
|
449
|
-
|
417
|
+
it "creates the 12 frames thumbnail when sent #make" do
|
450
418
|
dst = @thumb.make
|
451
419
|
cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
|
452
420
|
frames = `#{cmd}`.chomp.split(',')
|
@@ -454,31 +422,82 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
454
422
|
assert_frame_dimensions (60..70), frames
|
455
423
|
end
|
456
424
|
|
457
|
-
|
425
|
+
it "uses the -coalesce option" do
|
458
426
|
assert_equal @thumb.transformation_command.first, "-coalesce"
|
459
427
|
end
|
460
428
|
|
461
|
-
|
429
|
+
it "uses the -layers 'optimize' option" do
|
462
430
|
assert_equal @thumb.transformation_command.last, '-layers "optimize"'
|
463
431
|
end
|
464
432
|
end
|
465
433
|
|
466
434
|
context "with animated option set to false" do
|
467
|
-
|
468
|
-
@thumb = Paperclip::Thumbnail.new(@file, :
|
435
|
+
before do
|
436
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", animated: false)
|
469
437
|
end
|
470
438
|
|
471
|
-
|
439
|
+
it "outputs the gif format" do
|
472
440
|
dst = @thumb.make
|
473
441
|
cmd = %Q[identify "#{dst.path}"]
|
474
442
|
assert_match /GIF/, `#{cmd}`.chomp
|
475
443
|
end
|
476
444
|
|
477
|
-
|
445
|
+
it "creates the single frame thumbnail when sent #make" do
|
478
446
|
dst = @thumb.make
|
479
447
|
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
480
448
|
assert_equal "50x50", `#{cmd}`.chomp
|
481
449
|
end
|
482
450
|
end
|
451
|
+
|
452
|
+
context "with a specified frame_index" do
|
453
|
+
before do
|
454
|
+
@thumb = Paperclip::Thumbnail.new(
|
455
|
+
@file,
|
456
|
+
geometry: "50x50",
|
457
|
+
frame_index: 5,
|
458
|
+
format: :jpg,
|
459
|
+
)
|
460
|
+
end
|
461
|
+
|
462
|
+
it "creates the thumbnail from the frame index when sent #make" do
|
463
|
+
@thumb.make
|
464
|
+
assert_equal 5, @thumb.frame_index
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
context "with a specified frame_index out of bounds" do
|
469
|
+
before do
|
470
|
+
@thumb = Paperclip::Thumbnail.new(
|
471
|
+
@file,
|
472
|
+
geometry: "50x50",
|
473
|
+
frame_index: 20,
|
474
|
+
format: :jpg,
|
475
|
+
)
|
476
|
+
end
|
477
|
+
|
478
|
+
it "errors when trying to create the thumbnail" do
|
479
|
+
assert_raises(Paperclip::Error) do
|
480
|
+
silence_stream(STDERR) do
|
481
|
+
@thumb.make
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
context "with a really long file name" do
|
489
|
+
before do
|
490
|
+
tempfile = Tempfile.new("f")
|
491
|
+
tempfile_additional_chars = tempfile.path.split("/")[-1].length + 15
|
492
|
+
image_file = File.new(fixture_file("5k.png"), "rb")
|
493
|
+
@file = Tempfile.new("f" * (255 - tempfile_additional_chars))
|
494
|
+
@file.write(image_file.read)
|
495
|
+
@file.rewind
|
496
|
+
end
|
497
|
+
|
498
|
+
it "does not throw Errno::ENAMETOOLONG" do
|
499
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
|
500
|
+
expect { thumb.make }.to_not raise_error
|
501
|
+
end
|
483
502
|
end
|
484
503
|
end
|