paperclip 4.2.0 → 4.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.

Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +6 -1
  3. data/Gemfile +1 -1
  4. data/NEWS +33 -0
  5. data/README.md +85 -7
  6. data/features/basic_integration.feature +15 -0
  7. data/features/step_definitions/rails_steps.rb +29 -0
  8. data/gemfiles/3.2.gemfile +13 -7
  9. data/gemfiles/4.0.gemfile +13 -7
  10. data/gemfiles/4.1.gemfile +15 -9
  11. data/gemfiles/4.2.gemfile +19 -0
  12. data/lib/paperclip.rb +1 -0
  13. data/lib/paperclip/attachment.rb +16 -8
  14. data/lib/paperclip/has_attached_file.rb +5 -3
  15. data/lib/paperclip/interpolations.rb +1 -1
  16. data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -0
  17. data/lib/paperclip/locales/ja.yml +18 -0
  18. data/lib/paperclip/locales/pt-BR.yml +18 -0
  19. data/lib/paperclip/locales/zh-CN.yml +18 -0
  20. data/lib/paperclip/locales/zh-HK.yml +18 -0
  21. data/lib/paperclip/locales/zh-TW.yml +18 -0
  22. data/lib/paperclip/processor.rb +0 -37
  23. data/lib/paperclip/processor_helpers.rb +50 -0
  24. data/lib/paperclip/schema.rb +11 -3
  25. data/lib/paperclip/storage/fog.rb +6 -1
  26. data/lib/paperclip/storage/s3.rb +16 -6
  27. data/lib/paperclip/url_generator.rb +11 -3
  28. data/lib/paperclip/version.rb +1 -1
  29. data/spec/paperclip/has_attached_file_spec.rb +24 -0
  30. data/spec/paperclip/interpolations_spec.rb +11 -4
  31. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +7 -0
  32. data/spec/paperclip/meta_class_spec.rb +1 -1
  33. data/spec/paperclip/processor_helpers_spec.rb +57 -0
  34. data/spec/paperclip/schema_spec.rb +50 -8
  35. data/spec/paperclip/storage/fog_spec.rb +30 -2
  36. data/spec/paperclip/storage/s3_spec.rb +33 -0
  37. data/spec/paperclip/url_generator_spec.rb +25 -0
  38. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +5 -0
  39. data/spec/support/matchers/have_column.rb +14 -0
  40. metadata +13 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cde0e56042ab5bd075c28a79c6fb2cac0948b01a
4
- data.tar.gz: f690007f67429569502696dcd1b1601cfdb8aaf5
3
+ metadata.gz: bfce4dd35d4417bbc321b3f2ca5c3a9fada39009
4
+ data.tar.gz: dde01d703ee5317817ebf0ba0758246cee52c5cc
5
5
  SHA512:
6
- metadata.gz: af5c881ab7c95be7c42bd61a9db37be53e8a50399e01371286d784ae543b339b16959e2c9327f771c12ee89b47769e86bcd989e67417b93a6093c0592f62ea82
7
- data.tar.gz: 39d1b2daf02a337b137a4a289a337d898578eaa6997bebdc25f107fc2147677a539815da7d11e516fcbf8ddd6e6f403dbf97c8df205d2db194a89d9b58f15fa4
6
+ metadata.gz: f629145edb2b10631f4b7364bd5384f637c8982843ac3d3978446997fe59915a6cad5284778bab30c662b33c1cd59bef5fd56a0355a69cd7f926584b3e22f387
7
+ data.tar.gz: 257d0074ad2ac069d17b5f691580a5ff83240722c07525d256370222afee012a4e7e42f578be8d3957c9b1925e1ad81def15fb1454101e1b8d8e1d595805e5ac
data/Appraisals CHANGED
@@ -9,6 +9,11 @@ appraise "4.0" do
9
9
  end
10
10
 
11
11
  appraise "4.1" do
12
- gem "rails", "~> 4.1.0.beta"
12
+ gem "rails", "~> 4.1.0"
13
+ gem "paperclip", :path => "../"
14
+ end
15
+
16
+ appraise "4.2" do
17
+ gem "rails", "~> 4.2.0.rc2"
13
18
  gem "paperclip", :path => "../"
14
19
  end
data/Gemfile CHANGED
@@ -16,5 +16,5 @@ gem 'pry'
16
16
  # Prevents bundler from taking a long-time to resolve
17
17
  group :development, :test do
18
18
  gem 'mime-types', '~> 1.16'
19
- gem 'builder', '~> 3.1.4'
19
+ gem 'builder'
20
20
  end
