paperclip 3.5.4 → 5.3.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/.gitignore +0 -6
- data/.hound.yml +1055 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +17 -20
- data/Appraisals +4 -16
- data/CONTRIBUTING.md +29 -13
- data/Gemfile +11 -3
- data/LICENSE +1 -3
- data/NEWS +241 -49
- data/README.md +471 -166
- data/RELEASING.md +17 -0
- data/Rakefile +6 -8
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +27 -8
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +36 -28
- data/features/step_definitions/html_steps.rb +2 -2
- data/features/step_definitions/rails_steps.rb +68 -37
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/step_definitions/web_steps.rb +1 -103
- data/features/support/env.rb +3 -2
- data/features/support/file_helpers.rb +2 -2
- data/features/support/fixtures/gemfile.txt +1 -1
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +2 -25
- data/gemfiles/4.2.gemfile +17 -0
- data/gemfiles/5.0.gemfile +17 -0
- data/lib/generators/paperclip/paperclip_generator.rb +9 -3
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +2 -2
- data/lib/paperclip/attachment.rb +151 -46
- data/lib/paperclip/attachment_registry.rb +3 -2
- data/lib/paperclip/callbacks.rb +13 -1
- data/lib/paperclip/content_type_detector.rb +26 -22
- data/lib/paperclip/errors.rb +8 -1
- data/lib/paperclip/file_command_content_type_detector.rb +6 -8
- data/lib/paperclip/geometry_detector_factory.rb +5 -3
- data/lib/paperclip/geometry_parser_factory.rb +1 -1
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +17 -1
- data/lib/paperclip/helpers.rb +15 -11
- data/lib/paperclip/interpolations/plural_cache.rb +6 -5
- data/lib/paperclip/interpolations.rb +26 -13
- data/lib/paperclip/io_adapters/abstract_adapter.rb +32 -4
- data/lib/paperclip/io_adapters/attachment_adapter.rb +13 -8
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +11 -16
- 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 +15 -16
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
- data/lib/paperclip/io_adapters/uri_adapter.rb +41 -19
- data/lib/paperclip/locales/en.yml +1 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +2 -1
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +2 -1
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
- data/lib/paperclip/media_type_spoof_detector.rb +90 -0
- data/lib/paperclip/processor.rb +5 -41
- data/lib/paperclip/processor_helpers.rb +50 -0
- data/lib/paperclip/rails_environment.rb +25 -0
- data/lib/paperclip/schema.rb +9 -7
- data/lib/paperclip/storage/filesystem.rb +14 -3
- data/lib/paperclip/storage/fog.rb +37 -19
- data/lib/paperclip/storage/s3.rb +129 -69
- data/lib/paperclip/style.rb +8 -2
- data/lib/paperclip/tempfile_factory.rb +5 -1
- data/lib/paperclip/thumbnail.rb +30 -18
- data/lib/paperclip/url_generator.rb +26 -14
- data/lib/paperclip/validators/attachment_content_type_validator.rb +4 -0
- data/lib/paperclip/validators/attachment_file_name_validator.rb +80 -0
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +29 -0
- data/lib/paperclip/validators/attachment_presence_validator.rb +4 -0
- data/lib/paperclip/validators/attachment_size_validator.rb +5 -3
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +27 -0
- data/lib/paperclip/validators.rb +11 -4
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +30 -11
- data/lib/tasks/paperclip.rake +34 -5
- data/paperclip.gemspec +21 -16
- data/shoulda_macros/paperclip.rb +0 -1
- data/spec/paperclip/attachment_definitions_spec.rb +13 -0
- data/{test/attachment_processing_test.rb → spec/paperclip/attachment_processing_spec.rb} +17 -20
- data/spec/paperclip/attachment_registry_spec.rb +158 -0
- data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +502 -407
- data/{test/content_type_detector_test.rb → spec/paperclip/content_type_detector_spec.rb} +17 -20
- data/spec/paperclip/file_command_content_type_detector_spec.rb +40 -0
- data/spec/paperclip/filename_cleaner_spec.rb +14 -0
- data/spec/paperclip/geometry_detector_spec.rb +39 -0
- data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
- data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +50 -52
- data/spec/paperclip/glue_spec.rb +44 -0
- data/spec/paperclip/has_attached_file_spec.rb +158 -0
- data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +137 -128
- data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +70 -46
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +132 -0
- data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +33 -32
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +89 -0
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
- data/{test/io_adapters/file_adapter_test.rb → spec/paperclip/io_adapters/file_adapter_spec.rb} +38 -42
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +121 -0
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
- data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
- data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +12 -9
- data/{test/io_adapters/stringio_adapter_test.rb → spec/paperclip/io_adapters/stringio_adapter_spec.rb} +21 -18
- data/{test/io_adapters/uploaded_file_adapter_test.rb → spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb} +46 -46
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +172 -0
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +109 -0
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +94 -0
- data/spec/paperclip/meta_class_spec.rb +30 -0
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
- data/spec/paperclip/paperclip_spec.rb +192 -0
- data/spec/paperclip/plural_cache_spec.rb +37 -0
- data/spec/paperclip/processor_helpers_spec.rb +57 -0
- data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +7 -7
- data/spec/paperclip/rails_environment_spec.rb +33 -0
- data/{test/rake_test.rb → spec/paperclip/rake_spec.rb} +15 -15
- data/spec/paperclip/schema_spec.rb +248 -0
- data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
- data/spec/paperclip/storage/fog_spec.rb +566 -0
- data/spec/paperclip/storage/s3_live_spec.rb +188 -0
- data/spec/paperclip/storage/s3_spec.rb +1693 -0
- data/spec/paperclip/style_spec.rb +255 -0
- data/spec/paperclip/tempfile_factory_spec.rb +33 -0
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +153 -134
- data/spec/paperclip/url_generator_spec.rb +222 -0
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
- data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +20 -20
- data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +77 -64
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +52 -0
- data/spec/paperclip/validators_spec.rb +164 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/support/assertions.rb +82 -0
- data/spec/support/conditional_filter_helper.rb +5 -0
- data/spec/support/fake_model.rb +25 -0
- data/spec/support/fake_rails.rb +12 -0
- data/spec/support/fixtures/empty.html +1 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/matchers/accept.rb +5 -0
- data/spec/support/matchers/exist.rb +5 -0
- data/spec/support/matchers/have_column.rb +23 -0
- data/{test → spec}/support/mock_attachment.rb +2 -0
- data/{test → spec}/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +68 -0
- data/spec/support/reporting.rb +11 -0
- data/spec/support/test_data.rb +13 -0
- data/spec/support/version_helper.rb +9 -0
- metadata +348 -225
- data/RUNNING_TESTS.md +0 -4
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/3.0.gemfile +0 -11
- data/gemfiles/3.1.gemfile +0 -11
- data/gemfiles/3.2.gemfile +0 -11
- data/gemfiles/4.0.gemfile +0 -11
- data/test/attachment_definitions_test.rb +0 -12
- data/test/attachment_registry_test.rb +0 -88
- data/test/file_command_content_type_detector_test.rb +0 -27
- data/test/filename_cleaner_test.rb +0 -14
- data/test/generator_test.rb +0 -84
- data/test/geometry_detector_test.rb +0 -24
- data/test/has_attached_file_test.rb +0 -125
- data/test/helper.rb +0 -232
- data/test/io_adapters/abstract_adapter_test.rb +0 -58
- data/test/io_adapters/data_uri_adapter_test.rb +0 -74
- data/test/io_adapters/empty_string_adapter_test.rb +0 -18
- data/test/io_adapters/http_url_proxy_adapter_test.rb +0 -102
- data/test/io_adapters/identity_adapter_test.rb +0 -8
- data/test/io_adapters/uri_adapter_test.rb +0 -102
- data/test/matchers/have_attached_file_matcher_test.rb +0 -24
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -110
- data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -69
- data/test/matchers/validate_attachment_size_matcher_test.rb +0 -86
- data/test/meta_class_test.rb +0 -32
- data/test/paperclip_missing_attachment_styles_test.rb +0 -90
- data/test/paperclip_test.rb +0 -217
- data/test/plural_cache_test.rb +0 -36
- data/test/schema_test.rb +0 -200
- data/test/storage/fog_test.rb +0 -473
- data/test/storage/s3_live_test.rb +0 -179
- data/test/storage/s3_test.rb +0 -1356
- data/test/style_test.rb +0 -213
- data/test/support/mock_model.rb +0 -2
- data/test/tempfile_factory_test.rb +0 -17
- data/test/url_generator_test.rb +0 -187
- data/test/validators/attachment_content_type_validator_test.rb +0 -324
- data/test/validators_test.rb +0 -61
- /data/{test → spec}/database.yml +0 -0
- /data/{test → spec/support}/fixtures/12k.png +0 -0
- /data/{test → spec/support}/fixtures/50x50.png +0 -0
- /data/{test → spec/support}/fixtures/5k.png +0 -0
- /data/{test → spec/support}/fixtures/animated +0 -0
- /data/{test → spec/support}/fixtures/animated.gif +0 -0
- /data/{test → spec/support}/fixtures/animated.unknown +0 -0
- /data/{test → spec/support}/fixtures/bad.png +0 -0
- /data/{test → spec/support}/fixtures/fog.yml +0 -0
- /data/{test → spec/support}/fixtures/rotated.jpg +0 -0
- /data/{test → spec/support}/fixtures/s3.yml +0 -0
- /data/{test → spec/support}/fixtures/spaced file.png +0 -0
- /data/{test → spec/support}/fixtures/text.txt +0 -0
- /data/{test → spec/support}/fixtures/twopage.pdf +0 -0
- /data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
- /data/{test → spec}/support/mock_interpolator.rb +0 -0
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
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'appraisal'
|
3
|
-
require '
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
require 'cucumber/rake/task'
|
5
5
|
|
6
6
|
desc 'Default: run unit tests.'
|
@@ -9,19 +9,17 @@ 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
|
12
|
+
exec('rake spec && cucumber')
|
13
13
|
else
|
14
|
+
exec("rm -f gemfiles/*.lock")
|
15
|
+
Rake::Task["appraisal:gemfiles"].execute
|
14
16
|
Rake::Task["appraisal:install"].execute
|
15
|
-
exec('rake appraisal
|
17
|
+
exec('rake appraisal')
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
desc 'Test the paperclip plugin.'
|
20
|
-
|
21
|
-
t.libs << 'lib' << 'profile'
|
22
|
-
t.pattern = 'test/**/*_test.rb'
|
23
|
-
t.verbose = true
|
24
|
-
end
|
22
|
+
RSpec::Core::RakeTask.new(:spec)
|
25
23
|
|
26
24
|
desc 'Run integration test'
|
27
25
|
Cucumber::Rake::Task.new do |t|
|
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,35 @@ 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 "
|
24
|
+
And I attach the file "spec/support/fixtures/animated.unknown" to "Attachment"
|
25
|
+
And I press "Submit"
|
26
|
+
Then I should see "Name: something"
|
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"
|
29
|
+
|
30
|
+
Scenario: Add custom processors
|
31
|
+
Given I add a "test" processor in "lib/paperclip"
|
32
|
+
And I add a "cool" processor in "lib/paperclip_processors"
|
33
|
+
And I attach :attachment with:
|
34
|
+
"""
|
35
|
+
styles: { original: {} }, processors: [:test, :cool]
|
36
|
+
"""
|
37
|
+
And I start the rails application
|
38
|
+
When I go to the new user page
|
39
|
+
And I fill in "Name" with "something"
|
40
|
+
And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
|
22
41
|
And I press "Submit"
|
23
42
|
Then I should see "Name: something"
|
24
43
|
And I should see an image with a path of "/paperclip/custom/attachments/original/5k.png"
|
25
|
-
And the file at "/paperclip/custom/attachments/original/5k.png" should be the same as "test/fixtures/5k.png"
|
26
44
|
|
27
45
|
Scenario: Filesystem integration test
|
28
46
|
Given I attach :attachment with:
|
@@ -32,11 +50,11 @@ Feature: Rails integration
|
|
32
50
|
And I start the rails application
|
33
51
|
When I go to the new user page
|
34
52
|
And I fill in "Name" with "something"
|
35
|
-
And I attach the file "
|
53
|
+
And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
|
36
54
|
And I press "Submit"
|
37
55
|
Then I should see "Name: something"
|
38
56
|
And I should see an image with a path of "/system/attachments/original/5k.png"
|
39
|
-
And the file at "/system/attachments/original/5k.png" should be the same as "
|
57
|
+
And the file at "/system/attachments/original/5k.png" should be the same as "spec/support/fixtures/5k.png"
|
40
58
|
|
41
59
|
Scenario: S3 Integration test
|
42
60
|
Given I attach :attachment with:
|
@@ -51,12 +69,13 @@ Feature: Rails integration
|
|
51
69
|
bucket: paperclip
|
52
70
|
access_key_id: access_key
|
53
71
|
secret_access_key: secret_key
|
72
|
+
s3_region: us-west-2
|
54
73
|
"""
|
55
74
|
And I start the rails application
|
56
75
|
When I go to the new user page
|
57
76
|
And I fill in "Name" with "something"
|
58
|
-
And I attach the file "
|
77
|
+
And I attach the file "spec/support/fixtures/5k.png" to "Attachment" on S3
|
59
78
|
And I press "Submit"
|
60
79
|
Then I should see "Name: something"
|
61
|
-
And I should see an image with a path of "
|
62
|
-
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"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module AttachmentHelpers
|
2
2
|
def fixture_path(filename)
|
3
|
-
File.expand_path("#{PROJECT_ROOT}/
|
3
|
+
File.expand_path("#{PROJECT_ROOT}/spec/support/fixtures/#{filename}")
|
4
4
|
end
|
5
5
|
|
6
6
|
def attachment_path(filename)
|
@@ -10,35 +10,37 @@ 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
|
+
name = content[/has_attached_file :\w+/][/:\w+/]
|
14
15
|
content.gsub!(/has_attached_file.+end/m, <<-FILE)
|
15
16
|
#{definition}
|
17
|
+
do_not_validate_attachment_file_type #{name}
|
16
18
|
end
|
17
19
|
FILE
|
18
20
|
|
19
21
|
write_file "app/models/user.rb", content
|
20
|
-
|
22
|
+
cd(".") { FileUtils.rm_rf ".rbx" }
|
21
23
|
end
|
22
24
|
|
23
25
|
When /^I upload the fixture "([^"]*)"$/ do |filename|
|
24
|
-
run_simple %(bundle exec
|
26
|
+
run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
|
25
27
|
end
|
26
28
|
|
27
29
|
Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
|
28
|
-
|
30
|
+
cd(".") do
|
29
31
|
geometry = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
|
30
|
-
geometry.
|
32
|
+
expect(geometry).to eq(dimension)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
Then /^the attachment "([^"]*)" should exist$/ do |filename|
|
35
|
-
|
36
|
-
File.
|
37
|
+
cd(".") do
|
38
|
+
expect(File.exist?(attachment_path(filename))).to be true
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
|
41
|
-
|
43
|
+
cd(".") do
|
42
44
|
require 'fileutils'
|
43
45
|
FileUtils.rm_f attachment_path(attachment_filename)
|
44
46
|
FileUtils.cp fixture_path(fixture_filename), attachment_path(attachment_filename)
|
@@ -46,50 +48,56 @@ When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachme
|
|
46
48
|
end
|
47
49
|
|
48
50
|
Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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)
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
56
65
|
Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
|
57
|
-
|
58
|
-
attachment_file_name = `bundle exec
|
59
|
-
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)
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
63
72
|
Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
|
64
|
-
|
65
|
-
attachment_file_size = `bundle exec
|
66
|
-
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)
|
67
76
|
end
|
68
77
|
end
|
69
78
|
|
70
79
|
Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist|
|
71
|
-
|
72
|
-
|
80
|
+
cd(".") do
|
81
|
+
expect(attachment_path(filename)).not_to be_an_existing_file
|
73
82
|
end
|
74
83
|
end
|
75
84
|
|
76
85
|
Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
|
77
|
-
|
78
|
-
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)
|
79
88
|
expect_columns = [
|
80
89
|
["#{attachment_name}_file_name", :string],
|
81
90
|
["#{attachment_name}_content_type", :string],
|
82
91
|
["#{attachment_name}_file_size", :integer],
|
83
92
|
["#{attachment_name}_updated_at", :datetime]
|
84
93
|
]
|
85
|
-
|
86
|
-
expect_columns.all?{ |column| columns.include? column }.should be_true
|
94
|
+
expect(columns).to include(*expect_columns)
|
87
95
|
end
|
88
96
|
end
|
89
97
|
|
90
98
|
Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
|
91
|
-
|
92
|
-
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)
|
93
101
|
expect_columns = [
|
94
102
|
["#{attachment_name}_file_name", :string],
|
95
103
|
["#{attachment_name}_content_type", :string],
|
@@ -97,6 +105,6 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
|
|
97
105
|
["#{attachment_name}_updated_at", :datetime]
|
98
106
|
]
|
99
107
|
|
100
|
-
|
108
|
+
expect(columns).not_to include(*expect_columns)
|
101
109
|
end
|
102
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", :platform => :ruby
|
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"
|
21
|
+
gem "racc", :platform => :rbx
|
22
|
+
gem "rubysl", :platform => :rbx
|
17
23
|
"""
|
18
24
|
And I remove turbolinks
|
25
|
+
And I comment out lines that contain "action_mailer" in "config/environments/*.rb"
|
19
26
|
And I empty the application.js file
|
20
27
|
And I configure the application to use "paperclip" from this project
|
21
|
-
And I reset Bundler environment variable
|
22
|
-
And I successfully run `bundle install --local`
|
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,16 +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"
|
78
|
+
cd(".") do
|
73
79
|
transform_file("app/models/user.rb") do |content|
|
74
80
|
content.sub(/end\Z/, "#{snippet}\nend")
|
75
81
|
end
|
@@ -77,7 +83,7 @@ def attach_attachment(name, definition = nil)
|
|
77
83
|
end
|
78
84
|
|
79
85
|
Given "I empty the application.js file" do
|
80
|
-
|
86
|
+
cd(".") do
|
81
87
|
transform_file("app/assets/javascripts/application.js") do |content|
|
82
88
|
""
|
83
89
|
end
|
@@ -85,19 +91,19 @@ Given "I empty the application.js file" do
|
|
85
91
|
end
|
86
92
|
|
87
93
|
Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
|
88
|
-
step %[I successfully run `
|
94
|
+
step %[I successfully run `rails generate scaffold #{model_name} #{attributes}`]
|
89
95
|
end
|
90
96
|
|
91
97
|
Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
|
92
|
-
step %[I successfully run `
|
98
|
+
step %[I successfully run `rails generate paperclip #{model_name} #{attachment_name}`]
|
93
99
|
end
|
94
100
|
|
95
101
|
Given /^I run a migration$/ do
|
96
|
-
step %[I successfully run `
|
102
|
+
step %[I successfully run `rake db:migrate --trace`]
|
97
103
|
end
|
98
104
|
|
99
105
|
When /^I rollback a migration$/ do
|
100
|
-
step %[I successfully run `
|
106
|
+
step %[I successfully run `rake db:rollback STEPS=1 --trace`]
|
101
107
|
end
|
102
108
|
|
103
109
|
Given /^I update my new user view to include the file upload field$/ do
|
@@ -127,7 +133,7 @@ end
|
|
127
133
|
|
128
134
|
Given /^I add this snippet to the User model:$/ do |snippet|
|
129
135
|
file_name = "app/models/user.rb"
|
130
|
-
|
136
|
+
cd(".") do
|
131
137
|
content = File.read(file_name)
|
132
138
|
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
|
133
139
|
end
|
@@ -135,16 +141,18 @@ end
|
|
135
141
|
|
136
142
|
Given /^I add this snippet to config\/application.rb:$/ do |snippet|
|
137
143
|
file_name = "config/application.rb"
|
138
|
-
|
144
|
+
cd(".") do
|
139
145
|
content = File.read(file_name)
|
140
146
|
File.open(file_name, 'w') {|f| f << content.sub(/class Application < Rails::Application.*$/, "class Application < Rails::Application\n#{snippet}\n")}
|
141
147
|
end
|
142
148
|
end
|
143
149
|
|
144
150
|
Given /^I start the rails application$/ do
|
145
|
-
|
151
|
+
cd(".") do
|
152
|
+
require "rails"
|
146
153
|
require "./config/environment"
|
147
|
-
require "capybara
|
154
|
+
require "capybara"
|
155
|
+
Capybara.app = Rails.application
|
148
156
|
end
|
149
157
|
end
|
150
158
|
|
@@ -153,7 +161,7 @@ Given /^I reload my application$/ do
|
|
153
161
|
end
|
154
162
|
|
155
163
|
When /^I turn off class caching$/ do
|
156
|
-
|
164
|
+
cd(".") do
|
157
165
|
file = "config/environments/test.rb"
|
158
166
|
config = IO.read(file)
|
159
167
|
config.gsub!(%r{^\s*config.cache_classes.*$},
|
@@ -165,12 +173,12 @@ end
|
|
165
173
|
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
|
166
174
|
expected = IO.read(path)
|
167
175
|
actual = read_from_web(web_file)
|
168
|
-
actual.
|
176
|
+
expect(actual).to eq(expected)
|
169
177
|
end
|
170
178
|
|
171
179
|
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
|
172
180
|
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
|
173
|
-
steps %{And I run `bundle install --local`}
|
181
|
+
steps %{And I successfully run `bundle install --local`}
|
174
182
|
end
|
175
183
|
|
176
184
|
When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
|
@@ -189,14 +197,37 @@ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
|
|
189
197
|
comment_out_gem_in_gemfile gemname
|
190
198
|
end
|
191
199
|
|
192
|
-
Given
|
193
|
-
|
194
|
-
|
200
|
+
Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
|
201
|
+
filename = "#{directory}/#{processor}.rb"
|
202
|
+
cd(".") do
|
203
|
+
FileUtils.mkdir_p directory
|
204
|
+
File.open(filename, "w") do |f|
|
205
|
+
f.write(<<-CLASS)
|
206
|
+
module Paperclip
|
207
|
+
class #{processor.capitalize} < Processor
|
208
|
+
def make
|
209
|
+
basename = File.basename(file.path, File.extname(file.path))
|
210
|
+
dst_format = options[:format] ? ".\#{options[:format]}" : ''
|
211
|
+
|
212
|
+
dst = Tempfile.new([basename, dst_format])
|
213
|
+
dst.binmode
|
214
|
+
|
215
|
+
convert(':src :dst',
|
216
|
+
src: File.expand_path(file.path),
|
217
|
+
dst: File.expand_path(dst.path)
|
218
|
+
)
|
219
|
+
|
220
|
+
dst
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
CLASS
|
225
|
+
end
|
195
226
|
end
|
196
227
|
end
|
197
228
|
|
198
229
|
def transform_file(filename)
|
199
|
-
if File.
|
230
|
+
if File.exist?(filename)
|
200
231
|
content = File.read(filename)
|
201
232
|
File.open(filename, "w") do |f|
|
202
233
|
content = yield(content)
|
@@ -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
|
|