jr-paperclip 8.0.1 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/NEWS +9 -0
- data/lib/paperclip/thumbnail.rb +18 -15
- data/lib/paperclip/version.rb +1 -1
- metadata +3 -245
- data/.github/FUNDING.yml +0 -3
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -18
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/.github/workflows/reviewdog.yml +0 -23
- data/.github/workflows/tests.yml +0 -56
- data/.gitignore +0 -19
- data/.qlty/.gitignore +0 -7
- data/.qlty/qlty.toml +0 -89
- data/Appraisals +0 -29
- data/Gemfile +0 -18
- data/bin/console +0 -11
- data/features/basic_integration.feature +0 -112
- data/features/migration.feature +0 -29
- data/features/rake_tasks.feature +0 -62
- data/features/step_definitions/attachment_steps.rb +0 -138
- data/features/step_definitions/html_steps.rb +0 -15
- data/features/step_definitions/rails_steps.rb +0 -271
- data/features/step_definitions/s3_steps.rb +0 -16
- data/features/step_definitions/web_steps.rb +0 -106
- data/features/support/env.rb +0 -12
- data/features/support/file_helpers.rb +0 -34
- data/features/support/fixtures/boot_config.txt +0 -15
- data/features/support/fixtures/gemfile.txt +0 -5
- data/features/support/fixtures/preinitializer.txt +0 -20
- data/features/support/paths.rb +0 -28
- data/features/support/rails.rb +0 -39
- data/features/support/selectors.rb +0 -19
- data/features/support/webmock_setup.rb +0 -8
- data/gemfiles/7.0.gemfile +0 -21
- data/gemfiles/7.1.gemfile +0 -21
- data/gemfiles/7.2.gemfile +0 -21
- data/gemfiles/8.0.gemfile +0 -21
- data/gemfiles/8.1.gemfile +0 -21
- data/paperclip.gemspec +0 -52
- data/spec/database.yml +0 -4
- data/spec/paperclip/attachment_definitions_spec.rb +0 -313
- data/spec/paperclip/attachment_processing_spec.rb +0 -79
- data/spec/paperclip/attachment_registry_spec.rb +0 -158
- data/spec/paperclip/attachment_spec.rb +0 -1617
- data/spec/paperclip/content_type_detector_spec.rb +0 -58
- data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -40
- data/spec/paperclip/filename_cleaner_spec.rb +0 -13
- data/spec/paperclip/geometry_detector_spec.rb +0 -96
- data/spec/paperclip/geometry_parser_spec.rb +0 -73
- data/spec/paperclip/geometry_spec.rb +0 -270
- data/spec/paperclip/glue_spec.rb +0 -63
- data/spec/paperclip/has_attached_file_spec.rb +0 -78
- data/spec/paperclip/helpers_spec.rb +0 -49
- data/spec/paperclip/integration_spec.rb +0 -702
- data/spec/paperclip/interpolations_spec.rb +0 -270
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +0 -160
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +0 -167
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +0 -88
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +0 -17
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +0 -134
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +0 -142
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +0 -8
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +0 -25
- data/spec/paperclip/io_adapters/registry_spec.rb +0 -35
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +0 -64
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +0 -146
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +0 -231
- data/spec/paperclip/lazy_thumbnail_compatibility_spec.rb +0 -266
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +0 -19
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +0 -108
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +0 -69
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +0 -88
- data/spec/paperclip/media_type_spoof_detector_spec.rb +0 -126
- data/spec/paperclip/meta_class_spec.rb +0 -30
- data/spec/paperclip/migration_guide_example_spec.rb +0 -44
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +0 -88
- data/spec/paperclip/paperclip_spec.rb +0 -196
- data/spec/paperclip/plural_cache_spec.rb +0 -37
- data/spec/paperclip/processor_helpers_spec.rb +0 -57
- data/spec/paperclip/processor_spec.rb +0 -60
- data/spec/paperclip/rails_environment_spec.rb +0 -30
- data/spec/paperclip/rake_spec.rb +0 -103
- data/spec/paperclip/schema_spec.rb +0 -298
- data/spec/paperclip/storage/filesystem_spec.rb +0 -102
- data/spec/paperclip/storage/fog_spec.rb +0 -606
- data/spec/paperclip/storage/s3_live_spec.rb +0 -188
- data/spec/paperclip/storage/s3_spec.rb +0 -1974
- data/spec/paperclip/style_spec.rb +0 -309
- data/spec/paperclip/tempfile_factory_spec.rb +0 -33
- data/spec/paperclip/tempfile_spec.rb +0 -35
- data/spec/paperclip/thumbnail_custom_options_spec.rb +0 -225
- data/spec/paperclip/thumbnail_loader_options_spec.rb +0 -53
- data/spec/paperclip/thumbnail_security_spec.rb +0 -42
- data/spec/paperclip/thumbnail_spec.rb +0 -1460
- data/spec/paperclip/url_generator_spec.rb +0 -231
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +0 -410
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +0 -249
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +0 -85
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +0 -325
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +0 -48
- data/spec/paperclip/validators_spec.rb +0 -179
- data/spec/spec_helper.rb +0 -52
- data/spec/support/assertions.rb +0 -84
- data/spec/support/fake_model.rb +0 -24
- data/spec/support/fake_rails.rb +0 -12
- data/spec/support/fixtures/12k.png +0 -0
- data/spec/support/fixtures/50x50.png +0 -0
- data/spec/support/fixtures/5k.png +0 -0
- data/spec/support/fixtures/animated +0 -0
- data/spec/support/fixtures/animated.gif +0 -0
- data/spec/support/fixtures/animated.unknown +0 -0
- data/spec/support/fixtures/aws_s3.yml +0 -13
- data/spec/support/fixtures/bad.png +0 -1
- data/spec/support/fixtures/empty.html +0 -1
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/fog.yml +0 -8
- data/spec/support/fixtures/rotated.jpg +0 -0
- data/spec/support/fixtures/s3.yml +0 -8
- data/spec/support/fixtures/sample.xlsm +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/fixtures/spaced file.png +0 -0
- data/spec/support/fixtures/text.txt +0 -1
- data/spec/support/fixtures/twopage.pdf +0 -0
- data/spec/support/fixtures/uppercase.PNG +0 -0
- data/spec/support/matchers/accept.rb +0 -5
- data/spec/support/matchers/exist.rb +0 -5
- data/spec/support/matchers/have_column.rb +0 -23
- data/spec/support/mock_attachment.rb +0 -24
- data/spec/support/mock_interpolator.rb +0 -24
- data/spec/support/mock_url_generator_builder.rb +0 -26
- data/spec/support/model_reconstruction.rb +0 -72
- data/spec/support/reporting.rb +0 -11
- data/spec/support/test_data.rb +0 -13
- data/spec/support/version_helper.rb +0 -9
data/bin/console
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
And I allow the attachment to be submitted
|
|
11
|
-
And I replace this snippet to app/views/layouts/application.html.erb:
|
|
12
|
-
"""
|
|
13
|
-
<%= javascript_tag 'application', 'data-turbolinks-track': 'reload' %>
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
Scenario: Configure defaults for all attachments through Railtie
|
|
17
|
-
Given I add this snippet to config/application.rb:
|
|
18
|
-
"""
|
|
19
|
-
config.paperclip_defaults = {
|
|
20
|
-
:url => "/paperclip/custom/:attachment/:style/:filename",
|
|
21
|
-
:validate_media_type => false
|
|
22
|
-
}
|
|
23
|
-
"""
|
|
24
|
-
And I attach :attachment
|
|
25
|
-
And I start the rails application
|
|
26
|
-
When I go to the new user page
|
|
27
|
-
And I fill in "Name" with "something"
|
|
28
|
-
And I attach the file "spec/support/fixtures/animated.unknown" to "Attachment"
|
|
29
|
-
And I press "Submit"
|
|
30
|
-
Then I should see "Name: something"
|
|
31
|
-
And I should see an image with a path of "/paperclip/custom/attachments/original/animated.unknown"
|
|
32
|
-
And the file at "/paperclip/custom/attachments/original/animated.unknown" should be the same as "spec/support/fixtures/animated.unknown"
|
|
33
|
-
|
|
34
|
-
Scenario: Add custom processors
|
|
35
|
-
Given I add a "test" processor in "lib/paperclip"
|
|
36
|
-
And I add a "cool" processor in "lib/paperclip"
|
|
37
|
-
And I attach :attachment with:
|
|
38
|
-
"""
|
|
39
|
-
styles: { original: {} }, processors: [:test, :cool]
|
|
40
|
-
"""
|
|
41
|
-
And I start the rails application
|
|
42
|
-
When I go to the new user page
|
|
43
|
-
And I fill in "Name" with "something"
|
|
44
|
-
And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
|
|
45
|
-
And I press "Submit"
|
|
46
|
-
Then I should see "Name: something"
|
|
47
|
-
And I should see an image with a path of "/paperclip/custom/attachments/original/5k.png"
|
|
48
|
-
|
|
49
|
-
Scenario: Filesystem integration test
|
|
50
|
-
Given I attach :attachment with:
|
|
51
|
-
"""
|
|
52
|
-
:url => "/system/:attachment/:style/:filename"
|
|
53
|
-
"""
|
|
54
|
-
And I start the rails application
|
|
55
|
-
When I go to the new user page
|
|
56
|
-
And I fill in "Name" with "something"
|
|
57
|
-
And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
|
|
58
|
-
And I press "Submit"
|
|
59
|
-
Then I should see "Name: something"
|
|
60
|
-
And I should see an image with a path of "/system/attachments/original/5k.png"
|
|
61
|
-
And the file at "/system/attachments/original/5k.png" should be the same as "spec/support/fixtures/5k.png"
|
|
62
|
-
|
|
63
|
-
Scenario: S3 Integration test
|
|
64
|
-
Given I attach :attachment with:
|
|
65
|
-
"""
|
|
66
|
-
:storage => :s3,
|
|
67
|
-
:path => "/:attachment/:style/:filename",
|
|
68
|
-
:s3_credentials => Rails.root.join("config/s3.yml"),
|
|
69
|
-
:styles => { :square => "100x100#" }
|
|
70
|
-
"""
|
|
71
|
-
And I write to "config/s3.yml" with:
|
|
72
|
-
"""
|
|
73
|
-
bucket: paperclip
|
|
74
|
-
access_key_id: access_key
|
|
75
|
-
secret_access_key: secret_key
|
|
76
|
-
s3_region: us-west-2
|
|
77
|
-
"""
|
|
78
|
-
And I start the rails application
|
|
79
|
-
When I go to the new user page
|
|
80
|
-
And I fill in "Name" with "something"
|
|
81
|
-
And I attach the file "spec/support/fixtures/5k.png" to "Attachment" on S3
|
|
82
|
-
And I press "Submit"
|
|
83
|
-
Then I should see "Name: something"
|
|
84
|
-
And I should see an image with a path of "//s3.amazonaws.com/paperclip/attachments/original/5k.png"
|
|
85
|
-
And the file at "//s3.amazonaws.com/paperclip/attachments/original/5k.png" should be uploaded to S3
|
|
86
|
-
|
|
87
|
-
Scenario: libvips integration test
|
|
88
|
-
Given I add this snippet to config/application.rb:
|
|
89
|
-
"""
|
|
90
|
-
config.paperclip_defaults = {
|
|
91
|
-
:backend => :vips
|
|
92
|
-
}
|
|
93
|
-
"""
|
|
94
|
-
And I attach :attachment with:
|
|
95
|
-
"""
|
|
96
|
-
url: "/system/:attachment/:style/:filename",
|
|
97
|
-
styles: { thumb: "100x100#" }
|
|
98
|
-
"""
|
|
99
|
-
And I start the rails application
|
|
100
|
-
And I overwrite "app/views/users/show.html.erb" with:
|
|
101
|
-
"""
|
|
102
|
-
<p>Name: <%= @user.name %></p>
|
|
103
|
-
<p>Original: <%= image_tag @user.attachment.url(:original) %></p>
|
|
104
|
-
<p>Thumb: <%= image_tag @user.attachment.url(:thumb) %></p>
|
|
105
|
-
"""
|
|
106
|
-
When I go to the new user page
|
|
107
|
-
And I fill in "Name" with "vips user"
|
|
108
|
-
And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
|
|
109
|
-
And I press "Submit"
|
|
110
|
-
Then I should see "Name: vips user"
|
|
111
|
-
And the file at "/system/attachments/original/5k.png" should have dimensions "434x66"
|
|
112
|
-
And the file at "/system/attachments/thumb/5k.png" should have dimensions "100x100"
|
data/features/migration.feature
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
Feature: Migration
|
|
2
|
-
|
|
3
|
-
Background:
|
|
4
|
-
Given I generate a new rails application
|
|
5
|
-
And I generate a "User" model:
|
|
6
|
-
|
|
7
|
-
Scenario: Vintage syntax
|
|
8
|
-
Given I run a paperclip migration to add a paperclip "attach" to the "User" model
|
|
9
|
-
|
|
10
|
-
And I run a migration
|
|
11
|
-
Then I should have attachment columns for "attach"
|
|
12
|
-
|
|
13
|
-
When I rollback a migration
|
|
14
|
-
Then I should not have attachment columns for "attach"
|
|
15
|
-
|
|
16
|
-
Scenario: New syntax with create_table
|
|
17
|
-
Given I run a paperclip migration to add a paperclip "attach" to the "User" model
|
|
18
|
-
|
|
19
|
-
And I run a migration
|
|
20
|
-
Then I should have attachment columns for "attach"
|
|
21
|
-
|
|
22
|
-
Scenario: New syntax outside of create_table
|
|
23
|
-
Given I run a paperclip migration to add a paperclip "attachment_sample" to the "User" model
|
|
24
|
-
|
|
25
|
-
And I run a migration
|
|
26
|
-
Then I should have attachment columns for "attachment_sample"
|
|
27
|
-
|
|
28
|
-
When I rollback a migration
|
|
29
|
-
Then I should not have attachment columns for "attachment_sample"
|
data/features/rake_tasks.feature
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
Feature: Rake tasks
|
|
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 attach :attachment with:
|
|
9
|
-
"""
|
|
10
|
-
:path => ":rails_root/public/system/:attachment/:style/:filename"
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
Scenario: Paperclip refresh thumbnails task
|
|
14
|
-
When I modify my attachment definition to:
|
|
15
|
-
"""
|
|
16
|
-
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
|
|
17
|
-
:styles => { :medium => "200x200#" }
|
|
18
|
-
"""
|
|
19
|
-
And I upload the fixture "5k.png"
|
|
20
|
-
Then the attachment "medium/5k.png" should have a dimension of 200x200
|
|
21
|
-
When I modify my attachment definition to:
|
|
22
|
-
"""
|
|
23
|
-
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
|
|
24
|
-
:styles => { :medium => "100x100#" }
|
|
25
|
-
"""
|
|
26
|
-
When I successfully run `bundle exec rake paperclip:refresh:thumbnails CLASS=User --trace`
|
|
27
|
-
Then the attachment "original/5k.png" should exist
|
|
28
|
-
And the attachment "medium/5k.png" should have a dimension of 100x100
|
|
29
|
-
|
|
30
|
-
Scenario: Paperclip refresh metadata task
|
|
31
|
-
When I upload the fixture "5k.png"
|
|
32
|
-
And I swap the attachment "original/5k.png" with the fixture "12k.png"
|
|
33
|
-
And I successfully run `bundle exec rake paperclip:refresh:metadata CLASS=User --trace`
|
|
34
|
-
Then the attachment should have the same content type as the fixture "12k.png"
|
|
35
|
-
And the attachment should have the same file size as the fixture "12k.png"
|
|
36
|
-
|
|
37
|
-
Scenario: Paperclip refresh missing styles task
|
|
38
|
-
When I upload the fixture "5k.png"
|
|
39
|
-
Then the attachment file "original/5k.png" should exist
|
|
40
|
-
And the attachment file "medium/5k.png" should not exist
|
|
41
|
-
When I modify my attachment definition to:
|
|
42
|
-
"""
|
|
43
|
-
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
|
|
44
|
-
:styles => { :medium => "200x200#" }
|
|
45
|
-
"""
|
|
46
|
-
When I successfully run `bundle exec rake paperclip:refresh:missing_styles --trace`
|
|
47
|
-
Then the attachment file "original/5k.png" should exist
|
|
48
|
-
And the attachment file "medium/5k.png" should exist
|
|
49
|
-
|
|
50
|
-
Scenario: Paperclip clean task
|
|
51
|
-
When I upload the fixture "5k.png"
|
|
52
|
-
And I upload the fixture "12k.png"
|
|
53
|
-
Then the attachment file "original/5k.png" should exist
|
|
54
|
-
And the attachment file "original/12k.png" should exist
|
|
55
|
-
When I modify my attachment definition to:
|
|
56
|
-
"""
|
|
57
|
-
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
|
|
58
|
-
validates_attachment_size :attachment, :less_than => 10.kilobytes
|
|
59
|
-
"""
|
|
60
|
-
And I successfully run `bundle exec rake paperclip:clean CLASS=User --trace`
|
|
61
|
-
Then the attachment file "original/5k.png" should exist
|
|
62
|
-
But the attachment file "original/12k.png" should not exist
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
module AttachmentHelpers
|
|
2
|
-
def fixture_path(filename)
|
|
3
|
-
File.expand_path("#{PROJECT_ROOT}/spec/support/fixtures/#{filename}")
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
def attachment_path(filename)
|
|
7
|
-
File.expand_path("public/system/attachments/#{filename}")
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
World(AttachmentHelpers)
|
|
11
|
-
|
|
12
|
-
When /^I modify my attachment definition to:$/ do |definition|
|
|
13
|
-
content = cd(".") { File.read("app/models/user.rb") }
|
|
14
|
-
name = content[/has_attached_file :\w+/][/:\w+/]
|
|
15
|
-
content.gsub!(/has_attached_file.+end/m, <<-FILE)
|
|
16
|
-
#{definition}
|
|
17
|
-
do_not_validate_attachment_file_type #{name}
|
|
18
|
-
end
|
|
19
|
-
FILE
|
|
20
|
-
|
|
21
|
-
write_file "app/models/user.rb", content
|
|
22
|
-
cd(".") { FileUtils.rm_rf ".rbx" }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
When /^I upload the fixture "([^"]*)"$/ do |filename|
|
|
26
|
-
aruba_run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
|
|
30
|
-
cd(".") do
|
|
31
|
-
geometry = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
|
|
32
|
-
expect(geometry).to eq(dimension)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
Then /^the attachment "([^"]*)" should exist$/ do |filename|
|
|
37
|
-
cd(".") do
|
|
38
|
-
expect(File.exist?(attachment_path(filename))).to be true
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
|
|
43
|
-
cd(".") do
|
|
44
|
-
require "fileutils"
|
|
45
|
-
FileUtils.rm_f attachment_path(attachment_filename)
|
|
46
|
-
FileUtils.cp fixture_path(fixture_filename), attachment_path(attachment_filename)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
|
|
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)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
|
|
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)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
|
|
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)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist|
|
|
80
|
-
cd(".") do
|
|
81
|
-
if not_exist
|
|
82
|
-
expect(File.exist?(attachment_path(filename))).to be false
|
|
83
|
-
else
|
|
84
|
-
expect(File.exist?(attachment_path(filename))).to be true
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
Then /^the file at "([^"]*)" should have dimensions "([^"]*)"$/ do |web_path, dimension|
|
|
90
|
-
cd(".") do
|
|
91
|
-
local_path = "public#{web_path}"
|
|
92
|
-
# Try identify first, then vipsheader
|
|
93
|
-
require "shellwords"
|
|
94
|
-
escaped_path = Shellwords.escape(local_path)
|
|
95
|
-
geometry = `identify -format "%wx%h" #{escaped_path} 2>/dev/null`.strip
|
|
96
|
-
if geometry.empty?
|
|
97
|
-
width = `vipsheader -f width #{escaped_path} 2>/dev/null`.strip
|
|
98
|
-
height = `vipsheader -f height #{escaped_path} 2>/dev/null`.strip
|
|
99
|
-
geometry = "#{width}x#{height}"
|
|
100
|
-
end
|
|
101
|
-
raise "Could not determine dimensions for #{local_path}" if geometry == "x" || geometry.empty?
|
|
102
|
-
expect(geometry).to eq(dimension)
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
|
|
107
|
-
cd(".") do
|
|
108
|
-
columns = eval(`bundle exec rails runner "puts User.columns.map{ |column| [column.name, column.sql_type] }.inspect"`.strip)
|
|
109
|
-
expect(columns).to include(["#{attachment_name}_file_name", "varchar"])
|
|
110
|
-
expect(columns).to include(["#{attachment_name}_content_type", "varchar"])
|
|
111
|
-
expect(columns).to include(["#{attachment_name}_file_size", "bigint"])
|
|
112
|
-
# Rails 7+ uses datetime(6) with precision, so match with regex
|
|
113
|
-
datetime_column = columns.find { |col| col[0] == "#{attachment_name}_updated_at" }
|
|
114
|
-
expect(datetime_column).to be_present
|
|
115
|
-
expect(datetime_column[1]).to match(/^datetime/)
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
|
|
120
|
-
cd(".") do
|
|
121
|
-
columns = eval(`bundle exec rails runner "puts User.columns.map{ |column| [column.name, column.sql_type] }.inspect"`.strip)
|
|
122
|
-
column_names = columns.map { |col| col[0] }
|
|
123
|
-
expect(column_names).not_to include("#{attachment_name}_file_name")
|
|
124
|
-
expect(column_names).not_to include("#{attachment_name}_content_type")
|
|
125
|
-
expect(column_names).not_to include("#{attachment_name}_file_size")
|
|
126
|
-
expect(column_names).not_to include("#{attachment_name}_updated_at")
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
# we have to support different versions of aruba, and this method was renamed for 1.0
|
|
131
|
-
# https://github.com/cucumber/aruba/pull/438
|
|
132
|
-
def aruba_run_simple(*args)
|
|
133
|
-
if respond_to?(:run_simple)
|
|
134
|
-
run_simple(*args)
|
|
135
|
-
elsif respond_to?(:run_command_and_stop)
|
|
136
|
-
run_command_and_stop(*args)
|
|
137
|
-
end
|
|
138
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Then %r{I should see an image with a path of "([^"]*)"} do |path|
|
|
2
|
-
expect(page).to have_css("img[src^='#{path}']")
|
|
3
|
-
end
|
|
4
|
-
|
|
5
|
-
Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
|
|
6
|
-
expected = IO.read(path)
|
|
7
|
-
actual = if web_file.match %r{^https?://}
|
|
8
|
-
Net::HTTP.get(URI.parse(web_file))
|
|
9
|
-
else
|
|
10
|
-
visit(web_file)
|
|
11
|
-
page.body
|
|
12
|
-
end
|
|
13
|
-
actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
|
|
14
|
-
expect(actual).to eq(expected)
|
|
15
|
-
end
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
Given /^I generate a new rails application$/ do
|
|
2
|
-
steps %{
|
|
3
|
-
When I successfully run `rails new #{APP_NAME} --skip-bundle --skip-javascript`
|
|
4
|
-
And I cd to "#{APP_NAME}"
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
FileUtils.chdir("tmp/aruba/testapp/")
|
|
8
|
-
|
|
9
|
-
# Remove assets initializer if it exists (causes issues with Rails 8+)
|
|
10
|
-
FileUtils.rm_f("config/initializers/assets.rb")
|
|
11
|
-
|
|
12
|
-
# Determine sqlite3 version based on Rails version
|
|
13
|
-
sqlite3_version = framework_version.to_f >= 7.2 ? ', "~> 2.0"' : ', "~> 1.4"'
|
|
14
|
-
|
|
15
|
-
steps %{
|
|
16
|
-
And I turn off class caching
|
|
17
|
-
And I write to "Gemfile" with:
|
|
18
|
-
"""
|
|
19
|
-
source "https://rubygems.org"
|
|
20
|
-
gem "rails", "#{framework_version}"
|
|
21
|
-
gem "sqlite3"#{sqlite3_version}, :platform => [:ruby, :rbx]
|
|
22
|
-
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
|
23
|
-
gem "jruby-openssl", :platform => :jruby
|
|
24
|
-
gem "capybara"
|
|
25
|
-
gem "gherkin"
|
|
26
|
-
gem "aws-sdk-s3"
|
|
27
|
-
gem "racc", :platform => :rbx
|
|
28
|
-
gem "rubysl", :platform => :rbx
|
|
29
|
-
"""
|
|
30
|
-
And I remove turbolinks
|
|
31
|
-
And I comment out lines that contain "action_mailer" in "config/environments/*.rb"
|
|
32
|
-
And I empty the application.js file
|
|
33
|
-
And I configure the application to use "paperclip" from this project
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
FileUtils.chdir("../../..")
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
Given /^I generate a "([^"]*)" model:$/ do |model_name|
|
|
40
|
-
step %[I successfully run `rails generate model #{model_name}`]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
Given /^I run a paperclip migration to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
|
|
44
|
-
step %[I successfully run `rails generate paperclip #{model_name} #{attachment_name}`]
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
Given "I allow the attachment to be submitted" do
|
|
48
|
-
cd(".") do
|
|
49
|
-
transform_file("app/controllers/users_controller.rb") do |content|
|
|
50
|
-
# Handle both Rails 7 style (require/permit) and Rails 8 style (expect)
|
|
51
|
-
content
|
|
52
|
-
.gsub("params.require(:user).permit(:name)", "params.require(:user).permit!")
|
|
53
|
-
.gsub(/params\.expect\(user: \[.*?\]\)/, "params.require(:user).permit!")
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
Given "I remove turbolinks" do
|
|
59
|
-
cd(".") do
|
|
60
|
-
# These files may not exist in modern Rails (7+)
|
|
61
|
-
transform_file("app/assets/javascripts/application.js") do |content|
|
|
62
|
-
content.gsub("//= require turbolinks", "")
|
|
63
|
-
end
|
|
64
|
-
transform_file("app/views/layouts/application.html.erb") do |content|
|
|
65
|
-
content.gsub(', "data-turbolinks-track" => true', "")
|
|
66
|
-
.gsub(", 'data-turbolinks-track': 'reload'", "")
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|
|
|
72
|
-
cd(".") do
|
|
73
|
-
Dir.glob(glob).each do |file|
|
|
74
|
-
transform_file(file) do |content|
|
|
75
|
-
content.gsub(/^(.*?#{contains}.*?)$/) { |line| "# #{line}" }
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
Given /^I attach :attachment$/ do
|
|
82
|
-
attach_attachment("attachment")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
Given /^I attach :attachment with:$/ do |definition|
|
|
86
|
-
attach_attachment("attachment", definition)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def attach_attachment(name, definition = nil)
|
|
90
|
-
snippet = "has_attached_file :#{name}"
|
|
91
|
-
if definition
|
|
92
|
-
snippet += ", \n"
|
|
93
|
-
snippet += definition
|
|
94
|
-
end
|
|
95
|
-
snippet += "\ndo_not_validate_attachment_file_type :#{name}\n"
|
|
96
|
-
cd(".") do
|
|
97
|
-
transform_file("app/models/user.rb") do |content|
|
|
98
|
-
content.sub(/end\Z/, "#{snippet}\nend")
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
Given "I empty the application.js file" do
|
|
104
|
-
cd(".") do
|
|
105
|
-
# This file may not exist in modern Rails (7+) with --skip-asset-pipeline
|
|
106
|
-
transform_file("app/assets/javascripts/application.js") do |_content|
|
|
107
|
-
""
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
|
|
113
|
-
step %[I successfully run `rails generate scaffold #{model_name} #{attributes}`]
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
|
|
117
|
-
step %[I successfully run `rails generate paperclip #{model_name} #{attachment_name}`]
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
Given /^I run a migration$/ do
|
|
121
|
-
step %[I successfully run `rake db:migrate --trace`]
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
When /^I rollback a migration$/ do
|
|
125
|
-
step %[I successfully run `rake db:rollback STEPS=1 --trace`]
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
Given /^I update my new user view to include the file upload field$/ do
|
|
129
|
-
steps %{
|
|
130
|
-
Given I overwrite "app/views/users/new.html.erb" with:
|
|
131
|
-
"""
|
|
132
|
-
<%= form_for @user, :html => { :multipart => true } do |f| %>
|
|
133
|
-
<%= f.label :name %>
|
|
134
|
-
<%= f.text_field :name %>
|
|
135
|
-
<%= f.label :attachment %>
|
|
136
|
-
<%= f.file_field :attachment %>
|
|
137
|
-
<%= submit_tag "Submit" %>
|
|
138
|
-
<% end %>
|
|
139
|
-
"""
|
|
140
|
-
}
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
Given /^I update my user view to include the attachment$/ do
|
|
144
|
-
steps %{
|
|
145
|
-
Given I overwrite "app/views/users/show.html.erb" with:
|
|
146
|
-
"""
|
|
147
|
-
<p>Name: <%= @user.name %></p>
|
|
148
|
-
<p>Attachment: <%= image_tag @user.attachment.url %></p>
|
|
149
|
-
"""
|
|
150
|
-
}
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
Given /^I add this snippet to the User model:$/ do |snippet|
|
|
154
|
-
file_name = "app/models/user.rb"
|
|
155
|
-
cd(".") do
|
|
156
|
-
content = File.read(file_name)
|
|
157
|
-
File.open(file_name, "w") { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
Given /^I add this snippet to config\/application.rb:$/ do |snippet|
|
|
162
|
-
file_name = "config/application.rb"
|
|
163
|
-
cd(".") do
|
|
164
|
-
content = File.read(file_name)
|
|
165
|
-
File.open(file_name, "w") do |f|
|
|
166
|
-
f << content.sub(/class Application < Rails::Application.*$/,
|
|
167
|
-
"class Application < Rails::Application\n#{snippet}\n")
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
Given /^I replace this snippet to app\/views\/layouts\/application.html.erb:$/ do |snippet|
|
|
173
|
-
file_name = "app/views/layouts/application.html.erb"
|
|
174
|
-
cd(".") do
|
|
175
|
-
content = File.read(file_name)
|
|
176
|
-
File.open(file_name, "w") do |f|
|
|
177
|
-
f << content.sub(/<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>$/,
|
|
178
|
-
"#{snippet}")
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
Given /^I start the rails application$/ do
|
|
184
|
-
cd(".") do
|
|
185
|
-
require "rails"
|
|
186
|
-
require "./config/environment"
|
|
187
|
-
require "capybara"
|
|
188
|
-
Capybara.app = Rails.application
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
Given /^I reload my application$/ do
|
|
193
|
-
Rails::Application.reload!
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
When /^I turn off class caching$/ do
|
|
197
|
-
cd(".") do
|
|
198
|
-
file = "config/environments/test.rb"
|
|
199
|
-
config = IO.read(file)
|
|
200
|
-
# Rails 8+ uses enable_reloading instead of cache_classes
|
|
201
|
-
config.gsub!(%r{^\s*config.cache_classes.*$},
|
|
202
|
-
"config.cache_classes = false")
|
|
203
|
-
config.gsub!(%r{^\s*config.enable_reloading.*$},
|
|
204
|
-
"config.enable_reloading = true")
|
|
205
|
-
File.open(file, "w") { |f| f.write(config) }
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
|
|
210
|
-
expected = IO.read(path)
|
|
211
|
-
actual = read_from_web(web_file)
|
|
212
|
-
expect(actual).to eq(expected)
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
|
|
216
|
-
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
|
|
217
|
-
steps %{And I successfully run `bundle install --local`}
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
|
|
221
|
-
append_to_gemfile "gem '#{gem_name}'"
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
When /^I append gems from Appraisal Gemfile$/ do
|
|
225
|
-
File.read(ENV["BUNDLE_GEMFILE"]).split(/\n/).each do |line|
|
|
226
|
-
append_to_gemfile line.strip if line =~ /^gem "(?!rails|appraisal)/
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
|
|
231
|
-
comment_out_gem_in_gemfile gemname
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
|
|
235
|
-
filename = "#{directory}/#{processor}.rb"
|
|
236
|
-
cd(".") do
|
|
237
|
-
FileUtils.mkdir_p directory
|
|
238
|
-
File.open(filename, "w") do |f|
|
|
239
|
-
f.write(<<-CLASS)
|
|
240
|
-
module Paperclip
|
|
241
|
-
class #{processor.capitalize} < Processor
|
|
242
|
-
def make
|
|
243
|
-
basename = File.basename(file.path, File.extname(file.path))
|
|
244
|
-
dst_format = options[:format] ? ".\#{options[:format]}" : ''
|
|
245
|
-
|
|
246
|
-
dst = Tempfile.new([basename, dst_format])
|
|
247
|
-
dst.binmode
|
|
248
|
-
|
|
249
|
-
convert(':src :dst',
|
|
250
|
-
src: File.expand_path(file.path),
|
|
251
|
-
dst: File.expand_path(dst.path)
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
dst
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
CLASS
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
def transform_file(filename)
|
|
264
|
-
if File.exist?(filename)
|
|
265
|
-
content = File.read(filename)
|
|
266
|
-
File.open(filename, "w") do |f|
|
|
267
|
-
content = yield(content)
|
|
268
|
-
f.write(content)
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
|
|
2
|
-
# Stub S3 PUT requests for any region and track them
|
|
3
|
-
stub_request(:put, %r{https://paperclip\.s3\.[a-z0-9-]+\.amazonaws\.com/.*})
|
|
4
|
-
.to_return(status: 200, body: "", headers: {})
|
|
5
|
-
|
|
6
|
-
step "I attach the file \"#{file_path}\" to \"#{field}\""
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
Then /^the file at "([^"]*)" should be uploaded to S3$/ do |url|
|
|
10
|
-
# Extract the path from the URL (e.g., "//s3.amazonaws.com/paperclip/attachments/original/5k.png")
|
|
11
|
-
# becomes "/attachments/original/5k.png"
|
|
12
|
-
path = url.sub(%r{^//s3\.amazonaws\.com/paperclip}, "")
|
|
13
|
-
|
|
14
|
-
# Verify a PUT request was made to S3 with this path
|
|
15
|
-
expect(WebMock).to have_requested(:put, %r{https://paperclip\.s3\.[a-z0-9-]+\.amazonaws\.com#{Regexp.escape(path)}})
|
|
16
|
-
end
|