paperclip 2.4.5 → 2.5.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.
- data/.gitignore +22 -0
- data/.travis.yml +13 -0
- data/Appraisals +14 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +5 -0
- data/NEWS +23 -0
- data/README.md +72 -42
- data/Rakefile +1 -46
- data/cucumber/paperclip_steps.rb +6 -0
- data/features/basic_integration.feature +46 -0
- data/features/rake_tasks.feature +63 -0
- data/features/step_definitions/attachment_steps.rb +65 -0
- data/features/step_definitions/html_steps.rb +15 -0
- data/features/step_definitions/rails_steps.rb +182 -0
- data/features/step_definitions/s3_steps.rb +14 -0
- data/features/step_definitions/web_steps.rb +209 -0
- data/features/support/env.rb +8 -0
- data/features/support/fakeweb.rb +3 -0
- data/features/support/fixtures/.boot_config.rb.swo +0 -0
- data/features/support/fixtures/boot_config.txt +15 -0
- data/features/support/fixtures/gemfile.txt +5 -0
- data/features/support/fixtures/preinitializer.txt +20 -0
- data/features/support/paths.rb +28 -0
- data/features/support/rails.rb +46 -0
- data/features/support/selectors.rb +19 -0
- data/gemfiles/rails2.gemfile +9 -0
- data/gemfiles/rails3.gemfile +9 -0
- data/gemfiles/rails3_1.gemfile +9 -0
- data/lib/paperclip.rb +26 -19
- data/lib/paperclip/attachment.rb +123 -109
- data/lib/paperclip/interpolations.rb +7 -4
- data/lib/paperclip/matchers.rb +33 -2
- data/lib/paperclip/missing_attachment_styles.rb +1 -1
- data/lib/paperclip/railtie.rb +5 -0
- data/lib/paperclip/schema.rb +39 -0
- data/lib/paperclip/storage/fog.rb +21 -10
- data/lib/paperclip/storage/s3.rb +107 -40
- data/lib/paperclip/style.rb +13 -5
- data/lib/paperclip/url_generator.rb +64 -0
- data/lib/paperclip/version.rb +1 -1
- data/lib/tasks/paperclip.rake +1 -1
- data/paperclip.gemspec +41 -0
- data/test/.gitignore +1 -0
- data/test/attachment_test.rb +155 -168
- data/test/fixtures/question?mark.png +0 -0
- data/test/helper.rb +24 -1
- data/test/interpolations_test.rb +16 -2
- data/test/paperclip_missing_attachment_styles_test.rb +16 -0
- data/test/paperclip_test.rb +72 -22
- data/test/schema_test.rb +98 -0
- data/test/storage/filesystem_test.rb +2 -2
- data/test/{fog_test.rb → storage/fog_test.rb} +35 -8
- data/test/storage/s3_live_test.rb +63 -13
- data/test/storage/s3_test.rb +394 -91
- data/test/style_test.rb +50 -21
- data/test/support/mock_attachment.rb +22 -0
- data/test/support/mock_interpolator.rb +24 -0
- data/test/support/mock_model.rb +2 -0
- data/test/support/mock_url_generator_builder.rb +27 -0
- data/test/url_generator_test.rb +187 -0
- metadata +307 -125
- data/lib/paperclip/options.rb +0 -78
- data/test/options_test.rb +0 -75
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
rvm:
|
2
|
+
- 1.8.7
|
3
|
+
- 1.9.2
|
4
|
+
- ree
|
5
|
+
- rbx-2.0
|
6
|
+
|
7
|
+
before_script: "sudo ntpdate -ub ntp.ubuntu.com pool.ntp.org; true"
|
8
|
+
script: "bundle exec rake clean test cucumber"
|
9
|
+
|
10
|
+
gemfile:
|
11
|
+
- gemfiles/rails2.gemfile
|
12
|
+
- gemfiles/rails3.gemfile
|
13
|
+
- gemfiles/rails3_1.gemfile
|
data/Appraisals
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
appraise "rails2" do
|
2
|
+
gem "rails", "~> 2.3.14"
|
3
|
+
gem "paperclip", :path => "../"
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "rails3" do
|
7
|
+
gem "rails", "~> 3.0.10"
|
8
|
+
gem "paperclip", :path => "../"
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "rails3_1" do
|
12
|
+
gem "rails", "~> 3.1.0"
|
13
|
+
gem "paperclip", :path => "../"
|
14
|
+
end
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
We love pull requests. Here's a quick guide:
|
2
|
+
|
3
|
+
1. Fork the repo.
|
4
|
+
|
5
|
+
2. Run the tests. We only take pull requests with passing tests, and it's great
|
6
|
+
to know that you have a clean slate: `bundle && rake`
|
7
|
+
|
8
|
+
3. Add a test for your change. Only refactoring and documentation changes
|
9
|
+
require no new tests. If you are adding functionality or fixing a bug, we need
|
10
|
+
a test!
|
11
|
+
|
12
|
+
4. Make the test pass.
|
13
|
+
|
14
|
+
5. Push to your fork and submit a pull request.
|
15
|
+
|
16
|
+
|
17
|
+
At this point you're waiting on us. We like to at least comment on, if not
|
18
|
+
accept, pull requests within three business days (and, typically, one business
|
19
|
+
day). We may suggest some changes or improvements or alternatives.
|
20
|
+
|
21
|
+
Some things that will increase the chance that your pull request is accepted,
|
22
|
+
taken straight from the Ruby on Rails guide:
|
23
|
+
|
24
|
+
* Use Rails idioms and helpers
|
25
|
+
* Include tests that fail without your code, and pass with it
|
26
|
+
* Update the documentation, the surrounding one, examples elsewhere, guides,
|
27
|
+
whatever is affected by your contribution
|
28
|
+
|
29
|
+
Syntax:
|
30
|
+
|
31
|
+
* Two spaces, no tabs.
|
32
|
+
* No trailing whitespace. Blank lines should not have any space.
|
33
|
+
* Prefer &&/|| over and/or.
|
34
|
+
* MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
35
|
+
* a = b and not a=b.
|
36
|
+
* Follow the conventions you see used in the source already.
|
37
|
+
|
38
|
+
And in case we didn't emphasize it enough: we love tests!
|
data/Gemfile
ADDED
data/NEWS
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
New in 2.5.0:
|
2
|
+
|
3
|
+
* Performance: Only connect to S3 when absolutely needed.
|
4
|
+
* Bug fix: STI with cached classes respect new options.
|
5
|
+
* Bug fix: conditional validations broke, and now work again.
|
6
|
+
* Feature: URL generation is now parameterized and can be changed with plugins or custom code.
|
7
|
+
* Feature: :convert_options and :source_file_options to control the ImageMagick processing.
|
8
|
+
* Performance: String geometry specifications now parse more quickly.
|
9
|
+
* Bug fix: Handle files with question marks in the filename.
|
10
|
+
* Bug fix: Don't raise an error when generating an expiring URL on an unassigned attachment.
|
11
|
+
* Bug fix: The rake task runs over all instances of an ActiveRecord model, ignoring default scopes.
|
12
|
+
* Feature: DB migration has_attached_file and drop_attached_file methods.
|
13
|
+
* Bug fix: Switch from AWS::S3 to AWS::SDK for the S3 backend.
|
14
|
+
* Bug fix: URL generator uses '?' in the URL unless it already appears and there is no prior '='.
|
15
|
+
* Bug fix: Always convert the content type to a string before stripping blanks.
|
16
|
+
* Feature: The :keep_old_files option preserves the files in storage even when the attachment is cleared or changed.
|
17
|
+
* Performance: Optimize Fog's public_url access by avoiding it when possible.
|
18
|
+
* Bug fix: Avoid a runtime error when generating the ID partition for an unsaved attachment.
|
19
|
+
* Performance: Do not calculate the fingerprint if it is never persisted.
|
20
|
+
* Bug fix: Process the :original style before all others, in case of a dependency.
|
21
|
+
* Feature: S3 headers can be set at runtime by passing a proc object as the value.
|
22
|
+
* Bug fix: Generating missing attachment styles for a model which has had its attachment changed should not raise.
|
23
|
+
* Bug fix: Do not collide with the built-in Ruby hashing method.
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
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)
|
5
|
+
|
6
|
+
Paperclip is intended as an easy file attachment library for Active Record. The
|
4
7
|
intent behind it was to keep setup as easy as possible and to treat files as
|
5
8
|
much like other attributes as possible. This means they aren't saved to their
|
6
9
|
final locations on disk, nor are they deleted if set to nil, until
|
@@ -12,11 +15,12 @@ packages). Attached files are saved to the filesystem and referenced in the
|
|
12
15
|
browser by an easily understandable specification, which has sensible and
|
13
16
|
useful defaults.
|
14
17
|
|
15
|
-
See the documentation for `has_attached_file` in Paperclip::ClassMethods for
|
18
|
+
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
16
19
|
more detailed options.
|
17
20
|
|
18
21
|
The complete [RDoc](http://rdoc.info/gems/paperclip) is online.
|
19
22
|
|
23
|
+
|
20
24
|
Requirements
|
21
25
|
------------
|
22
26
|
|
@@ -32,14 +36,16 @@ In development mode, you might add this line to `config/environments/development
|
|
32
36
|
|
33
37
|
Paperclip.options[:command_path] = "/usr/local/bin/"
|
34
38
|
|
35
|
-
If you're on Mac
|
39
|
+
If you're on Mac OS X, you'll want to run the following with Homebrew:
|
36
40
|
|
37
41
|
brew install imagemagick
|
38
42
|
|
39
|
-
If you are dealing with pdf uploads or running the test suite, also
|
43
|
+
If you are dealing with pdf uploads or running the test suite, you'll also need
|
44
|
+
GhostScript to be installed. On Mac OS X, you can also install that using Homebrew:
|
40
45
|
|
41
46
|
brew install gs
|
42
47
|
|
48
|
+
|
43
49
|
Installation
|
44
50
|
------------
|
45
51
|
|
@@ -49,9 +55,18 @@ well with gems.
|
|
49
55
|
|
50
56
|
Include the gem in your Gemfile:
|
51
57
|
|
52
|
-
gem "paperclip", "~> 2.
|
58
|
+
gem "paperclip", "~> 2.0"
|
59
|
+
|
60
|
+
Or, if you want to get the latest, you can get master from the main paperclip repository:
|
53
61
|
|
54
|
-
|
62
|
+
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
|
63
|
+
|
64
|
+
If you're trying to use features that don't seem to be in the latest released gem, but are
|
65
|
+
mentioned in this README, then you probably need to specify the master branch if you want to
|
66
|
+
use them. This README is probably ahead of the latest released version, if you're reading it
|
67
|
+
on GitHub.
|
68
|
+
|
69
|
+
Anyway, if you don't use Bundler (though you probably should, even in Rails 2), with config.gem
|
55
70
|
|
56
71
|
# In config/environment.rb
|
57
72
|
...
|
@@ -60,6 +75,7 @@ Or, if you don't use Bundler (though you probably should, even in Rails 2), with
|
|
60
75
|
config.gem "paperclip", :version => "~> 2.4"
|
61
76
|
...
|
62
77
|
end
|
78
|
+
|
63
79
|
For Non-Rails usage:
|
64
80
|
|
65
81
|
class ModuleName < ActiveRecord::Base
|
@@ -80,17 +96,13 @@ In your migrations:
|
|
80
96
|
|
81
97
|
class AddAvatarColumnsToUser < ActiveRecord::Migration
|
82
98
|
def self.up
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
add_column :users, :avatar_updated_at, :datetime
|
99
|
+
change_table :users do |t|
|
100
|
+
t.has_attached_file :avatar
|
101
|
+
end
|
87
102
|
end
|
88
103
|
|
89
104
|
def self.down
|
90
|
-
|
91
|
-
remove_column :users, :avatar_content_type
|
92
|
-
remove_column :users, :avatar_file_size
|
93
|
-
remove_column :users, :avatar_updated_at
|
105
|
+
drop_attached_file :users, :avatar
|
94
106
|
end
|
95
107
|
end
|
96
108
|
|
@@ -121,44 +133,60 @@ Usage
|
|
121
133
|
-----
|
122
134
|
|
123
135
|
The basics of paperclip are quite simple: Declare that your model has an
|
124
|
-
attachment with the has_attached_file method, and give it a name.
|
125
|
-
|
136
|
+
attachment with the `has_attached_file` method, and give it a name.
|
137
|
+
|
138
|
+
Paperclip will wrap up up to four attributes (all prefixed with that attachment's name,
|
126
139
|
so you can have multiple attachments per model if you wish) and give them a
|
127
|
-
friendly front end.
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
140
|
+
friendly front end. These attributes are:
|
141
|
+
|
142
|
+
* `<attachment>_file_name`
|
143
|
+
* `<attachment>_file_size`
|
144
|
+
* `<attachment>_content_type`
|
145
|
+
* `<attachment>_updated_at`
|
132
146
|
|
133
|
-
|
134
|
-
|
135
|
-
|
147
|
+
By default, only `<attachment>_file_name` is required for paperclip to operate.
|
148
|
+
You'll need to add `<attachment>_content_type` in case you want to use content type
|
149
|
+
validation.
|
150
|
+
|
151
|
+
More information about the options to `has_attached_file` is available in the
|
152
|
+
documentation of [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
153
|
+
|
154
|
+
For validations, attachments can be validated with these Paperclip's validation methods:
|
155
|
+
|
156
|
+
* `validates_attachment_presence`
|
157
|
+
* `validates_attachment_content_type`
|
158
|
+
* `validates_attachment_size`
|
136
159
|
|
137
160
|
Storage
|
138
161
|
-------
|
139
162
|
|
140
163
|
The files that are assigned as attachments are, by default, placed in the
|
141
|
-
directory specified by the
|
142
|
-
location is
|
164
|
+
directory specified by the `:path` option to `has_attached_file`. By default, this
|
165
|
+
location is `:rails_root/public/system/:attachment/:id/:style/:filename`. This
|
143
166
|
location was chosen because on standard Capistrano deployments, the
|
144
|
-
public/system directory is symlinked to the app's shared directory, meaning it
|
145
|
-
will survive between deployments. For example, using that
|
167
|
+
`public/system` directory is symlinked to the app's shared directory, meaning it
|
168
|
+
will survive between deployments. For example, using that `:path`, you may have a
|
146
169
|
file at
|
147
170
|
|
148
171
|
/data/myapp/releases/20081229172410/public/system/avatars/13/small/my_pic.png
|
149
172
|
|
150
|
-
|
173
|
+
_**NOTE**: This is a change from previous versions of Paperclip, but is overall a
|
151
174
|
safer choice for the default file store._
|
152
175
|
|
153
|
-
You may also choose to store your files using Amazon's S3 service.
|
154
|
-
|
155
|
-
|
176
|
+
You may also choose to store your files using Amazon's S3 service. To do so, include
|
177
|
+
the `aws-sdk` gem in your Gemfile:
|
178
|
+
|
179
|
+
gem 'aws-sdk'
|
180
|
+
|
181
|
+
And then you can specify using S3 from `has_attached_file`.
|
182
|
+
You can find more information about configuring and using S3 storage in
|
183
|
+
[the `Paperclip::Storage::S3` documentation](http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
156
184
|
|
157
185
|
Files on the local filesystem (and in the Rails app's public directory) will be
|
158
186
|
available to the internet at large. If you require access control, it's
|
159
187
|
possible to place your files in a different location. You will need to change
|
160
|
-
both the
|
161
|
-
to the public. Both
|
188
|
+
both the `:path` and `:url` options in order to make sure the files are unavailable
|
189
|
+
to the public. Both `:path` and `:url` allow the same set of interpolated
|
162
190
|
variables.
|
163
191
|
|
164
192
|
Post Processing
|
@@ -169,11 +197,11 @@ a set of styles for an attachment, by default it is expected that those
|
|
169
197
|
"styles" are actually "thumbnails". However, you can do much more than just
|
170
198
|
thumbnail images. By defining a subclass of Paperclip::Processor, you can
|
171
199
|
perform any processing you want on the files that are attached. Any file in
|
172
|
-
your Rails app's lib/
|
200
|
+
your Rails app's lib/paperclip\_processors directory is automatically loaded by
|
173
201
|
paperclip, allowing you to easily define custom processors. You can specify a
|
174
|
-
processor with the :processors option to
|
202
|
+
processor with the :processors option to has\_attached\_file:
|
175
203
|
|
176
|
-
|
204
|
+
has_attached\_file :scan, :styles => { :text => { :quality => :better } },
|
177
205
|
:processors => [:ocr]
|
178
206
|
|
179
207
|
This would load the hypothetical class Paperclip::Ocr, which would have the
|
@@ -188,7 +216,8 @@ geometry and a format, which the file will be converted to, like so:
|
|
188
216
|
|
189
217
|
This will convert the "thumb" style to a 32x32 square in png format, regardless
|
190
218
|
of what was uploaded. If the format is not specified, it is kept the same (i.e.
|
191
|
-
jpgs will remain jpgs).
|
219
|
+
jpgs will remain jpgs). For more information on the accepted style formats, see
|
220
|
+
[http://www.imagemagick.org/script/command-line-processing.php#geometry](here).
|
192
221
|
|
193
222
|
Multiple processors can be specified, and they will be invoked in the order
|
194
223
|
they are defined in the :processors array. Each successive processor will
|
@@ -222,8 +251,8 @@ are called before and after the processing of each attachment), and the
|
|
222
251
|
attachment-specific `before_<attachment>_post_process` and
|
223
252
|
`after_<attachment>_post_process`. The callbacks are intended to be as close to
|
224
253
|
normal ActiveRecord callbacks as possible, so if you return false (specifically
|
225
|
-
|
226
|
-
will halt. Returning false in an
|
254
|
+
\- returning nil is not the same) in a before\_ filter, the post processing step
|
255
|
+
will halt. Returning false in an after\_ filter will not halt anything, but you
|
227
256
|
can access the model and the attachment if necessary.
|
228
257
|
|
229
258
|
_NOTE: Post processing will not even *start* if the attachment is not valid
|
@@ -349,7 +378,7 @@ Now you don't have to remember to refresh thumbnails in production everytime you
|
|
349
378
|
Unfortunately it does not work with dynamic styles - it just ignores them.
|
350
379
|
|
351
380
|
If you already have working app and don't want `rake paperclip:refresh:missing_styles` to refresh old pictures, you need to tell
|
352
|
-
Paperclip about existing styles. Simply create
|
381
|
+
Paperclip about existing styles. Simply create paperclip\_attachments.yml file by hand. For example:
|
353
382
|
|
354
383
|
class User < ActiveRecord::Base
|
355
384
|
has_attached_file :avatar, :styles => {:thumb => 'x100', :croppable => '600x600>', :big => '1000x1000>'}
|
@@ -412,3 +441,4 @@ License
|
|
412
441
|
-------
|
413
442
|
|
414
443
|
Paperclip is Copyright © 2008-2011 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
444
|
+
|
data/Rakefile
CHANGED
@@ -1,15 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require 'bundler/setup'
|
1
|
+
require 'bundler/gem_tasks'
|
3
2
|
require 'appraisal'
|
4
|
-
|
5
|
-
require 'rake'
|
6
3
|
require 'rake/testtask'
|
7
|
-
require 'rdoc/task'
|
8
4
|
require 'cucumber/rake/task'
|
9
5
|
|
10
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
11
|
-
require 'paperclip'
|
12
|
-
|
13
6
|
desc 'Default: run unit tests.'
|
14
7
|
task :default => [:clean, 'appraisal:install', :all]
|
15
8
|
|
@@ -36,20 +29,6 @@ task :shell do |t|
|
|
36
29
|
exec 'irb -I lib/ -I lib/paperclip -r rubygems -r active_record -r tempfile -r init'
|
37
30
|
end
|
38
31
|
|
39
|
-
desc 'Generate documentation for the paperclip plugin.'
|
40
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
41
|
-
rdoc.rdoc_dir = 'doc'
|
42
|
-
rdoc.title = 'Paperclip'
|
43
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
44
|
-
rdoc.rdoc_files.include('README*')
|
45
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
-
end
|
47
|
-
|
48
|
-
desc 'Update documentation on website'
|
49
|
-
task :sync_docs => 'rdoc' do
|
50
|
-
`rsync -ave ssh doc/ dev@dev.thoughtbot.com:/home/dev/www/dev.thoughtbot.com/paperclip`
|
51
|
-
end
|
52
|
-
|
53
32
|
desc 'Clean up files.'
|
54
33
|
task :clean do |t|
|
55
34
|
FileUtils.rm_rf "doc"
|
@@ -60,27 +39,3 @@ task :clean do |t|
|
|
60
39
|
FileUtils.rm "test/paperclip.db" rescue nil
|
61
40
|
Dir.glob("paperclip-*.gem").each{|f| FileUtils.rm f }
|
62
41
|
end
|
63
|
-
|
64
|
-
desc 'Build the gemspec.'
|
65
|
-
task :gemspec do |t|
|
66
|
-
exec 'gem build paperclip.gemspec'
|
67
|
-
end
|
68
|
-
|
69
|
-
desc "Print a list of the files to be put into the gem"
|
70
|
-
task :manifest => :clean do
|
71
|
-
spec.files.each do |file|
|
72
|
-
puts file
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
desc "Generate a gemspec file for GitHub"
|
77
|
-
task :gemspec => :clean do
|
78
|
-
File.open("#{spec.name}.gemspec", 'w') do |f|
|
79
|
-
f.write spec.to_ruby
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
desc "Build the gem into the current directory"
|
84
|
-
task :gem => :gemspec do
|
85
|
-
`gem build #{spec.name}.gemspec`
|
86
|
-
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
When /^I attach an? "([^\"]*)" "([^\"]*)" file to an? "([^\"]*)" on S3$/ do |attachment, extension, model|
|
2
|
+
stub_paperclip_s3(model, attachment, extension)
|
3
|
+
attach_file attachment,
|
4
|
+
"features/support/paperclip/#{model.gsub(" ", "_").underscore}/#{attachment}.#{extension}"
|
5
|
+
end
|
6
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: Rails integration
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I generate a new rails application
|
5
|
+
And I run a rails generator to generate a "User" scaffold with "name:string"
|
6
|
+
And I run a paperclip generator to add a paperclip "attachment" to the "User" model
|
7
|
+
And I run a migration
|
8
|
+
And I update my new user view to include the file upload field
|
9
|
+
And I update my user view to include the attachment
|
10
|
+
|
11
|
+
Scenario: Filesystem integration test
|
12
|
+
Given I add this snippet to the User model:
|
13
|
+
"""
|
14
|
+
has_attached_file :attachment
|
15
|
+
"""
|
16
|
+
And I start the rails application
|
17
|
+
When I go to the new user page
|
18
|
+
And I fill in "Name" with "something"
|
19
|
+
And I attach the file "test/fixtures/5k.png" to "Attachment"
|
20
|
+
And I press "Submit"
|
21
|
+
Then I should see "Name: something"
|
22
|
+
And I should see an image with a path of "/system/attachments/1/original/5k.png"
|
23
|
+
And the file at "/system/attachments/1/original/5k.png" should be the same as "test/fixtures/5k.png"
|
24
|
+
|
25
|
+
Scenario: S3 Integration test
|
26
|
+
Given I add this snippet to the User model:
|
27
|
+
"""
|
28
|
+
has_attached_file :attachment,
|
29
|
+
:storage => :s3,
|
30
|
+
:path => "/:attachment/:id/:style/:filename",
|
31
|
+
:s3_credentials => Rails.root.join("config/s3.yml")
|
32
|
+
"""
|
33
|
+
And I write to "config/s3.yml" with:
|
34
|
+
"""
|
35
|
+
bucket: paperclip
|
36
|
+
access_key_id: access_key
|
37
|
+
secret_access_key: secret_key
|
38
|
+
"""
|
39
|
+
And I start the rails application
|
40
|
+
When I go to the new user page
|
41
|
+
And I fill in "Name" with "something"
|
42
|
+
And I attach the file "test/fixtures/5k.png" to "Attachment" on S3
|
43
|
+
And I press "Submit"
|
44
|
+
Then I should see "Name: something"
|
45
|
+
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png"
|
46
|
+
And the file at "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png" should be uploaded to S3
|