paperclip 5.0.0.beta2 → 5.0.0
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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +10 -4
- data/NEWS +16 -2
- data/README.md +44 -14
- data/gemfiles/5.0.awsv2.0.gemfile +1 -1
- data/gemfiles/5.0.awsv2.1.gemfile +1 -1
- data/gemfiles/5.0.awsv2.gemfile +1 -6
- data/lib/paperclip.rb +2 -1
- data/lib/paperclip/attachment.rb +3 -2
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/helpers.rb +12 -9
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uri_adapter.rb +3 -1
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/storage/fog.rb +1 -0
- data/lib/paperclip/version.rb +3 -1
- data/lib/tasks/paperclip.rake +1 -1
- data/paperclip.gemspec +0 -1
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_spec.rb +1 -1
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +12 -0
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +27 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +12 -3
- data/spec/paperclip/storage/fog_spec.rb +7 -0
- data/spec/paperclip/storage/s3_spec.rb +3 -2
- data/spec/paperclip/validators_spec.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4787def2cfada09ed3791a17a356d403c289df8a
|
4
|
+
data.tar.gz: fa4e3a08de8f08483299905ea9ed65e9246bcf9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c34f90ee3cce719d4915eab1703bb0825584e2361230402bc705e6d5ac0e98e5cc5dc524380d5bed415c38e208604156223f3315044b76ef98b11ddd8cb1817
|
7
|
+
data.tar.gz: b1b9a56925bb9d9c35725a500f241deab6631c9b1142815dfd1d93104a99de12aa74ae68f4a415599fb3f966ce1b189577e977a1c2d24d521b5f35e592cc76ae
|
data/CONTRIBUTING.md
CHANGED
@@ -10,16 +10,22 @@ Here's a quick guide for contributing:
|
|
10
10
|
|
11
11
|
1. Fork the repo.
|
12
12
|
|
13
|
-
|
13
|
+
1. Make sure you have ImageMagick and Ghostscript installed. See [this section]
|
14
|
+
(./README.md#image-processor) of the README.
|
15
|
+
|
16
|
+
1. Run the tests. We only take pull requests with passing tests, and it's great
|
14
17
|
to know that you have a clean slate: `bundle && bundle exec rake`
|
15
18
|
|
16
|
-
|
19
|
+
1. Add a test for your change. Only refactoring and documentation changes
|
17
20
|
require no new tests. If you are adding functionality or fixing a bug, we need
|
18
21
|
a test!
|
19
22
|
|
20
|
-
|
23
|
+
1. Make the test pass.
|
24
|
+
|
25
|
+
1. Mention how your changes affect the project to other developers and users in
|
26
|
+
the `NEWS.md` file.
|
21
27
|
|
22
|
-
|
28
|
+
1. Push to your fork and submit a pull request.
|
23
29
|
|
24
30
|
At this point you're waiting on us. We like to at least comment on, if not
|
25
31
|
accept, pull requests within seven business days (most of the work on Paperclip
|
data/NEWS
CHANGED
@@ -1,12 +1,26 @@
|
|
1
|
-
|
1
|
+
master:
|
2
|
+
|
3
|
+
5.0.0 (2016-07-01):
|
4
|
+
|
5
|
+
* Improvement: Add `read_timeout` configuration for URI Adapter download_content method.
|
6
|
+
* README adjustments for Ruby beginners (add links, elucidate model in Quick Start)
|
7
|
+
* Bugfix: Now it's possible to save images from URLs with special characters [#1932]
|
8
|
+
* Bugfix: Return false when file to copy is not present in cloud storage [#2173]
|
9
|
+
* Automatically close file while checking mime type [#2016]
|
10
|
+
* Add `read_timeout` option to `UriAdapter#download_content` method [#2232]
|
11
|
+
* Fix a nil error in content type validation matcher [#1910]
|
12
|
+
* Documentation improvements
|
13
|
+
|
14
|
+
5.0.0.beta2 (2016-04-01):
|
2
15
|
|
3
16
|
* Bugfix: Dynamic fog directory option is now respected
|
4
17
|
* Bugfix: Fixes cocaine duplicated paths [#2169]
|
5
18
|
* Removal of dead code (older versions of Rails and AWS SDK)
|
6
19
|
* README adjustments
|
7
20
|
|
8
|
-
5.0.0.beta1 (
|
21
|
+
5.0.0.beta1 (2016-03-13):
|
9
22
|
|
23
|
+
* Bug Fix: megabytes of mime-types info in logs when a spoofed media type is detected.
|
10
24
|
* Drop support to end-of-life'd ruby 2.0.
|
11
25
|
* Drop support for end-of-life'd Rails 3.2 and 4.1
|
12
26
|
* Drop support for AWS v1
|
data/README.md
CHANGED
@@ -14,6 +14,10 @@ https://github.com/thoughtbot/paperclip/releases
|
|
14
14
|
[![Inline docs](http://inch-ci.org/github/thoughtbot/paperclip.svg)](http://inch-ci.org/github/thoughtbot/paperclip)
|
15
15
|
[![Security](https://hakiri.io/github/thoughtbot/paperclip/master.svg)](https://hakiri.io/github/thoughtbot/paperclip/master)
|
16
16
|
|
17
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
18
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
19
|
+
|
20
|
+
|
17
21
|
- [Requirements](#requirements)
|
18
22
|
- [Ruby and Rails](#ruby-and-rails)
|
19
23
|
- [Image Processor](#image-processor)
|
@@ -25,7 +29,7 @@ https://github.com/thoughtbot/paperclip/releases
|
|
25
29
|
- [Edit and New Views](#edit-and-new-views)
|
26
30
|
- [Edit and New Views with Simple Form](#edit-and-new-views-with-simple-form)
|
27
31
|
- [Controller](#controller)
|
28
|
-
- [
|
32
|
+
- [View Helpers](#view-helpers)
|
29
33
|
- [Deleting an Attachment](#deleting-an-attachment)
|
30
34
|
- [Usage](#usage)
|
31
35
|
- [Validations](#validations)
|
@@ -45,15 +49,18 @@ https://github.com/thoughtbot/paperclip/releases
|
|
45
49
|
- [File Preservation for Soft-Delete](#file-preservation-for-soft-delete)
|
46
50
|
- [Custom Attachment Processors](#custom-attachment-processors)
|
47
51
|
- [Dynamic Configuration](#dynamic-configuration)
|
48
|
-
- [Dynamic Styles](#dynamic-styles)
|
49
|
-
- [Dynamic Processors](#dynamic-processors)
|
52
|
+
- [Dynamic Styles:](#dynamic-styles)
|
53
|
+
- [Dynamic Processors:](#dynamic-processors)
|
50
54
|
- [Logging](#logging)
|
51
55
|
- [Deployment](#deployment)
|
56
|
+
- [Attachment Styles](#attachment-styles)
|
52
57
|
- [Testing](#testing)
|
53
58
|
- [Contributing](#contributing)
|
54
59
|
- [License](#license)
|
55
60
|
- [About thoughtbot](#about-thoughtbot)
|
56
61
|
|
62
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
63
|
+
|
57
64
|
Paperclip is intended as an easy file attachment library for ActiveRecord. The
|
58
65
|
intent behind it was to keep setup as easy as possible and to treat files as
|
59
66
|
much like other attributes as possible. This means they aren't saved to their
|
@@ -97,7 +104,7 @@ In development mode, you might add this line to `config/environments/development
|
|
97
104
|
Paperclip.options[:command_path] = "/usr/local/bin/"
|
98
105
|
```
|
99
106
|
|
100
|
-
If you're on Mac OS X, you'll want to run the following with Homebrew:
|
107
|
+
If you're on Mac OS X, you'll want to run the following with [Homebrew] (http://www.brew.sh):
|
101
108
|
|
102
109
|
brew install imagemagick
|
103
110
|
|
@@ -159,7 +166,7 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
|
|
159
166
|
Include the gem in your Gemfile:
|
160
167
|
|
161
168
|
```ruby
|
162
|
-
gem "paperclip", "~> 5.0.0
|
169
|
+
gem "paperclip", "~> 5.0.0"
|
163
170
|
```
|
164
171
|
|
165
172
|
Or, if you want to get the latest, you can get master from the main paperclip repository:
|
@@ -220,7 +227,8 @@ end
|
|
220
227
|
<% end %>
|
221
228
|
```
|
222
229
|
|
223
|
-
### Edit and New Views with Simple Form
|
230
|
+
### Edit and New Views with [Simple Form](https://github.com/plataformatec/simple_form)
|
231
|
+
|
224
232
|
```erb
|
225
233
|
<%= simple_form_for @user, url: users_path do |form| %>
|
226
234
|
<%= form.input :avatar, as: :file %>
|
@@ -244,7 +252,7 @@ def user_params
|
|
244
252
|
end
|
245
253
|
```
|
246
254
|
|
247
|
-
###
|
255
|
+
### View Helpers
|
248
256
|
|
249
257
|
```erb
|
250
258
|
<%= image_tag @user.avatar.url %>
|
@@ -559,8 +567,8 @@ The files that are assigned as attachments are, by default, placed in the
|
|
559
567
|
directory specified by the `:path` option to `has_attached_file`. By default, this
|
560
568
|
location is `:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename`.
|
561
569
|
This location was chosen because, on standard Capistrano deployments, the
|
562
|
-
`public/system` directory
|
563
|
-
|
570
|
+
`public/system` directory can be symlinked to the app's shared directory, meaning it
|
571
|
+
survives between deployments. For example, using that `:path`, you may have a
|
564
572
|
file at
|
565
573
|
|
566
574
|
/data/myapp/releases/20081229172410/public/system/users/avatar/000/000/013/small/my_pic.png
|
@@ -608,7 +616,8 @@ has_attached_file :scan, styles: { text: { quality: :better } },
|
|
608
616
|
|
609
617
|
This would load the hypothetical class Paperclip::Ocr, which would have the
|
610
618
|
hash "{ quality: :better }" passed to it along with the uploaded file. For
|
611
|
-
more information about defining processors, see
|
619
|
+
more information about defining processors, see
|
620
|
+
[Paperclip::Processor](https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/processor.rb).
|
612
621
|
|
613
622
|
The default processor is Paperclip::Thumbnail. For backward compatibility
|
614
623
|
reasons, you can pass a single geometry string or an array containing a
|
@@ -821,6 +830,16 @@ More information in the [rdocs](http://www.rubydoc.info/github/thoughtbot/paperc
|
|
821
830
|
Deployment
|
822
831
|
----------
|
823
832
|
|
833
|
+
To make Capistrano symlink the `public/system` directory so that attachments
|
834
|
+
survive new deployments, set the `linked_dirs` option in your `config/deploy.rb`
|
835
|
+
file:
|
836
|
+
|
837
|
+
```ruby
|
838
|
+
set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
|
839
|
+
```
|
840
|
+
|
841
|
+
### Attachment Styles
|
842
|
+
|
824
843
|
Paperclip is aware of new attachment styles you have added in previous deploys. The only thing you should do after each deployment is to call
|
825
844
|
`rake paperclip:refresh:missing_styles`. It will store current attachment styles in `RAILS_ROOT/public/system/paperclip_attachments.yml`
|
826
845
|
by default. You can change it by:
|
@@ -832,9 +851,9 @@ Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachment
|
|
832
851
|
Here is an example for Capistrano:
|
833
852
|
|
834
853
|
```ruby
|
835
|
-
namespace :
|
854
|
+
namespace :paperclip do
|
836
855
|
desc "build missing paperclip styles"
|
837
|
-
task :
|
856
|
+
task :build_missing_styles do
|
838
857
|
on roles(:app) do
|
839
858
|
within release_path do
|
840
859
|
with rails_env: fetch(:rails_env) do
|
@@ -845,7 +864,7 @@ namespace :deploy do
|
|
845
864
|
end
|
846
865
|
end
|
847
866
|
|
848
|
-
after("deploy:compile_assets", "
|
867
|
+
after("deploy:compile_assets", "paperclip:build_missing_styles")
|
849
868
|
```
|
850
869
|
|
851
870
|
Now you don't have to remember to refresh thumbnails in production every time you add a new style.
|
@@ -928,6 +947,17 @@ config.after(:suite) do
|
|
928
947
|
FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
|
929
948
|
end
|
930
949
|
```
|
950
|
+
|
951
|
+
**Example of test configuration with Factory Girl**
|
952
|
+
|
953
|
+
|
954
|
+
```ruby
|
955
|
+
FactoryGirl.define do
|
956
|
+
factory :user do
|
957
|
+
avatar { File.new("#{Rails.root}/spec/support/fixtures/image.jpg") }
|
958
|
+
end
|
959
|
+
end
|
960
|
+
```
|
931
961
|
---
|
932
962
|
|
933
963
|
Contributing
|
@@ -943,7 +973,7 @@ guidelines:
|
|
943
973
|
about writing tests for paperclip, please open a
|
944
974
|
[GitHub issue](https://github.com/thoughtbot/paperclip/issues/new).
|
945
975
|
|
946
|
-
Please see `CONTRIBUTING.md` for more details on contributing and running test.
|
976
|
+
Please see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for more details on contributing and running test.
|
947
977
|
|
948
978
|
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/graphs/contributors)!
|
949
979
|
|
data/gemfiles/5.0.awsv2.gemfile
CHANGED
@@ -8,12 +8,7 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
8
8
|
gem "rubysl", :platforms => :rbx
|
9
9
|
gem "racc", :platforms => :rbx
|
10
10
|
gem "pry"
|
11
|
-
gem "rails",
|
12
|
-
gem "sprockets-rails", :github => "rails/sprockets-rails"
|
13
|
-
gem "sprockets", :github => "rails/sprockets"
|
14
|
-
gem "sass-rails", :github => "rails/sass-rails"
|
15
|
-
gem "arel", :github => "rails/arel"
|
16
|
-
gem "rack", :github => "rack/rack"
|
11
|
+
gem "rails", "~> 5.0.0"
|
17
12
|
gem "aws-sdk", "~> 2.0"
|
18
13
|
|
19
14
|
group :development, :test do
|
data/lib/paperclip.rb
CHANGED
data/lib/paperclip/attachment.rb
CHANGED
@@ -50,7 +50,8 @@ module Paperclip
|
|
50
50
|
# +url+ - a relative URL of the attachment. This is interpolated using +interpolator+
|
51
51
|
# +path+ - where on the filesystem to store the attachment. This is interpolated using +interpolator+
|
52
52
|
# +styles+ - a hash of options for processing the attachment. See +has_attached_file+ for the details
|
53
|
-
# +only_process+ - style args to be run through the post-processor. This defaults to the empty list
|
53
|
+
# +only_process+ - style args to be run through the post-processor. This defaults to the empty list (which is
|
54
|
+
# a special case that indicates all styles should be processed)
|
54
55
|
# +default_url+ - a URL for the missing image
|
55
56
|
# +default_style+ - the style to use when an argument is not specified e.g. #url, #path
|
56
57
|
# +storage+ - the storage mechanism. Defaults to :filesystem
|
@@ -348,7 +349,7 @@ module Paperclip
|
|
348
349
|
|
349
350
|
# Returns true if a file has been assigned.
|
350
351
|
def file?
|
351
|
-
|
352
|
+
original_filename.present?
|
352
353
|
end
|
353
354
|
|
354
355
|
alias :present? :file?
|
@@ -67,8 +67,9 @@ module Paperclip
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def type_from_mime_magic
|
70
|
-
@type_from_mime_magic ||=
|
71
|
-
MimeMagic.by_magic(
|
70
|
+
@type_from_mime_magic ||= File.open(@filepath) do |file|
|
71
|
+
MimeMagic.by_magic(file).try(:type)
|
72
|
+
end
|
72
73
|
end
|
73
74
|
|
74
75
|
def type_from_file_command
|
data/lib/paperclip/errors.rb
CHANGED
@@ -19,7 +19,9 @@ module Paperclip
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Will be thrown when ImageMagic cannot determine the uploaded file's
|
22
|
-
# metadata, usually this would mean the file is not an image.
|
22
|
+
# metadata, usually this would mean the file is not an image. If you are
|
23
|
+
# consistently receiving this error on PDFs make sure that you have
|
24
|
+
# installed Ghostscript.
|
23
25
|
class NotIdentifiedByImageMagickError < Paperclip::Error
|
24
26
|
end
|
25
27
|
|
data/lib/paperclip/helpers.rb
CHANGED
@@ -8,19 +8,22 @@ module Paperclip
|
|
8
8
|
Paperclip::Interpolations[key] = block
|
9
9
|
end
|
10
10
|
|
11
|
-
# The run method takes the name of a binary to run, the arguments
|
12
|
-
# and some options
|
11
|
+
# The run method takes the name of a binary to run, the arguments
|
12
|
+
# to that binary, the values to interpolate and some local options.
|
13
13
|
#
|
14
|
-
#
|
15
|
-
# on the filesystem. Colon-separated, just like $PATH.
|
14
|
+
# :cmd -> The name of a binary to run.
|
16
15
|
#
|
17
|
-
#
|
18
|
-
# of the binary. Defaults to [0].
|
16
|
+
# :arguments -> The command line arguments to that binary.
|
19
17
|
#
|
20
|
-
#
|
21
|
-
# This will only log if logging in general is set to true as well.
|
18
|
+
# :interpolation_values -> Values to be interpolated into the arguments.
|
22
19
|
#
|
23
|
-
#
|
20
|
+
# :local_options -> The options to be used by Cocain::CommandLine.
|
21
|
+
# These could be: runner
|
22
|
+
# logger
|
23
|
+
# swallow_stderr
|
24
|
+
# expected_outcodes
|
25
|
+
# environment
|
26
|
+
# runner_options
|
24
27
|
#
|
25
28
|
def run(cmd, arguments = "", interpolation_values = {}, local_options = {})
|
26
29
|
command_path = options[:command_path]
|
@@ -40,9 +40,9 @@ module Paperclip
|
|
40
40
|
|
41
41
|
def failure_message
|
42
42
|
"#{expected_attachment}\n".tap do |message|
|
43
|
-
message << accepted_types_and_failures
|
43
|
+
message << accepted_types_and_failures.to_s
|
44
44
|
message << "\n\n" if @allowed_types.present? && @rejected_types.present?
|
45
|
-
message << rejected_types_and_failures
|
45
|
+
message << rejected_types_and_failures.to_s
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -55,7 +55,7 @@ module Paperclip
|
|
55
55
|
def accepted_types_and_failures
|
56
56
|
if @allowed_types.present?
|
57
57
|
"Accept content types: #{@allowed_types.join(", ")}\n".tap do |message|
|
58
|
-
if @missing_allowed_types.
|
58
|
+
if @missing_allowed_types.present?
|
59
59
|
message << " #{@missing_allowed_types.join(", ")} were rejected."
|
60
60
|
else
|
61
61
|
message << " All were accepted successfully."
|
@@ -66,7 +66,7 @@ module Paperclip
|
|
66
66
|
def rejected_types_and_failures
|
67
67
|
if @rejected_types.present?
|
68
68
|
"Reject content types: #{@rejected_types.join(", ")}\n".tap do |message|
|
69
|
-
if @missing_rejected_types.
|
69
|
+
if @missing_rejected_types.present?
|
70
70
|
message << " #{@missing_rejected_types.join(", ")} were accepted."
|
71
71
|
else
|
72
72
|
message << " All were rejected successfully."
|
@@ -170,6 +170,7 @@ module Paperclip
|
|
170
170
|
log("copying #{path(style)} to local file #{local_dest_path}")
|
171
171
|
::File.open(local_dest_path, 'wb') do |local_file|
|
172
172
|
file = directory.files.get(path(style))
|
173
|
+
return false unless file
|
173
174
|
local_file.write(file.body)
|
174
175
|
end
|
175
176
|
rescue ::Fog::Errors::Error => e
|
data/lib/paperclip/version.rb
CHANGED
data/lib/tasks/paperclip.rake
CHANGED
@@ -18,7 +18,7 @@ module Paperclip
|
|
18
18
|
raise "Class #{klass.name} has no attachments specified"
|
19
19
|
end
|
20
20
|
|
21
|
-
if
|
21
|
+
if name.present? && attachment_names.map(&:to_s).include?(name.to_s)
|
22
22
|
[ name ]
|
23
23
|
else
|
24
24
|
attachment_names
|
data/paperclip.gemspec
CHANGED
@@ -40,7 +40,6 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.add_development_dependency('cucumber', '~> 1.3.18')
|
41
41
|
s.add_development_dependency('aruba', '~> 0.9.0')
|
42
42
|
s.add_development_dependency('nokogiri')
|
43
|
-
# Ruby version < 1.9.3 can't install capybara > 2.0.3.
|
44
43
|
s.add_development_dependency('capybara')
|
45
44
|
s.add_development_dependency('bundler')
|
46
45
|
s.add_development_dependency('fog-aws')
|
@@ -2,11 +2,9 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'Attachment Processing' do
|
5
|
-
|
6
|
-
before do
|
7
|
-
rebuild_class
|
8
|
-
end
|
5
|
+
before { rebuild_class }
|
9
6
|
|
7
|
+
context 'using validates_attachment_content_type' do
|
10
8
|
it 'processes attachments given a valid assignment' do
|
11
9
|
file = File.new(fixture_file("5k.png"))
|
12
10
|
Dummy.validates_attachment_content_type :avatar, content_type: "image/png"
|
@@ -1121,7 +1121,7 @@ describe Paperclip::Attachment do
|
|
1121
1121
|
context "with a file assigned but not saved yet" do
|
1122
1122
|
it "clears out any attached files" do
|
1123
1123
|
@attachment.assign(@file)
|
1124
|
-
assert
|
1124
|
+
assert @attachment.queued_for_write.present?
|
1125
1125
|
@attachment.clear
|
1126
1126
|
assert @attachment.queued_for_write.blank?
|
1127
1127
|
end
|
@@ -98,4 +98,16 @@ describe Paperclip::HttpUrlProxyAdapter do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
context "a url with special characters in the filename" do
|
102
|
+
it "returns a encoded filename" do
|
103
|
+
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).
|
104
|
+
returns(StringIO.new("x"))
|
105
|
+
url = "https://github.com/thoughtbot/paperclip-öäü字´½♥زÈ.png"
|
106
|
+
subject = Paperclip.io_adapters.for(url)
|
107
|
+
filename = "paperclip-%C3%B6%C3%A4%C3%BC%E5%AD%97%C2%B4%C2%BD%E2%99%A5"\
|
108
|
+
"%C3%98%C2%B2%C3%88.png"
|
109
|
+
|
110
|
+
assert_equal filename, subject.original_filename
|
111
|
+
end
|
112
|
+
end
|
101
113
|
end
|
@@ -99,4 +99,31 @@ describe Paperclip::UriAdapter do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
describe "#download_content" do
|
103
|
+
before do
|
104
|
+
Paperclip::UriAdapter.any_instance.stubs(:open).returns(StringIO.new("xxx"))
|
105
|
+
@uri = URI.parse("https://github.com/thoughtbot/paper:clip.jpg")
|
106
|
+
@subject = Paperclip.io_adapters.for(@uri)
|
107
|
+
end
|
108
|
+
|
109
|
+
after do
|
110
|
+
@subject.send(:download_content)
|
111
|
+
end
|
112
|
+
|
113
|
+
context "with default read_timeout" do
|
114
|
+
it "calls open without options" do
|
115
|
+
@subject.expects(:open).with(@uri, {}).at_least_once
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with custom read_timeout" do
|
120
|
+
before do
|
121
|
+
Paperclip.options[:read_timeout] = 120
|
122
|
+
end
|
123
|
+
|
124
|
+
it "calls open with read_timeout option" do
|
125
|
+
@subject.expects(:open).with(@uri, read_timeout: 120).at_least_once
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
102
129
|
end
|
@@ -17,22 +17,26 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
17
17
|
|
18
18
|
it "rejects a class with no validation" do
|
19
19
|
expect(matcher).to_not accept(Dummy)
|
20
|
+
expect { matcher.failure_message }.to_not raise_error
|
20
21
|
end
|
21
22
|
|
22
23
|
it 'rejects a class when the validation fails' do
|
23
24
|
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
|
24
25
|
expect(matcher).to_not accept(Dummy)
|
26
|
+
expect { matcher.failure_message }.to_not raise_error
|
25
27
|
end
|
26
28
|
|
27
29
|
it "accepts a class with a matching validation" do
|
28
30
|
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
|
29
31
|
expect(matcher).to accept(Dummy)
|
32
|
+
expect { matcher.failure_message }.to_not raise_error
|
30
33
|
end
|
31
34
|
|
32
35
|
it "accepts a class with other validations but matching types" do
|
33
36
|
Dummy.validates_presence_of :title
|
34
37
|
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
|
35
38
|
expect(matcher).to accept(Dummy)
|
39
|
+
expect { matcher.failure_message }.to_not raise_error
|
36
40
|
end
|
37
41
|
|
38
42
|
it "accepts a class that matches and a matcher that only specifies 'allowing'" do
|
@@ -40,6 +44,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
40
44
|
matcher = plain_matcher.allowing(%w(image/png image/jpeg))
|
41
45
|
|
42
46
|
expect(matcher).to accept(Dummy)
|
47
|
+
expect { matcher.failure_message }.to_not raise_error
|
43
48
|
end
|
44
49
|
|
45
50
|
it "rejects a class that does not match and a matcher that only specifies 'allowing'" do
|
@@ -47,6 +52,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
47
52
|
matcher = plain_matcher.allowing(%w(image/png image/jpeg))
|
48
53
|
|
49
54
|
expect(matcher).to_not accept(Dummy)
|
55
|
+
expect { matcher.failure_message }.to_not raise_error
|
50
56
|
end
|
51
57
|
|
52
58
|
it "accepts a class that matches and a matcher that only specifies 'rejecting'" do
|
@@ -54,6 +60,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
54
60
|
matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))
|
55
61
|
|
56
62
|
expect(matcher).to accept(Dummy)
|
63
|
+
expect { matcher.failure_message }.to_not raise_error
|
57
64
|
end
|
58
65
|
|
59
66
|
it "rejects a class that does not match and a matcher that only specifies 'rejecting'" do
|
@@ -61,6 +68,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
61
68
|
matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))
|
62
69
|
|
63
70
|
expect(matcher).to_not accept(Dummy)
|
71
|
+
expect { matcher.failure_message }.to_not raise_error
|
64
72
|
end
|
65
73
|
|
66
74
|
context "using an :if to control the validation" do
|
@@ -75,12 +83,14 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
75
83
|
dummy = Dummy.new
|
76
84
|
dummy.go = true
|
77
85
|
expect(matcher).to accept(dummy)
|
86
|
+
expect { matcher.failure_message }.to_not raise_error
|
78
87
|
end
|
79
88
|
|
80
89
|
it "does not run the validation if the control is false" do
|
81
90
|
dummy = Dummy.new
|
82
91
|
dummy.go = false
|
83
92
|
expect(matcher).to_not accept(dummy)
|
93
|
+
expect { matcher.failure_message }.to_not raise_error
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|
@@ -44,9 +44,18 @@ describe Paperclip::MediaTypeSpoofDetector do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
file
|
49
|
-
|
47
|
+
context "file named .html and is as HTML, but we're told JPG" do
|
48
|
+
let(:file) { File.open(fixture_file("empty.html")) }
|
49
|
+
let(:spoofed?) { Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "image/jpg").spoofed? }
|
50
|
+
|
51
|
+
it "rejects the file" do
|
52
|
+
assert spoofed?
|
53
|
+
end
|
54
|
+
|
55
|
+
it "logs info about the detected spoof" do
|
56
|
+
Paperclip.expects(:log).with('Content Type Spoof: Filename empty.html (image/jpg from Headers, ["text/html"] from Extension), content type discovered from file command: text/html. See documentation to allow this combination.')
|
57
|
+
spoofed?
|
58
|
+
end
|
50
59
|
end
|
51
60
|
|
52
61
|
it "does not reject if content_type is empty but otherwise checks out" do
|
@@ -183,6 +183,13 @@ describe Paperclip::Storage::Fog do
|
|
183
183
|
tempfile.close
|
184
184
|
end
|
185
185
|
|
186
|
+
it 'is able to be handled when missing while copying to a local file' do
|
187
|
+
tempfile = Tempfile.new("known_location")
|
188
|
+
tempfile.binmode
|
189
|
+
assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path)
|
190
|
+
tempfile.close
|
191
|
+
end
|
192
|
+
|
186
193
|
it "passes the content type to the Fog::Storage::AWS::Files instance" do
|
187
194
|
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
|
188
195
|
hash[:content_type]
|
@@ -672,7 +672,9 @@ describe Paperclip::Storage::S3 do
|
|
672
672
|
s3_host_name: "s3-world-end.amazonaws.com" },
|
673
673
|
development: {
|
674
674
|
s3_region: "ap-northeast-1",
|
675
|
-
s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
|
675
|
+
s3_host_name: "s3-ap-northeast-1.amazonaws.com" },
|
676
|
+
test: {
|
677
|
+
s3_region: "" }
|
676
678
|
}
|
677
679
|
@dummy = Dummy.new
|
678
680
|
end
|
@@ -1578,5 +1580,4 @@ describe Paperclip::Storage::S3 do
|
|
1578
1580
|
Rails.env = stored_env
|
1579
1581
|
end
|
1580
1582
|
end
|
1581
|
-
|
1582
1583
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.0
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Yurek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -606,9 +606,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
606
606
|
version: 2.1.0
|
607
607
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
608
608
|
requirements:
|
609
|
-
- - "
|
609
|
+
- - ">="
|
610
610
|
- !ruby/object:Gem::Version
|
611
|
-
version:
|
611
|
+
version: '0'
|
612
612
|
requirements:
|
613
613
|
- ImageMagick
|
614
614
|
rubyforge_project:
|