paperclip 2.8.0 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- data/.gitignore +1 -0
- data/.travis.yml +9 -7
- data/Appraisals +6 -12
- data/Gemfile +2 -0
- data/NEWS +24 -0
- data/README.md +53 -21
- data/Rakefile +7 -2
- data/UPGRADING +14 -0
- data/features/basic_integration.feature +8 -8
- data/features/rake_tasks.feature +1 -1
- data/features/step_definitions/attachment_steps.rb +11 -2
- data/features/step_definitions/rails_steps.rb +17 -79
- data/features/support/env.rb +3 -0
- data/features/support/file_helpers.rb +24 -0
- data/features/support/rails.rb +3 -3
- data/gemfiles/{rails3_1.gemfile → 3.0.gemfile} +3 -1
- data/gemfiles/{rails2.gemfile → 3.1.gemfile} +3 -1
- data/gemfiles/{rails3.gemfile → 3.2.gemfile} +3 -1
- data/images.rake +21 -0
- data/lib/generators/paperclip/paperclip_generator.rb +1 -2
- data/lib/paperclip.rb +48 -319
- data/lib/paperclip/attachment.rb +33 -81
- data/lib/paperclip/attachment_options.rb +0 -1
- data/lib/paperclip/callbacks.rb +30 -0
- data/lib/paperclip/errors.rb +27 -0
- data/lib/paperclip/geometry.rb +6 -4
- data/lib/paperclip/glue.rb +15 -0
- data/lib/paperclip/helpers.rb +71 -0
- data/lib/paperclip/instance_methods.rb +35 -0
- data/lib/paperclip/interpolations.rb +2 -2
- data/lib/paperclip/io_adapters/attachment_adapter.rb +62 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +81 -0
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -0
- data/lib/paperclip/io_adapters/nil_adapter.rb +34 -0
- data/lib/paperclip/io_adapters/registry.rb +32 -0
- data/lib/paperclip/io_adapters/stringio_adapter.rb +64 -0
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +63 -0
- data/lib/paperclip/locales/en.yml +17 -0
- data/lib/paperclip/logger.rb +21 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +1 -1
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +2 -2
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +7 -7
- data/lib/paperclip/processor.rb +32 -17
- data/lib/paperclip/railtie.rb +10 -15
- data/lib/paperclip/storage/filesystem.rb +5 -14
- data/lib/paperclip/storage/fog.rb +2 -21
- data/lib/paperclip/storage/s3.rb +12 -29
- data/lib/paperclip/tempfile.rb +41 -0
- data/lib/paperclip/thumbnail.rb +2 -3
- data/lib/paperclip/validators.rb +45 -0
- data/lib/paperclip/validators/attachment_content_type_validator.rb +47 -0
- data/lib/paperclip/validators/attachment_presence_validator.rb +26 -0
- data/lib/paperclip/validators/attachment_size_validator.rb +102 -0
- data/lib/paperclip/version.rb +1 -1
- data/lib/tasks/paperclip.rake +3 -11
- data/paperclip.gemspec +15 -5
- data/test/adapter_registry_test.rb +32 -0
- data/test/attachment_adapter_test.rb +48 -0
- data/test/attachment_options_test.rb +0 -13
- data/test/attachment_test.rb +27 -55
- data/test/file_adapter_test.rb +43 -0
- data/test/generator_test.rb +78 -0
- data/test/geometry_test.rb +5 -5
- data/test/helper.rb +9 -11
- data/test/identity_adapter_test.rb +8 -0
- data/test/integration_test.rb +39 -94
- data/test/interpolations_test.rb +8 -1
- data/test/matchers/validate_attachment_size_matcher_test.rb +16 -2
- data/test/nil_adapter_test.rb +25 -0
- data/test/paperclip_test.rb +30 -189
- data/test/storage/filesystem_test.rb +0 -14
- data/test/storage/fog_test.rb +0 -14
- data/test/storage/s3_live_test.rb +22 -9
- data/test/storage/s3_test.rb +70 -34
- data/test/stringio_adapter_test.rb +42 -0
- data/test/style_test.rb +10 -16
- data/test/thumbnail_test.rb +16 -10
- data/test/uploaded_file_adapter_test.rb +98 -0
- data/test/validators/attachment_content_type_validator_test.rb +140 -0
- data/test/validators/attachment_presence_validator_test.rb +85 -0
- data/test/validators/attachment_size_validator_test.rb +207 -0
- data/test/validators_test.rb +25 -0
- metadata +152 -30
- data/gemfiles/rails3_2.gemfile +0 -9
- data/generators/paperclip/USAGE +0 -5
- data/generators/paperclip/paperclip_generator.rb +0 -27
- data/generators/paperclip/templates/paperclip_migration.rb.erb +0 -19
- data/init.rb +0 -4
- data/lib/paperclip/callback_compatibility.rb +0 -61
- data/lib/paperclip/iostream.rb +0 -45
- data/lib/paperclip/upfile.rb +0 -64
- data/rails/init.rb +0 -2
- data/test/iostream_test.rb +0 -71
- data/test/upfile_test.rb +0 -53
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
rvm:
|
2
|
-
- 1.8.7
|
3
2
|
- 1.9.2
|
4
|
-
-
|
5
|
-
-
|
3
|
+
- 1.9.3
|
4
|
+
- jruby-19mode
|
6
5
|
|
7
6
|
before_script: "sudo ntpdate -ub ntp.ubuntu.com pool.ntp.org; true"
|
8
7
|
script: "bundle exec rake clean test cucumber"
|
9
8
|
|
10
9
|
gemfile:
|
11
|
-
- gemfiles/
|
12
|
-
- gemfiles/
|
13
|
-
- gemfiles/
|
14
|
-
|
10
|
+
- gemfiles/3.0.gemfile
|
11
|
+
- gemfiles/3.1.gemfile
|
12
|
+
- gemfiles/3.2.gemfile
|
13
|
+
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: jruby-19mode
|
data/Appraisals
CHANGED
@@ -1,20 +1,14 @@
|
|
1
|
-
appraise "
|
2
|
-
gem "rails", "~>
|
1
|
+
appraise "3.0" do
|
2
|
+
gem "rails", "~> 3.0.12"
|
3
3
|
gem "paperclip", :path => "../"
|
4
4
|
end
|
5
5
|
|
6
|
-
appraise "
|
7
|
-
gem "rails", "~> 3.
|
6
|
+
appraise "3.1" do
|
7
|
+
gem "rails", "~> 3.1.4"
|
8
8
|
gem "paperclip", :path => "../"
|
9
9
|
end
|
10
10
|
|
11
|
-
appraise "
|
12
|
-
gem "rails", "~> 3.
|
11
|
+
appraise "3.2" do
|
12
|
+
gem "rails", "~> 3.2.2"
|
13
13
|
gem "paperclip", :path => "../"
|
14
14
|
end
|
15
|
-
|
16
|
-
appraise "rails3_2" do
|
17
|
-
gem "rails", "~> 3.2.0"
|
18
|
-
gem "paperclip", :path => "../"
|
19
|
-
end
|
20
|
-
|
data/Gemfile
CHANGED
data/NEWS
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
New in 3.0.1
|
2
|
+
|
3
|
+
* Feature: Introduce Paperlip IO adapter.
|
4
|
+
* Bug fix: Regression in AttachmentContentTypeValidator has been fixed.
|
5
|
+
|
6
|
+
New in 3.0.0:
|
7
|
+
|
8
|
+
* API CHANGE: Paperclip now requires at least Ruby on Rails version 3.0.0
|
9
|
+
* API CHANGE: The default :url and :path have changed. The new scheme avoids
|
10
|
+
filesystem conflicts and scales to handle larger numbers of uploads.
|
11
|
+
|
12
|
+
The easiest way to upgrade is to add an explicit :url and :path to your
|
13
|
+
has_attached_file calls:
|
14
|
+
|
15
|
+
has_attached_file :avatar,
|
16
|
+
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
|
17
|
+
:url => "/system/:attachment/:id/:style/:filename"
|
18
|
+
|
19
|
+
* Feature: Adding Rails 3 style validators, and adding `validates_attachment` method as a shorthand.
|
20
|
+
* Bug fix: Paperclip's rake tasks now loading records in batch.
|
21
|
+
* Bug fix: Attachment style name with leading number now not raising an error.
|
22
|
+
* Bug fix: File given to S3 and Fog storage will now be rewinded after flush_write.
|
23
|
+
* Feature: You can now pass addional parameter to S3 expiring URL, such as :content_type.
|
24
|
+
|
1
25
|
New in 2.7.0:
|
2
26
|
|
3
27
|
* Bug fix: Checking the existence of a file on S3 handles all AWS errors.
|
data/README.md
CHANGED
@@ -24,7 +24,15 @@ The complete [RDoc](http://rdoc.info/gems/paperclip) is online.
|
|
24
24
|
Requirements
|
25
25
|
------------
|
26
26
|
|
27
|
-
|
27
|
+
### Ruby and Rails
|
28
|
+
|
29
|
+
Paperclip now requires Ruby version **>= 1.9.2** and Rails version **>= 3.0** (Only if you're going to use Paperclip with Ruby on Rails.)
|
30
|
+
|
31
|
+
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.
|
32
|
+
|
33
|
+
### Image Processor
|
34
|
+
|
35
|
+
[ImageMagick](http://www.imagemagick.org) must be installed and Paperclip must have access to it. To ensure
|
28
36
|
that it does, on your command line, run `which convert` (one of the ImageMagick
|
29
37
|
utilities). This will give you the path where that utility is installed. For
|
30
38
|
example, it might return `/usr/local/bin/convert`.
|
@@ -49,13 +57,15 @@ GhostScript to be installed. On Mac OS X, you can also install that using Homebr
|
|
49
57
|
Installation
|
50
58
|
------------
|
51
59
|
|
52
|
-
Paperclip is distributed as a gem, which is how it should be used in your app.
|
53
|
-
technically still installable as a plugin, but that's discouraged, as Rails plays
|
54
|
-
well with gems.
|
60
|
+
Paperclip is distributed as a gem, which is how it should be used in your app.
|
55
61
|
|
56
62
|
Include the gem in your Gemfile:
|
57
63
|
|
58
|
-
gem "paperclip", "~>
|
64
|
+
gem "paperclip", "~> 3.0"
|
65
|
+
|
66
|
+
If you're still using Rails 2.3.x, you should do this instead:
|
67
|
+
|
68
|
+
gem "paperclip", "~> 2.7"
|
59
69
|
|
60
70
|
Or, if you want to get the latest, you can get master from the main paperclip repository:
|
61
71
|
|
@@ -66,16 +76,6 @@ mentioned in this README, then you probably need to specify the master branch if
|
|
66
76
|
use them. This README is probably ahead of the latest released version, if you're reading it
|
67
77
|
on GitHub.
|
68
78
|
|
69
|
-
Anyway, if you don't use Bundler (though you probably should, even in Rails 2), with config.gem
|
70
|
-
|
71
|
-
# In config/environment.rb
|
72
|
-
...
|
73
|
-
Rails::Initializer.run do |config|
|
74
|
-
...
|
75
|
-
config.gem "paperclip", :version => "~> 2.4"
|
76
|
-
...
|
77
|
-
end
|
78
|
-
|
79
79
|
For Non-Rails usage:
|
80
80
|
|
81
81
|
class ModuleName < ActiveRecord::Base
|
@@ -106,6 +106,8 @@ In your migrations:
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
(Or you can use migration generator: `rails generate paperclip user avatar`)
|
110
|
+
|
109
111
|
In your edit and new views:
|
110
112
|
|
111
113
|
<%= form_for :user, @user, :url => user_path, :html => { :multipart => true } do |form| %>
|
@@ -151,12 +153,33 @@ validation.
|
|
151
153
|
More information about the options to `has_attached_file` is available in the
|
152
154
|
documentation of [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
153
155
|
|
154
|
-
For validations,
|
156
|
+
For validations, Paperclip introduces several validators to validate your attachment:
|
157
|
+
|
158
|
+
* `AttachmentContentTypeValidator`
|
159
|
+
* `AttachmentPresenceValidator`
|
160
|
+
* `AttachmentSizeValidator`
|
161
|
+
|
162
|
+
Example Usage:
|
163
|
+
|
164
|
+
validates :avatar, :attachment_presence => true
|
165
|
+
validates_with AttachmentPresenceValidator, :attributes => :avatar
|
166
|
+
|
167
|
+
Validators can also be defined using the old helper style:
|
155
168
|
|
156
169
|
* `validates_attachment_presence`
|
157
170
|
* `validates_attachment_content_type`
|
158
171
|
* `validates_attachment_size`
|
159
172
|
|
173
|
+
Example Usage:
|
174
|
+
|
175
|
+
validates_attachment_presence :avatar
|
176
|
+
|
177
|
+
Lastly, you can also define multiple validations on a single attachment using `validates_attachment`:
|
178
|
+
|
179
|
+
validates_attachment :avatar, :presence => true,
|
180
|
+
:content_type => { :content_type => "image/jpg" },
|
181
|
+
:size => { :in => 0..10.kilobytes }
|
182
|
+
|
160
183
|
Storage
|
161
184
|
-------
|
162
185
|
|
@@ -199,9 +222,9 @@ thumbnail images. By defining a subclass of Paperclip::Processor, you can
|
|
199
222
|
perform any processing you want on the files that are attached. Any file in
|
200
223
|
your Rails app's lib/paperclip\_processors directory is automatically loaded by
|
201
224
|
paperclip, allowing you to easily define custom processors. You can specify a
|
202
|
-
processor with the :processors option to
|
225
|
+
processor with the :processors option to `has_attached_file`:
|
203
226
|
|
204
|
-
|
227
|
+
has_attached_file :scan, :styles => { :text => { :quality => :better } },
|
205
228
|
:processors => [:ocr]
|
206
229
|
|
207
230
|
This would load the hypothetical class Paperclip::Ocr, which would have the
|
@@ -251,14 +274,24 @@ are called before and after the processing of each attachment), and the
|
|
251
274
|
attachment-specific `before_<attachment>_post_process` and
|
252
275
|
`after_<attachment>_post_process`. The callbacks are intended to be as close to
|
253
276
|
normal ActiveRecord callbacks as possible, so if you return false (specifically
|
254
|
-
\- returning nil is not the same) in a
|
255
|
-
will halt. Returning false in an
|
277
|
+
\- returning nil is not the same) in a `before_filter`, the post processing step
|
278
|
+
will halt. Returning false in an `after_filter` will not halt anything, but you
|
256
279
|
can access the model and the attachment if necessary.
|
257
280
|
|
258
281
|
_NOTE: Post processing will not even *start* if the attachment is not valid
|
259
282
|
according to the validations. Your callbacks and processors will *only* be
|
260
283
|
called with valid attachments._
|
261
284
|
|
285
|
+
class Message < ActiveRecord::Base
|
286
|
+
has_attached_file :asset, styles: {thumb: "100x100#"}
|
287
|
+
|
288
|
+
before_post_process :skip_for_audio
|
289
|
+
|
290
|
+
def skip_for_audio
|
291
|
+
! %w(audio/ogg application/ogg).include?(asset_content_type)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
262
295
|
URI Obfuscation
|
263
296
|
---------------
|
264
297
|
|
@@ -441,4 +474,3 @@ License
|
|
441
474
|
-------
|
442
475
|
|
443
476
|
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
@@ -4,11 +4,16 @@ require 'rake/testtask'
|
|
4
4
|
require 'cucumber/rake/task'
|
5
5
|
|
6
6
|
desc 'Default: run unit tests.'
|
7
|
-
task :default => [:clean,
|
7
|
+
task :default => [:clean, :all]
|
8
8
|
|
9
9
|
desc 'Test the paperclip plugin under all supported Rails versions.'
|
10
10
|
task :all do |t|
|
11
|
-
|
11
|
+
if ENV['BUNDLE_GEMFILE']
|
12
|
+
exec('rake test cucumber')
|
13
|
+
else
|
14
|
+
Rake::Task["appraisal:install"].execute
|
15
|
+
exec('rake appraisal test cucumber')
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
desc 'Test the paperclip plugin.'
|
data/UPGRADING
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
##################################################
|
2
|
+
# NOTE FOR UPGRADING FROM PRE-3.0 VERSION #
|
3
|
+
##################################################
|
4
|
+
|
5
|
+
Paperclip 3.0 introduces a non-backward compatible change in your attachment
|
6
|
+
path. This will help to prevent attachment name clashes when you have
|
7
|
+
multiple attachments with the same name. If you didn't alter your
|
8
|
+
attachment's path and are using Paperclip's default, you'll have to add
|
9
|
+
`:path` and `:url` to your `has_attached_file` definition. For example:
|
10
|
+
|
11
|
+
has_attached_file :avatar,
|
12
|
+
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
|
13
|
+
:url => "/system/:attachment/:id/:style/:filename"
|
14
|
+
|
@@ -11,8 +11,8 @@ Feature: Rails integration
|
|
11
11
|
Scenario: Filesystem integration test
|
12
12
|
Given I add this snippet to the User model:
|
13
13
|
"""
|
14
|
-
|
15
|
-
|
14
|
+
attr_accessible :name, :attachment
|
15
|
+
has_attached_file :attachment, :url => "/system/:attachment/:style/:filename"
|
16
16
|
"""
|
17
17
|
And I start the rails application
|
18
18
|
When I go to the new user page
|
@@ -20,17 +20,17 @@ Feature: Rails integration
|
|
20
20
|
And I attach the file "test/fixtures/5k.png" to "Attachment"
|
21
21
|
And I press "Submit"
|
22
22
|
Then I should see "Name: something"
|
23
|
-
And I should see an image with a path of "/system/attachments/
|
24
|
-
And the file at "/system/attachments/
|
23
|
+
And I should see an image with a path of "/system/attachments/original/5k.png"
|
24
|
+
And the file at "/system/attachments/original/5k.png" should be the same as "test/fixtures/5k.png"
|
25
25
|
|
26
26
|
Scenario: S3 Integration test
|
27
27
|
Given I add this snippet to the User model:
|
28
28
|
"""
|
29
|
+
attr_accessible :name, :attachment
|
29
30
|
has_attached_file :attachment,
|
30
31
|
:storage => :s3,
|
31
|
-
:path => "/:attachment/:
|
32
|
+
:path => "/:attachment/:style/:filename",
|
32
33
|
:s3_credentials => Rails.root.join("config/s3.yml")
|
33
|
-
attr_protected
|
34
34
|
"""
|
35
35
|
And I write to "config/s3.yml" with:
|
36
36
|
"""
|
@@ -44,5 +44,5 @@ Feature: Rails integration
|
|
44
44
|
And I attach the file "test/fixtures/5k.png" to "Attachment" on S3
|
45
45
|
And I press "Submit"
|
46
46
|
Then I should see "Name: something"
|
47
|
-
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/
|
48
|
-
And the file at "http://s3.amazonaws.com/paperclip/attachments/
|
47
|
+
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/original/5k.png"
|
48
|
+
And the file at "http://s3.amazonaws.com/paperclip/attachments/original/5k.png" should be uploaded to S3
|
data/features/rake_tasks.feature
CHANGED
@@ -5,9 +5,9 @@ Feature: Rake tasks
|
|
5
5
|
And I run a rails generator to generate a "User" scaffold with "name:string"
|
6
6
|
And I run a paperclip generator to add a paperclip "attachment" to the "User" model
|
7
7
|
And I run a migration
|
8
|
-
And I add the paperclip rake task to a Rails 2.3 application
|
9
8
|
And I add this snippet to the User model:
|
10
9
|
"""
|
10
|
+
attr_accessible :name, :attachment
|
11
11
|
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
|
12
12
|
"""
|
13
13
|
|
@@ -10,11 +10,13 @@ end
|
|
10
10
|
World(AttachmentHelpers)
|
11
11
|
|
12
12
|
When /^I modify my attachment definition to:$/ do |definition|
|
13
|
-
|
14
|
-
|
13
|
+
content = in_current_dir { File.read("app/models/user.rb") }
|
14
|
+
content.gsub!(/has_attached_file.+end/m, <<-FILE)
|
15
15
|
#{definition}
|
16
16
|
end
|
17
17
|
FILE
|
18
|
+
|
19
|
+
write_file "app/models/user.rb", content
|
18
20
|
in_current_dir { FileUtils.rm_rf ".rbx" }
|
19
21
|
end
|
20
22
|
|
@@ -51,6 +53,13 @@ Then /^the attachment should have the same content type as the fixture "([^"]*)"
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
56
|
+
Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
|
57
|
+
in_current_dir do
|
58
|
+
attachment_file_name = `bundle exec #{runner_command} "puts User.last.attachment_file_name"`.strip
|
59
|
+
attachment_file_name.should == File.name(fixture_path(filename)).to_s
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
54
63
|
Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
|
55
64
|
in_current_dir do
|
56
65
|
attachment_file_size = `bundle exec #{runner_command} "puts User.last.attachment_file_size"`.strip
|
@@ -1,13 +1,15 @@
|
|
1
1
|
Given /^I generate a new rails application$/ do
|
2
2
|
steps %{
|
3
|
-
When I run `bundle exec #{new_application_command} #{APP_NAME}`
|
3
|
+
When I run `bundle exec #{new_application_command} #{APP_NAME} --skip-bundle`
|
4
4
|
And I cd to "#{APP_NAME}"
|
5
5
|
And I turn off class caching
|
6
6
|
And I write to "Gemfile" with:
|
7
7
|
"""
|
8
8
|
source "http://rubygems.org"
|
9
9
|
gem "rails", "#{framework_version}"
|
10
|
-
gem "sqlite3"
|
10
|
+
gem "sqlite3", :platform => :ruby
|
11
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
12
|
+
gem "jruby-openssl", :platform => :jruby
|
11
13
|
gem "capybara"
|
12
14
|
gem "gherkin"
|
13
15
|
gem "aws-sdk"
|
@@ -31,33 +33,18 @@ Given /^I run a migration$/ do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
Given /^I update my new user view to include the file upload field$/ do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
<%=
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
}
|
47
|
-
else
|
48
|
-
steps %{
|
49
|
-
Given I overwrite "app/views/users/new.html.erb" with:
|
50
|
-
"""
|
51
|
-
<% form_for @user, :html => { :multipart => true } do |f| %>
|
52
|
-
<%= f.label :name %>
|
53
|
-
<%= f.text_field :name %>
|
54
|
-
<%= f.label :attachment %>
|
55
|
-
<%= f.file_field :attachment %>
|
56
|
-
<%= submit_tag "Submit" %>
|
57
|
-
<% end %>
|
58
|
-
"""
|
59
|
-
}
|
60
|
-
end
|
36
|
+
steps %{
|
37
|
+
Given I overwrite "app/views/users/new.html.erb" with:
|
38
|
+
"""
|
39
|
+
<%= form_for @user, :html => { :multipart => true } do |f| %>
|
40
|
+
<%= f.label :name %>
|
41
|
+
<%= f.text_field :name %>
|
42
|
+
<%= f.label :attachment %>
|
43
|
+
<%= f.file_field :attachment %>
|
44
|
+
<%= submit_tag "Submit" %>
|
45
|
+
<% end %>
|
46
|
+
"""
|
47
|
+
}
|
61
48
|
end
|
62
49
|
|
63
50
|
Given /^I update my user view to include the attachment$/ do
|
@@ -89,7 +76,7 @@ Given /^I reload my application$/ do
|
|
89
76
|
Rails::Application.reload!
|
90
77
|
end
|
91
78
|
|
92
|
-
When
|
79
|
+
When /^I turn off class caching$/ do
|
93
80
|
in_current_dir do
|
94
81
|
file = "config/environments/test.rb"
|
95
82
|
config = IO.read(file)
|
@@ -99,30 +86,6 @@ When %r{I turn off class caching} do
|
|
99
86
|
end
|
100
87
|
end
|
101
88
|
|
102
|
-
Given /^I update my application to use Bundler$/ do
|
103
|
-
if framework_version?("2")
|
104
|
-
boot_config_template = File.read('features/support/fixtures/boot_config.txt')
|
105
|
-
preinitializer_template = File.read('features/support/fixtures/preinitializer.txt')
|
106
|
-
gemfile_template = File.read('features/support/fixtures/gemfile.txt')
|
107
|
-
in_current_dir do
|
108
|
-
content = File.read("config/boot.rb").sub(/Rails\.boot!/, boot_config_template)
|
109
|
-
File.open("config/boot.rb", "w") { |file| file.write(content) }
|
110
|
-
File.open("config/preinitializer.rb", "w") { |file| file.write(preinitializer_template) }
|
111
|
-
File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
Given /^I add the paperclip rake task to a Rails 2.3 application$/ do
|
117
|
-
if framework_version?("2.3")
|
118
|
-
require 'fileutils'
|
119
|
-
source = File.expand_path('lib/tasks/paperclip.rake')
|
120
|
-
destination = in_current_dir { File.expand_path("lib/tasks") }
|
121
|
-
FileUtils.cp source, destination
|
122
|
-
append_to "Rakefile", "require 'paperclip'"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
89
|
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
|
127
90
|
expected = IO.read(path)
|
128
91
|
actual = if web_file.match %r{^https?://}
|
@@ -155,28 +118,3 @@ end
|
|
155
118
|
When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
|
156
119
|
comment_out_gem_in_gemfile gemname
|
157
120
|
end
|
158
|
-
|
159
|
-
module FileHelpers
|
160
|
-
def append_to(path, contents)
|
161
|
-
in_current_dir do
|
162
|
-
File.open(path, "a") do |file|
|
163
|
-
file.puts
|
164
|
-
file.puts contents
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def append_to_gemfile(contents)
|
170
|
-
append_to('Gemfile', contents)
|
171
|
-
end
|
172
|
-
|
173
|
-
def comment_out_gem_in_gemfile(gemname)
|
174
|
-
in_current_dir do
|
175
|
-
gemfile = File.read("Gemfile")
|
176
|
-
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
|
177
|
-
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
World(FileHelpers)
|