data/NEWS CHANGED
@@ -1,3 +1,36 @@
1
+ New in 4.2.1:
2
+
3
+ * Improvement: Added `validate_media_type` options to allow/bypass spoof check
4
+ * Improvement: Added incremental backoff when AWS gives us a SlowDown error.
5
+ * Improvement: Stream downloads when usign aws-sdk.
6
+ * Improvement: Documentation fixes, includes Windows instructions.
7
+ * Improvement: Added pt-BR, zh-HK, zh-CN, zh-TW, and ja-JP locales.
8
+ * Improvement: Better escaping for characters in URLs
9
+ * Improvement: Honor `fog_credentials[:scheme]`
10
+ * Improvement: Also look for custom processors in lib/paperclip
11
+ * Improvement: id partitioning for string IDs works liks integer id
12
+ * Improvement: Can pass options to DB adapters in migrations
13
+ * Improvement: Update expiring_url creation for later versions of fog
14
+ * Improvement: `path` can be a Proc in S3 attachments
15
+ * Test Fix: Improves speed and reliability of the specs
16
+ * Bug Fix: #original_filename= does not error when passed `nil`
17
+
18
+ New in 4.2.0:
19
+
20
+ * Improvement: Converted test suite from test/unit to RSpec
21
+ * Improvement: Refactored Paperclip::Attachment#assign
22
+ * Improvement: Added Spanish and German locales
23
+ * Improvement: Required Validators accept validator subclasses
24
+ * Improvement: EXIF orientation checking can be turned off for performance
25
+ * Improvement: Documentation updates
26
+ * Improvement: Better #human_size method for AttachmentSizeValidators
27
+ * Bug Fix: Allow MIME-types with dots in them
28
+ * Improvement: Travis CI updates
29
+ * Improvement: Validators can take multiple messages
30
+ * Improvement: Per-style options for S3 storage
31
+ * Improvement: Allow `nil` geometry strings
32
+ * Improvement: Use `eager_load!`
33
+
1
34
  New in 4.1.1:
2
35
 
