paperclip 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- data/lib/paperclip.rb +5 -2
- data/lib/paperclip/attachment.rb +15 -3
- data/lib/paperclip/storage.rb +1 -1
- data/test/attachment_test.rb +36 -2
- data/test/integration_test.rb +17 -0
- data/test/iostream_test.rb +2 -1
- metadata +2 -2
data/lib/paperclip.rb
CHANGED
@@ -43,12 +43,14 @@ end
|
|
43
43
|
# documentation for Paperclip::ClassMethods for more useful information.
|
44
44
|
module Paperclip
|
45
45
|
|
46
|
-
VERSION = "2.2.
|
46
|
+
VERSION = "2.2.1"
|
47
47
|
|
48
48
|
class << self
|
49
49
|
# Provides configurability to Paperclip. There are a number of options available, such as:
|
50
50
|
# * whiny_thumbnails: Will raise an error if Paperclip cannot process thumbnails of
|
51
51
|
# an uploaded image. Defaults to true.
|
52
|
+
# * log: Logs progress to the Rails log. Uses ActiveRecord's logger, so honors
|
53
|
+
# log levels, etc. Defaults to true.
|
52
54
|
# * command_path: Defines the path at which to find the command line
|
53
55
|
# programs if they are not visible to Rails the system's search path. Defaults to
|
54
56
|
# nil, which uses the first executable found in the user's search path.
|
@@ -57,7 +59,8 @@ module Paperclip
|
|
57
59
|
@options ||= {
|
58
60
|
:whiny_thumbnails => true,
|
59
61
|
:image_magick_path => nil,
|
60
|
-
:command_path => nil
|
62
|
+
:command_path => nil,
|
63
|
+
:log => true
|
61
64
|
}
|
62
65
|
end
|
63
66
|
|
data/lib/paperclip/attachment.rb
CHANGED
@@ -67,6 +67,7 @@ module Paperclip
|
|
67
67
|
|
68
68
|
if uploaded_file.is_a?(Paperclip::Attachment)
|
69
69
|
uploaded_file = uploaded_file.to_file(:original)
|
70
|
+
close_uploaded_file = uploaded_file.respond_to?(:close)
|
70
71
|
end
|
71
72
|
|
72
73
|
return nil unless valid_assignment?(uploaded_file)
|
@@ -91,8 +92,9 @@ module Paperclip
|
|
91
92
|
post_process if valid?
|
92
93
|
|
93
94
|
# Reset the file size if the original file was reprocessed.
|
94
|
-
instance_write(:file_size,
|
95
|
+
instance_write(:file_size, @queued_for_write[:original].size.to_i)
|
95
96
|
ensure
|
97
|
+
uploaded_file.close if close_uploaded_file
|
96
98
|
validate
|
97
99
|
end
|
98
100
|
|
@@ -212,6 +214,7 @@ module Paperclip
|
|
212
214
|
# the post-process again.
|
213
215
|
def reprocess!
|
214
216
|
new_original = Tempfile.new("paperclip-reprocess")
|
217
|
+
new_original.binmode
|
215
218
|
if old_original = to_file(:original)
|
216
219
|
new_original.write( old_original.read )
|
217
220
|
new_original.rewind
|
@@ -256,7 +259,11 @@ module Paperclip
|
|
256
259
|
end
|
257
260
|
|
258
261
|
def log message
|
259
|
-
logger.info("[paperclip] #{message}")
|
262
|
+
logger.info("[paperclip] #{message}") if logging?
|
263
|
+
end
|
264
|
+
|
265
|
+
def logging?
|
266
|
+
Paperclip.options[:log]
|
260
267
|
end
|
261
268
|
|
262
269
|
def valid_assignment? file #:nodoc:
|
@@ -304,7 +311,12 @@ module Paperclip
|
|
304
311
|
end
|
305
312
|
|
306
313
|
def extra_options_for(style) #:nodoc:
|
307
|
-
|
314
|
+
all_options = convert_options[:all]
|
315
|
+
all_options = all_options.call(instance) if all_options.respond_to?(:call)
|
316
|
+
style_options = convert_options[style]
|
317
|
+
style_options = style_options.call(instance) if style_options.respond_to?(:call)
|
318
|
+
|
319
|
+
[ style_options, all_options ].compact.join(" ")
|
308
320
|
end
|
309
321
|
|
310
322
|
def post_process #:nodoc:
|
data/lib/paperclip/storage.rb
CHANGED
@@ -38,11 +38,11 @@ module Paperclip
|
|
38
38
|
def flush_writes #:nodoc:
|
39
39
|
logger.info("[paperclip] Writing files for #{name}")
|
40
40
|
@queued_for_write.each do |style, file|
|
41
|
+
file.close
|
41
42
|
FileUtils.mkdir_p(File.dirname(path(style)))
|
42
43
|
logger.info("[paperclip] -> #{path(style)}")
|
43
44
|
FileUtils.mv(file.path, path(style))
|
44
45
|
FileUtils.chmod(0644, path(style))
|
45
|
-
file.close
|
46
46
|
end
|
47
47
|
@queued_for_write = {}
|
48
48
|
end
|
data/test/attachment_test.rb
CHANGED
@@ -138,6 +138,38 @@ class AttachmentTest < Test::Unit::TestCase
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
+
context "An attachment with :convert_options that is a proc" do
|
142
|
+
setup do
|
143
|
+
rebuild_model :styles => {
|
144
|
+
:thumb => "100x100",
|
145
|
+
:large => "400x400"
|
146
|
+
},
|
147
|
+
:convert_options => {
|
148
|
+
:all => lambda{|i| i.all },
|
149
|
+
:thumb => lambda{|i| i.thumb }
|
150
|
+
}
|
151
|
+
Dummy.class_eval do
|
152
|
+
def all; "-all"; end
|
153
|
+
def thumb; "-thumb"; end
|
154
|
+
end
|
155
|
+
@dummy = Dummy.new
|
156
|
+
@dummy.avatar
|
157
|
+
end
|
158
|
+
|
159
|
+
should "report the correct options when sent #extra_options_for(:thumb)" do
|
160
|
+
assert_equal "-thumb -all", @dummy.avatar.send(:extra_options_for, :thumb), @dummy.avatar.convert_options.inspect
|
161
|
+
end
|
162
|
+
|
163
|
+
should "report the correct options when sent #extra_options_for(:large)" do
|
164
|
+
assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large)
|
165
|
+
end
|
166
|
+
|
167
|
+
before_should "call extra_options_for(:thumb/:large)" do
|
168
|
+
Paperclip::Attachment.any_instance.expects(:extra_options_for).with(:thumb)
|
169
|
+
Paperclip::Attachment.any_instance.expects(:extra_options_for).with(:large)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
141
173
|
context "An attachment with both 'normal' and hash-style styles" do
|
142
174
|
setup do
|
143
175
|
rebuild_model :styles => {
|
@@ -266,11 +298,13 @@ class AttachmentTest < Test::Unit::TestCase
|
|
266
298
|
rebuild_model
|
267
299
|
|
268
300
|
@not_file = mock
|
301
|
+
@tempfile = mock
|
269
302
|
@not_file.stubs(:nil?).returns(false)
|
270
|
-
@not_file.expects(:
|
303
|
+
@not_file.expects(:size).returns(10)
|
304
|
+
@tempfile.expects(:size).returns(10)
|
305
|
+
@not_file.expects(:to_tempfile).returns(@tempfile)
|
271
306
|
@not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n")
|
272
307
|
@not_file.expects(:content_type).returns("image/png\r\n")
|
273
|
-
@not_file.expects(:size).returns(10).times(2)
|
274
308
|
|
275
309
|
@dummy = Dummy.new
|
276
310
|
@attachment = @dummy.avatar
|
data/test/integration_test.rb
CHANGED
@@ -51,6 +51,23 @@ class IntegrationTest < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
context "A model that modifies its original" do
|
55
|
+
setup do
|
56
|
+
rebuild_model :styles => { :original => "2x2#" }
|
57
|
+
@dummy = Dummy.new
|
58
|
+
@file = File.new(File.join(File.dirname(__FILE__),
|
59
|
+
"fixtures",
|
60
|
+
"5k.png"), 'rb')
|
61
|
+
@dummy.avatar = @file
|
62
|
+
end
|
63
|
+
|
64
|
+
should "report the file size of the processed file and not the original" do
|
65
|
+
assert_not_equal @file.size, @dummy.avatar.size
|
66
|
+
end
|
67
|
+
|
68
|
+
teardown { @file.close }
|
69
|
+
end
|
70
|
+
|
54
71
|
context "A model with attachments scoped under an id" do
|
55
72
|
setup do
|
56
73
|
rebuild_model :styles => { :large => "100x100",
|
data/test/iostream_test.rb
CHANGED
@@ -20,7 +20,8 @@ class IOStreamTest < Test::Unit::TestCase
|
|
20
20
|
|
21
21
|
context "and given a String" do
|
22
22
|
setup do
|
23
|
-
|
23
|
+
FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
|
24
|
+
assert @result = @file.stream_to(File.join(ROOT, 'tmp', 'iostream.string.test'))
|
24
25
|
end
|
25
26
|
|
26
27
|
should "return a File" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Yurek
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-30 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|