paperclip 3.4.1 → 3.4.2

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.

@@ -3,6 +3,7 @@ rvm:
3
3
  - 1.9.3
4
4
  - jruby-19mode
5
5
  - rbx-19mode
6
+ - 2.0.0
6
7
 
7
8
  before_script: "sudo ntpdate -ub ntp.ubuntu.com pool.ntp.org; true"
8
9
  script: "bundle exec rake clean test cucumber"
@@ -16,3 +17,4 @@ matrix:
16
17
  allow_failures:
17
18
  - rvm: jruby-19mode
18
19
  - rvm: rbx-19mode
20
+ - rvm: 2.0.0
data/Appraisals CHANGED
@@ -1,7 +1,7 @@
1
- appraise "3.0" do
2
- gem "rails", "~> 3.0.15"
3
- gem "paperclip", :path => "../"
4
- end
1
+ # appraise "3.0" do
2
+ # gem "rails", "~> 3.0.15"
3
+ # gem "paperclip", :path => "../"
4
+ # end
5
5
 
6
6
  appraise "3.1" do
7
7
  gem "rails", "~> 3.1.6"
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
data/NEWS CHANGED
@@ -1,7 +1,17 @@
1
+ New in 3.4.2:
2
+
3
+ * Improvement: Use https for Gemfile urls
4
+ * Improvement: Updated and more correct documentation
5
+ * Improvement: Use the -optimize flag on animated GIFs
6
+ * Improvement: Remove the Gemfile.lock
7
+ * Improvement: Add #expiring_url as an alias for #url until the storage defines it
8
+ * Improvement: Remove path clash checking, as it's unnecessary
9
+ * Bug Fix: Do not rely on checking version numbers for aws-sdk
10
+
1
11
  New in 3.4.1:
2
12
 
3
13
  * Improvement: Various documentation fixes and improvements
4
- * Bug Fix: Clearing an attachment with `perserve_files` on should still clear the attachment
14
+ * Bug Fix: Clearing an attachment with `preserve_files` on should still clear the attachment
5
15
  * Bug Fix: Instances are #changed? when a new file is assigned
6
16
  * Bug Fix: Correctly deal with S3 styles when using a lambda
7
17
  * Improvement: Accept and pass :credential_provider option to AWS-SDK
data/README.md CHANGED
@@ -174,6 +174,9 @@ validation.
174
174
  More information about the options to `has_attached_file` is available in the
