paperclip 4.3.7 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +3 -0
- data/.hound.yml +5 -16
- data/.travis.yml +15 -12
- data/Appraisals +4 -8
- data/CONTRIBUTING.md +16 -5
- data/Gemfile +3 -8
- data/LICENSE +1 -1
- data/MIGRATING-ES.md +317 -0
- data/MIGRATING.md +375 -0
- data/NEWS +126 -31
- data/README.md +264 -156
- data/Rakefile +1 -1
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +3 -2
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +14 -14
- data/features/step_definitions/rails_steps.rb +29 -28
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/support/env.rb +1 -0
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/4.2.gemfile +3 -5
- data/gemfiles/{3.2.gemfile → 5.0.gemfile} +4 -6
- data/lib/generators/paperclip/paperclip_generator.rb +9 -1
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +14 -12
- data/lib/paperclip/attachment.rb +44 -20
- data/lib/paperclip/attachment_registry.rb +2 -1
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/file_command_content_type_detector.rb +1 -1
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry_detector_factory.rb +3 -3
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +7 -1
- data/lib/paperclip/helpers.rb +15 -11
- data/lib/paperclip/interpolations.rb +7 -2
- data/lib/paperclip/io_adapters/abstract_adapter.rb +31 -4
- data/lib/paperclip/io_adapters/attachment_adapter.rb +17 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
- data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +8 -7
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
- data/lib/paperclip/io_adapters/uri_adapter.rb +22 -17
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +11 -7
- data/lib/paperclip/processor.rb +15 -6
- data/lib/paperclip/schema.rb +3 -9
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +21 -14
- data/lib/paperclip/storage/s3.rb +81 -61
- data/lib/paperclip/style.rb +0 -1
- data/lib/paperclip/thumbnail.rb +22 -9
- data/lib/paperclip/url_generator.rb +17 -13
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +4 -0
- data/lib/paperclip/version.rb +3 -1
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +13 -10
- data/spec/paperclip/attachment_processing_spec.rb +2 -5
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +89 -20
- data/spec/paperclip/content_type_detector_spec.rb +1 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +15 -1
- data/spec/paperclip/filename_cleaner_spec.rb +0 -1
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +42 -5
- data/spec/paperclip/interpolations_spec.rb +9 -0
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +104 -22
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +47 -13
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +104 -11
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +1 -1
- data/spec/paperclip/media_type_spoof_detector_spec.rb +41 -0
- data/spec/paperclip/paperclip_spec.rb +15 -45
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/schema_spec.rb +46 -46
- data/spec/paperclip/storage/fog_spec.rb +31 -0
- data/spec/paperclip/storage/s3_live_spec.rb +20 -14
- data/spec/paperclip/storage/s3_spec.rb +359 -192
- data/spec/paperclip/style_spec.rb +0 -1
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +43 -38
- data/spec/paperclip/url_generator_spec.rb +54 -44
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +5 -5
- data/spec/spec_helper.rb +5 -2
- data/spec/support/assertions.rb +12 -1
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +11 -3
- data/spec/support/reporting.rb +11 -0
- metadata +64 -61
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/4.1.gemfile +0 -19
- data/lib/paperclip/deprecations.rb +0 -42
- data/lib/paperclip/locales/de.yml +0 -18
- data/lib/paperclip/locales/es.yml +0 -18
- data/lib/paperclip/locales/ja.yml +0 -18
- data/lib/paperclip/locales/pt-BR.yml +0 -18
- data/lib/paperclip/locales/zh-CN.yml +0 -18
- data/lib/paperclip/locales/zh-HK.yml +0 -18
- data/lib/paperclip/locales/zh-TW.yml +0 -18
- data/spec/paperclip/deprecations_spec.rb +0 -65
- data/spec/support/deprecations.rb +0 -9
- data/spec/support/rails_helpers.rb +0 -7
data/README.md
CHANGED
@@ -1,12 +1,48 @@
|
|
1
1
|
Paperclip
|
2
2
|
=========
|
3
3
|
|
4
|
-
|
4
|
+
# Deprecated
|
5
|
+
|
6
|
+
**[Paperclip is deprecated]**.
|
7
|
+
|
8
|
+
For new projects, we recommend Rails' own [ActiveStorage].
|
9
|
+
|
10
|
+
For existing projects, please consult and contribute to [the migration guide] ([en español]).
|
11
|
+
|
12
|
+
|
13
|
+
We will leave the Issues open as a discussion forum _only_. We do _not_
|
14
|
+
guarantee a response from us in the Issues.
|
15
|
+
|
16
|
+
We are no longer accepting pull requests _except_ pull requests against the
|
17
|
+
migration guide. All other pull requests will be closed without merging.
|
18
|
+
|
19
|
+
[Paperclip is deprecated]: https://robots.thoughtbot.com/closing-the-trombone
|
20
|
+
[ActiveStorage]: http://guides.rubyonrails.org/active_storage_overview.html
|
21
|
+
[the migration guide]: https://github.com/thoughtbot/paperclip/blob/master/MIGRATING.md
|
22
|
+
[en español]: https://github.com/thoughtbot/paperclip/blob/master/MIGRATING-ES.md
|
23
|
+
|
24
|
+
# Existing documentation
|
25
|
+
|
26
|
+
## Documentation valid for `master` branch
|
27
|
+
|
28
|
+
Please check the documentation for the paperclip version you are using:
|
29
|
+
https://github.com/thoughtbot/paperclip/releases
|
30
|
+
|
31
|
+
---
|
32
|
+
|
33
|
+
[![Build Status](https://secure.travis-ci.org/thoughtbot/paperclip.svg?branch=master)](http://travis-ci.org/thoughtbot/paperclip)
|
34
|
+
[![Dependency Status](https://gemnasium.com/thoughtbot/paperclip.svg?travis)](https://gemnasium.com/thoughtbot/paperclip)
|
35
|
+
[![Code Climate](https://codeclimate.com/github/thoughtbot/paperclip.svg)](https://codeclimate.com/github/thoughtbot/paperclip)
|
36
|
+
[![Inline docs](http://inch-ci.org/github/thoughtbot/paperclip.svg)](http://inch-ci.org/github/thoughtbot/paperclip)
|
37
|
+
[![Security](https://hakiri.io/github/thoughtbot/paperclip/master.svg)](https://hakiri.io/github/thoughtbot/paperclip/master)
|
38
|
+
|
39
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
40
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
5
41
|
|
6
42
|
- [Requirements](#requirements)
|
7
|
-
- [Ruby
|
43
|
+
- [Ruby and Rails](#ruby-and-rails)
|
8
44
|
- [Image Processor](#image-processor)
|
9
|
-
- [file](#file)
|
45
|
+
- [`file`](#file)
|
10
46
|
- [Installation](#installation)
|
11
47
|
- [Quick Start](#quick-start)
|
12
48
|
- [Models](#models)
|
@@ -14,35 +50,41 @@ Paperclip
|
|
14
50
|
- [Edit and New Views](#edit-and-new-views)
|
15
51
|
- [Edit and New Views with Simple Form](#edit-and-new-views-with-simple-form)
|
16
52
|
- [Controller](#controller)
|
17
|
-
- [
|
53
|
+
- [View Helpers](#view-helpers)
|
54
|
+
- [Checking a File Exists](#checking-a-file-exists)
|
18
55
|
- [Deleting an Attachment](#deleting-an-attachment)
|
19
56
|
- [Usage](#usage)
|
20
57
|
- [Validations](#validations)
|
58
|
+
- [Internationalization (I18n)](#internationalization-i18n)
|
21
59
|
- [Security Validations](#security-validations)
|
22
60
|
- [Defaults](#defaults)
|
23
61
|
- [Migrations](#migrations-1)
|
24
|
-
- [Table
|
62
|
+
- [Add Attachment Column To A Table](#add-attachment-column-to-a-table)
|
25
63
|
- [Schema Definition](#schema-definition)
|
26
64
|
- [Vintage Syntax](#vintage-syntax)
|
27
65
|
- [Storage](#storage)
|
28
66
|
- [Understanding Storage](#understanding-storage)
|
67
|
+
- [IO Adapters](#io-adapters)
|
29
68
|
- [Post Processing](#post-processing)
|
69
|
+
- [Custom Attachment Processors](#custom-attachment-processors)
|
30
70
|
- [Events](#events)
|
31
71
|
- [URI Obfuscation](#uri-obfuscation)
|
32
|
-
|
33
|
-
|
34
|
-
- [Custom Attachment Processors](#custom-attachment-processors)
|
72
|
+
- [Checksum / Fingerprint](#checksum--fingerprint)
|
73
|
+
- [File Preservation for Soft-Delete](#file-preservation-for-soft-delete)
|
35
74
|
- [Dynamic Configuration](#dynamic-configuration)
|
36
|
-
- [Dynamic Styles](#dynamic-styles)
|
37
|
-
- [Dynamic Processors](#dynamic-processors)
|
75
|
+
- [Dynamic Styles:](#dynamic-styles)
|
76
|
+
- [Dynamic Processors:](#dynamic-processors)
|
38
77
|
- [Logging](#logging)
|
39
78
|
- [Deployment](#deployment)
|
79
|
+
- [Attachment Styles](#attachment-styles)
|
40
80
|
- [Testing](#testing)
|
41
81
|
- [Contributing](#contributing)
|
42
82
|
- [License](#license)
|
43
83
|
- [About thoughtbot](#about-thoughtbot)
|
44
84
|
|
45
|
-
|
85
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
86
|
+
|
87
|
+
Paperclip is intended as an easy file attachment library for ActiveRecord. The
|
46
88
|
intent behind it was to keep setup as easy as possible and to treat files as
|
47
89
|
much like other attributes as possible. This means they aren't saved to their
|
48
90
|
final locations on disk, nor are they deleted if set to nil, until
|
@@ -54,10 +96,10 @@ packages). Attached files are saved to the filesystem and referenced in the
|
|
54
96
|
browser by an easily understandable specification, which has sensible and
|
55
97
|
useful defaults.
|
56
98
|
|
57
|
-
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
99
|
+
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
58
100
|
more detailed options.
|
59
101
|
|
60
|
-
The complete [RDoc](http://
|
102
|
+
The complete [RDoc](http://www.rubydoc.info/gems/paperclip) is online.
|
61
103
|
|
62
104
|
---
|
63
105
|
|
@@ -66,9 +108,8 @@ Requirements
|
|
66
108
|
|
67
109
|
### Ruby and Rails
|
68
110
|
|
69
|
-
Paperclip now requires Ruby version **>= 2.
|
70
|
-
|
71
|
-
If you're still on Ruby 1.8.7 or Ruby on Rails 2.3.x, you can still use Paperclip 2.7.x with your project. Also, everything in this README might not apply to your version of Paperclip, and you should read [the README for version 2.7](http://rubydoc.info/gems/paperclip/2.7.0) instead.
|
111
|
+
Paperclip now requires Ruby version **>= 2.1** and Rails version **>= 4.2**
|
112
|
+
(only if you're going to use Paperclip with Ruby on Rails).
|
72
113
|
|
73
114
|
### Image Processor
|
74
115
|
|
@@ -86,7 +127,7 @@ In development mode, you might add this line to `config/environments/development
|
|
86
127
|
Paperclip.options[:command_path] = "/usr/local/bin/"
|
87
128
|
```
|
88
129
|
|
89
|
-
If you're on Mac OS X, you'll want to run the following with Homebrew:
|
130
|
+
If you're on Mac OS X, you'll want to run the following with [Homebrew](http://www.brew.sh):
|
90
131
|
|
91
132
|
brew install imagemagick
|
92
133
|
|
@@ -95,17 +136,14 @@ to install GhostScript. On Mac OS X, you can also install that using Homebrew:
|
|
95
136
|
|
96
137
|
brew install gs
|
97
138
|
|
98
|
-
If you
|
99
|
-
|
100
|
-
sudo apt-get install imagemagick -y
|
101
|
-
|
102
|
-
If you're on Ubuntu (or any Debian base Linux distribution), you'll want to run the following with apt-get:
|
139
|
+
If you are on Ubuntu (or any Debian base Linux distribution), you'll want to run
|
140
|
+
the following with apt-get:
|
103
141
|
|
104
142
|
sudo apt-get install imagemagick -y
|
105
143
|
|
106
144
|
### `file`
|
107
145
|
|
108
|
-
The Unix [`file` command](
|
146
|
+
The Unix [`file` command](https://en.wikipedia.org/wiki/File_(command)) is required for content-type checking.
|
109
147
|
This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
|
110
148
|
so Windows users must make sure that the devkit is installed and added to the system `PATH`.
|
111
149
|
|
@@ -151,18 +189,18 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
|
|
151
189
|
Include the gem in your Gemfile:
|
152
190
|
|
153
191
|
```ruby
|
154
|
-
gem "paperclip", "~>
|
192
|
+
gem "paperclip", "~> 6.0.0"
|
155
193
|
```
|
156
194
|
|
157
195
|
Or, if you want to get the latest, you can get master from the main paperclip repository:
|
158
196
|
|
159
197
|
```ruby
|
160
|
-
gem "paperclip", :
|
198
|
+
gem "paperclip", git: "git://github.com/thoughtbot/paperclip.git"
|
161
199
|
```
|
162
200
|
|
163
201
|
If you're trying to use features that don't seem to be in the latest released gem, but are
|
164
202
|
mentioned in this README, then you probably need to specify the master branch if you want to
|
165
|
-
use them. This README is probably ahead of the latest released version
|
203
|
+
use them. This README is probably ahead of the latest released version if you're reading it
|
166
204
|
on GitHub.
|
167
205
|
|
168
206
|
For Non-Rails usage:
|
@@ -181,27 +219,17 @@ Quick Start
|
|
181
219
|
|
182
220
|
### Models
|
183
221
|
|
184
|
-
**Rails 3**
|
185
|
-
|
186
222
|
```ruby
|
187
223
|
class User < ActiveRecord::Base
|
188
|
-
|
189
|
-
|
190
|
-
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
|
191
|
-
end
|
192
|
-
```
|
193
|
-
|
194
|
-
**Rails 4**
|
195
|
-
|
196
|
-
```ruby
|
197
|
-
class User < ActiveRecord::Base
|
198
|
-
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
|
199
|
-
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
|
224
|
+
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
|
225
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\z/
|
200
226
|
end
|
201
227
|
```
|
202
228
|
|
203
229
|
### Migrations
|
204
230
|
|
231
|
+
|
232
|
+
Assuming you have a `users` table, add an `avatar` column to the `users` table:
|
205
233
|
```ruby
|
206
234
|
class AddAvatarColumnsToUsers < ActiveRecord::Migration
|
207
235
|
def up
|
@@ -217,35 +245,28 @@ end
|
|
217
245
|
(Or you can use the Rails migration generator: `rails generate paperclip user avatar`)
|
218
246
|
|
219
247
|
### Edit and New Views
|
220
|
-
|
248
|
+
Make sure you have corresponding methods in your controller:
|
221
249
|
```erb
|
222
|
-
<%= form_for @user, :
|
250
|
+
<%= form_for @user, url: users_path, html: { multipart: true } do |form| %>
|
223
251
|
<%= form.file_field :avatar %>
|
252
|
+
<%= form.submit %>
|
224
253
|
<% end %>
|
225
254
|
```
|
226
255
|
|
227
|
-
### Edit and New Views with Simple Form
|
256
|
+
### Edit and New Views with [Simple Form](https://github.com/plataformatec/simple_form)
|
257
|
+
|
228
258
|
```erb
|
229
259
|
<%= simple_form_for @user, url: users_path do |form| %>
|
230
260
|
<%= form.input :avatar, as: :file %>
|
261
|
+
<%= form.submit %>
|
231
262
|
<% end %>
|
232
263
|
```
|
233
264
|
|
234
265
|
### Controller
|
235
266
|
|
236
|
-
**Rails 3**
|
237
|
-
|
238
|
-
```ruby
|
239
|
-
def create
|
240
|
-
@user = User.create( params[:user] )
|
241
|
-
end
|
242
|
-
```
|
243
|
-
|
244
|
-
**Rails 4**
|
245
|
-
|
246
267
|
```ruby
|
247
268
|
def create
|
248
|
-
@user = User.create(
|
269
|
+
@user = User.create(user_params)
|
249
270
|
end
|
250
271
|
|
251
272
|
private
|
@@ -258,14 +279,24 @@ def user_params
|
|
258
279
|
end
|
259
280
|
```
|
260
281
|
|
261
|
-
###
|
262
|
-
|
282
|
+
### View Helpers
|
283
|
+
Add these to the view where you want your images displayed:
|
263
284
|
```erb
|
264
285
|
<%= image_tag @user.avatar.url %>
|
265
286
|
<%= image_tag @user.avatar.url(:medium) %>
|
266
287
|
<%= image_tag @user.avatar.url(:thumb) %>
|
267
288
|
```
|
268
289
|
|
290
|
+
### Checking a File Exists
|
291
|
+
|
292
|
+
There are two methods for checking if a file exists:
|
293
|
+
|
294
|
+
- `file?` and `present?` checks if the `_file_name` field is populated
|
295
|
+
- `exists?` checks if the file exists (will perform a TCP connection if stored in the cloud)
|
296
|
+
|
297
|
+
Keep this in mind if you are checking if files are present in a loop. The first
|
298
|
+
version is significantly more performant, but has different semantics.
|
299
|
+
|
269
300
|
### Deleting an Attachment
|
270
301
|
|
271
302
|
Set the attribute to `nil` and save.
|
@@ -296,7 +327,7 @@ You'll need to add `<attachment>_content_type` in case you want to use content t
|
|
296
327
|
validation.
|
297
328
|
|
298
329
|
More information about the options passed to `has_attached_file` is available in the
|
299
|
-
documentation of [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
330
|
+
documentation of [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
300
331
|
|
301
332
|
Validations
|
302
333
|
-----------
|
@@ -310,9 +341,9 @@ For validations, Paperclip introduces several validators to validate your attach
|
|
310
341
|
Example Usage:
|
311
342
|
|
312
343
|
```ruby
|
313
|
-
validates :avatar, :
|
314
|
-
validates_with AttachmentPresenceValidator, :
|
315
|
-
validates_with AttachmentSizeValidator, :
|
344
|
+
validates :avatar, attachment_presence: true
|
345
|
+
validates_with AttachmentPresenceValidator, attributes: :avatar
|
346
|
+
validates_with AttachmentSizeValidator, attributes: :avatar, less_than: 1.megabytes
|
316
347
|
|
317
348
|
```
|
318
349
|
|
@@ -331,9 +362,9 @@ validates_attachment_presence :avatar
|
|
331
362
|
Lastly, you can also define multiple validations on a single attachment using `validates_attachment`:
|
332
363
|
|
333
364
|
```ruby
|
334
|
-
validates_attachment :avatar, :
|
335
|
-
|
336
|
-
:
|
365
|
+
validates_attachment :avatar, presence: true,
|
366
|
+
content_type: "image/jpeg",
|
367
|
+
size: { in: 0..10.kilobytes }
|
337
368
|
```
|
338
369
|
|
339
370
|
_NOTE: Post-processing will not even **start** if the attachment is not valid
|
@@ -342,7 +373,7 @@ called with valid attachments._
|
|
342
373
|
|
343
374
|
```ruby
|
344
375
|
class Message < ActiveRecord::Base
|
345
|
-
has_attached_file :asset, styles: {thumb: "100x100#"}
|
376
|
+
has_attached_file :asset, styles: { thumb: "100x100#" }
|
346
377
|
|
347
378
|
before_post_process :skip_for_audio
|
348
379
|
|
@@ -358,8 +389,8 @@ afterwards, then assign manually:
|
|
358
389
|
|
359
390
|
```ruby
|
360
391
|
class Book < ActiveRecord::Base
|
361
|
-
has_attached_file :document, styles: {thumbnail: "60x60#"}
|
362
|
-
validates_attachment :document, content_type:
|
392
|
+
has_attached_file :document, styles: { thumbnail: "60x60#" }
|
393
|
+
validates_attachment :document, content_type: "application/pdf"
|
363
394
|
validates_something_else # Other validations that conflict with Paperclip's
|
364
395
|
end
|
365
396
|
|
@@ -391,7 +422,7 @@ image-y ones:
|
|
391
422
|
|
392
423
|
```ruby
|
393
424
|
validates_attachment :avatar,
|
394
|
-
|
425
|
+
content_type: ["image/jpeg", "image/gif", "image/png"]
|
395
426
|
```
|
396
427
|
|
397
428
|
`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
|
@@ -399,6 +430,12 @@ inferred content_type, regardless of the actual contents of the file.
|
|
399
430
|
|
400
431
|
---
|
401
432
|
|
433
|
+
Internationalization (I18n)
|
434
|
+
---------------------------
|
435
|
+
|
436
|
+
For using or adding locale files in different languages, check the project
|
437
|
+
https://github.com/thoughtbot/paperclip-i18n.
|
438
|
+
|
402
439
|
Security Validations
|
403
440
|
====================
|
404
441
|
|
@@ -415,9 +452,9 @@ do this.
|
|
415
452
|
class ActiveRecord::Base
|
416
453
|
has_attached_file :avatar
|
417
454
|
# Validate content type
|
418
|
-
validates_attachment_content_type :avatar, :
|
455
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage/
|
419
456
|
# Validate filename
|
420
|
-
validates_attachment_file_name :avatar, :
|
457
|
+
validates_attachment_file_name :avatar, matches: [/png\z/, /jpe?g\z/]
|
421
458
|
# Explicitly do not validate
|
422
459
|
do_not_validate_attachment_file_type :avatar
|
423
460
|
end
|
@@ -437,14 +474,13 @@ will not cause errors to be raised.
|
|
437
474
|
|
438
475
|
This can sometimes cause false validation errors in applications that use custom
|
439
476
|
file extensions. In these cases you may wish to add your custom extension to the
|
440
|
-
list of
|
441
|
-
gem:
|
477
|
+
list of content type mappings by creating `config/initializers/paperclip.rb`:
|
442
478
|
|
443
479
|
```ruby
|
444
480
|
# Allow ".foo" as an extension for files with the MIME type "text/plain".
|
445
|
-
|
446
|
-
|
447
|
-
|
481
|
+
Paperclip.options[:content_type_mappings] = {
|
482
|
+
foo: %w(text/plain)
|
483
|
+
}
|
448
484
|
```
|
449
485
|
|
450
486
|
---
|
@@ -460,7 +496,7 @@ module YourApp
|
|
460
496
|
class Application < Rails::Application
|
461
497
|
# Other code...
|
462
498
|
|
463
|
-
config.paperclip_defaults = {:
|
499
|
+
config.paperclip_defaults = { storage: :fog, fog_credentials: { provider: "Local", local_root: "#{Rails.root}/public"}, fog_directory: "", fog_host: "localhost"}
|
464
500
|
end
|
465
501
|
end
|
466
502
|
```
|
@@ -471,7 +507,7 @@ An example Rails initializer would look something like this:
|
|
471
507
|
|
472
508
|
```ruby
|
473
509
|
Paperclip::Attachment.default_options[:storage] = :fog
|
474
|
-
Paperclip::Attachment.default_options[:fog_credentials] = {:
|
510
|
+
Paperclip::Attachment.default_options[:fog_credentials] = { provider: "Local", local_root: "#{Rails.root}/public"}
|
475
511
|
Paperclip::Attachment.default_options[:fog_directory] = ""
|
476
512
|
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"
|
477
513
|
```
|
@@ -493,6 +529,7 @@ class CreateUsersWithAttachments < ActiveRecord::Migration
|
|
493
529
|
create_table :users do |t|
|
494
530
|
t.attachment :avatar
|
495
531
|
end
|
532
|
+
end
|
496
533
|
|
497
534
|
# This is assuming you are only using the users table for Paperclip attachment. Drop with care!
|
498
535
|
def down
|
@@ -539,7 +576,7 @@ class AddAttachmentColumnsToUsers < ActiveRecord::Migration
|
|
539
576
|
end
|
540
577
|
```
|
541
578
|
|
542
|
-
### Vintage
|
579
|
+
### Vintage Syntax
|
543
580
|
|
544
581
|
Vintage syntax (such as `t.has_attached_file` and `drop_attached_file`) is still supported in
|
545
582
|
Paperclip 3.x, but you're advised to update those migration files to use this new syntax.
|
@@ -552,12 +589,13 @@ Storage
|
|
552
589
|
Paperclip ships with 3 storage adapters:
|
553
590
|
|
554
591
|
* File Storage
|
555
|
-
* S3 Storage (via `aws-sdk`)
|
592
|
+
* S3 Storage (via `aws-sdk-s3`)
|
556
593
|
* Fog Storage
|
557
594
|
|
558
595
|
If you would like to use Paperclip with another storage, you can install these
|
559
596
|
gems along side with Paperclip:
|
560
597
|
|
598
|
+
* [paperclip-azure](https://github.com/supportify/paperclip-azure)
|
561
599
|
* [paperclip-azure-storage](https://github.com/gmontard/paperclip-azure-storage)
|
562
600
|
* [paperclip-dropbox](https://github.com/janko-m/paperclip-dropbox)
|
563
601
|
|
@@ -566,9 +604,9 @@ gems along side with Paperclip:
|
|
566
604
|
The files that are assigned as attachments are, by default, placed in the
|
567
605
|
directory specified by the `:path` option to `has_attached_file`. By default, this
|
568
606
|
location is `:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename`.
|
569
|
-
This location was chosen because on standard Capistrano deployments, the
|
570
|
-
`public/system` directory
|
571
|
-
|
607
|
+
This location was chosen because, on standard Capistrano deployments, the
|
608
|
+
`public/system` directory can be symlinked to the app's shared directory, meaning it
|
609
|
+
survives between deployments. For example, using that `:path`, you may have a
|
572
610
|
file at
|
573
611
|
|
574
612
|
/data/myapp/releases/20081229172410/public/system/users/avatar/000/000/013/small/my_pic.png
|
@@ -577,15 +615,15 @@ _**NOTE**: This is a change from previous versions of Paperclip, but is overall
|
|
577
615
|
safer choice for the default file store._
|
578
616
|
|
579
617
|
You may also choose to store your files using Amazon's S3 service. To do so, include
|
580
|
-
the `aws-sdk` gem in your Gemfile:
|
618
|
+
the `aws-sdk-s3` gem in your Gemfile:
|
581
619
|
|
582
620
|
```ruby
|
583
|
-
gem 'aws-sdk'
|
621
|
+
gem 'aws-sdk-s3'
|
584
622
|
```
|
585
623
|
|
586
624
|
And then you can specify using S3 from `has_attached_file`.
|
587
625
|
You can find more information about configuring and using S3 storage in
|
588
|
-
[the `Paperclip::Storage::S3` documentation](http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
626
|
+
[the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
589
627
|
|
590
628
|
Files on the local filesystem (and in the Rails app's public directory) will be
|
591
629
|
available to the internet at large. If you require access control, it's
|
@@ -596,64 +634,121 @@ variables.
|
|
596
634
|
|
597
635
|
---
|
598
636
|
|
637
|
+
IO Adapters
|
638
|
+
-----------
|
639
|
+
|
640
|
+
When a file is uploaded or attached, it can be in one of a few different input
|
641
|
+
forms, from Rails' UploadedFile object to a StringIO to a Tempfile or even a
|
642
|
+
simple String that is a URL that points to an image.
|
643
|
+
|
644
|
+
Paperclip will accept, by default, many of these sources. It also is capable of
|
645
|
+
handling even more with a little configuration. The IO Adapters that handle
|
646
|
+
images from non-local sources are not enabled by default. They can be enabled by
|
647
|
+
adding a line similar to the following into `config/initializers/paperclip.rb`:
|
648
|
+
|
649
|
+
```ruby
|
650
|
+
Paperclip::DataUriAdapter.register
|
651
|
+
```
|
652
|
+
|
653
|
+
It's best to only enable a remote-loading adapter if you need it. Otherwise
|
654
|
+
there's a chance that someone can gain insight into your internal network
|
655
|
+
structure using it as a vector.
|
656
|
+
|
657
|
+
The following adapters are *not* loaded by default:
|
658
|
+
|
659
|
+
* `Paperclip::UriAdapter` - which accepts a `URI` instance.
|
660
|
+
* `Paperclip::HttpUrlProxyAdapter` - which accepts a `http` string.
|
661
|
+
* `Paperclip::DataUriAdapter` - which accepts a Base64-encoded `data:` string.
|
662
|
+
|
663
|
+
---
|
664
|
+
|
599
665
|
Post Processing
|
600
666
|
---------------
|
601
667
|
|
602
668
|
Paperclip supports an extensible selection of post-processors. When you define
|
603
669
|
a set of styles for an attachment, by default it is expected that those
|
604
|
-
"styles" are actually "thumbnails."
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
automatically loaded by Paperclip, allowing you to easily define custom
|
609
|
-
processors. You can specify a processor with the `:processors` option to
|
610
|
-
`has_attached_file`:
|
670
|
+
"styles" are actually "thumbnails." These are processed by
|
671
|
+
`Paperclip::Thumbnail`. For backward compatibility reasons you can pass either
|
672
|
+
a single geometry string, or an array containing a geometry and a format that
|
673
|
+
the file will be converted to, like so:
|
611
674
|
|
612
675
|
```ruby
|
613
|
-
has_attached_file :
|
614
|
-
:processors => [:ocr]
|
676
|
+
has_attached_file :avatar, styles: { thumb: ["32x32#", :png] }
|
615
677
|
```
|
616
678
|
|
617
|
-
This
|
618
|
-
|
619
|
-
|
679
|
+
This will convert the "thumb" style to a 32x32 square in PNG format, regardless
|
680
|
+
of what was uploaded. If the format is not specified, it is kept the same (e.g.
|
681
|
+
JPGs will remain JPGs). `Paperclip::Thumbnail` uses ImageMagick to process
|
682
|
+
images; [ImageMagick's geometry documentation](http://www.imagemagick.org/script/command-line-processing.php#geometry)
|
683
|
+
has more information on the accepted style formats.
|
620
684
|
|
621
|
-
|
622
|
-
reasons, you can pass a single geometry string or an array containing a
|
623
|
-
geometry and a format that the file will be converted to, like so:
|
685
|
+
For more fine-grained control of the conversion process, `source_file_options` and `convert_options` can be used to pass flags and settings directly to ImageMagick's powerful Convert tool, [documented here](https://www.imagemagick.org/script/convert.php). For example:
|
624
686
|
|
625
687
|
```ruby
|
626
|
-
has_attached_file :
|
688
|
+
has_attached_file :image, styles: { regular: ['800x800>', :png]},
|
689
|
+
source_file_options: { regular: "-density 96 -depth 8 -quality 85" },
|
690
|
+
convert_options: { regular: "-posterize 3"}
|
627
691
|
```
|
628
692
|
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
693
|
+
ImageMagick supports a number of environment variables for controlling its resource limits. For example, you can enforce memory or execution time limits by setting the following variables in your application's process environment:
|
694
|
+
|
695
|
+
* `MAGICK_MEMORY_LIMIT=128MiB`
|
696
|
+
* `MAGICK_MAP_LIMIT=64MiB`
|
697
|
+
* `MAGICK_TIME_LIMIT=30`
|
698
|
+
|
699
|
+
For a full list of variables and description, see [ImageMagick's resources documentation](http://www.imagemagick.org/script/resources.php).
|
700
|
+
|
701
|
+
---
|
702
|
+
|
703
|
+
Custom Attachment Processors
|
704
|
+
-------
|
705
|
+
|
706
|
+
You can write your own custom attachment processors to carry out tasks like
|
707
|
+
adding watermarks, compressing images, or encrypting files. Custom processors
|
708
|
+
must be defined within the `Paperclip` module, inherit from
|
709
|
+
`Paperclip::Processor` (see [`lib/paperclip/processor.rb`](https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/processor.rb)),
|
710
|
+
and implement a `make` method that returns a `File`. All files in your Rails
|
711
|
+
app's `lib/paperclip` and `lib/paperclip_processors` directories will be
|
712
|
+
automatically loaded by Paperclip. Processors are specified using the
|
713
|
+
`:processors` option to `has_attached_file`:
|
714
|
+
|
715
|
+
```ruby
|
716
|
+
has_attached_file :scan, styles: { text: { quality: :better } },
|
717
|
+
processors: [:ocr]
|
718
|
+
```
|
719
|
+
|
720
|
+
This would load the hypothetical class `Paperclip::Ocr`, and pass it the
|
721
|
+
options hash `{ quality: :better }`, along with the uploaded file.
|
633
722
|
|
634
723
|
Multiple processors can be specified, and they will be invoked in the order
|
635
|
-
they are defined in the `:processors` array. Each successive processor
|
636
|
-
|
637
|
-
|
638
|
-
|
724
|
+
they are defined in the `:processors` array. Each successive processor is given
|
725
|
+
the result from the previous processor. All processors receive the same
|
726
|
+
parameters, which are defined in the `:styles` hash. For example, assuming we
|
727
|
+
had this definition:
|
639
728
|
|
640
729
|
```ruby
|
641
|
-
has_attached_file :scan, :
|
642
|
-
:
|
730
|
+
has_attached_file :scan, styles: { text: { quality: :better } },
|
731
|
+
processors: [:rotator, :ocr]
|
643
732
|
```
|
644
733
|
|
645
|
-
|
646
|
-
options `{ :
|
647
|
-
|
734
|
+
Both the `:rotator` processor and the `:ocr` processor would receive the
|
735
|
+
options `{ quality: :better }`. If a processor receives an option it doesn't
|
736
|
+
recognise, it's expected to ignore it.
|
648
737
|
|
649
738
|
_NOTE: Because processors operate by turning the original attachment into the
|
650
739
|
styles, no processors will be run if there are no styles defined._
|
651
740
|
|
652
741
|
If you're interested in caching your thumbnail's width, height and size in the
|
653
|
-
database, take a look at the [paperclip-meta](https://github.com/teeparham/paperclip-meta)
|
742
|
+
database, take a look at the [paperclip-meta](https://github.com/teeparham/paperclip-meta)
|
743
|
+
gem.
|
654
744
|
|
655
745
|
Also, if you're interested in generating the thumbnail on-the-fly, you might want
|
656
|
-
to look into the [attachment_on_the_fly](https://github.com/drpentode/Attachment-on-the-Fly)
|
746
|
+
to look into the [attachment_on_the_fly](https://github.com/drpentode/Attachment-on-the-Fly)
|
747
|
+
gem.
|
748
|
+
|
749
|
+
Paperclip's thumbnail generator (see [`lib/paperclip/thumbnail.rb`](lib/paperclip/thumbnail.rb))
|
750
|
+
is implemented as a processor, and may be a good reference for writing your own
|
751
|
+
processors.
|
657
752
|
|
658
753
|
---
|
659
754
|
|
@@ -677,7 +772,7 @@ called with valid attachments._
|
|
677
772
|
|
678
773
|
```ruby
|
679
774
|
class Message < ActiveRecord::Base
|
680
|
-
has_attached_file :asset, styles: {thumb: "100x100#"}
|
775
|
+
has_attached_file :asset, styles: { thumb: "100x100#" }
|
681
776
|
|
682
777
|
before_post_process :skip_for_audio
|
683
778
|
|
@@ -699,8 +794,8 @@ Example Usage:
|
|
699
794
|
|
700
795
|
```ruby
|
701
796
|
has_attached_file :avatar, {
|
702
|
-
:
|
703
|
-
:
|
797
|
+
url: "/system/:hash.:extension",
|
798
|
+
hash_secret: "longSecretString"
|
704
799
|
}
|
705
800
|
```
|
706
801
|
|
@@ -712,10 +807,10 @@ is specified in `:hash_data`. The default value for `:hash_data` is `":class/:at
|
|
712
807
|
|
713
808
|
For more on this feature, read [the author's own explanation](https://github.com/thoughtbot/paperclip/pull/416)
|
714
809
|
|
715
|
-
|
810
|
+
Checksum / Fingerprint
|
716
811
|
-------
|
717
812
|
|
718
|
-
|
813
|
+
A checksum of the original file assigned will be placed in the model if it
|
719
814
|
has an attribute named fingerprint. Following the user model migration example
|
720
815
|
above, the migration would look like the following:
|
721
816
|
|
@@ -731,6 +826,17 @@ class AddAvatarFingerprintColumnToUser < ActiveRecord::Migration
|
|
731
826
|
end
|
732
827
|
```
|
733
828
|
|
829
|
+
The algorithm can be specified using a configuration option; it defaults to MD5
|
830
|
+
for backwards compatibility with Paperclip 5 and earlier.
|
831
|
+
|
832
|
+
```ruby
|
833
|
+
has_attached_file :some_attachment, adapter_options: { hash_digest: Digest::SHA256 }
|
834
|
+
```
|
835
|
+
|
836
|
+
Run `CLASS=User ATTACHMENT=avatar rake paperclip:refresh:fingerprints` after
|
837
|
+
changing the digest on existing attachments to update the fingerprints in the
|
838
|
+
database.
|
839
|
+
|
734
840
|
File Preservation for Soft-Delete
|
735
841
|
-------
|
736
842
|
|
@@ -738,7 +844,7 @@ An option is available to preserve attachments in order to play nicely with soft
|
|
738
844
|
|
739
845
|
```ruby
|
740
846
|
has_attached_file :some_attachment, {
|
741
|
-
:
|
847
|
+
preserve_files: true,
|
742
848
|
}
|
743
849
|
```
|
744
850
|
|
@@ -746,25 +852,6 @@ This will prevent ```some_attachment``` from being wiped out when the model gets
|
|
746
852
|
|
747
853
|
---
|
748
854
|
|
749
|
-
Custom Attachment Processors
|
750
|
-
-------
|
751
|
-
|
752
|
-
Custom attachment processors can be implemented and their only requirement is
|
753
|
-
to inherit from `Paperclip::Processor` (see `lib/paperclip/processor.rb`).
|
754
|
-
For example, when `:styles` are specified for an image attachment, the
|
755
|
-
thumbnail processor (see `lib/paperclip/thumbnail.rb`) is loaded without having
|
756
|
-
to specify it as a `:processor` parameter to `has_attached_file`. When any
|
757
|
-
other processor is defined, it must be called out in the `:processors`
|
758
|
-
parameter if it is to be applied to the attachment. The thumbnail processor
|
759
|
-
uses the ImageMagick `convert` command to do the work of resizing image
|
760
|
-
thumbnails. It would be easy to create a custom processor that watermarks
|
761
|
-
an image using ImageMagick's `composite` command. Following the
|
762
|
-
implementation pattern of the thumbnail processor would be a way to implement a
|
763
|
-
watermark processor. All kinds of attachment processors can be created;
|
764
|
-
a few utility examples would be compression and encryption processors.
|
765
|
-
|
766
|
-
---
|
767
|
-
|
768
855
|
Dynamic Configuration
|
769
856
|
---------------------
|
770
857
|
|
@@ -786,7 +873,7 @@ look as follows where a boss will receive a `300x300` thumbnail otherwise a
|
|
786
873
|
|
787
874
|
```ruby
|
788
875
|
class User < ActiveRecord::Base
|
789
|
-
has_attached_file :avatar, :
|
876
|
+
has_attached_file :avatar, styles: lambda { |attachment| { thumb: (attachment.instance.boss? ? "300x300>" : "100x100>") } }
|
790
877
|
end
|
791
878
|
```
|
792
879
|
|
@@ -803,7 +890,7 @@ processors, where a defined `watermark` processor is invoked after the
|
|
803
890
|
|
804
891
|
```ruby
|
805
892
|
class User < ActiveRecord::Base
|
806
|
-
has_attached_file :avatar, :
|
893
|
+
has_attached_file :avatar, processors: lambda { |instance| instance.processors }
|
807
894
|
attr_accessor :processors
|
808
895
|
end
|
809
896
|
```
|
@@ -813,7 +900,7 @@ end
|
|
813
900
|
Logging
|
814
901
|
----------
|
815
902
|
|
816
|
-
By default Paperclip outputs logging according to your logger level. If you want to disable logging (e.g. during testing) add this
|
903
|
+
By default, Paperclip outputs logging according to your logger level. If you want to disable logging (e.g. during testing) add this into your environment's configuration:
|
817
904
|
```ruby
|
818
905
|
Your::Application.configure do
|
819
906
|
...
|
@@ -822,13 +909,23 @@ Your::Application.configure do
|
|
822
909
|
end
|
823
910
|
```
|
824
911
|
|
825
|
-
More information in the [rdocs](http://
|
912
|
+
More information in the [rdocs](http://www.rubydoc.info/github/thoughtbot/paperclip/Paperclip.options)
|
826
913
|
|
827
914
|
---
|
828
915
|
|
829
916
|
Deployment
|
830
917
|
----------
|
831
918
|
|
919
|
+
To make Capistrano symlink the `public/system` directory so that attachments
|
920
|
+
survive new deployments, set the `linked_dirs` option in your `config/deploy.rb`
|
921
|
+
file:
|
922
|
+
|
923
|
+
```ruby
|
924
|
+
set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
|
925
|
+
```
|
926
|
+
|
927
|
+
### Attachment Styles
|
928
|
+
|
832
929
|
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
|
833
930
|
`rake paperclip:refresh:missing_styles`. It will store current attachment styles in `RAILS_ROOT/public/system/paperclip_attachments.yml`
|
834
931
|
by default. You can change it by:
|
@@ -840,9 +937,9 @@ Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachment
|
|
840
937
|
Here is an example for Capistrano:
|
841
938
|
|
842
939
|
```ruby
|
843
|
-
namespace :
|
940
|
+
namespace :paperclip do
|
844
941
|
desc "build missing paperclip styles"
|
845
|
-
task :
|
942
|
+
task :build_missing_styles do
|
846
943
|
on roles(:app) do
|
847
944
|
within release_path do
|
848
945
|
with rails_env: fetch(:rails_env) do
|
@@ -853,7 +950,7 @@ namespace :deploy do
|
|
853
950
|
end
|
854
951
|
end
|
855
952
|
|
856
|
-
after("deploy:compile_assets", "
|
953
|
+
after("deploy:compile_assets", "paperclip:build_missing_styles")
|
857
954
|
```
|
858
955
|
|
859
956
|
Now you don't have to remember to refresh thumbnails in production every time you add a new style.
|
@@ -864,12 +961,12 @@ Paperclip about existing styles. Simply create a `paperclip_attachments.yml` fil
|
|
864
961
|
|
865
962
|
```ruby
|
866
963
|
class User < ActiveRecord::Base
|
867
|
-
has_attached_file :avatar, :
|
964
|
+
has_attached_file :avatar, styles: { thumb: 'x100', croppable: '600x600>', big: '1000x1000>' }
|
868
965
|
end
|
869
966
|
|
870
967
|
class Book < ActiveRecord::Base
|
871
|
-
has_attached_file :cover, :
|
872
|
-
has_attached_file :sample, :
|
968
|
+
has_attached_file :cover, styles: { small: 'x100', large: '1000x1000>' }
|
969
|
+
has_attached_file :sample, styles: { thumb: 'x100' }
|
873
970
|
end
|
874
971
|
```
|
875
972
|
|
@@ -896,7 +993,7 @@ Testing
|
|
896
993
|
-------
|
897
994
|
|
898
995
|
Paperclip provides rspec-compatible matchers for testing attachments. See the
|
899
|
-
documentation on [Paperclip::Shoulda::Matchers](http://rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
996
|
+
documentation on [Paperclip::Shoulda::Matchers](http://www.rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
900
997
|
for more information.
|
901
998
|
|
902
999
|
**Parallel Tests**
|
@@ -920,7 +1017,7 @@ similar mechanism for whichever parallel testing library you use.
|
|
920
1017
|
|
921
1018
|
**Integration Tests**
|
922
1019
|
|
923
|
-
Using integration tests with
|
1020
|
+
Using integration tests with FactoryBot may save multiple copies of
|
924
1021
|
your test files within the app. To avoid this, specify a custom path in
|
925
1022
|
the `config/environments/test.rb` like so:
|
926
1023
|
|
@@ -936,6 +1033,17 @@ config.after(:suite) do
|
|
936
1033
|
FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
|
937
1034
|
end
|
938
1035
|
```
|
1036
|
+
|
1037
|
+
**Example of test configuration with Factory Bot**
|
1038
|
+
|
1039
|
+
|
1040
|
+
```ruby
|
1041
|
+
FactoryBot.define do
|
1042
|
+
factory :user do
|
1043
|
+
avatar { File.new("#{Rails.root}/spec/support/fixtures/image.jpg") }
|
1044
|
+
end
|
1045
|
+
end
|
1046
|
+
```
|
939
1047
|
---
|
940
1048
|
|
941
1049
|
Contributing
|
@@ -951,20 +1059,20 @@ guidelines:
|
|
951
1059
|
about writing tests for paperclip, please open a
|
952
1060
|
[GitHub issue](https://github.com/thoughtbot/paperclip/issues/new).
|
953
1061
|
|
954
|
-
Please see `CONTRIBUTING.md` for more details on contributing and running test.
|
1062
|
+
Please see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for more details on contributing and running test.
|
955
1063
|
|
956
|
-
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/contributors)!
|
1064
|
+
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/graphs/contributors)!
|
957
1065
|
|
958
1066
|
License
|
959
1067
|
-------
|
960
1068
|
|
961
|
-
Paperclip is Copyright © 2008-
|
1069
|
+
Paperclip is Copyright © 2008-2017 thoughtbot, inc. It is free software, and may be
|
962
1070
|
redistributed under the terms specified in the MIT-LICENSE file.
|
963
1071
|
|
964
1072
|
About thoughtbot
|
965
1073
|
----------------
|
966
1074
|
|
967
|
-
![thoughtbot](
|
1075
|
+
![thoughtbot](http://presskit.thoughtbot.com/images/thoughtbot-logo-for-readmes.svg)
|
968
1076
|
|
969
1077
|
Paperclip is maintained and funded by thoughtbot.
|
970
1078
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|