kt-paperclip 5.4.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/issue_template.md +3 -0
- data/.hound.yml +27 -32
- data/.travis.yml +23 -2
- data/Appraisals +17 -0
- data/Gemfile +9 -7
- data/NEWS +21 -0
- data/README.md +27 -37
- data/Rakefile +29 -21
- data/UPGRADING +3 -3
- data/features/basic_integration.feature +4 -0
- data/features/migration.feature +10 -51
- data/features/step_definitions/attachment_steps.rb +12 -12
- data/features/step_definitions/html_steps.rb +5 -5
- data/features/step_definitions/rails_steps.rb +29 -9
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +5 -6
- data/features/support/env.rb +4 -4
- data/features/support/fakeweb.rb +3 -5
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +4 -4
- data/features/support/rails.rb +7 -7
- data/features/support/selectors.rb +1 -1
- data/gemfiles/4.2.gemfile +7 -4
- data/gemfiles/5.0.gemfile +7 -4
- data/gemfiles/5.1.gemfile +20 -0
- data/gemfiles/5.2.gemfile +20 -0
- data/gemfiles/6.0.gemfile +20 -0
- data/lib/generators/paperclip/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +102 -104
- data/lib/paperclip/attachment_registry.rb +2 -2
- data/lib/paperclip/file_command_content_type_detector.rb +1 -3
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry.rb +18 -19
- data/lib/paperclip/geometry_detector_factory.rb +13 -16
- data/lib/paperclip/geometry_parser_factory.rb +5 -5
- data/lib/paperclip/glue.rb +3 -3
- data/lib/paperclip/has_attached_file.rb +5 -4
- data/lib/paperclip/helpers.rb +3 -3
- data/lib/paperclip/interpolations.rb +42 -38
- data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
- data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
- data/lib/paperclip/io_adapters/registry.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
- data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
- data/lib/paperclip/matchers.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +13 -13
- data/lib/paperclip/missing_attachment_styles.rb +11 -6
- data/lib/paperclip/processor.rb +13 -6
- data/lib/paperclip/processor_helpers.rb +3 -1
- data/lib/paperclip/rails_environment.rb +1 -5
- data/lib/paperclip/railtie.rb +5 -5
- data/lib/paperclip/schema.rb +18 -14
- data/lib/paperclip/storage/filesystem.rb +5 -7
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +67 -75
- data/lib/paperclip/style.rb +3 -6
- data/lib/paperclip/tempfile.rb +4 -5
- data/lib/paperclip/tempfile_factory.rb +0 -1
- data/lib/paperclip/thumbnail.rb +11 -11
- data/lib/paperclip/url_generator.rb +5 -12
- data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
- data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
- data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +12 -13
- data/lib/paperclip/version.rb +1 -3
- data/lib/paperclip.rb +49 -48
- data/lib/tasks/paperclip.rake +23 -24
- data/paperclip.gemspec +29 -33
- data/shoulda_macros/paperclip.rb +16 -16
- data/spec/paperclip/attachment_definitions_spec.rb +5 -5
- data/spec/paperclip/attachment_processing_spec.rb +22 -23
- data/spec/paperclip/attachment_registry_spec.rb +15 -15
- data/spec/paperclip/attachment_spec.rb +238 -196
- data/spec/paperclip/content_type_detector_spec.rb +11 -12
- data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
- data/spec/paperclip/filename_cleaner_spec.rb +3 -4
- data/spec/paperclip/geometry_detector_spec.rb +7 -8
- data/spec/paperclip/geometry_parser_spec.rb +31 -31
- data/spec/paperclip/geometry_spec.rb +24 -24
- data/spec/paperclip/glue_spec.rb +3 -5
- data/spec/paperclip/has_attached_file_spec.rb +46 -126
- data/spec/paperclip/integration_spec.rb +111 -77
- data/spec/paperclip/interpolations_spec.rb +101 -93
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
- data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
- data/spec/paperclip/meta_class_spec.rb +3 -3
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
- data/spec/paperclip/paperclip_spec.rb +15 -11
- data/spec/paperclip/plural_cache_spec.rb +8 -8
- data/spec/paperclip/processor_helpers_spec.rb +35 -35
- data/spec/paperclip/processor_spec.rb +8 -8
- data/spec/paperclip/rails_environment_spec.rb +7 -10
- data/spec/paperclip/rake_spec.rb +39 -39
- data/spec/paperclip/schema_spec.rb +57 -53
- data/spec/paperclip/storage/filesystem_spec.rb +6 -6
- data/spec/paperclip/storage/fog_spec.rb +76 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +585 -583
- data/spec/paperclip/style_spec.rb +67 -71
- data/spec/paperclip/tempfile_factory_spec.rb +5 -5
- data/spec/paperclip/thumbnail_spec.rb +68 -67
- data/spec/paperclip/url_generator_spec.rb +18 -29
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +40 -40
- data/spec/spec_helper.rb +21 -23
- data/spec/support/assertions.rb +8 -6
- data/spec/support/fake_model.rb +1 -2
- data/spec/support/fake_rails.rb +1 -1
- data/spec/support/matchers/exist.rb +1 -1
- data/spec/support/matchers/have_column.rb +1 -1
- data/spec/support/mock_url_generator_builder.rb +2 -3
- data/spec/support/model_reconstruction.rb +16 -12
- data/spec/support/reporting.rb +1 -1
- data/spec/support/test_data.rb +2 -2
- metadata +49 -105
- data/lib/kt-paperclip.rb +0 -1
- data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Paperclip::Style do
|
5
4
|
context "A style rule" do
|
6
5
|
before do
|
7
6
|
@attachment = attachment path: ":basename.:extension",
|
8
|
-
styles: { foo: {geometry: "100x100#", format: :png} },
|
7
|
+
styles: { foo: { geometry: "100x100#", format: :png } },
|
9
8
|
whiny: true
|
10
9
|
@style = @attachment.styles[:foo]
|
11
10
|
end
|
@@ -40,13 +39,13 @@ describe Paperclip::Style do
|
|
40
39
|
before do
|
41
40
|
@attachment = attachment path: ":basename.:extension",
|
42
41
|
whiny_thumbnails: true,
|
43
|
-
processors: lambda {|
|
42
|
+
processors: lambda { |_a| [:test] },
|
44
43
|
styles: {
|
45
|
-
foo: lambda{|
|
44
|
+
foo: lambda { |_a| "300x300#" },
|
46
45
|
bar: {
|
47
|
-
geometry: lambda{|
|
48
|
-
convert_options: lambda{|
|
49
|
-
source_file_options: lambda{|
|
46
|
+
geometry: lambda { |_a| "300x300#" },
|
47
|
+
convert_options: lambda { |_a| "-do_stuff" },
|
48
|
+
source_file_options: lambda { |_a| "-do_extra_stuff" }
|
50
49
|
}
|
51
50
|
}
|
52
51
|
end
|
@@ -65,7 +64,7 @@ describe Paperclip::Style do
|
|
65
64
|
before do
|
66
65
|
styles = {}
|
67
66
|
styles[:aslist] = ["100x100", :png]
|
68
|
-
styles[:ashash] = {geometry: "100x100", format: :png}
|
67
|
+
styles[:ashash] = { geometry: "100x100", format: :png }
|
69
68
|
styles[:asstring] = "100x100"
|
70
69
|
@attachment = attachment path: ":basename.:extension",
|
71
70
|
styles: styles
|
@@ -102,21 +101,21 @@ describe Paperclip::Style do
|
|
102
101
|
context "An attachment with :convert_options" do
|
103
102
|
it "does not have called extra_options_for(:thumb/:large) on initialization" do
|
104
103
|
@attachment = attachment path: ":basename.:extension",
|
105
|
-
styles: {thumb: "100x100", large: "400x400"},
|
106
|
-
convert_options: {all: "-do_stuff", thumb: "-thumbnailize"}
|
107
|
-
@attachment.
|
104
|
+
styles: { thumb: "100x100", large: "400x400" },
|
105
|
+
convert_options: { all: "-do_stuff", thumb: "-thumbnailize" }
|
106
|
+
expect(@attachment).to_not receive(:extra_options_for)
|
108
107
|
@style = @attachment.styles[:thumb]
|
109
108
|
end
|
110
109
|
|
111
110
|
it "calls extra_options_for(:thumb/:large) when convert options are requested" do
|
112
111
|
@attachment = attachment path: ":basename.:extension",
|
113
|
-
styles: {thumb: "100x100", large: "400x400"},
|
114
|
-
convert_options: {all: "-do_stuff", thumb: "-thumbnailize"}
|
112
|
+
styles: { thumb: "100x100", large: "400x400" },
|
113
|
+
convert_options: { all: "-do_stuff", thumb: "-thumbnailize" }
|
115
114
|
@style = @attachment.styles[:thumb]
|
116
115
|
@file = StringIO.new("...")
|
117
|
-
@file.
|
116
|
+
allow(@file).to receive(:original_filename).and_return("file.jpg")
|
118
117
|
|
119
|
-
@attachment.
|
118
|
+
expect(@attachment).to receive(:extra_options_for).with(:thumb)
|
120
119
|
@attachment.styles[:thumb].convert_options
|
121
120
|
end
|
122
121
|
end
|
@@ -124,21 +123,21 @@ describe Paperclip::Style do
|
|
124
123
|
context "An attachment with :source_file_options" do
|
125
124
|
it "does not have called extra_source_file_options_for(:thumb/:large) on initialization" do
|
126
125
|
@attachment = attachment path: ":basename.:extension",
|
127
|
-
styles: {thumb: "100x100", large: "400x400"},
|
128
|
-
source_file_options: {all: "-density 400", thumb: "-depth 8"}
|
129
|
-
@attachment.
|
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)
|
130
129
|
@style = @attachment.styles[:thumb]
|
131
130
|
end
|
132
131
|
|
133
132
|
it "calls extra_options_for(:thumb/:large) when convert options are requested" do
|
134
133
|
@attachment = attachment path: ":basename.:extension",
|
135
|
-
styles: {thumb: "100x100", large: "400x400"},
|
136
|
-
source_file_options: {all: "-density 400", thumb: "-depth 8"}
|
134
|
+
styles: { thumb: "100x100", large: "400x400" },
|
135
|
+
source_file_options: { all: "-density 400", thumb: "-depth 8" }
|
137
136
|
@style = @attachment.styles[:thumb]
|
138
137
|
@file = StringIO.new("...")
|
139
|
-
@file.
|
138
|
+
allow(@file).to receive(:original_filename).and_return("file.jpg")
|
140
139
|
|
141
|
-
@attachment.
|
140
|
+
expect(@attachment).to receive(:extra_source_file_options_for).with(:thumb)
|
142
141
|
@attachment.styles[:thumb].source_file_options
|
143
142
|
end
|
144
143
|
end
|
@@ -151,21 +150,20 @@ describe Paperclip::Style do
|
|
151
150
|
geometry: "100x100#",
|
152
151
|
format: :png,
|
153
152
|
processors: [:test]
|
154
|
-
|
155
|
-
|
153
|
+
}
|
154
|
+
},
|
156
155
|
processors: [:thumbnail]
|
157
156
|
@style = @attachment.styles[:foo]
|
158
157
|
end
|
159
158
|
|
160
159
|
it "does not get processors from the attachment" do
|
161
|
-
@attachment.
|
160
|
+
expect(@attachment).to_not receive(:processors)
|
162
161
|
assert_not_equal [:thumbnail], @style.processors
|
163
162
|
end
|
164
163
|
|
165
164
|
it "reports its own processors" do
|
166
165
|
assert_equal [:test], @style.processors
|
167
166
|
end
|
168
|
-
|
169
167
|
end
|
170
168
|
|
171
169
|
context "A style rule with :processors supplied as procs" do
|
@@ -175,9 +173,9 @@ describe Paperclip::Style do
|
|
175
173
|
foo: {
|
176
174
|
geometry: "100x100#",
|
177
175
|
format: :png,
|
178
|
-
processors: lambda{|
|
179
|
-
|
180
|
-
|
176
|
+
processors: lambda { |_a| [:test] }
|
177
|
+
}
|
178
|
+
},
|
181
179
|
processors: [:thumbnail]
|
182
180
|
end
|
183
181
|
|
@@ -195,13 +193,12 @@ describe Paperclip::Style do
|
|
195
193
|
@attachment = attachment path: ":basename.:extension",
|
196
194
|
styles: {
|
197
195
|
thumb: "100x100",
|
198
|
-
large: {geometry: "400x400",
|
199
|
-
|
200
|
-
|
201
|
-
}
|
196
|
+
large: { geometry: "400x400",
|
197
|
+
convert_options: "-do_stuff",
|
198
|
+
source_file_options: "-do_extra_stuff" }
|
202
199
|
}
|
203
200
|
@file = StringIO.new("...")
|
204
|
-
@file.
|
201
|
+
allow(@file).to receive(:original_filename).and_return("file.jpg")
|
205
202
|
end
|
206
203
|
|
207
204
|
it "has empty options for :thumb style" do
|
@@ -216,40 +213,39 @@ describe Paperclip::Style do
|
|
216
213
|
end
|
217
214
|
|
218
215
|
context "A style rule supplied with default format" do
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
end
|
216
|
+
before do
|
217
|
+
@attachment = attachment default_format: :png,
|
218
|
+
styles: {
|
219
|
+
asstring: "300x300#",
|
220
|
+
aslist: ["300x300#", :jpg],
|
221
|
+
ashash: {
|
222
|
+
geometry: "300x300#",
|
223
|
+
convert_options: "-do_stuff"
|
224
|
+
}
|
225
|
+
}
|
226
|
+
end
|
227
|
+
|
228
|
+
it "has the right number of styles" do
|
229
|
+
expect(@attachment.styles).to be_a Hash
|
230
|
+
assert_equal 3, @attachment.styles.size
|
231
|
+
end
|
232
|
+
|
233
|
+
it "has styles as Style objects" do
|
234
|
+
[:aslist, :ashash, :aslist].each do |s|
|
235
|
+
expect(@attachment.styles[s]).to be_a Paperclip::Style
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
it "has the right geometries" do
|
240
|
+
[:aslist, :ashash, :aslist].each do |s|
|
241
|
+
assert_equal @attachment.styles[s].geometry, "300x300#"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
it "has the right formats" do
|
246
|
+
assert_equal @attachment.styles[:aslist].format, :jpg
|
247
|
+
assert_equal @attachment.styles[:ashash].format, :png
|
248
|
+
assert_equal @attachment.styles[:asstring].format, :png
|
249
|
+
end
|
250
|
+
end
|
255
251
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::TempfileFactory do
|
4
4
|
it "is able to generate a tempfile with the right name" do
|
@@ -17,14 +17,14 @@ describe Paperclip::TempfileFactory do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "is able to generate a tempfile from a file with a really long name" do
|
20
|
-
filename = "#{
|
20
|
+
filename = "#{'longfilename' * 100}.png"
|
21
21
|
file = subject.generate(filename)
|
22
22
|
assert File.extname(file.path), "png"
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
|
27
|
-
|
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
28
|
end
|
29
29
|
|
30
30
|
it "does not throw Errno::ENAMETOOLONG when it has a really long name" do
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Thumbnail do
|
4
4
|
context "An image" do
|
5
5
|
before do
|
6
|
-
@file = File.new(fixture_file("5k.png"),
|
6
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
7
7
|
end
|
8
8
|
|
9
9
|
after { @file.close }
|
@@ -11,15 +11,14 @@ describe Paperclip::Thumbnail do
|
|
11
11
|
[["600x600>", "434x66"],
|
12
12
|
["400x400>", "400x61"],
|
13
13
|
["32x32<", "434x66"],
|
14
|
-
[nil, "434x66"]
|
15
|
-
].each do |args|
|
14
|
+
[nil, "434x66"]].each do |args|
|
16
15
|
context "being thumbnailed with a geometry of #{args[0]}" do
|
17
16
|
before do
|
18
17
|
@thumb = Paperclip::Thumbnail.new(@file, geometry: args[0])
|
19
18
|
end
|
20
19
|
|
21
20
|
it "starts with dimensions of 434x66" do
|
22
|
-
cmd = %
|
21
|
+
cmd = %[identify -format "%wx%h" "#{@file.path}"]
|
23
22
|
assert_equal "434x66", `#{cmd}`.chomp
|
24
23
|
end
|
25
24
|
|
@@ -33,7 +32,7 @@ describe Paperclip::Thumbnail do
|
|
33
32
|
end
|
34
33
|
|
35
34
|
it "is the size we expect it to be" do
|
36
|
-
cmd = %
|
35
|
+
cmd = %[identify -format "%wx%h" "#{@thumb_result.path}"]
|
37
36
|
assert_equal args[1], `#{cmd}`.chomp
|
38
37
|
end
|
39
38
|
end
|
@@ -46,18 +45,18 @@ describe Paperclip::Thumbnail do
|
|
46
45
|
end
|
47
46
|
|
48
47
|
it "lets us know when a command isn't found versus a processing error" do
|
49
|
-
old_path = ENV[
|
48
|
+
old_path = ENV["PATH"]
|
50
49
|
begin
|
51
|
-
Terrapin::CommandLine.path =
|
52
|
-
Paperclip.options[:command_path] =
|
53
|
-
ENV[
|
50
|
+
Terrapin::CommandLine.path = ""
|
51
|
+
Paperclip.options[:command_path] = ""
|
52
|
+
ENV["PATH"] = ""
|
54
53
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
55
54
|
silence_stream(STDERR) do
|
56
55
|
@thumb.make
|
57
56
|
end
|
58
57
|
end
|
59
58
|
ensure
|
60
|
-
ENV[
|
59
|
+
ENV["PATH"] = old_path
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
@@ -83,9 +82,9 @@ describe Paperclip::Thumbnail do
|
|
83
82
|
end
|
84
83
|
|
85
84
|
it "sends the right command to convert when sent #make" do
|
86
|
-
@thumb.
|
85
|
+
expect(@thumb).to receive(:convert) do |*arg|
|
87
86
|
arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' &&
|
88
|
-
|
87
|
+
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
89
88
|
end
|
90
89
|
@thumb.make
|
91
90
|
end
|
@@ -96,8 +95,8 @@ describe Paperclip::Thumbnail do
|
|
96
95
|
end
|
97
96
|
end
|
98
97
|
|
99
|
-
it
|
100
|
-
file = File.new(fixture_file(
|
98
|
+
it "crops a EXIF-rotated image properly" do
|
99
|
+
file = File.new(fixture_file("rotated.jpg"))
|
101
100
|
thumb = Paperclip::Thumbnail.new(file, geometry: "50x50#")
|
102
101
|
|
103
102
|
output_file = thumb.make
|
@@ -118,9 +117,9 @@ describe Paperclip::Thumbnail do
|
|
118
117
|
end
|
119
118
|
|
120
119
|
it "sends the right command to convert when sent #make" do
|
121
|
-
@thumb.
|
120
|
+
expect(@thumb).to receive(:convert) do |*arg|
|
122
121
|
arg[0] == '-strip :source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' &&
|
123
|
-
|
122
|
+
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
124
123
|
end
|
125
124
|
@thumb.make
|
126
125
|
end
|
@@ -159,9 +158,9 @@ describe Paperclip::Thumbnail do
|
|
159
158
|
end
|
160
159
|
|
161
160
|
it "sends the right command to convert when sent #make" do
|
162
|
-
@thumb.
|
161
|
+
expect(@thumb).to receive(:convert) do |*arg|
|
163
162
|
arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
|
164
|
-
|
163
|
+
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
165
164
|
end
|
166
165
|
@thumb.make
|
167
166
|
end
|
@@ -179,26 +178,28 @@ describe Paperclip::Thumbnail do
|
|
179
178
|
end
|
180
179
|
|
181
180
|
it "errors when trying to create the thumbnail" do
|
182
|
-
|
183
|
-
|
181
|
+
silence_stream(STDERR) do
|
182
|
+
expect do
|
184
183
|
@thumb.make
|
185
|
-
end
|
184
|
+
end.to raise_error(
|
185
|
+
Paperclip::Error, /unrecognized option `-this-aint-no-option'/
|
186
|
+
)
|
186
187
|
end
|
187
188
|
end
|
188
189
|
|
189
190
|
it "lets us know when a command isn't found versus a processing error" do
|
190
|
-
old_path = ENV[
|
191
|
+
old_path = ENV["PATH"]
|
191
192
|
begin
|
192
|
-
Terrapin::CommandLine.path =
|
193
|
-
Paperclip.options[:command_path] =
|
194
|
-
ENV[
|
193
|
+
Terrapin::CommandLine.path = ""
|
194
|
+
Paperclip.options[:command_path] = ""
|
195
|
+
ENV["PATH"] = ""
|
195
196
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
196
197
|
silence_stream(STDERR) do
|
197
198
|
@thumb.make
|
198
199
|
end
|
199
200
|
end
|
200
201
|
ensure
|
201
|
-
ENV[
|
202
|
+
ENV["PATH"] = old_path
|
202
203
|
end
|
203
204
|
end
|
204
205
|
end
|
@@ -219,9 +220,9 @@ describe Paperclip::Thumbnail do
|
|
219
220
|
context "being thumbnailed with default animated option (true)" do
|
220
221
|
it "calls identify to check for animated images when sent #make" do
|
221
222
|
thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
|
222
|
-
thumb.
|
223
|
-
arg[0] ==
|
224
|
-
|
223
|
+
expect(thumb).to receive(:identify).at_least(1).times do |*arg|
|
224
|
+
arg[0] == "-format %m :file" &&
|
225
|
+
arg[1][:file] == "#{File.expand_path(thumb.file.path)}[0]"
|
225
226
|
end
|
226
227
|
thumb.make
|
227
228
|
end
|
@@ -234,27 +235,27 @@ describe Paperclip::Thumbnail do
|
|
234
235
|
|
235
236
|
it "produces the appropriate transformation_command" do
|
236
237
|
GeoParser = Class.new do
|
237
|
-
def self.from_file(
|
238
|
+
def self.from_file(_file)
|
238
239
|
new
|
239
240
|
end
|
240
241
|
|
241
|
-
def transformation_to(
|
242
|
+
def transformation_to(_target, _should_crop)
|
242
243
|
["SCALE", "CROP"]
|
243
244
|
end
|
244
245
|
end
|
245
246
|
|
246
|
-
thumb = Paperclip::Thumbnail.new(@file, geometry:
|
247
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", file_geometry_parser: ::GeoParser)
|
247
248
|
|
248
249
|
transformation_command = thumb.transformation_command
|
249
250
|
|
250
|
-
assert transformation_command.include?(
|
251
|
-
|
251
|
+
assert transformation_command.include?("-crop"),
|
252
|
+
%{expected #{transformation_command.inspect} to include '-crop'}
|
252
253
|
assert transformation_command.include?('"CROP"'),
|
253
|
-
|
254
|
-
assert transformation_command.include?(
|
255
|
-
|
254
|
+
%{expected #{transformation_command.inspect} to include '"CROP"'}
|
255
|
+
assert transformation_command.include?("-resize"),
|
256
|
+
%{expected #{transformation_command.inspect} to include '-resize'}
|
256
257
|
assert transformation_command.include?('"SCALE"'),
|
257
|
-
|
258
|
+
%{expected #{transformation_command.inspect} to include '"SCALE"'}
|
258
259
|
end
|
259
260
|
end
|
260
261
|
|
@@ -265,7 +266,7 @@ describe Paperclip::Thumbnail do
|
|
265
266
|
|
266
267
|
it "produces the appropriate transformation_command" do
|
267
268
|
GeoParser = Class.new do
|
268
|
-
def self.parse(
|
269
|
+
def self.parse(_s)
|
269
270
|
new
|
270
271
|
end
|
271
272
|
|
@@ -274,26 +275,26 @@ describe Paperclip::Thumbnail do
|
|
274
275
|
end
|
275
276
|
end
|
276
277
|
|
277
|
-
thumb = Paperclip::Thumbnail.new(@file, geometry:
|
278
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", string_geometry_parser: ::GeoParser)
|
278
279
|
|
279
280
|
transformation_command = thumb.transformation_command
|
280
281
|
|
281
282
|
assert transformation_command.include?('"151x167"'),
|
282
|
-
|
283
|
+
%{expected #{transformation_command.inspect} to include '151x167'}
|
283
284
|
end
|
284
285
|
end
|
285
286
|
end
|
286
287
|
|
287
288
|
context "A multipage PDF" do
|
288
289
|
before do
|
289
|
-
@file = File.new(fixture_file("twopage.pdf"),
|
290
|
+
@file = File.new(fixture_file("twopage.pdf"), "rb")
|
290
291
|
end
|
291
292
|
|
292
293
|
after { @file.close }
|
293
294
|
|
294
295
|
it "starts with two pages with dimensions 612x792" do
|
295
|
-
cmd = %
|
296
|
-
assert_equal "612x792"*2, `#{cmd}`.chomp
|
296
|
+
cmd = %[identify -format "%wx%h" "#{@file.path}"]
|
297
|
+
assert_equal "612x792" * 2, `#{cmd}`.chomp
|
297
298
|
end
|
298
299
|
|
299
300
|
context "being thumbnailed at 100x100 with cropping" do
|
@@ -319,37 +320,37 @@ describe Paperclip::Thumbnail do
|
|
319
320
|
|
320
321
|
context "An animated gif" do
|
321
322
|
before do
|
322
|
-
@file = File.new(fixture_file("animated.gif"),
|
323
|
+
@file = File.new(fixture_file("animated.gif"), "rb")
|
323
324
|
end
|
324
325
|
|
325
326
|
after { @file.close }
|
326
327
|
|
327
328
|
it "starts with 12 frames with size 100x100" do
|
328
|
-
cmd = %
|
329
|
-
assert_equal "100x100"*12, `#{cmd}`.chomp
|
329
|
+
cmd = %[identify -format "%wx%h" "#{@file.path}"]
|
330
|
+
assert_equal "100x100" * 12, `#{cmd}`.chomp
|
330
331
|
end
|
331
332
|
|
332
333
|
context "with static output" do
|
333
334
|
before do
|
334
|
-
|
335
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :jpg)
|
335
336
|
end
|
336
337
|
|
337
338
|
it "creates the single frame thumbnail when sent #make" do
|
338
339
|
dst = @thumb.make
|
339
|
-
cmd = %
|
340
|
+
cmd = %[identify -format "%wx%h" "#{dst.path}"]
|
340
341
|
assert_equal "50x50", `#{cmd}`.chomp
|
341
342
|
end
|
342
343
|
end
|
343
344
|
|
344
345
|
context "with animated output format" do
|
345
346
|
before do
|
346
|
-
|
347
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
|
347
348
|
end
|
348
349
|
|
349
350
|
it "creates the 12 frames thumbnail when sent #make" do
|
350
351
|
dst = @thumb.make
|
351
|
-
cmd = %
|
352
|
-
frames = `#{cmd}`.chomp.split(
|
352
|
+
cmd = %[identify -format "%wx%h," "#{dst.path}"]
|
353
|
+
frames = `#{cmd}`.chomp.split(",")
|
353
354
|
assert_equal 12, frames.size
|
354
355
|
assert_frame_dimensions (45..50), frames
|
355
356
|
end
|
@@ -365,13 +366,13 @@ describe Paperclip::Thumbnail do
|
|
365
366
|
|
366
367
|
context "with omitted output format" do
|
367
368
|
before do
|
368
|
-
|
369
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50")
|
369
370
|
end
|
370
371
|
|
371
372
|
it "creates the 12 frames thumbnail when sent #make" do
|
372
373
|
dst = @thumb.make
|
373
|
-
cmd = %
|
374
|
-
frames = `#{cmd}`.chomp.split(
|
374
|
+
cmd = %[identify -format "%wx%h," "#{dst.path}"]
|
375
|
+
frames = `#{cmd}`.chomp.split(",")
|
375
376
|
assert_equal 12, frames.size
|
376
377
|
assert_frame_dimensions (45..50), frames
|
377
378
|
end
|
@@ -387,14 +388,14 @@ describe Paperclip::Thumbnail do
|
|
387
388
|
|
388
389
|
context "with unidentified source format" do
|
389
390
|
before do
|
390
|
-
@unidentified_file = File.new(fixture_file("animated.unknown"),
|
391
|
+
@unidentified_file = File.new(fixture_file("animated.unknown"), "rb")
|
391
392
|
@thumb = Paperclip::Thumbnail.new(@file, geometry: "60x60")
|
392
393
|
end
|
393
394
|
|
394
395
|
it "creates the 12 frames thumbnail when sent #make" do
|
395
396
|
dst = @thumb.make
|
396
|
-
cmd = %
|
397
|
-
frames = `#{cmd}`.chomp.split(
|
397
|
+
cmd = %[identify -format "%wx%h," "#{dst.path}"]
|
398
|
+
frames = `#{cmd}`.chomp.split(",")
|
398
399
|
assert_equal 12, frames.size
|
399
400
|
assert_frame_dimensions (55..60), frames
|
400
401
|
end
|
@@ -410,14 +411,14 @@ describe Paperclip::Thumbnail do
|
|
410
411
|
|
411
412
|
context "with no source format" do
|
412
413
|
before do
|
413
|
-
@unidentified_file = File.new(fixture_file("animated"),
|
414
|
+
@unidentified_file = File.new(fixture_file("animated"), "rb")
|
414
415
|
@thumb = Paperclip::Thumbnail.new(@file, geometry: "70x70")
|
415
416
|
end
|
416
417
|
|
417
418
|
it "creates the 12 frames thumbnail when sent #make" do
|
418
419
|
dst = @thumb.make
|
419
|
-
cmd = %
|
420
|
-
frames = `#{cmd}`.chomp.split(
|
420
|
+
cmd = %[identify -format "%wx%h," "#{dst.path}"]
|
421
|
+
frames = `#{cmd}`.chomp.split(",")
|
421
422
|
assert_equal 12, frames.size
|
422
423
|
assert_frame_dimensions (60..70), frames
|
423
424
|
end
|
@@ -433,18 +434,18 @@ describe Paperclip::Thumbnail do
|
|
433
434
|
|
434
435
|
context "with animated option set to false" do
|
435
436
|
before do
|
436
|
-
|
437
|
+
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", animated: false)
|
437
438
|
end
|
438
439
|
|
439
440
|
it "outputs the gif format" do
|
440
441
|
dst = @thumb.make
|
441
|
-
cmd = %
|
442
|
+
cmd = %[identify "#{dst.path}"]
|
442
443
|
assert_match /GIF/, `#{cmd}`.chomp
|
443
444
|
end
|
444
445
|
|
445
446
|
it "creates the single frame thumbnail when sent #make" do
|
446
447
|
dst = @thumb.make
|
447
|
-
cmd = %
|
448
|
+
cmd = %[identify -format "%wx%h" "#{dst.path}"]
|
448
449
|
assert_equal "50x50", `#{cmd}`.chomp
|
449
450
|
end
|
450
451
|
end
|
@@ -455,7 +456,7 @@ describe Paperclip::Thumbnail do
|
|
455
456
|
@file,
|
456
457
|
geometry: "50x50",
|
457
458
|
frame_index: 5,
|
458
|
-
format: :jpg
|
459
|
+
format: :jpg
|
459
460
|
)
|
460
461
|
end
|
461
462
|
|
@@ -471,7 +472,7 @@ describe Paperclip::Thumbnail do
|
|
471
472
|
@file,
|
472
473
|
geometry: "50x50",
|
473
474
|
frame_index: 20,
|
474
|
-
format: :jpg
|
475
|
+
format: :jpg
|
475
476
|
)
|
476
477
|
end
|
477
478
|
|