175
175
  documentation of [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
176
176
 
177
+ Validations
178
+ -----------
179
+
177
180
  For validations, Paperclip introduces several validators to validate your attachment:
178
181
 
179
182
  * `AttachmentContentTypeValidator`
@@ -207,6 +210,49 @@ validates_attachment :avatar, :presence => true,
207
210
  :size => { :in => 0..10.kilobytes }
208
211
  ```
209
212
 
213
+ _NOTE: Post processing will not even *start* if the attachment is not valid
214
+ according to the validations. Your callbacks and processors will *only* be
215
+ called with valid attachments._
216
+
217
+ ```ruby
218
+ class Message < ActiveRecord::Base
219
+ has_attached_file :asset, styles: {thumb: "100x100#"}
220
+
221
+ before_post_process :skip_for_audio
222
+
223
+ def skip_for_audio
224
+ ! %w(audio/ogg application/ogg).include?(asset_content_type)
225
+ end
226
+ end
227
+ ```
228
+
229
+ If you have other validations that depend on assignment order, the recommended
230
+ course of action is to prevent the assignment of the attachment until
231
+ afterwards, then assign manually:
232
+
233
+ ```ruby
234
+ class Book < ActiveRecord::Base
235
+ has_attached_file :document, styles: {thumbnail: "60x60#"}
236
+ validates_attachment :document, content_type: "application/pdf"
237
+ validates_something_else # Other validations that conflict with Paperclip's
238
+ end
239
+
240
+ class BooksController < ApplicationController
241
+ def create
242
+ @book = Book.new(book_params)
243
+ @book.document = params[:book][:document]
244
+ @book.save
245
+ respond_with @book
246
+ end
247
+
248
+ private
249
+
250
+ def book_params
251
+ params.require(:book).permit(:title, :author)
252
+ end
253
+ end
254
+ ```
255
+
210
256
  Defaults
211
257
  --------
212
258
  Global defaults for all your paperclip attachments can be defined by changing the Paperclip::Attachment.default_options Hash, this can be useful for setting your default storage settings per example so you won't have to define them in every has_attached_file definition.
@@ -327,7 +373,7 @@ You may also choose to store your files using Amazon's S3 service. To do so, inc
327
373
  the `aws-sdk` gem in your Gemfile:
328
374
 
329
375
  ```ruby
330
- gem 'aws-sdk', '~> 1.3.4'
376
+ gem 'aws-sdk', '~> 1.5.7'
331
377
  ```
332
378
 
333
379
  And then you can specify using S3 from `has_attached_file`.
@@ -532,6 +578,20 @@ class User < ActiveRecord::Base
532
578
  end
533
579
  ```
534
580
 
581
+ Logging
582
+ ----------
583
+
584
+ By default Paperclip outputs logging according to your logger level. If you want to disable logging (e.g. during testing) add this in to your environment's configuration:
585
+ ```ruby
586
+ Your::Application.configure do
587
+ ...
588
+ Paperclip.options[:log] = false
589
+ ...
590
+ end
591
+ ```
592
+
593
+ More information in the [rdocs](http://rdoc.info/github/thoughtbot/paperclip/Paperclip.options)
594
+
535
595
  Deployment
536
596
  ----------
537
597
 
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "http://rubygems.org"
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "jruby-openssl", :platform=>:jruby
6
6
  gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "http://rubygems.org"
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "jruby-openssl", :platform=>:jruby
6
6
  gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "http://rubygems.org"
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "jruby-openssl", :platform=>:jruby
6
6
  gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
@@ -183,7 +183,6 @@ module Paperclip
183
183
 
184
184
  attachment_definitions[name] = Paperclip::AttachmentOptions.new(options)
185
185
  Paperclip.classes_with_attachments << self.name
186
- Paperclip.check_for_path_clash(name,attachment_definitions[name][:path],self.name)
187
186
 
188
187
  after_save :save_attached_files
189
188
  before_destroy :prepare_for_destroy
@@ -146,6 +146,13 @@ module Paperclip
146
146
  end
147
147
  end
148
148
 
149
+ # Alias to +url+ that allows using the expiring_url method provided by the cloud
150
+ # storage implementations, but keep using filesystem storage for development and
151
+ # testing.
152
+ def expiring_url(time = 3600, style_name = default_style)
153
+ url(style_name)
154
+ end
155
+
149
156
  # Returns the path of the attachment as defined by the :path option. If the
150
157
  # file is stored in the filesystem the path refers to the path of the file
151
158
  # on disk. If the file is stored in S3, the path is the "key" part of the
@@ -8,9 +8,9 @@ module Paperclip
8
8
  end
9
9
 
10
10
  def detect
11
- if blank?
11
+ if blank_name?
12
12
  SENSIBLE_DEFAULT
13
- elsif empty?
13
+ elsif empty_file?
14
14
  EMPTY_TYPE
15
15
  elsif !match?
16
16
  type_from_file_command
@@ -23,11 +23,11 @@ module Paperclip
23
23
 
24
24
  private
25
25
 
26
- def empty?
26
+ def empty_file?
27
27
  File.exists?(@filename) && File.size(@filename) == 0
28
28
  end
29
29
 
30
- def blank?
30
+ def blank_name?
31
31
  @filename.nil? || @filename.empty?
32
32
  end
33
33
 
@@ -49,15 +49,6 @@ module Paperclip
49
49
  end
50
50
  end
51
51
 
52
- def check_for_path_clash(name,path,klass)
53
- @names_path ||= {}
54
- default_path = path || Attachment.default_options[:path]
55
- if @names_path[name] && @names_path[name][:path] == default_path && @names_path[name][:class] != klass && @names_path[name][:path] !~ /:class/
56
- log("Duplicate path for #{name} with #{default_path}. This will clash with attachment defined in #{@names_path[name][:class]} class")
57
- end
58
- @names_path[name] = {:path => default_path, :class => klass}
59
- end
60
-
61
52
  def reset_duplicate_clash_check!
62
53
  @names_url = nil
63
54
  end
@@ -15,7 +15,7 @@ module Paperclip
15
15
  #
16
16
  # And _include_ the module:
17
17
  #
18
- # Spec::Runner.configure do |config|
18
+ # RSpec.configure do |config|
19
19
  # config.include Paperclip::Shoulda::Matchers
20
20
  # end
21
21
  #
@@ -99,14 +99,14 @@ module Paperclip
99
99
  raise e
100
100
  end unless defined?(AWS::Core)
101
101
 
102
- # Overriding AWS::Core::LogFormatter to make sure it return a UTF-8 string
103
- if AWS::VERSION >= "1.3.9"
102
+ # Overriding log formatter to make sure it return a UTF-8 string
103
+ if defined?(AWS::Core::LogFormatter)
104
104
  AWS::Core::LogFormatter.class_eval do
105
105
  def summarize_hash(hash)
106
106
  hash.map { |key, value| ":#{key}=>#{summarize_value(value)}".force_encoding('UTF-8') }.sort.join(',')
107
107
  end
108
108
  end
109
- else
109
+ elsif defined?(AWS::Core::ClientLogging)
110
110
  AWS::Core::ClientLogging.class_eval do
111
111
  def sanitize_hash(hash)
112
112
  hash.map { |key, value| "#{sanitize_value(key)}=>#{sanitize_value(value)}".force_encoding('UTF-8') }.sort.join(',')
@@ -96,6 +96,7 @@ module Paperclip
96
96
  trans << "-auto-orient" if auto_orient
97
97
  trans << "-resize" << %["#{scale}"] unless scale.nil? || scale.empty?
98
98
  trans << "-crop" << %["#{crop}"] << "+repage" if crop
99
+ trans << '-layers "optimize"' if animated?
99
100
  trans
100
101
  end
101
102
 
@@ -1,3 +1,3 @@
1
1
  module Paperclip
2
- VERSION = "3.4.1" unless defined? Paperclip::VERSION
2
+ VERSION = "3.4.2" unless defined? Paperclip::VERSION
3
3
  end
@@ -953,6 +953,10 @@ class AttachmentTest < Test::Unit::TestCase
953
953
  assert_match @attachment.to_s, @attachment.url
954
954
  assert_match @attachment.to_s(:small), @attachment.url(:small)
955
955
  end
956
+
957
+ should "have matching expiring_url and url methods when using the filesystem storage" do
958
+ assert_match @attachment.expiring_url, @attachment.url
959
+ end
956
960
  end
957
961
 
958
962
  context "An attachment" do
@@ -197,3 +197,11 @@ end
197
197
  def assert_file_not_exists(path)
198
198
  assert !File.exists?(path), %(Expect "#{path}" to not exists.)
199
199
  end
200
+
201
+ def assert_frame_dimensions(range, frames)
202
+ frames.each_with_index do |frame, frame_index|
203
+ frame.split('x').each_with_index do |dimension, dimension_index |
204
+ assert range.include?(dimension.to_i), "Frame #{frame_index}[#{dimension_index}] should have been within #{range.inspect}, but was #{dimension}"
205
+ end
206
+ end
207
+ end
@@ -107,45 +107,6 @@ class PaperclipTest < Test::Unit::TestCase
107
107
  end
108
108
  end
109
109
 
110
- context "Attachments with clashing URLs should raise error" do
111
- setup do
112
- class Dummy2 < ActiveRecord::Base
113
- include Paperclip::Glue
114
- end
115
- end
116
-
117
- should "generate warning if attachment is redefined with the same path string" do
118
- expected_log_msg = "Duplicate path for blah with /system/:id/:style/:filename. This will clash with attachment defined in Dummy class"
119
- Paperclip.expects(:log).with(expected_log_msg)
120
- Dummy.class_eval do
121
- has_attached_file :blah, :path => '/system/:id/:style/:filename'
122
- end
123
- Dummy2.class_eval do
124
- has_attached_file :blah, :path => '/system/:id/:style/:filename'
125
- end
126
- end
127
-
128
- should "not generate warning if attachment is redefined with the same path string but has :class in it" do
129
- Paperclip.expects(:log).never
130
- Dummy.class_eval do
131
- has_attached_file :blah, :path => "/system/:class/:attachment/:id/:style/:filename"
132
- end
133
- Dummy2.class_eval do
134
- has_attached_file :blah, :path => "/system/:class/:attachment/:id/:style/:filename"
135
- end
136
- end
137
-
138
- should "not generate warning if attachment is defined with the same URL string" do
139
- Paperclip.expects(:log).never
140
- Dummy.class_eval do
141
- has_attached_file :blah, :path => "/system/:class/:attachment/:id/:style/:filename", :url => ":s3_alias_url"
142
- end
143
- Dummy2.class_eval do
144
- has_attached_file :blah, :path => "/system/:class/:attachment/:id/:style/:filename", :url => ":s3_alias_url"
145
- end
146
- end
147
- end
148
-
149
110
  context "An ActiveRecord model with an 'avatar' attachment" do
150
111
  setup do
151
112
  rebuild_model :path => "tmp/:class/omg/:style.:extension"
@@ -309,7 +309,7 @@ class FogTest < Test::Unit::TestCase
309
309
 
310
310
  context "with a valid bucket name for a subdomain" do
311
311
  should "provide an url in subdomain style" do
312
- assert_match @dummy.avatar.url, /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/
312
+ assert_match /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url
313
313
  end
314
314
 
315
315
  should "provide an url that expires in subdomain style" do
@@ -380,13 +380,19 @@ class ThumbnailTest < Test::Unit::TestCase
380
380
 
381
381
  should "create the 12 frames thumbnail when sent #make" do
382
382
  dst = @thumb.make
383
- cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
384
- assert_equal "50x50"*12, `#{cmd}`.chomp
383
+ cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
384
+ frames = `#{cmd}`.chomp.split(',')
385
+ assert_equal 12, frames.size
386
+ assert_frame_dimensions (45..50), frames
385
387
  end
386
388
 
387
389
  should "use the -coalesce option" do
388
390
  assert_equal @thumb.transformation_command.first, "-coalesce"
389
391
  end
392
+
393
+ should "use the -layers 'optimize' option" do
394
+ assert_equal @thumb.transformation_command.last, '-layers "optimize"'
395
+ end
390
396
  end
391
397
 
392
398
  context "with omitted output format" do
@@ -396,13 +402,19 @@ class ThumbnailTest < Test::Unit::TestCase
396
402
 
397
403
  should "create the 12 frames thumbnail when sent #make" do
398
404
  dst = @thumb.make
399
- cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
400
- assert_equal "50x50"*12, `#{cmd}`.chomp
405
+ cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
406
+ frames = `#{cmd}`.chomp.split(',')
407
+ assert_equal 12, frames.size
408
+ assert_frame_dimensions (45..50), frames
401
409
  end
402
410
 
403
411
  should "use the -coalesce option" do
404
412
  assert_equal @thumb.transformation_command.first, "-coalesce"
405
413
  end
414
+
415
+ should "use the -layers 'optimize' option" do
416
+ assert_equal @thumb.transformation_command.last, '-layers "optimize"'
417
+ end
406
418
  end
407
419
 
408
420
  context "with unidentified source format" do
@@ -413,13 +425,19 @@ class ThumbnailTest < Test::Unit::TestCase
413
425
 
414
426
  should "create the 12 frames thumbnail when sent #make" do
415
427
  dst = @thumb.make
416
- cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
417
- assert_equal "60x60"*12, `#{cmd}`.chomp
428
+ cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
429
+ frames = `#{cmd}`.chomp.split(',')
430
+ assert_equal 12, frames.size
431
+ assert_frame_dimensions (55..60), frames
418
432
  end
419
433
 
420
434
  should "use the -coalesce option" do
421
435
  assert_equal @thumb.transformation_command.first, "-coalesce"
422
436
  end
437
+
438
+ should "use the -layers 'optimize' option" do
439
+ assert_equal @thumb.transformation_command.last, '-layers "optimize"'
440
+ end
423
441
  end
424
442
 
425
443
  context "with no source format" do
@@ -430,13 +448,19 @@ class ThumbnailTest < Test::Unit::TestCase
430
448
 
431
449
  should "create the 12 frames thumbnail when sent #make" do
432
450
  dst = @thumb.make
433
- cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
434
- assert_equal "70x70"*12, `#{cmd}`.chomp
451
+ cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
452
+ frames = `#{cmd}`.chomp.split(',')
453
+ assert_equal 12, frames.size
454
+ assert_frame_dimensions (60..70), frames
435
455
  end
436
456
 
437
457
  should "use the -coalesce option" do
438
458
  assert_equal @thumb.transformation_command.first, "-coalesce"
439
459
  end
460
+
461
+ should "use the -layers 'optimize' option" do
462
+ assert_equal @thumb.transformation_command.last, '-layers "optimize"'
463
+ end
440
464
  end
441
465
 
442
466
  context "with animated option set to false" 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: 3.4.1
4
+ version: 3.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -397,7 +397,6 @@ files:
397
397
  - Appraisals
398
398
  - CONTRIBUTING.md
399
399
  - Gemfile
400
- - Gemfile.lock
401
400
  - LICENSE
402
401
  - NEWS
403
402
  - README.md
@@ -654,4 +653,3 @@ test_files:
654
653
  - test/validators/attachment_presence_validator_test.rb
655
654
  - test/validators/attachment_size_validator_test.rb
656
655
  - test/validators_test.rb
657
- has_rdoc: