paperclip-v2_7-patched-ruby-1_8_6 2.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +14 -0
- data/Appraisals +20 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +5 -0
- data/LICENSE +26 -0
- data/NEWS +69 -0
- data/README.md +444 -0
- data/Rakefile +41 -0
- data/cucumber/paperclip_steps.rb +6 -0
- data/features/basic_integration.feature +48 -0
- data/features/rake_tasks.feature +68 -0
- data/features/step_definitions/attachment_steps.rb +65 -0
- data/features/step_definitions/html_steps.rb +15 -0
- data/features/step_definitions/rails_steps.rb +193 -0
- data/features/step_definitions/s3_steps.rb +14 -0
- data/features/step_definitions/web_steps.rb +209 -0
- data/features/support/env.rb +8 -0
- data/features/support/fakeweb.rb +3 -0
- data/features/support/fixtures/.boot_config.rb.swo +0 -0
- data/features/support/fixtures/boot_config.txt +15 -0
- data/features/support/fixtures/gemfile.txt +5 -0
- data/features/support/fixtures/preinitializer.txt +20 -0
- data/features/support/paths.rb +28 -0
- data/features/support/rails.rb +46 -0
- data/features/support/selectors.rb +19 -0
- data/gemfiles/rails2.gemfile +9 -0
- data/gemfiles/rails3.gemfile +9 -0
- data/gemfiles/rails3_1.gemfile +9 -0
- data/gemfiles/rails3_2.gemfile +9 -0
- data/generators/paperclip/USAGE +5 -0
- data/generators/paperclip/paperclip_generator.rb +27 -0
- data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/init.rb +4 -0
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +33 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip.rb +493 -0
- data/lib/paperclip/attachment.rb +491 -0
- data/lib/paperclip/attachment_options.rb +10 -0
- data/lib/paperclip/callback_compatibility.rb +61 -0
- data/lib/paperclip/geometry.rb +120 -0
- data/lib/paperclip/interpolations.rb +174 -0
- data/lib/paperclip/iostream.rb +45 -0
- data/lib/paperclip/matchers.rb +64 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
- data/lib/paperclip/missing_attachment_styles.rb +87 -0
- data/lib/paperclip/processor.rb +58 -0
- data/lib/paperclip/railtie.rb +35 -0
- data/lib/paperclip/schema.rb +39 -0
- data/lib/paperclip/storage.rb +3 -0
- data/lib/paperclip/storage/filesystem.rb +81 -0
- data/lib/paperclip/storage/fog.rb +191 -0
- data/lib/paperclip/storage/s3.rb +351 -0
- data/lib/paperclip/style.rb +103 -0
- data/lib/paperclip/thumbnail.rb +105 -0
- data/lib/paperclip/upfile.rb +64 -0
- data/lib/paperclip/url_generator.rb +64 -0
- data/lib/paperclip/version.rb +3 -0
- data/lib/tasks/paperclip.rake +101 -0
- data/paperclip.gemspec +41 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +124 -0
- data/test/attachment_options_test.rb +40 -0
- data/test/attachment_test.rb +1211 -0
- data/test/database.yml +4 -0
- data/test/fixtures/12k.png +0 -0
- data/test/fixtures/50x50.png +0 -0
- data/test/fixtures/5k.png +0 -0
- data/test/fixtures/animated.gif +0 -0
- data/test/fixtures/bad.png +1 -0
- data/test/fixtures/fog.yml +8 -0
- data/test/fixtures/s3.yml +8 -0
- data/test/fixtures/spaced file.png +0 -0
- data/test/fixtures/text.txt +1 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/fixtures/uppercase.PNG +0 -0
- data/test/geometry_test.rb +206 -0
- data/test/helper.rb +181 -0
- data/test/integration_test.rb +652 -0
- data/test/interpolations_test.rb +219 -0
- data/test/iostream_test.rb +71 -0
- data/test/matchers/have_attached_file_matcher_test.rb +24 -0
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +110 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +47 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +72 -0
- data/test/paperclip_missing_attachment_styles_test.rb +96 -0
- data/test/paperclip_test.rb +409 -0
- data/test/processor_test.rb +10 -0
- data/test/schema_test.rb +98 -0
- data/test/storage/filesystem_test.rb +62 -0
- data/test/storage/fog_test.rb +280 -0
- data/test/storage/s3_live_test.rb +138 -0
- data/test/storage/s3_test.rb +1093 -0
- data/test/style_test.rb +215 -0
- data/test/support/mock_attachment.rb +22 -0
- data/test/support/mock_interpolator.rb +24 -0
- data/test/support/mock_model.rb +2 -0
- data/test/support/mock_url_generator_builder.rb +27 -0
- data/test/thumbnail_test.rb +396 -0
- data/test/upfile_test.rb +53 -0
- data/test/url_generator_test.rb +187 -0
- metadata +374 -0
data/test/style_test.rb
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require './test/helper'
|
3
|
+
|
4
|
+
class StyleTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "A style rule" do
|
7
|
+
setup do
|
8
|
+
@attachment = attachment :path => ":basename.:extension",
|
9
|
+
:styles => { :foo => {:geometry => "100x100#", :format => :png} },
|
10
|
+
:whiny => true
|
11
|
+
@style = @attachment.styles[:foo]
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be held as a Style object" do
|
15
|
+
assert_kind_of Paperclip::Style, @style
|
16
|
+
end
|
17
|
+
|
18
|
+
should "get processors from the attachment definition" do
|
19
|
+
assert_equal [:thumbnail], @style.processors
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have the right geometry" do
|
23
|
+
assert_equal "100x100#", @style.geometry
|
24
|
+
end
|
25
|
+
|
26
|
+
should "be whiny if the attachment is" do
|
27
|
+
assert @style.whiny?
|
28
|
+
end
|
29
|
+
|
30
|
+
should "respond to hash notation" do
|
31
|
+
assert_equal [:thumbnail], @style[:processors]
|
32
|
+
assert_equal "100x100#", @style[:geometry]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "A style rule with properties supplied as procs" do
|
37
|
+
setup do
|
38
|
+
@attachment = attachment :path => ":basename.:extension",
|
39
|
+
:whiny_thumbnails => true,
|
40
|
+
:processors => lambda {|a| [:test]},
|
41
|
+
:styles => {
|
42
|
+
:foo => lambda{|a| "300x300#"},
|
43
|
+
:bar => {
|
44
|
+
:geometry => lambda{|a| "300x300#"},
|
45
|
+
:convert_options => lambda{|a| "-do_stuff"},
|
46
|
+
:source_file_options => lambda{|a| "-do_extra_stuff"}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
should "call procs when they are needed" do
|
52
|
+
assert_equal "300x300#", @attachment.styles[:foo].geometry
|
53
|
+
assert_equal "300x300#", @attachment.styles[:bar].geometry
|
54
|
+
assert_equal [:test], @attachment.styles[:foo].processors
|
55
|
+
assert_equal [:test], @attachment.styles[:bar].processors
|
56
|
+
assert_equal "-do_stuff", @attachment.styles[:bar].convert_options
|
57
|
+
assert_equal "-do_extra_stuff", @attachment.styles[:bar].source_file_options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "An attachment with style rules in various forms" do
|
62
|
+
setup do
|
63
|
+
styles = ActiveSupport::OrderedHash.new
|
64
|
+
styles[:aslist] = ["100x100", :png]
|
65
|
+
styles[:ashash] = {:geometry => "100x100", :format => :png}
|
66
|
+
styles[:asstring] = "100x100"
|
67
|
+
@attachment = attachment :path => ":basename.:extension",
|
68
|
+
:styles => styles
|
69
|
+
end
|
70
|
+
should "have the right number of styles" do
|
71
|
+
assert_kind_of Hash, @attachment.styles
|
72
|
+
assert_equal 3, @attachment.styles.size
|
73
|
+
end
|
74
|
+
|
75
|
+
should "have styles as Style objects" do
|
76
|
+
[:aslist, :ashash, :aslist].each do |s|
|
77
|
+
assert_kind_of Paperclip::Style, @attachment.styles[s]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
should "have the right geometries" do
|
82
|
+
[:aslist, :ashash, :aslist].each do |s|
|
83
|
+
assert_equal @attachment.styles[s].geometry, "100x100"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
should "have the right formats" do
|
88
|
+
assert_equal @attachment.styles[:aslist].format, :png
|
89
|
+
assert_equal @attachment.styles[:ashash].format, :png
|
90
|
+
assert_nil @attachment.styles[:asstring].format
|
91
|
+
end
|
92
|
+
|
93
|
+
should "retain order" do
|
94
|
+
assert_equal [:aslist, :ashash, :asstring], @attachment.styles.keys
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "An attachment with :convert_options" do
|
99
|
+
should "not have called extra_options_for(:thumb/:large) on initialization" do
|
100
|
+
@attachment = attachment :path => ":basename.:extension",
|
101
|
+
:styles => {:thumb => "100x100", :large => "400x400"},
|
102
|
+
:convert_options => {:all => "-do_stuff", :thumb => "-thumbnailize"}
|
103
|
+
@attachment.expects(:extra_options_for).never
|
104
|
+
@style = @attachment.styles[:thumb]
|
105
|
+
@file = StringIO.new("...")
|
106
|
+
@file.stubs(:original_filename).returns("file.jpg")
|
107
|
+
end
|
108
|
+
|
109
|
+
should "call extra_options_for(:thumb/:large) when convert options are requested" do
|
110
|
+
@attachment = attachment :path => ":basename.:extension",
|
111
|
+
:styles => {:thumb => "100x100", :large => "400x400"},
|
112
|
+
:convert_options => {:all => "-do_stuff", :thumb => "-thumbnailize"}
|
113
|
+
@style = @attachment.styles[:thumb]
|
114
|
+
@file = StringIO.new("...")
|
115
|
+
@file.stubs(:original_filename).returns("file.jpg")
|
116
|
+
@attachment.expects(:extra_options_for).with(:thumb)
|
117
|
+
@attachment.styles[:thumb].convert_options
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "An attachment with :source_file_options" do
|
122
|
+
should "not have called extra_source_file_options_for(:thumb/:large) on initialization" do
|
123
|
+
@attachment = attachment :path => ":basename.:extension",
|
124
|
+
:styles => {:thumb => "100x100", :large => "400x400"},
|
125
|
+
:source_file_options => {:all => "-density 400", :thumb => "-depth 8"}
|
126
|
+
@attachment.expects(:extra_source_file_options_for).never
|
127
|
+
@style = @attachment.styles[:thumb]
|
128
|
+
@file = StringIO.new("...")
|
129
|
+
@file.stubs(:original_filename).returns("file.jpg")
|
130
|
+
end
|
131
|
+
|
132
|
+
should "call 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
|
+
@file.stubs(:original_filename).returns("file.jpg")
|
139
|
+
@attachment.expects(:extra_source_file_options_for).with(:thumb)
|
140
|
+
@attachment.styles[:thumb].source_file_options
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "A style rule with its own :processors" do
|
145
|
+
setup do
|
146
|
+
@attachment = attachment :path => ":basename.:extension",
|
147
|
+
:styles => {
|
148
|
+
:foo => {
|
149
|
+
:geometry => "100x100#",
|
150
|
+
:format => :png,
|
151
|
+
:processors => [:test]
|
152
|
+
}
|
153
|
+
},
|
154
|
+
:processors => [:thumbnail]
|
155
|
+
@style = @attachment.styles[:foo]
|
156
|
+
end
|
157
|
+
|
158
|
+
should "not get processors from the attachment" do
|
159
|
+
@attachment.expects(:processors).never
|
160
|
+
assert_not_equal [:thumbnail], @style.processors
|
161
|
+
end
|
162
|
+
|
163
|
+
should "report its own processors" do
|
164
|
+
assert_equal [:test], @style.processors
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
context "A style rule with :processors supplied as procs" do
|
170
|
+
setup 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
|
+
should "defer processing of procs until they are needed" do
|
183
|
+
assert_kind_of Proc, @attachment.styles[:foo].instance_variable_get("@processors")
|
184
|
+
end
|
185
|
+
|
186
|
+
should "call 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
|
+
setup 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
|
+
}
|
201
|
+
@file = StringIO.new("...")
|
202
|
+
@file.stubs(:original_filename).returns("file.jpg")
|
203
|
+
end
|
204
|
+
|
205
|
+
should "have empty options for :thumb style" do
|
206
|
+
assert_equal "", @attachment.styles[:thumb].processor_options[:convert_options]
|
207
|
+
assert_equal "", @attachment.styles[:thumb].processor_options[:source_file_options]
|
208
|
+
end
|
209
|
+
|
210
|
+
should "have the right options for :large style" do
|
211
|
+
assert_equal "-do_stuff", @attachment.styles[:large].processor_options[:convert_options]
|
212
|
+
assert_equal "-do_extra_stuff", @attachment.styles[:large].processor_options[:source_file_options]
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class MockAttachment
|
2
|
+
attr_accessor :updated_at, :original_filename
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
@model = options[:model]
|
6
|
+
@responds_to_updated_at = options[:responds_to_updated_at]
|
7
|
+
@updated_at = options[:updated_at]
|
8
|
+
@original_filename = options[:original_filename]
|
9
|
+
end
|
10
|
+
|
11
|
+
def instance
|
12
|
+
@model
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to?(meth)
|
16
|
+
if meth.to_s == "updated_at"
|
17
|
+
@responds_to_updated_at || @updated_at
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class MockInterpolator
|
2
|
+
def initialize(options = {})
|
3
|
+
@options = options
|
4
|
+
end
|
5
|
+
|
6
|
+
def interpolate(pattern, attachment, style_name)
|
7
|
+
@interpolated_pattern = pattern
|
8
|
+
@interpolated_attachment = attachment
|
9
|
+
@interpolated_style_name = style_name
|
10
|
+
@options[:result]
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_interpolated_pattern?(pattern)
|
14
|
+
@interpolated_pattern == pattern
|
15
|
+
end
|
16
|
+
|
17
|
+
def has_interpolated_style_name?(style_name)
|
18
|
+
@interpolated_style_name == style_name
|
19
|
+
end
|
20
|
+
|
21
|
+
def has_interpolated_attachment?(attachment)
|
22
|
+
@interpolated_attachment == attachment
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class MockUrlGeneratorBuilder
|
2
|
+
def initializer
|
3
|
+
end
|
4
|
+
|
5
|
+
def new(attachment, attachment_options)
|
6
|
+
@attachment = attachment
|
7
|
+
@attachment_options = attachment_options
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def for(style_name, options)
|
12
|
+
@generated_url_with_style_name = style_name
|
13
|
+
@generated_url_with_options = options
|
14
|
+
"hello"
|
15
|
+
end
|
16
|
+
|
17
|
+
def has_generated_url_with_options?(options)
|
18
|
+
# options.is_a_subhash_of(@generated_url_with_options)
|
19
|
+
options.inject(true) do |acc,(k,v)|
|
20
|
+
acc && @generated_url_with_options[k] == v
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def has_generated_url_with_style_name?(style_name)
|
25
|
+
@generated_url_with_style_name == style_name
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,396 @@
|
|
1
|
+
require './test/helper'
|
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
|
+
should "have its path contain a real extension" do
|
11
|
+
assert_equal ".jpg", File.extname(@tempfile.path)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be a real Tempfile" do
|
15
|
+
assert @tempfile.is_a?(::Tempfile)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "Another Paperclip Tempfile" do
|
20
|
+
setup do
|
21
|
+
@tempfile = Paperclip::Tempfile.new("file")
|
22
|
+
end
|
23
|
+
|
24
|
+
should "not have an extension if not given one" do
|
25
|
+
assert_equal "", File.extname(@tempfile.path)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "still be a real Tempfile" do
|
29
|
+
assert @tempfile.is_a?(::Tempfile)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "An image" do
|
34
|
+
setup do
|
35
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
|
36
|
+
end
|
37
|
+
|
38
|
+
teardown { @file.close }
|
39
|
+
|
40
|
+
[["600x600>", "434x66"],
|
41
|
+
["400x400>", "400x61"],
|
42
|
+
["32x32<", "434x66"]
|
43
|
+
].each do |args|
|
44
|
+
context "being thumbnailed with a geometry of #{args[0]}" do
|
45
|
+
setup do
|
46
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
|
47
|
+
end
|
48
|
+
|
49
|
+
should "start with dimensions of 434x66" do
|
50
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
51
|
+
assert_equal "434x66", `#{cmd}`.chomp
|
52
|
+
end
|
53
|
+
|
54
|
+
should "report the correct target geometry" do
|
55
|
+
assert_equal args[0], @thumb.target_geometry.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when made" do
|
59
|
+
setup do
|
60
|
+
@thumb_result = @thumb.make
|
61
|
+
end
|
62
|
+
|
63
|
+
should "be the size we expect it to be" do
|
64
|
+
cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
|
65
|
+
assert_equal args[1], `#{cmd}`.chomp
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "being thumbnailed at 100x50 with cropping" do
|
72
|
+
setup do
|
73
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
|
74
|
+
end
|
75
|
+
|
76
|
+
should "let us know when a command isn't found versus a processing error" do
|
77
|
+
old_path = ENV['PATH']
|
78
|
+
begin
|
79
|
+
Cocaine::CommandLine.path = ''
|
80
|
+
Paperclip.options[:command_path] = ''
|
81
|
+
ENV['PATH'] = ''
|
82
|
+
assert_raises(Paperclip::CommandNotFoundError) do
|
83
|
+
@thumb.make
|
84
|
+
end
|
85
|
+
ensure
|
86
|
+
ENV['PATH'] = old_path
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
should "report its correct current and target geometries" do
|
91
|
+
assert_equal "100x50#", @thumb.target_geometry.to_s
|
92
|
+
assert_equal "434x66", @thumb.current_geometry.to_s
|
93
|
+
end
|
94
|
+
|
95
|
+
should "report its correct format" do
|
96
|
+
assert_nil @thumb.format
|
97
|
+
end
|
98
|
+
|
99
|
+
should "have whiny turned on by default" do
|
100
|
+
assert @thumb.whiny
|
101
|
+
end
|
102
|
+
|
103
|
+
should "have convert_options set to nil by default" do
|
104
|
+
assert_equal nil, @thumb.convert_options
|
105
|
+
end
|
106
|
+
|
107
|
+
should "have source_file_options set to nil by default" do
|
108
|
+
assert_equal nil, @thumb.source_file_options
|
109
|
+
end
|
110
|
+
|
111
|
+
should "send the right command to convert when sent #make" do
|
112
|
+
Paperclip.expects(:run).with do |*arg|
|
113
|
+
arg[0] == 'convert' &&
|
114
|
+
arg[1] == ':source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
|
115
|
+
arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
116
|
+
end
|
117
|
+
@thumb.make
|
118
|
+
end
|
119
|
+
|
120
|
+
should "create the thumbnail when sent #make" do
|
121
|
+
dst = @thumb.make
|
122
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "being thumbnailed with source file options set" do
|
127
|
+
setup do
|
128
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
129
|
+
:geometry => "100x50#",
|
130
|
+
:source_file_options => "-strip")
|
131
|
+
end
|
132
|
+
|
133
|
+
should "have source_file_options value set" do
|
134
|
+
assert_equal ["-strip"], @thumb.source_file_options
|
135
|
+
end
|
136
|
+
|
137
|
+
should "send the right command to convert when sent #make" do
|
138
|
+
Paperclip.expects(:run).with do |*arg|
|
139
|
+
arg[0] == 'convert' &&
|
140
|
+
arg[1] == '-strip :source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
|
141
|
+
arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
142
|
+
end
|
143
|
+
@thumb.make
|
144
|
+
end
|
145
|
+
|
146
|
+
should "create the thumbnail when sent #make" do
|
147
|
+
dst = @thumb.make
|
148
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
149
|
+
end
|
150
|
+
|
151
|
+
context "redefined to have bad source_file_options setting" do
|
152
|
+
setup do
|
153
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
154
|
+
:geometry => "100x50#",
|
155
|
+
:source_file_options => "-this-aint-no-option")
|
156
|
+
end
|
157
|
+
|
158
|
+
should "error when trying to create the thumbnail" do
|
159
|
+
assert_raises(Paperclip::PaperclipError) do
|
160
|
+
@thumb.make
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "being thumbnailed with convert options set" do
|
167
|
+
setup do
|
168
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
169
|
+
:geometry => "100x50#",
|
170
|
+
:convert_options => "-strip -depth 8")
|
171
|
+
end
|
172
|
+
|
173
|
+
should "have convert_options value set" do
|
174
|
+
assert_equal %w"-strip -depth 8", @thumb.convert_options
|
175
|
+
end
|
176
|
+
|
177
|
+
should "send the right command to convert when sent #make" do
|
178
|
+
Paperclip.expects(:run).with do |*arg|
|
179
|
+
arg[0] == 'convert' &&
|
180
|
+
arg[1] == ':source -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
|
181
|
+
arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
|
182
|
+
end
|
183
|
+
@thumb.make
|
184
|
+
end
|
185
|
+
|
186
|
+
should "create the thumbnail when sent #make" do
|
187
|
+
dst = @thumb.make
|
188
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
189
|
+
end
|
190
|
+
|
191
|
+
context "redefined to have bad convert_options setting" do
|
192
|
+
setup do
|
193
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
194
|
+
:geometry => "100x50#",
|
195
|
+
:convert_options => "-this-aint-no-option")
|
196
|
+
end
|
197
|
+
|
198
|
+
should "error when trying to create the thumbnail" do
|
199
|
+
assert_raises(Paperclip::PaperclipError) do
|
200
|
+
@thumb.make
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
should "let us know when a command isn't found versus a processing error" do
|
205
|
+
old_path = ENV['PATH']
|
206
|
+
begin
|
207
|
+
Cocaine::CommandLine.path = ''
|
208
|
+
Paperclip.options[:command_path] = ''
|
209
|
+
ENV['PATH'] = ''
|
210
|
+
assert_raises(Paperclip::CommandNotFoundError) do
|
211
|
+
@thumb.make
|
212
|
+
end
|
213
|
+
ensure
|
214
|
+
ENV['PATH'] = old_path
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "being thumbnailed with a blank geometry string" do
|
221
|
+
setup do
|
222
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
223
|
+
:geometry => "",
|
224
|
+
:convert_options => "-gravity center -crop \"300x300+0-0\"")
|
225
|
+
end
|
226
|
+
|
227
|
+
should "not get resized by default" do
|
228
|
+
assert !@thumb.transformation_command.include?("-resize")
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context "passing a custom file geometry parser" do
|
233
|
+
teardown do
|
234
|
+
self.class.send(:remove_const, :GeoParser)
|
235
|
+
end
|
236
|
+
|
237
|
+
should "produce the appropriate transformation_command" do
|
238
|
+
GeoParser = Class.new do
|
239
|
+
def self.from_file(file)
|
240
|
+
new
|
241
|
+
end
|
242
|
+
|
243
|
+
def transformation_to(target, should_crop)
|
244
|
+
["SCALE", "CROP"]
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :file_geometry_parser => GeoParser)
|
249
|
+
|
250
|
+
transformation_command = thumb.transformation_command
|
251
|
+
|
252
|
+
assert transformation_command.include?('-crop'),
|
253
|
+
%{expected #{transformation_command.inspect} to include '-crop'}
|
254
|
+
assert transformation_command.include?('"CROP"'),
|
255
|
+
%{expected #{transformation_command.inspect} to include '"CROP"'}
|
256
|
+
assert transformation_command.include?('-resize'),
|
257
|
+
%{expected #{transformation_command.inspect} to include '-resize'}
|
258
|
+
assert transformation_command.include?('"SCALE"'),
|
259
|
+
%{expected #{transformation_command.inspect} to include '"SCALE"'}
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context "passing a custom geometry string parser" do
|
264
|
+
teardown do
|
265
|
+
self.class.send(:remove_const, :GeoParser)
|
266
|
+
end
|
267
|
+
|
268
|
+
should "produce the appropriate transformation_command" do
|
269
|
+
GeoParser = Class.new do
|
270
|
+
def self.parse(s)
|
271
|
+
new
|
272
|
+
end
|
273
|
+
|
274
|
+
def to_s
|
275
|
+
"151x167"
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :string_geometry_parser => GeoParser)
|
280
|
+
|
281
|
+
transformation_command = thumb.transformation_command
|
282
|
+
|
283
|
+
assert transformation_command.include?('"151x167"'),
|
284
|
+
%{expected #{transformation_command.inspect} to include '151x167'}
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
context "A multipage PDF" do
|
290
|
+
setup do
|
291
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb')
|
292
|
+
end
|
293
|
+
|
294
|
+
teardown { @file.close }
|
295
|
+
|
296
|
+
should "start with two pages with dimensions 612x792" do
|
297
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
298
|
+
assert_equal "612x792"*2, `#{cmd}`.chomp
|
299
|
+
end
|
300
|
+
|
301
|
+
context "being thumbnailed at 100x100 with cropping" do
|
302
|
+
setup do
|
303
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
|
304
|
+
end
|
305
|
+
|
306
|
+
should "report its correct current and target geometries" do
|
307
|
+
assert_equal "100x100#", @thumb.target_geometry.to_s
|
308
|
+
assert_equal "612x792", @thumb.current_geometry.to_s
|
309
|
+
end
|
310
|
+
|
311
|
+
should "report its correct format" do
|
312
|
+
assert_equal :png, @thumb.format
|
313
|
+
end
|
314
|
+
|
315
|
+
should "create the thumbnail when sent #make" do
|
316
|
+
dst = @thumb.make
|
317
|
+
assert_match /100x100/, `identify "#{dst.path}"`
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
context "An animated gif" do
|
323
|
+
setup do
|
324
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "animated.gif"), 'rb')
|
325
|
+
end
|
326
|
+
|
327
|
+
teardown { @file.close }
|
328
|
+
|
329
|
+
should "start with 12 frames with size 100x100" do
|
330
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
331
|
+
assert_equal "100x100"*12, `#{cmd}`.chomp
|
332
|
+
end
|
333
|
+
|
334
|
+
context "with static output" do
|
335
|
+
setup do
|
336
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :format => :jpg)
|
337
|
+
end
|
338
|
+
|
339
|
+
should "create the single frame thumbnail when sent #make" do
|
340
|
+
dst = @thumb.make
|
341
|
+
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
342
|
+
assert_equal "50x50", `#{cmd}`.chomp
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context "with animated output format" do
|
347
|
+
setup do
|
348
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :format => :gif)
|
349
|
+
end
|
350
|
+
|
351
|
+
should "create the 12 frames thumbnail when sent #make" do
|
352
|
+
dst = @thumb.make
|
353
|
+
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
354
|
+
assert_equal "50x50"*12, `#{cmd}`.chomp
|
355
|
+
end
|
356
|
+
|
357
|
+
should "use the -coalesce option" do
|
358
|
+
assert_equal @thumb.transformation_command.first, "-coalesce"
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context "with omitted output format" do
|
363
|
+
setup do
|
364
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50")
|
365
|
+
end
|
366
|
+
|
367
|
+
should "create the 12 frames thumbnail when sent #make" do
|
368
|
+
dst = @thumb.make
|
369
|
+
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
370
|
+
assert_equal "50x50"*12, `#{cmd}`.chomp
|
371
|
+
end
|
372
|
+
|
373
|
+
should "use the -coalesce option" do
|
374
|
+
assert_equal @thumb.transformation_command.first, "-coalesce"
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
context "with animated option set to false" do
|
379
|
+
setup do
|
380
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :animated => false)
|
381
|
+
end
|
382
|
+
|
383
|
+
should "output the gif format" do
|
384
|
+
dst = @thumb.make
|
385
|
+
cmd = %Q[identify "#{dst.path}"]
|
386
|
+
assert_match /GIF/, `#{cmd}`.chomp
|
387
|
+
end
|
388
|
+
|
389
|
+
should "create the single frame thumbnail when sent #make" do
|
390
|
+
dst = @thumb.make
|
391
|
+
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
|
392
|
+
assert_equal "50x50", `#{cmd}`.chomp
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|