jr-paperclip 8.0.1 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/NEWS +9 -0
- data/lib/paperclip/thumbnail.rb +18 -15
- data/lib/paperclip/version.rb +1 -1
- metadata +3 -245
- data/.github/FUNDING.yml +0 -3
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -18
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/.github/workflows/reviewdog.yml +0 -23
- data/.github/workflows/tests.yml +0 -56
- data/.gitignore +0 -19
- data/.qlty/.gitignore +0 -7
- data/.qlty/qlty.toml +0 -89
- data/Appraisals +0 -29
- data/Gemfile +0 -18
- data/bin/console +0 -11
- data/features/basic_integration.feature +0 -112
- data/features/migration.feature +0 -29
- data/features/rake_tasks.feature +0 -62
- data/features/step_definitions/attachment_steps.rb +0 -138
- data/features/step_definitions/html_steps.rb +0 -15
- data/features/step_definitions/rails_steps.rb +0 -271
- data/features/step_definitions/s3_steps.rb +0 -16
- data/features/step_definitions/web_steps.rb +0 -106
- data/features/support/env.rb +0 -12
- data/features/support/file_helpers.rb +0 -34
- data/features/support/fixtures/boot_config.txt +0 -15
- data/features/support/fixtures/gemfile.txt +0 -5
- data/features/support/fixtures/preinitializer.txt +0 -20
- data/features/support/paths.rb +0 -28
- data/features/support/rails.rb +0 -39
- data/features/support/selectors.rb +0 -19
- data/features/support/webmock_setup.rb +0 -8
- data/gemfiles/7.0.gemfile +0 -21
- data/gemfiles/7.1.gemfile +0 -21
- data/gemfiles/7.2.gemfile +0 -21
- data/gemfiles/8.0.gemfile +0 -21
- data/gemfiles/8.1.gemfile +0 -21
- data/paperclip.gemspec +0 -52
- data/spec/database.yml +0 -4
- data/spec/paperclip/attachment_definitions_spec.rb +0 -313
- data/spec/paperclip/attachment_processing_spec.rb +0 -79
- data/spec/paperclip/attachment_registry_spec.rb +0 -158
- data/spec/paperclip/attachment_spec.rb +0 -1617
- data/spec/paperclip/content_type_detector_spec.rb +0 -58
- data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -40
- data/spec/paperclip/filename_cleaner_spec.rb +0 -13
- data/spec/paperclip/geometry_detector_spec.rb +0 -96
- data/spec/paperclip/geometry_parser_spec.rb +0 -73
- data/spec/paperclip/geometry_spec.rb +0 -270
- data/spec/paperclip/glue_spec.rb +0 -63
- data/spec/paperclip/has_attached_file_spec.rb +0 -78
- data/spec/paperclip/helpers_spec.rb +0 -49
- data/spec/paperclip/integration_spec.rb +0 -702
- data/spec/paperclip/interpolations_spec.rb +0 -270
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +0 -160
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +0 -167
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +0 -88
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +0 -17
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +0 -134
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +0 -142
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +0 -8
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +0 -25
- data/spec/paperclip/io_adapters/registry_spec.rb +0 -35
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +0 -64
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +0 -146
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +0 -231
- data/spec/paperclip/lazy_thumbnail_compatibility_spec.rb +0 -266
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +0 -19
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +0 -108
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +0 -69
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +0 -88
- data/spec/paperclip/media_type_spoof_detector_spec.rb +0 -126
- data/spec/paperclip/meta_class_spec.rb +0 -30
- data/spec/paperclip/migration_guide_example_spec.rb +0 -44
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +0 -88
- data/spec/paperclip/paperclip_spec.rb +0 -196
- data/spec/paperclip/plural_cache_spec.rb +0 -37
- data/spec/paperclip/processor_helpers_spec.rb +0 -57
- data/spec/paperclip/processor_spec.rb +0 -60
- data/spec/paperclip/rails_environment_spec.rb +0 -30
- data/spec/paperclip/rake_spec.rb +0 -103
- data/spec/paperclip/schema_spec.rb +0 -298
- data/spec/paperclip/storage/filesystem_spec.rb +0 -102
- data/spec/paperclip/storage/fog_spec.rb +0 -606
- data/spec/paperclip/storage/s3_live_spec.rb +0 -188
- data/spec/paperclip/storage/s3_spec.rb +0 -1974
- data/spec/paperclip/style_spec.rb +0 -309
- data/spec/paperclip/tempfile_factory_spec.rb +0 -33
- data/spec/paperclip/tempfile_spec.rb +0 -35
- data/spec/paperclip/thumbnail_custom_options_spec.rb +0 -225
- data/spec/paperclip/thumbnail_loader_options_spec.rb +0 -53
- data/spec/paperclip/thumbnail_security_spec.rb +0 -42
- data/spec/paperclip/thumbnail_spec.rb +0 -1460
- data/spec/paperclip/url_generator_spec.rb +0 -231
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +0 -410
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +0 -249
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +0 -85
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +0 -325
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +0 -48
- data/spec/paperclip/validators_spec.rb +0 -179
- data/spec/spec_helper.rb +0 -52
- data/spec/support/assertions.rb +0 -84
- data/spec/support/fake_model.rb +0 -24
- data/spec/support/fake_rails.rb +0 -12
- data/spec/support/fixtures/12k.png +0 -0
- data/spec/support/fixtures/50x50.png +0 -0
- data/spec/support/fixtures/5k.png +0 -0
- data/spec/support/fixtures/animated +0 -0
- data/spec/support/fixtures/animated.gif +0 -0
- data/spec/support/fixtures/animated.unknown +0 -0
- data/spec/support/fixtures/aws_s3.yml +0 -13
- data/spec/support/fixtures/bad.png +0 -1
- data/spec/support/fixtures/empty.html +0 -1
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/fog.yml +0 -8
- data/spec/support/fixtures/rotated.jpg +0 -0
- data/spec/support/fixtures/s3.yml +0 -8
- data/spec/support/fixtures/sample.xlsm +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/fixtures/spaced file.png +0 -0
- data/spec/support/fixtures/text.txt +0 -1
- data/spec/support/fixtures/twopage.pdf +0 -0
- data/spec/support/fixtures/uppercase.PNG +0 -0
- data/spec/support/matchers/accept.rb +0 -5
- data/spec/support/matchers/exist.rb +0 -5
- data/spec/support/matchers/have_column.rb +0 -23
- data/spec/support/mock_attachment.rb +0 -24
- data/spec/support/mock_interpolator.rb +0 -24
- data/spec/support/mock_url_generator_builder.rb +0 -26
- data/spec/support/model_reconstruction.rb +0 -72
- data/spec/support/reporting.rb +0 -11
- data/spec/support/test_data.rb +0 -13
- data/spec/support/version_helper.rb +0 -9
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Paperclip::Style do
|
|
4
|
-
context "A style rule" do
|
|
5
|
-
before do
|
|
6
|
-
@attachment = attachment path: ":basename.:extension",
|
|
7
|
-
styles: { foo: { geometry: "100x100#", format: :png } },
|
|
8
|
-
whiny: true
|
|
9
|
-
@style = @attachment.styles[:foo]
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "is held as a Style object" do
|
|
13
|
-
expect(@style).to be_a Paperclip::Style
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "gets processors from the attachment definition" do
|
|
17
|
-
assert_equal [:thumbnail], @style.processors
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "has the right geometry" do
|
|
21
|
-
assert_equal "100x100#", @style.geometry
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "is whiny if the attachment is" do
|
|
25
|
-
assert @style.whiny?
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "responds to hash notation" do
|
|
29
|
-
assert_equal [:thumbnail], @style[:processors]
|
|
30
|
-
assert_equal "100x100#", @style[:geometry]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "returns the name of the style in processor options" do
|
|
34
|
-
assert_equal :foo, @style.processor_options[:style]
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context "A style rule with properties supplied as procs" do
|
|
39
|
-
before do
|
|
40
|
-
@attachment = attachment path: ":basename.:extension",
|
|
41
|
-
whiny_thumbnails: true,
|
|
42
|
-
processors: lambda { |_a| [:test] },
|
|
43
|
-
styles: {
|
|
44
|
-
foo: lambda { |_a| "300x300#" },
|
|
45
|
-
bar: {
|
|
46
|
-
geometry: lambda { |_a| "300x300#" },
|
|
47
|
-
convert_options: lambda { |_a| "-do_stuff" },
|
|
48
|
-
source_file_options: lambda { |_a| "-do_extra_stuff" }
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "calls procs when they are needed" do
|
|
54
|
-
assert_equal "300x300#", @attachment.styles[:foo].geometry
|
|
55
|
-
assert_equal "300x300#", @attachment.styles[:bar].geometry
|
|
56
|
-
assert_equal [:test], @attachment.styles[:foo].processors
|
|
57
|
-
assert_equal [:test], @attachment.styles[:bar].processors
|
|
58
|
-
assert_equal "-do_stuff", @attachment.styles[:bar].convert_options
|
|
59
|
-
assert_equal "-do_extra_stuff", @attachment.styles[:bar].source_file_options
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context "An attachment with style rules in various forms" do
|
|
64
|
-
before do
|
|
65
|
-
styles = {}
|
|
66
|
-
styles[:aslist] = ["100x100", :png]
|
|
67
|
-
styles[:ashash] = { geometry: "100x100", format: :png }
|
|
68
|
-
styles[:asstring] = "100x100"
|
|
69
|
-
@attachment = attachment path: ":basename.:extension",
|
|
70
|
-
styles: styles
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "has the right number of styles" do
|
|
74
|
-
expect(@attachment.styles).to be_a Hash
|
|
75
|
-
assert_equal 3, @attachment.styles.size
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "has styles as Style objects" do
|
|
79
|
-
[:aslist, :ashash, :aslist].each do |s|
|
|
80
|
-
expect(@attachment.styles[s]).to be_a Paperclip::Style
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it "has the right geometries" do
|
|
85
|
-
[:aslist, :ashash, :aslist].each do |s|
|
|
86
|
-
assert_equal @attachment.styles[s].geometry, "100x100"
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "has the right formats" do
|
|
91
|
-
assert_equal @attachment.styles[:aslist].format, :png
|
|
92
|
-
assert_equal @attachment.styles[:ashash].format, :png
|
|
93
|
-
assert_nil @attachment.styles[:asstring].format
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "retains order" do
|
|
97
|
-
assert_equal [:aslist, :ashash, :asstring], @attachment.styles.keys
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
context "An attachment with :convert_options" do
|
|
102
|
-
it "does not have called extra_options_for(:thumb/:large) on initialization" do
|
|
103
|
-
@attachment = attachment path: ":basename.:extension",
|
|
104
|
-
styles: { thumb: "100x100", large: "400x400" },
|
|
105
|
-
convert_options: { all: "-do_stuff", thumb: "-thumbnailize" }
|
|
106
|
-
expect(@attachment).to_not receive(:extra_options_for)
|
|
107
|
-
@style = @attachment.styles[:thumb]
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "calls extra_options_for(:thumb/:large) when convert options are requested" do
|
|
111
|
-
@attachment = attachment path: ":basename.:extension",
|
|
112
|
-
styles: { thumb: "100x100", large: "400x400" },
|
|
113
|
-
convert_options: { all: "-do_stuff", thumb: "-thumbnailize" }
|
|
114
|
-
@style = @attachment.styles[:thumb]
|
|
115
|
-
@file = StringIO.new("...")
|
|
116
|
-
allow(@file).to receive(:original_filename).and_return("file.jpg")
|
|
117
|
-
|
|
118
|
-
expect(@attachment).to receive(:extra_options_for).with(:thumb)
|
|
119
|
-
@attachment.styles[:thumb].convert_options
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
context "An attachment with :source_file_options" do
|
|
124
|
-
it "does not have called extra_source_file_options_for(:thumb/:large) on initialization" do
|
|
125
|
-
@attachment = attachment path: ":basename.:extension",
|
|
126
|
-
styles: { thumb: "100x100", large: "400x400" },
|
|
127
|
-
source_file_options: { all: "-density 400", thumb: "-depth 8" }
|
|
128
|
-
expect(@attachment).to_not receive(:extra_source_file_options_for)
|
|
129
|
-
@style = @attachment.styles[:thumb]
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "calls extra_options_for(:thumb/:large) when convert options are requested" do
|
|
133
|
-
@attachment = attachment path: ":basename.:extension",
|
|
134
|
-
styles: { thumb: "100x100", large: "400x400" },
|
|
135
|
-
source_file_options: { all: "-density 400", thumb: "-depth 8" }
|
|
136
|
-
@style = @attachment.styles[:thumb]
|
|
137
|
-
@file = StringIO.new("...")
|
|
138
|
-
allow(@file).to receive(:original_filename).and_return("file.jpg")
|
|
139
|
-
|
|
140
|
-
expect(@attachment).to receive(:extra_source_file_options_for).with(:thumb)
|
|
141
|
-
@attachment.styles[:thumb].source_file_options
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
context "A style rule with its own :processors" do
|
|
146
|
-
before do
|
|
147
|
-
@attachment = attachment path: ":basename.:extension",
|
|
148
|
-
styles: {
|
|
149
|
-
foo: {
|
|
150
|
-
geometry: "100x100#",
|
|
151
|
-
format: :png,
|
|
152
|
-
processors: [:test]
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
processors: [:thumbnail]
|
|
156
|
-
@style = @attachment.styles[:foo]
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "does not get processors from the attachment" do
|
|
160
|
-
expect(@attachment).to_not receive(:processors)
|
|
161
|
-
assert_not_equal [:thumbnail], @style.processors
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it "reports its own processors" do
|
|
165
|
-
assert_equal [:test], @style.processors
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
context "A style rule with :processors supplied as procs" do
|
|
170
|
-
before do
|
|
171
|
-
@attachment = attachment path: ":basename.:extension",
|
|
172
|
-
styles: {
|
|
173
|
-
foo: {
|
|
174
|
-
geometry: "100x100#",
|
|
175
|
-
format: :png,
|
|
176
|
-
processors: lambda { |_a| [:test] }
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
processors: [:thumbnail]
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "defers processing of procs until they are needed" do
|
|
183
|
-
expect(@attachment.styles[:foo].instance_variable_get("@processors")).to be_a Proc
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
it "calls procs when they are needed" do
|
|
187
|
-
assert_equal [:test], @attachment.styles[:foo].processors
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
context "An attachment with :convert_options and :source_file_options in :styles" do
|
|
192
|
-
before do
|
|
193
|
-
@attachment = attachment path: ":basename.:extension",
|
|
194
|
-
styles: {
|
|
195
|
-
thumb: "100x100",
|
|
196
|
-
large: { geometry: "400x400",
|
|
197
|
-
convert_options: "-do_stuff",
|
|
198
|
-
source_file_options: "-do_extra_stuff" }
|
|
199
|
-
}
|
|
200
|
-
@file = StringIO.new("...")
|
|
201
|
-
allow(@file).to receive(:original_filename).and_return("file.jpg")
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
it "has empty options for :thumb style" do
|
|
205
|
-
assert_equal "", @attachment.styles[:thumb].processor_options[:convert_options]
|
|
206
|
-
assert_equal "", @attachment.styles[:thumb].processor_options[:source_file_options]
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
it "has the right options for :large style" do
|
|
210
|
-
assert_equal "-do_stuff", @attachment.styles[:large].processor_options[:convert_options]
|
|
211
|
-
assert_equal "-do_extra_stuff", @attachment.styles[:large].processor_options[:source_file_options]
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
context "A style rule with per-style backend selection" do
|
|
216
|
-
before do
|
|
217
|
-
@attachment = attachment path: ":basename.:extension",
|
|
218
|
-
styles: {
|
|
219
|
-
vips_style: {
|
|
220
|
-
geometry: "800x800>",
|
|
221
|
-
backend: :vips
|
|
222
|
-
},
|
|
223
|
-
magick_style: {
|
|
224
|
-
geometry: "100x100#",
|
|
225
|
-
backend: :image_magick
|
|
226
|
-
},
|
|
227
|
-
default_style: {
|
|
228
|
-
geometry: "200x200"
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
it "passes backend option through to processor_options for vips style" do
|
|
234
|
-
assert_equal :vips, @attachment.styles[:vips_style].processor_options[:backend]
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
it "passes backend option through to processor_options for image_magick style" do
|
|
238
|
-
assert_equal :image_magick, @attachment.styles[:magick_style].processor_options[:backend]
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
it "does not include backend in processor_options when not specified" do
|
|
242
|
-
expect(@attachment.styles[:default_style].processor_options).not_to have_key(:backend)
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
it "includes geometry correctly for each style" do
|
|
246
|
-
assert_equal "800x800>", @attachment.styles[:vips_style].geometry
|
|
247
|
-
assert_equal "100x100#", @attachment.styles[:magick_style].geometry
|
|
248
|
-
assert_equal "200x200", @attachment.styles[:default_style].geometry
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
it "allows accessing backend via hash notation" do
|
|
252
|
-
assert_equal :vips, @attachment.styles[:vips_style][:backend]
|
|
253
|
-
assert_equal :image_magick, @attachment.styles[:magick_style][:backend]
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
context "A style rule with backend as a proc" do
|
|
258
|
-
before do
|
|
259
|
-
@attachment = attachment path: ":basename.:extension",
|
|
260
|
-
styles: {
|
|
261
|
-
dynamic_backend: {
|
|
262
|
-
geometry: "500x500",
|
|
263
|
-
backend: lambda { |_a| :vips }
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
it "evaluates proc when processor_options are requested" do
|
|
269
|
-
assert_equal :vips, @attachment.styles[:dynamic_backend].processor_options[:backend]
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
context "A style rule supplied with default format" do
|
|
274
|
-
before do
|
|
275
|
-
@attachment = attachment default_format: :png,
|
|
276
|
-
styles: {
|
|
277
|
-
asstring: "300x300#",
|
|
278
|
-
aslist: ["300x300#", :jpg],
|
|
279
|
-
ashash: {
|
|
280
|
-
geometry: "300x300#",
|
|
281
|
-
convert_options: "-do_stuff"
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
it "has the right number of styles" do
|
|
287
|
-
expect(@attachment.styles).to be_a Hash
|
|
288
|
-
assert_equal 3, @attachment.styles.size
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
it "has styles as Style objects" do
|
|
292
|
-
[:aslist, :ashash, :aslist].each do |s|
|
|
293
|
-
expect(@attachment.styles[s]).to be_a Paperclip::Style
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
it "has the right geometries" do
|
|
298
|
-
[:aslist, :ashash, :aslist].each do |s|
|
|
299
|
-
assert_equal @attachment.styles[s].geometry, "300x300#"
|
|
300
|
-
end
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
it "has the right formats" do
|
|
304
|
-
assert_equal @attachment.styles[:aslist].format, :jpg
|
|
305
|
-
assert_equal @attachment.styles[:ashash].format, :png
|
|
306
|
-
assert_equal @attachment.styles[:asstring].format, :png
|
|
307
|
-
end
|
|
308
|
-
end
|
|
309
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Paperclip::TempfileFactory do
|
|
4
|
-
it "is able to generate a tempfile with the right name" do
|
|
5
|
-
file = subject.generate("omg.png")
|
|
6
|
-
assert File.extname(file.path), "png"
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "is able to generate a tempfile with the right name with a tilde at the beginning" do
|
|
10
|
-
file = subject.generate("~omg.png")
|
|
11
|
-
assert File.extname(file.path), "png"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "is able to generate a tempfile with the right name with a tilde at the end" do
|
|
15
|
-
file = subject.generate("omg.png~")
|
|
16
|
-
assert File.extname(file.path), "png"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "is able to generate a tempfile from a file with a really long name" do
|
|
20
|
-
filename = "#{'longfilename' * 100}.png"
|
|
21
|
-
file = subject.generate(filename)
|
|
22
|
-
assert File.extname(file.path), "png"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "is able to take nothing as a parameter and not error" do
|
|
26
|
-
file = subject.generate
|
|
27
|
-
assert File.exist?(file.path)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "does not throw Errno::ENAMETOOLONG when it has a really long name" do
|
|
31
|
-
expect { subject.generate("o" * 255) }.to_not raise_error
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Paperclip::Tempfile do
|
|
4
|
-
context "A Paperclip Tempfile" do
|
|
5
|
-
before do
|
|
6
|
-
@tempfile = described_class.new(["file", ".jpg"])
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after { @tempfile.close }
|
|
10
|
-
|
|
11
|
-
it "has its path contain a real extension" do
|
|
12
|
-
assert_equal ".jpg", File.extname(@tempfile.path)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "is a real Tempfile" do
|
|
16
|
-
assert @tempfile.is_a?(::Tempfile)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
context "Another Paperclip Tempfile" do
|
|
21
|
-
before do
|
|
22
|
-
@tempfile = described_class.new("file")
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
after { @tempfile.close }
|
|
26
|
-
|
|
27
|
-
it "does not have an extension if not given one" do
|
|
28
|
-
assert_equal "", File.extname(@tempfile.path)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "is a real Tempfile" do
|
|
32
|
-
assert @tempfile.is_a?(::Tempfile)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Paperclip::Thumbnail do
|
|
4
|
-
context "with ImageMagick specific + options" do
|
|
5
|
-
before do
|
|
6
|
-
@file = File.new(fixture_file("5k.png"), "rb")
|
|
7
|
-
@attachment = double("Attachment", options: {})
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after { @file.close }
|
|
11
|
-
|
|
12
|
-
it "correctly applies options starting with +" do
|
|
13
|
-
# The user's specific options - with Shellwords, quoted values are parsed correctly
|
|
14
|
-
convert_options = '-coalesce -quality 90 +profile "!icc,*" +set date:modify ' \
|
|
15
|
-
"+set date:create +set date:timestamp -define jpeg:dct-method=float"
|
|
16
|
-
thumb = Paperclip::Thumbnail.new(@file, {
|
|
17
|
-
geometry: "100x100",
|
|
18
|
-
convert_options: convert_options,
|
|
19
|
-
backend: :image_magick,
|
|
20
|
-
}, @attachment)
|
|
21
|
-
|
|
22
|
-
# Spy on the pipeline to verify the correct methods/arguments are called on it.
|
|
23
|
-
allow(thumb).to receive(:apply_imagemagick_option).and_call_original
|
|
24
|
-
expect { thumb.make }.not_to raise_error
|
|
25
|
-
|
|
26
|
-
# With Shellwords parsing, the outer quotes are stripped from "!icc,*" -> !icc,*
|
|
27
|
-
expect(thumb).to have_received(:apply_imagemagick_option).with(anything, "coalesce", nil, "-")
|
|
28
|
-
expect(thumb).to have_received(:apply_imagemagick_option).with(anything, "quality", "90", "-")
|
|
29
|
-
expect(thumb).to have_received(:apply_imagemagick_option).with(anything, "profile", "!icc,*", "+")
|
|
30
|
-
expect(thumb).to have_received(:apply_imagemagick_option).with(anything, "set", "date:modify", "+")
|
|
31
|
-
expect(thumb).to have_received(:apply_imagemagick_option).with(anything, "set", "date:create", "+")
|
|
32
|
-
expect(thumb).to have_received(:apply_imagemagick_option).with(anything, "set", "date:timestamp", "+")
|
|
33
|
-
expect(thumb).to have_received(:apply_imagemagick_option).with(anything, "define", "jpeg:dct-method=float", "-")
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context "with convert_options having multiple arguments for a flag" do
|
|
38
|
-
before do
|
|
39
|
-
@file = File.new(fixture_file("5k.png"), "rb")
|
|
40
|
-
@attachment = double("Attachment", options: {})
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
after { @file.close }
|
|
44
|
-
|
|
45
|
-
it "handles -set with two arguments correctly" do
|
|
46
|
-
# User provided example
|
|
47
|
-
convert_options = "-coalesce -set my_prop 123123"
|
|
48
|
-
|
|
49
|
-
thumb = Paperclip::Thumbnail.new(@file, {
|
|
50
|
-
geometry: "100x100",
|
|
51
|
-
convert_options: convert_options,
|
|
52
|
-
backend: :image_magick,
|
|
53
|
-
}, @attachment)
|
|
54
|
-
|
|
55
|
-
result = nil
|
|
56
|
-
expect { result = thumb.make }.not_to raise_error
|
|
57
|
-
|
|
58
|
-
# Verify property is set
|
|
59
|
-
require "shellwords"
|
|
60
|
-
output = `identify -verbose #{Shellwords.escape(result.path)}`
|
|
61
|
-
expect(output).to include("my_prop: 123123")
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
context "with convert_options having multiple arguments followed by other options" do
|
|
66
|
-
before do
|
|
67
|
-
@file = File.new(fixture_file("5k.png"), "rb")
|
|
68
|
-
@attachment = double("Attachment", options: {})
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
after { @file.close }
|
|
72
|
-
|
|
73
|
-
it "handles -set with two arguments followed by another option" do
|
|
74
|
-
# User provided example scenario
|
|
75
|
-
convert_options = "-set my_prop 123123 -auto-orient"
|
|
76
|
-
|
|
77
|
-
thumb = Paperclip::Thumbnail.new(@file, {
|
|
78
|
-
geometry: "100x100",
|
|
79
|
-
convert_options: convert_options,
|
|
80
|
-
backend: :image_magick,
|
|
81
|
-
}, @attachment)
|
|
82
|
-
|
|
83
|
-
result = nil
|
|
84
|
-
expect { result = thumb.make }.not_to raise_error
|
|
85
|
-
|
|
86
|
-
require "shellwords"
|
|
87
|
-
output = `identify -verbose #{Shellwords.escape(result.path)}`
|
|
88
|
-
expect(output).to include("my_prop: 123123")
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
context "with quoted values in convert_options (Shellwords parsing)" do
|
|
93
|
-
before do
|
|
94
|
-
@file = File.new(fixture_file("5k.png"), "rb")
|
|
95
|
-
@attachment = double("Attachment", options: {})
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
after { @file.close }
|
|
99
|
-
|
|
100
|
-
it "handles single-quoted values correctly" do
|
|
101
|
-
# Shellwords should parse 'Hello World' as a single token
|
|
102
|
-
convert_options = "-set my_comment 'Hello World'"
|
|
103
|
-
|
|
104
|
-
thumb = Paperclip::Thumbnail.new(@file, {
|
|
105
|
-
geometry: "100x100",
|
|
106
|
-
convert_options: convert_options,
|
|
107
|
-
backend: :image_magick,
|
|
108
|
-
}, @attachment)
|
|
109
|
-
|
|
110
|
-
allow(thumb).to receive(:apply_single_option).and_call_original
|
|
111
|
-
result = nil
|
|
112
|
-
expect { result = thumb.make }.not_to raise_error
|
|
113
|
-
|
|
114
|
-
# Verify that 'Hello World' was passed as a single value (without quotes)
|
|
115
|
-
expect(thumb).to have_received(:apply_single_option).with(anything, "set", "my_comment", "-")
|
|
116
|
-
|
|
117
|
-
# Check output includes the set property
|
|
118
|
-
require "shellwords"
|
|
119
|
-
output = `identify -verbose #{Shellwords.escape(result.path)}`
|
|
120
|
-
expect(output).to include("my_comment: Hello World")
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it "handles double-quoted values correctly" do
|
|
124
|
-
convert_options = '-set my_comment "Hello World"'
|
|
125
|
-
|
|
126
|
-
thumb = Paperclip::Thumbnail.new(@file, {
|
|
127
|
-
geometry: "100x100",
|
|
128
|
-
convert_options: convert_options,
|
|
129
|
-
backend: :image_magick,
|
|
130
|
-
}, @attachment)
|
|
131
|
-
|
|
132
|
-
result = nil
|
|
133
|
-
expect { result = thumb.make }.not_to raise_error
|
|
134
|
-
|
|
135
|
-
require "shellwords"
|
|
136
|
-
output = `identify -verbose #{Shellwords.escape(result.path)}`
|
|
137
|
-
expect(output).to include("my_comment: Hello World")
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it "handles escaped spaces correctly" do
|
|
141
|
-
convert_options = '-set my_comment Hello\ World'
|
|
142
|
-
|
|
143
|
-
thumb = Paperclip::Thumbnail.new(@file, {
|
|
144
|
-
geometry: "100x100",
|
|
145
|
-
convert_options: convert_options,
|
|
146
|
-
backend: :image_magick,
|
|
147
|
-
}, @attachment)
|
|
148
|
-
|
|
149
|
-
result = nil
|
|
150
|
-
expect { result = thumb.make }.not_to raise_error
|
|
151
|
-
|
|
152
|
-
require "shellwords"
|
|
153
|
-
output = `identify -verbose #{Shellwords.escape(result.path)}`
|
|
154
|
-
expect(output).to include("my_comment: Hello World")
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "handles multiple quoted options correctly" do
|
|
158
|
-
convert_options = "-set first_prop 'First Value' -set second_prop 'Second Value'"
|
|
159
|
-
|
|
160
|
-
thumb = Paperclip::Thumbnail.new(@file, {
|
|
161
|
-
geometry: "100x100",
|
|
162
|
-
convert_options: convert_options,
|
|
163
|
-
backend: :image_magick,
|
|
164
|
-
}, @attachment)
|
|
165
|
-
|
|
166
|
-
result = nil
|
|
167
|
-
expect { result = thumb.make }.not_to raise_error
|
|
168
|
-
|
|
169
|
-
require "shellwords"
|
|
170
|
-
output = `identify -verbose #{Shellwords.escape(result.path)}`
|
|
171
|
-
expect(output).to include("first_prop: First Value")
|
|
172
|
-
expect(output).to include("second_prop: Second Value")
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
context "with vips-specific convert_options" do
|
|
177
|
-
before do
|
|
178
|
-
begin
|
|
179
|
-
require "vips"
|
|
180
|
-
rescue LoadError
|
|
181
|
-
skip "libvips not installed"
|
|
182
|
-
end
|
|
183
|
-
@file = File.new(fixture_file("5k.png"), "rb")
|
|
184
|
-
@attachment = double("Attachment", options: {})
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
after { @file.close if @file && !@file.closed? }
|
|
188
|
-
|
|
189
|
-
it "processes vips-native options correctly" do
|
|
190
|
-
convert_options = "-rot90"
|
|
191
|
-
file = File.new(fixture_file("rotated.jpg"), "rb")
|
|
192
|
-
|
|
193
|
-
thumb = Paperclip::Thumbnail.new(file, {
|
|
194
|
-
geometry: "100x100",
|
|
195
|
-
convert_options: convert_options,
|
|
196
|
-
backend: :vips,
|
|
197
|
-
}, @attachment)
|
|
198
|
-
|
|
199
|
-
# Processes without error
|
|
200
|
-
result = nil
|
|
201
|
-
expect { result = thumb.make }.not_to raise_error
|
|
202
|
-
|
|
203
|
-
require "shellwords"
|
|
204
|
-
dimensions = `identify -format "%wx%h" "#{Shellwords.escape(result.path)}"`.strip
|
|
205
|
-
width, height = dimensions.split("x").map(&:to_i)
|
|
206
|
-
# After 90 degree rotate, width should be greater than height
|
|
207
|
-
expect(width).to be > height
|
|
208
|
-
file.close
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
it "logs warning for unsupported vips options" do
|
|
212
|
-
convert_options = "-coalesce -unknown_vips_option foo"
|
|
213
|
-
|
|
214
|
-
thumb = Paperclip::Thumbnail.new(@file, {
|
|
215
|
-
geometry: "100x100",
|
|
216
|
-
convert_options: convert_options,
|
|
217
|
-
backend: :vips,
|
|
218
|
-
}, @attachment)
|
|
219
|
-
|
|
220
|
-
expect(Paperclip).to receive(:log).with(/Warning.*coalesce.*not supported/)
|
|
221
|
-
expect(Paperclip).to receive(:log).with(/Warning.*unknown_vips_option.*not supported/)
|
|
222
|
-
expect { thumb.make }.not_to raise_error
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Paperclip::Thumbnail do
|
|
4
|
-
describe "#parse_loader_options" do
|
|
5
|
-
let(:file) { File.new(fixture_file("5k.png"), "rb") }
|
|
6
|
-
let(:thumb) { Paperclip::Thumbnail.new(file, geometry: "50x50") }
|
|
7
|
-
|
|
8
|
-
after { file.close }
|
|
9
|
-
|
|
10
|
-
it "correctly parses positive numeric values" do
|
|
11
|
-
options = "-density 300"
|
|
12
|
-
result = thumb.send(:parse_loader_options, options)
|
|
13
|
-
expect(result).to eq({ density: "300" })
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "correctly parses negative numeric values" do
|
|
17
|
-
# Some hypothetical loader option that might take a negative value
|
|
18
|
-
options = "-something -90"
|
|
19
|
-
result = thumb.send(:parse_loader_options, options)
|
|
20
|
-
expect(result).to eq({ something: "-90" })
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "still treats non-numeric tokens starting with - as new options" do
|
|
24
|
-
options = "-density 300 -strip"
|
|
25
|
-
result = thumb.send(:parse_loader_options, options)
|
|
26
|
-
expect(result).to eq({ density: "300", strip: true })
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "handles single-quoted values correctly" do
|
|
30
|
-
options = "-comment 'Hello World'"
|
|
31
|
-
result = thumb.send(:parse_loader_options, options)
|
|
32
|
-
expect(result).to eq({ comment: "Hello World" })
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "handles double-quoted values correctly" do
|
|
36
|
-
options = '-path "/some/path with spaces"'
|
|
37
|
-
result = thumb.send(:parse_loader_options, options)
|
|
38
|
-
expect(result).to eq({ path: "/some/path with spaces" })
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "handles escaped spaces correctly" do
|
|
42
|
-
options = '-label Hello\ World'
|
|
43
|
-
result = thumb.send(:parse_loader_options, options)
|
|
44
|
-
expect(result).to eq({ label: "Hello World" })
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "handles multiple options with quoted values" do
|
|
48
|
-
options = "-first 'Value One' -second 'Value Two'"
|
|
49
|
-
result = thumb.send(:parse_loader_options, options)
|
|
50
|
-
expect(result).to eq({ first: "Value One", second: "Value Two" })
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|