paperclip 4.2.4 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.hound.yml +1055 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +17 -15
- data/Appraisals +4 -16
- data/CONTRIBUTING.md +19 -8
- data/Gemfile +4 -8
- data/LICENSE +1 -1
- data/NEWS +105 -2
- data/README.md +327 -191
- data/RELEASING.md +17 -0
- data/Rakefile +2 -2
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +10 -6
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +33 -27
- data/features/step_definitions/html_steps.rb +2 -2
- data/features/step_definitions/rails_steps.rb +39 -38
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/step_definitions/web_steps.rb +1 -103
- data/features/support/env.rb +1 -0
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/4.2.gemfile +5 -7
- data/gemfiles/5.0.gemfile +17 -0
- data/lib/paperclip/attachment.rb +32 -20
- data/lib/paperclip/attachment_registry.rb +3 -2
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +27 -11
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/file_command_content_type_detector.rb +6 -8
- data/lib/paperclip/geometry_parser_factory.rb +1 -1
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +9 -2
- data/lib/paperclip/helpers.rb +14 -10
- data/lib/paperclip/interpolations/plural_cache.rb +6 -5
- data/lib/paperclip/interpolations.rb +19 -14
- data/lib/paperclip/io_adapters/abstract_adapter.rb +26 -3
- data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
- 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 +7 -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 +41 -19
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +2 -2
- data/lib/paperclip/processor.rb +5 -4
- data/lib/paperclip/rails_environment.rb +25 -0
- data/lib/paperclip/schema.rb +3 -9
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +30 -18
- data/lib/paperclip/storage/s3.rb +92 -65
- data/lib/paperclip/thumbnail.rb +16 -7
- data/lib/paperclip/url_generator.rb +16 -13
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +25 -12
- data/lib/tasks/paperclip.rake +33 -3
- data/paperclip.gemspec +17 -14
- data/spec/paperclip/attachment_definitions_spec.rb +1 -1
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_registry_spec.rb +84 -13
- data/spec/paperclip/attachment_spec.rb +130 -39
- data/spec/paperclip/content_type_detector_spec.rb +8 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -1
- data/spec/paperclip/geometry_spec.rb +1 -1
- data/spec/paperclip/glue_spec.rb +44 -0
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +4 -3
- data/spec/paperclip/interpolations_spec.rb +16 -13
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +47 -23
- 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 +6 -3
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +26 -6
- 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 +5 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +77 -7
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +28 -5
- data/spec/paperclip/paperclip_spec.rb +3 -28
- data/spec/paperclip/plural_cache_spec.rb +17 -16
- data/spec/paperclip/rails_environment_spec.rb +33 -0
- data/spec/paperclip/storage/fog_spec.rb +58 -3
- data/spec/paperclip/storage/s3_live_spec.rb +20 -14
- data/spec/paperclip/storage/s3_spec.rb +398 -213
- data/spec/paperclip/tempfile_factory_spec.rb +4 -0
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +51 -32
- data/spec/paperclip/url_generator_spec.rb +55 -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 +8 -1
- data/spec/support/assertions.rb +12 -1
- data/spec/support/conditional_filter_helper.rb +5 -0
- data/spec/support/fake_model.rb +4 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/matchers/have_column.rb +11 -2
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +9 -1
- data/spec/support/reporting.rb +11 -0
- metadata +105 -164
- data/RUNNING_TESTS.md +0 -4
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/3.2.gemfile +0 -19
- data/gemfiles/4.0.gemfile +0 -19
- data/gemfiles/4.1.gemfile +0 -19
- 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/support/mock_model.rb +0 -2
- data/spec/support/rails_helpers.rb +0 -7
data/RELEASING.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Releasing paperclip
|
2
|
+
|
3
|
+
1. Update `lib/paperclip/version.rb` file accordingly.
|
4
|
+
2. Update `NEWS` to reflect the changes since last release.
|
5
|
+
3. Commit changes. There shouldn’t be code changes, and thus CI doesn’t need to
|
6
|
+
run, you can then add “[ci skip]” to the commit message.
|
7
|
+
4. Tag the release: `git tag -m 'vVERSION' vVERSION`
|
8
|
+
5. Push changes: `git push --tags`
|
9
|
+
6. Build and publish the gem:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem build paperclip.gemspec
|
13
|
+
gem push paperclip-VERSION.gem
|
14
|
+
```
|
15
|
+
|
16
|
+
7. Announce the new release, making sure to say “thank you” to the contributors
|
17
|
+
who helped shape this version.
|
data/Rakefile
CHANGED
@@ -9,9 +9,9 @@ task :default => [:clean, :all]
|
|
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 spec cucumber')
|
12
|
+
exec('rake spec && cucumber')
|
13
13
|
else
|
14
|
-
exec("rm gemfiles/*.lock")
|
14
|
+
exec("rm -f gemfiles/*.lock")
|
15
15
|
Rake::Task["appraisal:gemfiles"].execute
|
16
16
|
Rake::Task["appraisal:install"].execute
|
17
17
|
exec('rake appraisal')
|
data/UPGRADING
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
##################################################
|
2
|
-
# NOTE FOR UPGRADING FROM
|
2
|
+
# NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER #
|
3
3
|
##################################################
|
4
4
|
|
5
|
-
Paperclip
|
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:
|
5
|
+
Paperclip is now compatible with aws-sdk >= 2.0.0.
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
:url => "/system/:attachment/:id/:style/:filename"
|
7
|
+
If you are using S3 storage, aws-sdk >= 2.0.0 requires you to make a few small
|
8
|
+
changes:
|
14
9
|
|
10
|
+
* You must set the `s3_region`
|
11
|
+
* If you are explicitly setting permissions anywhere, such as in an initializer,
|
12
|
+
note that the format of the permissions changed from using an underscore to
|
13
|
+
using a hyphen. For example, `:public_read` needs to be changed to
|
14
|
+
`public-read`.
|
15
|
+
|
16
|
+
For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
|
17
|
+
http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
|
@@ -12,17 +12,20 @@ Feature: Rails integration
|
|
12
12
|
Scenario: Configure defaults for all attachments through Railtie
|
13
13
|
Given I add this snippet to config/application.rb:
|
14
14
|
"""
|
15
|
-
config.paperclip_defaults = {
|
15
|
+
config.paperclip_defaults = {
|
16
|
+
:url => "/paperclip/custom/:attachment/:style/:filename",
|
17
|
+
:validate_media_type => false
|
18
|
+
}
|
16
19
|
"""
|
17
20
|
And I attach :attachment
|
18
21
|
And I start the rails application
|
19
22
|
When I go to the new user page
|
20
23
|
And I fill in "Name" with "something"
|
21
|
-
And I attach the file "spec/support/fixtures/
|
24
|
+
And I attach the file "spec/support/fixtures/animated.unknown" to "Attachment"
|
22
25
|
And I press "Submit"
|
23
26
|
Then I should see "Name: something"
|
24
|
-
And I should see an image with a path of "/paperclip/custom/attachments/original/
|
25
|
-
And the file at "/paperclip/custom/attachments/original/
|
27
|
+
And I should see an image with a path of "/paperclip/custom/attachments/original/animated.unknown"
|
28
|
+
And the file at "/paperclip/custom/attachments/original/animated.unknown" should be the same as "spec/support/fixtures/animated.unknown"
|
26
29
|
|
27
30
|
Scenario: Add custom processors
|
28
31
|
Given I add a "test" processor in "lib/paperclip"
|
@@ -66,6 +69,7 @@ Feature: Rails integration
|
|
66
69
|
bucket: paperclip
|
67
70
|
access_key_id: access_key
|
68
71
|
secret_access_key: secret_key
|
72
|
+
s3_region: us-west-2
|
69
73
|
"""
|
70
74
|
And I start the rails application
|
71
75
|
When I go to the new user page
|
@@ -73,5 +77,5 @@ Feature: Rails integration
|
|
73
77
|
And I attach the file "spec/support/fixtures/5k.png" to "Attachment" on S3
|
74
78
|
And I press "Submit"
|
75
79
|
Then I should see "Name: something"
|
76
|
-
And I should see an image with a path of "
|
77
|
-
And the file at "
|
80
|
+
And I should see an image with a path of "//s3.amazonaws.com/paperclip/attachments/original/5k.png"
|
81
|
+
And the file at "//s3.amazonaws.com/paperclip/attachments/original/5k.png" should be uploaded to S3
|
data/features/migration.feature
CHANGED
@@ -68,27 +68,3 @@ Feature: Migration
|
|
68
68
|
|
69
69
|
When I rollback a migration
|
70
70
|
Then I should not have attachment columns for "avatar"
|
71
|
-
|
72
|
-
Scenario: Rails 3.2 change method
|
73
|
-
Given I am using Rails newer than 3.1
|
74
|
-
When I write to "db/migrate/01_create_users.rb" with:
|
75
|
-
"""
|
76
|
-
class CreateUsers < ActiveRecord::Migration
|
77
|
-
def self.up
|
78
|
-
create_table :users
|
79
|
-
end
|
80
|
-
end
|
81
|
-
"""
|
82
|
-
When I write to "db/migrate/02_add_attachment_to_users.rb" with:
|
83
|
-
"""
|
84
|
-
class AddAttachmentToUsers < ActiveRecord::Migration
|
85
|
-
def change
|
86
|
-
add_attachment :users, :avatar
|
87
|
-
end
|
88
|
-
end
|
89
|
-
"""
|
90
|
-
And I run a migration
|
91
|
-
Then I should have attachment columns for "avatar"
|
92
|
-
|
93
|
-
When I rollback a migration
|
94
|
-
Then I should not have attachment columns for "avatar"
|
@@ -10,7 +10,7 @@ end
|
|
10
10
|
World(AttachmentHelpers)
|
11
11
|
|
12
12
|
When /^I modify my attachment definition to:$/ do |definition|
|
13
|
-
content =
|
13
|
+
content = cd(".") { File.read("app/models/user.rb") }
|
14
14
|
name = content[/has_attached_file :\w+/][/:\w+/]
|
15
15
|
content.gsub!(/has_attached_file.+end/m, <<-FILE)
|
16
16
|
#{definition}
|
@@ -19,28 +19,28 @@ When /^I modify my attachment definition to:$/ do |definition|
|
|
19
19
|
FILE
|
20
20
|
|
21
21
|
write_file "app/models/user.rb", content
|
22
|
-
|
22
|
+
cd(".") { FileUtils.rm_rf ".rbx" }
|
23
23
|
end
|
24
24
|
|
25
25
|
When /^I upload the fixture "([^"]*)"$/ do |filename|
|
26
|
-
run_simple %(bundle exec
|
26
|
+
run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
|
27
27
|
end
|
28
28
|
|
29
29
|
Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
|
30
|
-
|
30
|
+
cd(".") do
|
31
31
|
geometry = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
|
32
|
-
geometry.
|
32
|
+
expect(geometry).to eq(dimension)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
Then /^the attachment "([^"]*)" should exist$/ do |filename|
|
37
|
-
|
38
|
-
File.exist?(attachment_path(filename)).
|
37
|
+
cd(".") do
|
38
|
+
expect(File.exist?(attachment_path(filename))).to be true
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
|
43
|
-
|
43
|
+
cd(".") do
|
44
44
|
require 'fileutils'
|
45
45
|
FileUtils.rm_f attachment_path(attachment_filename)
|
46
46
|
FileUtils.cp fixture_path(fixture_filename), attachment_path(attachment_filename)
|
@@ -48,50 +48,56 @@ When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachme
|
|
48
48
|
end
|
49
49
|
|
50
50
|
Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
cd(".") do
|
52
|
+
begin
|
53
|
+
# Use mime/types/columnar if available, for reduced memory usage
|
54
|
+
require "mime/types/columnar"
|
55
|
+
rescue LoadError
|
56
|
+
require "mime/types"
|
57
|
+
end
|
58
|
+
|
59
|
+
attachment_content_type = `bundle exec rails runner "puts User.last.attachment_content_type"`.strip
|
60
|
+
expected = MIME::Types.type_for(filename).first.content_type
|
61
|
+
expect(attachment_content_type).to eq(expected)
|
55
62
|
end
|
56
63
|
end
|
57
64
|
|
58
65
|
Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
|
59
|
-
|
60
|
-
attachment_file_name = `bundle exec
|
61
|
-
attachment_file_name.
|
66
|
+
cd(".") do
|
67
|
+
attachment_file_name = `bundle exec rails runner "puts User.last.attachment_file_name"`.strip
|
68
|
+
expect(attachment_file_name).to eq(File.name(fixture_path(filename)).to_s)
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
65
72
|
Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
|
66
|
-
|
67
|
-
attachment_file_size = `bundle exec
|
68
|
-
attachment_file_size.
|
73
|
+
cd(".") do
|
74
|
+
attachment_file_size = `bundle exec rails runner "puts User.last.attachment_file_size"`.strip
|
75
|
+
expect(attachment_file_size).to eq(File.size(fixture_path(filename)).to_s)
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
72
79
|
Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist|
|
73
|
-
|
74
|
-
|
80
|
+
cd(".") do
|
81
|
+
expect(attachment_path(filename)).not_to be_an_existing_file
|
75
82
|
end
|
76
83
|
end
|
77
84
|
|
78
85
|
Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
|
79
|
-
|
80
|
-
columns = eval(`bundle exec
|
86
|
+
cd(".") do
|
87
|
+
columns = eval(`bundle exec rails runner "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
|
81
88
|
expect_columns = [
|
82
89
|
["#{attachment_name}_file_name", :string],
|
83
90
|
["#{attachment_name}_content_type", :string],
|
84
91
|
["#{attachment_name}_file_size", :integer],
|
85
92
|
["#{attachment_name}_updated_at", :datetime]
|
86
93
|
]
|
87
|
-
|
88
|
-
expect_columns.all?{ |column| columns.include? column }.should eq true
|
94
|
+
expect(columns).to include(*expect_columns)
|
89
95
|
end
|
90
96
|
end
|
91
97
|
|
92
98
|
Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
|
93
|
-
|
94
|
-
columns = eval(`bundle exec
|
99
|
+
cd(".") do
|
100
|
+
columns = eval(`bundle exec rails runner "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
|
95
101
|
expect_columns = [
|
96
102
|
["#{attachment_name}_file_name", :string],
|
97
103
|
["#{attachment_name}_content_type", :string],
|
@@ -99,6 +105,6 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
|
|
99
105
|
["#{attachment_name}_updated_at", :datetime]
|
100
106
|
]
|
101
107
|
|
102
|
-
|
108
|
+
expect(columns).not_to include(*expect_columns)
|
103
109
|
end
|
104
110
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
Then %r{I should see an image with a path of "([^"]*)"} do |path|
|
2
|
-
page.
|
2
|
+
expect(page).to have_css("img[src^='#{path}']")
|
3
3
|
end
|
4
4
|
|
5
5
|
Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
|
@@ -11,5 +11,5 @@ Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
|
|
11
11
|
page.body
|
12
12
|
end
|
13
13
|
actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
|
14
|
-
actual.
|
14
|
+
expect(actual).to eq(expected)
|
15
15
|
end
|
@@ -1,38 +1,37 @@
|
|
1
1
|
Given /^I generate a new rails application$/ do
|
2
2
|
steps %{
|
3
|
-
When I run `
|
3
|
+
When I successfully run `rails new #{APP_NAME} --skip-bundle`
|
4
4
|
And I cd to "#{APP_NAME}"
|
5
|
+
}
|
6
|
+
|
7
|
+
FileUtils.chdir("tmp/aruba/testapp/")
|
8
|
+
|
9
|
+
steps %{
|
5
10
|
And I turn off class caching
|
6
|
-
And I fix the application.rb for 3.0.12
|
7
11
|
And I write to "Gemfile" with:
|
8
12
|
"""
|
9
13
|
source "http://rubygems.org"
|
10
14
|
gem "rails", "#{framework_version}"
|
11
|
-
gem "sqlite3",
|
15
|
+
gem "sqlite3", :platform => [:ruby, :rbx]
|
12
16
|
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
13
17
|
gem "jruby-openssl", :platform => :jruby
|
14
18
|
gem "capybara"
|
15
19
|
gem "gherkin"
|
16
|
-
gem "aws-sdk"
|
20
|
+
gem "aws-sdk", "~> 2.0.0"
|
17
21
|
gem "racc", :platform => :rbx
|
18
22
|
gem "rubysl", :platform => :rbx
|
19
23
|
"""
|
20
24
|
And I remove turbolinks
|
25
|
+
And I comment out lines that contain "action_mailer" in "config/environments/*.rb"
|
21
26
|
And I empty the application.js file
|
22
27
|
And I configure the application to use "paperclip" from this project
|
23
28
|
}
|
24
|
-
end
|
25
29
|
|
26
|
-
|
27
|
-
in_current_dir do
|
28
|
-
File.open("config/application.rb", "a") do |f|
|
29
|
-
f << "ActionController::Base.config.relative_url_root = ''"
|
30
|
-
end
|
31
|
-
end
|
30
|
+
FileUtils.chdir("../../..")
|
32
31
|
end
|
33
32
|
|
34
33
|
Given "I allow the attachment to be submitted" do
|
35
|
-
|
34
|
+
cd(".") do
|
36
35
|
transform_file("app/controllers/users_controller.rb") do |content|
|
37
36
|
content.gsub("params.require(:user).permit(:name)",
|
38
37
|
"params.require(:user).permit!")
|
@@ -41,7 +40,7 @@ Given "I allow the attachment to be submitted" do
|
|
41
40
|
end
|
42
41
|
|
43
42
|
Given "I remove turbolinks" do
|
44
|
-
|
43
|
+
cd(".") do
|
45
44
|
transform_file("app/assets/javascripts/application.js") do |content|
|
46
45
|
content.gsub("//= require turbolinks", "")
|
47
46
|
end
|
@@ -51,6 +50,16 @@ Given "I remove turbolinks" do
|
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
53
|
+
Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|
|
54
|
+
cd(".") do
|
55
|
+
Dir.glob(glob).each do |file|
|
56
|
+
transform_file(file) do |content|
|
57
|
+
content.gsub(/^(.*?#{contains}.*?)$/) { |line| "# #{line}" }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
54
63
|
Given /^I attach :attachment$/ do
|
55
64
|
attach_attachment("attachment")
|
56
65
|
end
|
@@ -60,17 +69,13 @@ Given /^I attach :attachment with:$/ do |definition|
|
|
60
69
|
end
|
61
70
|
|
62
71
|
def attach_attachment(name, definition = nil)
|
63
|
-
snippet = ""
|
64
|
-
if using_protected_attributes?
|
65
|
-
snippet += "attr_accessible :name, :#{name}\n"
|
66
|
-
end
|
67
|
-
snippet += "has_attached_file :#{name}"
|
72
|
+
snippet = "has_attached_file :#{name}"
|
68
73
|
if definition
|
69
74
|
snippet += ", \n"
|
70
75
|
snippet += definition
|
71
76
|
end
|
72
77
|
snippet += "\ndo_not_validate_attachment_file_type :#{name}\n"
|
73
|
-
|
78
|
+
cd(".") do
|
74
79
|
transform_file("app/models/user.rb") do |content|
|
75
80
|
content.sub(/end\Z/, "#{snippet}\nend")
|
76
81
|
end
|
@@ -78,7 +83,7 @@ def attach_attachment(name, definition = nil)
|
|
78
83
|
end
|
79
84
|
|
80
85
|
Given "I empty the application.js file" do
|
81
|
-
|
86
|
+
cd(".") do
|
82
87
|
transform_file("app/assets/javascripts/application.js") do |content|
|
83
88
|
""
|
84
89
|
end
|
@@ -86,19 +91,19 @@ Given "I empty the application.js file" do
|
|
86
91
|
end
|
87
92
|
|
88
93
|
Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
|
89
|
-
step %[I successfully run `
|
94
|
+
step %[I successfully run `rails generate scaffold #{model_name} #{attributes}`]
|
90
95
|
end
|
91
96
|
|
92
97
|
Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
|
93
|
-
step %[I successfully run `
|
98
|
+
step %[I successfully run `rails generate paperclip #{model_name} #{attachment_name}`]
|
94
99
|
end
|
95
100
|
|
96
101
|
Given /^I run a migration$/ do
|
97
|
-
step %[I successfully run `
|
102
|
+
step %[I successfully run `rake db:migrate --trace`]
|
98
103
|
end
|
99
104
|
|
100
105
|
When /^I rollback a migration$/ do
|
101
|
-
step %[I successfully run `
|
106
|
+
step %[I successfully run `rake db:rollback STEPS=1 --trace`]
|
102
107
|
end
|
103
108
|
|
104
109
|
Given /^I update my new user view to include the file upload field$/ do
|
@@ -128,7 +133,7 @@ end
|
|
128
133
|
|
129
134
|
Given /^I add this snippet to the User model:$/ do |snippet|
|
130
135
|
file_name = "app/models/user.rb"
|
131
|
-
|
136
|
+
cd(".") do
|
132
137
|
content = File.read(file_name)
|
133
138
|
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
|
134
139
|
end
|
@@ -136,16 +141,18 @@ end
|
|
136
141
|
|
137
142
|
Given /^I add this snippet to config\/application.rb:$/ do |snippet|
|
138
143
|
file_name = "config/application.rb"
|
139
|
-
|
144
|
+
cd(".") do
|
140
145
|
content = File.read(file_name)
|
141
146
|
File.open(file_name, 'w') {|f| f << content.sub(/class Application < Rails::Application.*$/, "class Application < Rails::Application\n#{snippet}\n")}
|
142
147
|
end
|
143
148
|
end
|
144
149
|
|
145
150
|
Given /^I start the rails application$/ do
|
146
|
-
|
151
|
+
cd(".") do
|
152
|
+
require "rails"
|
147
153
|
require "./config/environment"
|
148
|
-
require "capybara
|
154
|
+
require "capybara"
|
155
|
+
Capybara.app = Rails.application
|
149
156
|
end
|
150
157
|
end
|
151
158
|
|
@@ -154,7 +161,7 @@ Given /^I reload my application$/ do
|
|
154
161
|
end
|
155
162
|
|
156
163
|
When /^I turn off class caching$/ do
|
157
|
-
|
164
|
+
cd(".") do
|
158
165
|
file = "config/environments/test.rb"
|
159
166
|
config = IO.read(file)
|
160
167
|
config.gsub!(%r{^\s*config.cache_classes.*$},
|
@@ -166,12 +173,12 @@ end
|
|
166
173
|
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
|
167
174
|
expected = IO.read(path)
|
168
175
|
actual = read_from_web(web_file)
|
169
|
-
actual.
|
176
|
+
expect(actual).to eq(expected)
|
170
177
|
end
|
171
178
|
|
172
179
|
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
|
173
180
|
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
|
174
|
-
steps %{And I run `bundle install --local`}
|
181
|
+
steps %{And I successfully run `bundle install --local`}
|
175
182
|
end
|
176
183
|
|
177
184
|
When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
|
@@ -190,15 +197,9 @@ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
|
|
190
197
|
comment_out_gem_in_gemfile gemname
|
191
198
|
end
|
192
199
|
|
193
|
-
Given /^I am using Rails newer than ([\d\.]+)$/ do |version|
|
194
|
-
if framework_version < version
|
195
|
-
pending "Not supported in Rails < #{version}"
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
200
|
Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
|
200
201
|
filename = "#{directory}/#{processor}.rb"
|
201
|
-
|
202
|
+
cd(".") do
|
202
203
|
FileUtils.mkdir_p directory
|
203
204
|
File.open(filename, "w") do |f|
|
204
205
|
f.write(<<-CLASS)
|
@@ -1,11 +1,11 @@
|
|
1
1
|
When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
|
2
2
|
definition = Paperclip::AttachmentRegistry.definitions_for(User)[field.downcase.to_sym]
|
3
|
-
path = "https://paperclip.s3.amazonaws.com#{definition[:path]}"
|
3
|
+
path = "https://paperclip.s3.us-west-2.amazonaws.com#{definition[:path]}"
|
4
4
|
path.gsub!(':filename', File.basename(file_path))
|
5
5
|
path.gsub!(/:([^\/\.]+)/) do |match|
|
6
6
|
"([^\/\.]+)"
|
7
7
|
end
|
8
|
-
FakeWeb.register_uri(:put, Regexp.new(path), :body => "
|
8
|
+
FakeWeb.register_uri(:put, Regexp.new(path), :body => "<xml></xml>")
|
9
9
|
step "I attach the file \"#{file_path}\" to \"#{field}\""
|
10
10
|
end
|
11
11
|
|
@@ -103,107 +103,5 @@ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
|
|
103
103
|
end
|
104
104
|
|
105
105
|
Then /^(?:|I )should see "([^"]*)"$/ do |text|
|
106
|
-
|
107
|
-
page.should have_content(text)
|
108
|
-
else
|
109
|
-
assert page.has_content?(text)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
|
114
|
-
regexp = Regexp.new(regexp)
|
115
|
-
|
116
|
-
if page.respond_to? :should
|
117
|
-
page.should have_xpath('//*', :text => regexp)
|
118
|
-
else
|
119
|
-
assert page.has_xpath?('//*', :text => regexp)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
|
124
|
-
if page.respond_to? :should
|
125
|
-
page.should have_no_content(text)
|
126
|
-
else
|
127
|
-
assert page.has_no_content?(text)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
|
132
|
-
regexp = Regexp.new(regexp)
|
133
|
-
|
134
|
-
if page.respond_to? :should
|
135
|
-
page.should have_no_xpath('//*', :text => regexp)
|
136
|
-
else
|
137
|
-
assert page.has_no_xpath?('//*', :text => regexp)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
|
142
|
-
with_scope(parent) do
|
143
|
-
field = find_field(field)
|
144
|
-
if field.value.respond_to? :should
|
145
|
-
field.value.should =~ /#{value}/
|
146
|
-
else
|
147
|
-
assert_match(/#{value}/, field.value)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
|
153
|
-
with_scope(parent) do
|
154
|
-
field = find_field(field)
|
155
|
-
if field.value.respond_to? :should_not
|
156
|
-
field.value.should_not =~ /#{value}/
|
157
|
-
else
|
158
|
-
assert_no_match(/#{value}/, field.value)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
|
164
|
-
with_scope(parent) do
|
165
|
-
field_checked = find_field(label)['checked']
|
166
|
-
if field_checked.respond_to? :should
|
167
|
-
field_checked.should eq true
|
168
|
-
else
|
169
|
-
assert field_checked
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
|
175
|
-
with_scope(parent) do
|
176
|
-
field_checked = find_field(label)['checked']
|
177
|
-
if field_checked.respond_to? :should
|
178
|
-
field_checked.should eq false
|
179
|
-
else
|
180
|
-
assert !field_checked
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
186
|
-
current_path = URI.parse(current_url).path
|
187
|
-
if current_path.respond_to? :should
|
188
|
-
current_path.should == path_to(page_name)
|
189
|
-
else
|
190
|
-
assert_equal path_to(page_name), current_path
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
195
|
-
query = URI.parse(current_url).query
|
196
|
-
actual_params = query ? CGI.parse(query) : {}
|
197
|
-
expected_params = {}
|
198
|
-
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
199
|
-
|
200
|
-
if actual_params.respond_to? :should
|
201
|
-
actual_params.should == expected_params
|
202
|
-
else
|
203
|
-
assert_equal expected_params, actual_params
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
Then /^show me the page$/ do
|
208
|
-
save_and_open_page
|
106
|
+
expect(page).to have_content(text)
|
209
107
|
end
|
data/features/support/env.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module FileHelpers
|
2
2
|
def append_to(path, contents)
|
3
|
-
|
3
|
+
cd(".") do
|
4
4
|
File.open(path, "a") do |file|
|
5
5
|
file.puts
|
6
6
|
file.puts contents
|
@@ -13,7 +13,7 @@ module FileHelpers
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def comment_out_gem_in_gemfile(gemname)
|
16
|
-
|
16
|
+
cd(".") do
|
17
17
|
gemfile = File.read("Gemfile")
|
18
18
|
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
|
19
19
|
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
|
data/features/support/paths.rb
CHANGED
@@ -17,7 +17,7 @@ module NavigationHelpers
|
|
17
17
|
page_name =~ /the (.*) page/
|
18
18
|
path_components = $1.split(/\s+/)
|
19
19
|
self.send(path_components.push('path').join('_').to_sym)
|
20
|
-
rescue Object
|
20
|
+
rescue Object
|
21
21
|
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
22
22
|
"Now, go and add a mapping in #{__FILE__}"
|
23
23
|
end
|
data/features/support/rails.rb
CHANGED
@@ -35,29 +35,5 @@ module RailsCommandHelpers
|
|
35
35
|
def framework_major_version
|
36
36
|
framework_version.split(".").first.to_i
|
37
37
|
end
|
38
|
-
|
39
|
-
def using_protected_attributes?
|
40
|
-
framework_major_version < 4
|
41
|
-
end
|
42
|
-
|
43
|
-
def new_application_command
|
44
|
-
"rails new"
|
45
|
-
end
|
46
|
-
|
47
|
-
def generator_command
|
48
|
-
if framework_major_version >= 4
|
49
|
-
"rails generate"
|
50
|
-
else
|
51
|
-
"script/rails generate"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def runner_command
|
56
|
-
if framework_major_version >= 4
|
57
|
-
"rails runner"
|
58
|
-
else
|
59
|
-
"script/rails runner"
|
60
|
-
end
|
61
|
-
end
|
62
38
|
end
|
63
39
|
World(RailsCommandHelpers)
|