3
36
  * Improvement: Add default translations for spoof validation
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Paperclip
2
2
  =========
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/thoughtbot/paperclip.png?branch=master)](http://travis-ci.org/thoughtbot/paperclip) [![Dependency Status](https://gemnasium.com/thoughtbot/paperclip.png?travis)](https://gemnasium.com/thoughtbot/paperclip) [![Code Climate](https://codeclimate.com/github/thoughtbot/paperclip.png)](https://codeclimate.com/github/thoughtbot/paperclip) [![Inline docs](http://inch-ci.org/github/thoughtbot/paperclip.png)](http://inch-ci.org/github/thoughtbot/paperclip)
4
+ [![Build Status](https://secure.travis-ci.org/thoughtbot/paperclip.png?branch=master)](http://travis-ci.org/thoughtbot/paperclip) [![Dependency Status](https://gemnasium.com/thoughtbot/paperclip.png?travis)](https://gemnasium.com/thoughtbot/paperclip) [![Code Climate](https://codeclimate.com/github/thoughtbot/paperclip.png)](https://codeclimate.com/github/thoughtbot/paperclip) [![Inline docs](http://inch-ci.org/github/thoughtbot/paperclip.png)](http://inch-ci.org/github/thoughtbot/paperclip) [![Security](https://hakiri.io/github/thoughtbot/paperclip/master.svg)](https://hakiri.io/github/thoughtbot/paperclip/master)
5
5
 
6
6
  Paperclip is intended as an easy file attachment library for Active Record. The
7
7
  intent behind it was to keep setup as easy as possible and to treat files as
@@ -20,6 +20,7 @@ more detailed options.
20
20
 
21
21
  The complete [RDoc](http://rdoc.info/gems/paperclip) is online.
22
22
 
23
+ ---
23
24
 
24
25
  Requirements
25
26
  ------------
@@ -55,12 +56,46 @@ GhostScript to be installed. On Mac OS X, you can also install that using Homebr
55
56
 
56
57
  brew install gs
57
58
 
58
- ### `file` command
59
+ ### `file`
59
60
 
60
61
  The Unix [`file` command](http://en.wikipedia.org/wiki/File_(command)) is required for content type checking.
61
62
  This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
62
63
  so Windows users must make sure that the devkit is installed and added to system `PATH`.
63
64
 
65
+ **Manual Installation**
66
+
67
+ If you're using Windows 7+ as a development environment, you may need to install the `file.exe` application manually. The `file spoofing` system in Paperclip 4+ relies on this; if you don't have it working, you'll receive `Validation failed: Upload file has an extension that does not match its contents.` errors.
68
+
69
+ To manually install, you should perform the following:
70
+
71
+ > **Download & install `file` from [this URL](http://gnuwin32.sourceforge.net/packages/file.htm)**
72
+
73
+ To test, you can use the following:
74
+ ![untitled](https://cloud.githubusercontent.com/assets/1104431/4524452/a1f8cce4-4d44-11e4-872e-17adb96f79c9.png)
75
+
76
+ Next, you need to integrate with your environment - preferrably through the `PATH` variable, or by changing your `config/environments/development.rb` file
77
+
78
+ **PATH**
79
+
80
+ 1. Click "Start"
81
+ 2. On "Computer", right-click and select "Properties"
82
+ 3. In properties, select "Advanced System Settings"
83
+ 4. Click the "Environment Variables" button
84
+ 5. Locate the "PATH" var - at the end, add the path to your newly installed `file.exe` (typically `C:\Program Files (x86)\GnuWin32\bin`)
85
+ 6. Restart any CMD shells you have open & see if it works
86
+
87
+ OR
88
+
89
+ **Environment**
90
+
91
+ 1. Open `config/environments/development.rb`
92
+ 2. Add the following line: `Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin'`
93
+ 3. Restart your Rails server
94
+
95
+ Either of these methods will give your Rails setup access to the `file.exe` functionality, this providing the ability to check the contents of a file (fixing the spoofing problem)
96
+
97
+ ---
98
+
64
99
  Installation
65
100
  ------------
66
101
 
@@ -69,7 +104,7 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
69
104
  Include the gem in your Gemfile:
70
105
 
71
106
  ```ruby
72
- gem "paperclip", "~> 4.1"
107
+ gem "paperclip", "~> 4.2"
73
108
  ```
74
109
 
75
110
  If you're still using Rails 2.3.x, you should do this instead:
@@ -98,6 +133,8 @@ class ModuleName < ActiveRecord::Base
98
133
  end
99
134
  ```
100
135
 
136
+ ---
137
+
101
138
  Quick Start
102
139
  -----------
103
140
 
@@ -189,6 +226,7 @@ Set the attribute to `nil` and save.
189
226
  @user.avatar = nil
190
227
  @user.save
191
228
  ```
229
+ ---
192
230
 
193
231
  Usage
194
232
  -----
@@ -311,6 +349,8 @@ validates_attachment :avatar,
311
349
  `Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
312
350
  inferred content_type, regardless of the actual contents of the file.
313
351
 
352
+ ---
353
+
314
354
  Security Validations
315
355
  ====================
316
356
 
@@ -347,6 +387,20 @@ being uploaded as JPEGs, but will not prevent GIFs from being uploaded with a
347
387
  .jpg extension. This validation will only add validation errors to the form. It
348
388
  will not cause Errors to be raised.
349
389
 
390
+ This can sometimes cause false validation errors in applications that use custom
391
+ file extensions. In these cases you may wish to add your custom extension to the
392
+ list of file extensions allowed for your mime type configured by the mime-types
393
+ gem:
394
+
395
+ ```ruby
396
+ # Allow ".foo" as an extension for files with the mime type "text/plain".
397
+ text_plain = MIME::Types["text/plain"].first
398
+ text_plain.extensions << "foo"
399
+ MIME::Types.index_extensions text_plain
400
+ ```
401
+
402
+ ---
403
+
350
404
  Defaults
351
405
  --------
352
406
  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.
@@ -373,6 +427,7 @@ Paperclip::Attachment.default_options[:fog_credentials] = {:provider => "Local",
373
427
  Paperclip::Attachment.default_options[:fog_directory] = ""
374
428
  Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"
375
429
  ```
430
+ ---
376
431
 
377
432
  Migrations
378
433
  ----------
@@ -433,6 +488,8 @@ end
433
488
  Vintage syntax (such as `t.has_attached_file` and `drop_attached_file`) are still supported in
434
489
  Paperclip 3.x, but you're advised to update those migration files to use this new syntax.
435
490
 
491
+ ---
492
+
436
493
  Storage
437
494
  -------
438
495
 
@@ -481,6 +538,8 @@ both the `:path` and `:url` options in order to make sure the files are unavaila
481
538
  to the public. Both `:path` and `:url` allow the same set of interpolated
482
539
  variables.
483
540
 
541
+ ---
542
+
484
543
  Post Processing
485
544
  ---------------
486
545
 
@@ -489,9 +548,10 @@ a set of styles for an attachment, by default it is expected that those
489
548
  "styles" are actually "thumbnails". However, you can do much more than just
490
549
  thumbnail images. By defining a subclass of Paperclip::Processor, you can
491
550
  perform any processing you want on the files that are attached. Any file in
492
- your Rails app's lib/paperclip\_processors directory is automatically loaded by
493
- paperclip, allowing you to easily define custom processors. You can specify a
494
- processor with the :processors option to `has_attached_file`:
551
+ your Rails app's `lib/paperclip` and `lib/paperclip_processors` directories is
552
+ automatically loaded by paperclip, allowing you to easily define custom
553
+ processors. You can specify a processor with the :processors option to
554
+ `has_attached_file`:
495
555
 
496
556
  ```ruby
497
557
  has_attached_file :scan, :styles => { :text => { :quality => :better } },
@@ -539,6 +599,8 @@ database, take a look at the [paperclip-meta](https://github.com/teeparham/paper
539
599
  Also, if you're interested in generating the thumbnail on-the-fly, you might want
540
600
  to look into the [attachment_on_the_fly](https://github.com/drpentode/Attachment-on-the-Fly) gem.
541
601
 
602
+ ---
603
+
542
604
  Events
543
605
  ------
544
606
 
@@ -569,6 +631,8 @@ class Message < ActiveRecord::Base
569
631
  end
570
632
  ```
571
633
 
634
+ ---
635
+
572
636
  URI Obfuscation
573
637
  ---------------
574
638
 
@@ -624,6 +688,8 @@ has_attached_file :some_attachment, {
624
688
 
625
689
  This will prevent ```some_attachment``` from being wiped out when the model gets destroyed, so it will still exist when the object is restored later.
626
690
 
691
+ ---
692
+
627
693
  Custom Attachment Processors
628
694
  -------
629
695
 
@@ -641,6 +707,7 @@ implementation pattern of the thumbnail processor would be a way to implement a
641
707
  watermark processor. All kinds of attachment processors can be created;
642
708
  a few utility examples would be compression and encryption processors.
643
709
 
710
+ ---
644
711
 
645
712
  Dynamic Configuration
646
713
  ---------------------
@@ -681,10 +748,12 @@ processors, where a defined `watermark` processor is invoked after the
681
748
  ```ruby
682
749
  class User < ActiveRecord::Base
683
750
  has_attached_file :avatar, :processors => lambda { |instance| instance.processors }
684
- attr_accessor :watermark
751
+ attr_accessor :processors
685
752
  end
686
753
  ```
687
754
 
755
+ ---
756
+
688
757
  Logging
689
758
  ----------
690
759
 
@@ -699,6 +768,8 @@ end
699
768
 
700
769
  More information in the [rdocs](http://rdoc.info/github/thoughtbot/paperclip/Paperclip.options)
701
770
 
771
+ ---
772
+
702
773
  Deployment
703
774
  ----------
704
775
 
@@ -759,6 +830,8 @@ Then in `RAILS_ROOT/public/system/paperclip_attachments.yml`:
759
830
  - :thumb
760
831
  ```
761
832
 
833
+ ---
834
+
762
835
  Testing
763
836
  -------
764
837
 
@@ -803,6 +876,7 @@ config.after(:suite) do
803
876
  FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
804
877
  end
805
878
  ```
879
+ ---
806
880
 
807
881
  Contributing
808
882
  ------------
@@ -819,6 +893,8 @@ guidelines:
819
893
 
820
894
  Please see `CONTRIBUTING.md` for more details on contributing and running test.
821
895
 
896
+ ---
897
+
822
898
  Credits
823
899
  -------
824
900
 
@@ -830,6 +906,8 @@ Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/cont
830
906
 
831
907
  The names and logos for thoughtbot are trademarks of thoughtbot, inc.
832
908
 
909
+ ---
910
+
833
911
  License
834
912
  -------
835
913
 
@@ -24,6 +24,21 @@ Feature: Rails integration
24
24
  And I should see an image with a path of "/paperclip/custom/attachments/original/5k.png"
25
25
  And the file at "/paperclip/custom/attachments/original/5k.png" should be the same as "spec/support/fixtures/5k.png"
26
26
 
27
+ Scenario: Add custom processors
28
+ Given I add a "test" processor in "lib/paperclip"
29
+ And I add a "cool" processor in "lib/paperclip_processors"
30
+ And I attach :attachment with:
31
+ """
32
+ styles: { original: {} }, processors: [:test, :cool]
33
+ """
34
+ And I start the rails application
35
+ When I go to the new user page
36
+ And I fill in "Name" with "something"
37
+ And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
38
+ And I press "Submit"
39
+ Then I should see "Name: something"
40
+ And I should see an image with a path of "/paperclip/custom/attachments/original/5k.png"
41
+
27
42
  Scenario: Filesystem integration test
28
43
  Given I attach :attachment with:
29
44
  """
@@ -196,6 +196,35 @@ Given /^I am using Rails newer than ([\d\.]+)$/ do |version|
196
196
  end
197
197
  end
198
198
 
199
+ Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
200
+ filename = "#{directory}/#{processor}.rb"
201
+ in_current_dir do
202
+ FileUtils.mkdir_p directory
203
+ File.open(filename, "w") do |f|
204
+ f.write(<<-CLASS)
205
+ module Paperclip
206
+ class #{processor.capitalize} < Processor
207
+ def make
208
+ basename = File.basename(file.path, File.extname(file.path))
209
+ dst_format = options[:format] ? ".\#{options[:format]}" : ''
210
+
211
+ dst = Tempfile.new([basename, dst_format])
212
+ dst.binmode
213
+
214
+ convert(':src :dst',
215
+ src: File.expand_path(file.path),
216
+ dst: File.expand_path(dst.path)
217
+ )
218
+
219
+ dst
220
+ end
221
+ end
222
+ end
223
+ CLASS
224
+ end
225
+ end
226
+ end
227
+
199
228
  def transform_file(filename)
200
229
  if File.exist?(filename)
201
230
  content = File.read(filename)
@@ -2,12 +2,18 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "sqlite3", "1.3.8", :platforms=>:ruby
6
- gem "jruby-openssl", :platforms=>:jruby
7
- gem "activerecord-jdbcsqlite3-adapter", :platforms=>:jruby
8
- gem "rubysl", :platforms=>:rbx
9
- gem "racc", :platforms=>:rbx
5
+ gem "sqlite3", "1.3.8", :platforms => :ruby
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
+ gem "rubysl", :platforms => :rbx
9
+ gem "racc", :platforms => :rbx
10
+ gem "pry"
10
11
  gem "rails", "~> 3.2.15"
11
- gem "paperclip", :path=>"../"
12
+ gem "paperclip", :path => "../"
12
13
 
13
- gemspec :path=>"../"
14
+ group :development, :test do
15
+ gem "mime-types", "~> 1.16"
16
+ gem "builder"
17
+ end
18
+
19
+ gemspec :path => "../"
@@ -2,12 +2,18 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "sqlite3", "1.3.8", :platforms=>:ruby
6
- gem "jruby-openssl", :platforms=>:jruby
7
- gem "activerecord-jdbcsqlite3-adapter", :platforms=>:jruby
8
- gem "rubysl", :platforms=>:rbx
9
- gem "racc", :platforms=>:rbx
5
+ gem "sqlite3", "1.3.8", :platforms => :ruby
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
+ gem "rubysl", :platforms => :rbx
9
+ gem "racc", :platforms => :rbx
10
+ gem "pry"
10
11
  gem "rails", "~> 4.0.0"
11
- gem "paperclip", :path=>"../"
12
+ gem "paperclip", :path => "../"
12
13
 
13
- gemspec :path=>"../"
14
+ group :development, :test do
15
+ gem "mime-types", "~> 1.16"
16
+ gem "builder"
17
+ end
18
+
19
+ gemspec :path => "../"
@@ -2,12 +2,18 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "sqlite3", "1.3.8", :platforms=>:ruby
6
- gem "jruby-openssl", :platforms=>:jruby
7
- gem "activerecord-jdbcsqlite3-adapter", :platforms=>:jruby
8
- gem "rubysl", :platforms=>:rbx
9
- gem "racc", :platforms=>:rbx
10
- gem "rails", "~> 4.1.0.beta"
11
- gem "paperclip", :path=>"../"
12
-
13
- gemspec :path=>"../"
5
+ gem "sqlite3", "1.3.8", :platforms => :ruby
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
+ gem "rubysl", :platforms => :rbx
9
+ gem "racc", :platforms => :rbx
10
+ gem "pry"
11
+ gem "rails", "~> 4.1.0"
12
+ gem "paperclip", :path => "../"
13
+
14
+ group :development, :test do
15
+ gem "mime-types", "~> 1.16"
16
+ gem "builder"
17
+ end
18
+
19
+ gemspec :path => "../"