paperclip-fix 4.3.7
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 +7 -0
- data/.gitignore +19 -0
- data/.hound.yml +1066 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +22 -0
- data/Appraisals +11 -0
- data/CONTRIBUTING.md +75 -0
- data/Gemfile +21 -0
- data/LICENSE +24 -0
- data/NEWS +420 -0
- data/README.md +979 -0
- data/RELEASING.md +17 -0
- data/Rakefile +44 -0
- data/UPGRADING +14 -0
- data/cucumber/paperclip_steps.rb +6 -0
- data/features/basic_integration.feature +80 -0
- data/features/migration.feature +94 -0
- data/features/rake_tasks.feature +62 -0
- data/features/step_definitions/attachment_steps.rb +110 -0
- data/features/step_definitions/html_steps.rb +15 -0
- data/features/step_definitions/rails_steps.rb +236 -0
- data/features/step_definitions/s3_steps.rb +14 -0
- data/features/step_definitions/web_steps.rb +107 -0
- data/features/support/env.rb +11 -0
- data/features/support/fakeweb.rb +13 -0
- data/features/support/file_helpers.rb +34 -0
- data/features/support/fixtures/boot_config.txt +15 -0
- data/features/support/fixtures/gemfile.txt +5 -0
- data/features/support/fixtures/preinitializer.txt +20 -0
- data/features/support/paths.rb +28 -0
- data/features/support/rails.rb +63 -0
- data/features/support/selectors.rb +19 -0
- data/gemfiles/3.2.gemfile +19 -0
- data/gemfiles/4.1.gemfile +19 -0
- data/gemfiles/4.2.gemfile +19 -0
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +30 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +15 -0
- data/lib/paperclip/attachment.rb +608 -0
- data/lib/paperclip/attachment_registry.rb +59 -0
- data/lib/paperclip/callbacks.rb +40 -0
- data/lib/paperclip/content_type_detector.rb +79 -0
- data/lib/paperclip/deprecations.rb +42 -0
- data/lib/paperclip/errors.rb +32 -0
- data/lib/paperclip/file_command_content_type_detector.rb +30 -0
- data/lib/paperclip/filename_cleaner.rb +16 -0
- data/lib/paperclip/geometry.rb +158 -0
- data/lib/paperclip/geometry_detector_factory.rb +48 -0
- data/lib/paperclip/geometry_parser_factory.rb +31 -0
- data/lib/paperclip/glue.rb +17 -0
- data/lib/paperclip/has_attached_file.rb +109 -0
- data/lib/paperclip/helpers.rb +56 -0
- data/lib/paperclip/interpolations/plural_cache.rb +18 -0
- data/lib/paperclip/interpolations.rb +197 -0
- data/lib/paperclip/io_adapters/abstract_adapter.rb +47 -0
- data/lib/paperclip/io_adapters/attachment_adapter.rb +36 -0
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +22 -0
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +18 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +22 -0
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +15 -0
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -0
- data/lib/paperclip/io_adapters/nil_adapter.rb +34 -0
- data/lib/paperclip/io_adapters/registry.rb +32 -0
- data/lib/paperclip/io_adapters/stringio_adapter.rb +33 -0
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +42 -0
- data/lib/paperclip/io_adapters/uri_adapter.rb +63 -0
- data/lib/paperclip/locales/de.yml +18 -0
- data/lib/paperclip/locales/en.yml +18 -0
- data/lib/paperclip/locales/es.yml +18 -0
- data/lib/paperclip/locales/ja.yml +18 -0
- data/lib/paperclip/locales/pt-BR.yml +18 -0
- data/lib/paperclip/locales/zh-CN.yml +18 -0
- data/lib/paperclip/locales/zh-HK.yml +18 -0
- data/lib/paperclip/locales/zh-TW.yml +18 -0
- data/lib/paperclip/logger.rb +21 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +54 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +100 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +59 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +96 -0
- data/lib/paperclip/matchers.rb +64 -0
- data/lib/paperclip/media_type_spoof_detector.rb +89 -0
- data/lib/paperclip/missing_attachment_styles.rb +79 -0
- data/lib/paperclip/processor.rb +48 -0
- data/lib/paperclip/processor_helpers.rb +50 -0
- data/lib/paperclip/rails_environment.rb +25 -0
- data/lib/paperclip/railtie.rb +31 -0
- data/lib/paperclip/schema.rb +83 -0
- data/lib/paperclip/storage/filesystem.rb +90 -0
- data/lib/paperclip/storage/fog.rb +241 -0
- data/lib/paperclip/storage/s3.rb +440 -0
- data/lib/paperclip/storage.rb +3 -0
- data/lib/paperclip/style.rb +109 -0
- data/lib/paperclip/tempfile.rb +43 -0
- data/lib/paperclip/tempfile_factory.rb +23 -0
- data/lib/paperclip/thumbnail.rb +121 -0
- data/lib/paperclip/url_generator.rb +72 -0
- data/lib/paperclip/validators/attachment_content_type_validator.rb +88 -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 +30 -0
- data/lib/paperclip/validators/attachment_size_validator.rb +115 -0
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +27 -0
- data/lib/paperclip/validators.rb +74 -0
- data/lib/paperclip/version.rb +3 -0
- data/lib/paperclip.rb +213 -0
- data/lib/tasks/paperclip.rake +127 -0
- data/paperclip.gemspec +51 -0
- data/shoulda_macros/paperclip.rb +134 -0
- data/spec/database.yml +4 -0
- data/spec/paperclip/attachment_definitions_spec.rb +13 -0
- data/spec/paperclip/attachment_processing_spec.rb +82 -0
- data/spec/paperclip/attachment_registry_spec.rb +130 -0
- data/spec/paperclip/attachment_spec.rb +1494 -0
- data/spec/paperclip/content_type_detector_spec.rb +48 -0
- data/spec/paperclip/deprecations_spec.rb +65 -0
- data/spec/paperclip/file_command_content_type_detector_spec.rb +26 -0
- data/spec/paperclip/filename_cleaner_spec.rb +14 -0
- data/spec/paperclip/geometry_detector_spec.rb +39 -0
- data/spec/paperclip/geometry_parser_spec.rb +73 -0
- data/spec/paperclip/geometry_spec.rb +255 -0
- data/spec/paperclip/glue_spec.rb +44 -0
- data/spec/paperclip/has_attached_file_spec.rb +142 -0
- data/spec/paperclip/integration_spec.rb +667 -0
- data/spec/paperclip/interpolations_spec.rb +262 -0
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +78 -0
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +139 -0
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +83 -0
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +131 -0
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +104 -0
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +25 -0
- data/spec/paperclip/io_adapters/registry_spec.rb +35 -0
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +64 -0
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +146 -0
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +127 -0
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +99 -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 +79 -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 +222 -0
- data/spec/paperclip/plural_cache_spec.rb +37 -0
- data/spec/paperclip/processor_helpers_spec.rb +57 -0
- data/spec/paperclip/processor_spec.rb +26 -0
- data/spec/paperclip/rails_environment_spec.rb +33 -0
- data/spec/paperclip/rake_spec.rb +103 -0
- data/spec/paperclip/schema_spec.rb +248 -0
- data/spec/paperclip/storage/filesystem_spec.rb +79 -0
- data/spec/paperclip/storage/fog_spec.rb +535 -0
- data/spec/paperclip/storage/s3_live_spec.rb +182 -0
- data/spec/paperclip/storage/s3_spec.rb +1526 -0
- data/spec/paperclip/style_spec.rb +255 -0
- data/spec/paperclip/tempfile_factory_spec.rb +33 -0
- data/spec/paperclip/thumbnail_spec.rb +500 -0
- data/spec/paperclip/url_generator_spec.rb +211 -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/spec/paperclip/validators/attachment_presence_validator_spec.rb +85 -0
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +229 -0
- 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 +43 -0
- data/spec/support/assertions.rb +71 -0
- data/spec/support/deprecations.rb +9 -0
- data/spec/support/fake_model.rb +25 -0
- data/spec/support/fake_rails.rb +12 -0
- 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/bad.png +1 -0
- data/spec/support/fixtures/empty.html +1 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/fog.yml +8 -0
- data/spec/support/fixtures/rotated.jpg +0 -0
- data/spec/support/fixtures/s3.yml +8 -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 +1 -0
- data/spec/support/fixtures/twopage.pdf +0 -0
- data/spec/support/fixtures/uppercase.PNG +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/spec/support/mock_attachment.rb +22 -0
- data/spec/support/mock_interpolator.rb +24 -0
- data/spec/support/mock_url_generator_builder.rb +27 -0
- data/spec/support/model_reconstruction.rb +60 -0
- data/spec/support/rails_helpers.rb +7 -0
- data/spec/support/test_data.rb +13 -0
- data/spec/support/version_helper.rb +9 -0
- metadata +606 -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
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
require 'appraisal'
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
require 'cucumber/rake/task'
|
|
5
|
+
|
|
6
|
+
desc 'Default: run unit tests.'
|
|
7
|
+
task :default => [:clean, :all]
|
|
8
|
+
|
|
9
|
+
desc 'Test the paperclip plugin under all supported Rails versions.'
|
|
10
|
+
task :all do |t|
|
|
11
|
+
if ENV['BUNDLE_GEMFILE']
|
|
12
|
+
exec('rake spec cucumber')
|
|
13
|
+
else
|
|
14
|
+
exec("rm -f gemfiles/*.lock")
|
|
15
|
+
Rake::Task["appraisal:gemfiles"].execute
|
|
16
|
+
Rake::Task["appraisal:install"].execute
|
|
17
|
+
exec('rake appraisal')
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
desc 'Test the paperclip plugin.'
|
|
22
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
23
|
+
|
|
24
|
+
desc 'Run integration test'
|
|
25
|
+
Cucumber::Rake::Task.new do |t|
|
|
26
|
+
t.cucumber_opts = %w{--format progress}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
desc 'Start an IRB session with all necessary files required.'
|
|
30
|
+
task :shell do |t|
|
|
31
|
+
chdir File.dirname(__FILE__)
|
|
32
|
+
exec 'irb -I lib/ -I lib/paperclip -r rubygems -r active_record -r tempfile -r init'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
desc 'Clean up files.'
|
|
36
|
+
task :clean do |t|
|
|
37
|
+
FileUtils.rm_rf "doc"
|
|
38
|
+
FileUtils.rm_rf "tmp"
|
|
39
|
+
FileUtils.rm_rf "pkg"
|
|
40
|
+
FileUtils.rm_rf "public"
|
|
41
|
+
FileUtils.rm "test/debug.log" rescue nil
|
|
42
|
+
FileUtils.rm "test/paperclip.db" rescue nil
|
|
43
|
+
Dir.glob("paperclip-*.gem").each{|f| FileUtils.rm f }
|
|
44
|
+
end
|
data/UPGRADING
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
##################################################
|
|
2
|
+
# NOTE FOR UPGRADING FROM PRE-3.0 VERSION #
|
|
3
|
+
##################################################
|
|
4
|
+
|
|
5
|
+
Paperclip 3.0 introduces a non-backward compatible change in your attachment
|
|
6
|
+
path. This will help to prevent attachment name clashes when you have
|
|
7
|
+
multiple attachments with the same name. If you didn't alter your
|
|
8
|
+
attachment's path and are using Paperclip's default, you'll have to add
|
|
9
|
+
`:path` and `:url` to your `has_attached_file` definition. For example:
|
|
10
|
+
|
|
11
|
+
has_attached_file :avatar,
|
|
12
|
+
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
|
|
13
|
+
:url => "/system/:attachment/:id/:style/:filename"
|
|
14
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
When /^I attach an? "([^\"]*)" "([^\"]*)" file to an? "([^\"]*)" on S3$/ do |attachment, extension, model|
|
|
2
|
+
stub_paperclip_s3(model, attachment, extension)
|
|
3
|
+
attach_file attachment,
|
|
4
|
+
"features/support/paperclip/#{model.gsub(" ", "_").underscore}/#{attachment}.#{extension}"
|
|
5
|
+
end
|
|
6
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
|
|
12
|
+
Scenario: Configure defaults for all attachments through Railtie
|
|
13
|
+
Given I add this snippet to config/application.rb:
|
|
14
|
+
"""
|
|
15
|
+
config.paperclip_defaults = {
|
|
16
|
+
:url => "/paperclip/custom/:attachment/:style/:filename",
|
|
17
|
+
:validate_media_type => false
|
|
18
|
+
}
|
|
19
|
+
"""
|
|
20
|
+
And I attach :attachment
|
|
21
|
+
And I start the rails application
|
|
22
|
+
When I go to the new user page
|
|
23
|
+
And I fill in "Name" with "something"
|
|
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"
|
|
41
|
+
And I press "Submit"
|
|
42
|
+
Then I should see "Name: something"
|
|
43
|
+
And I should see an image with a path of "/paperclip/custom/attachments/original/5k.png"
|
|
44
|
+
|
|
45
|
+
Scenario: Filesystem integration test
|
|
46
|
+
Given I attach :attachment with:
|
|
47
|
+
"""
|
|
48
|
+
:url => "/system/:attachment/:style/:filename"
|
|
49
|
+
"""
|
|
50
|
+
And I start the rails application
|
|
51
|
+
When I go to the new user page
|
|
52
|
+
And I fill in "Name" with "something"
|
|
53
|
+
And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
|
|
54
|
+
And I press "Submit"
|
|
55
|
+
Then I should see "Name: something"
|
|
56
|
+
And I should see an image with a path of "/system/attachments/original/5k.png"
|
|
57
|
+
And the file at "/system/attachments/original/5k.png" should be the same as "spec/support/fixtures/5k.png"
|
|
58
|
+
|
|
59
|
+
Scenario: S3 Integration test
|
|
60
|
+
Given I attach :attachment with:
|
|
61
|
+
"""
|
|
62
|
+
:storage => :s3,
|
|
63
|
+
:path => "/:attachment/:style/:filename",
|
|
64
|
+
:s3_credentials => Rails.root.join("config/s3.yml"),
|
|
65
|
+
:styles => { :square => "100x100#" }
|
|
66
|
+
"""
|
|
67
|
+
And I write to "config/s3.yml" with:
|
|
68
|
+
"""
|
|
69
|
+
bucket: paperclip
|
|
70
|
+
access_key_id: access_key
|
|
71
|
+
secret_access_key: secret_key
|
|
72
|
+
"""
|
|
73
|
+
And I start the rails application
|
|
74
|
+
When I go to the new user page
|
|
75
|
+
And I fill in "Name" with "something"
|
|
76
|
+
And I attach the file "spec/support/fixtures/5k.png" to "Attachment" on S3
|
|
77
|
+
And I press "Submit"
|
|
78
|
+
Then I should see "Name: something"
|
|
79
|
+
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/original/5k.png"
|
|
80
|
+
And the file at "http://s3.amazonaws.com/paperclip/attachments/original/5k.png" should be uploaded to S3
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Feature: Migration
|
|
2
|
+
|
|
3
|
+
Background:
|
|
4
|
+
Given I generate a new rails application
|
|
5
|
+
And I write to "app/models/user.rb" with:
|
|
6
|
+
"""
|
|
7
|
+
class User < ActiveRecord::Base; end
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
Scenario: Vintage syntax
|
|
11
|
+
When I write to "db/migrate/01_add_attachment_to_users.rb" with:
|
|
12
|
+
"""
|
|
13
|
+
class AddAttachmentToUsers < ActiveRecord::Migration
|
|
14
|
+
def self.up
|
|
15
|
+
create_table :users do |t|
|
|
16
|
+
t.has_attached_file :avatar
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.down
|
|
21
|
+
drop_attached_file :users, :avatar
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
"""
|
|
25
|
+
And I run a migration
|
|
26
|
+
Then I should have attachment columns for "avatar"
|
|
27
|
+
|
|
28
|
+
When I rollback a migration
|
|
29
|
+
Then I should not have attachment columns for "avatar"
|
|
30
|
+
|
|
31
|
+
Scenario: New syntax with create_table
|
|
32
|
+
When I write to "db/migrate/01_add_attachment_to_users.rb" with:
|
|
33
|
+
"""
|
|
34
|
+
class AddAttachmentToUsers < ActiveRecord::Migration
|
|
35
|
+
def self.up
|
|
36
|
+
create_table :users do |t|
|
|
37
|
+
t.attachment :avatar
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
"""
|
|
42
|
+
And I run a migration
|
|
43
|
+
Then I should have attachment columns for "avatar"
|
|
44
|
+
|
|
45
|
+
Scenario: New syntax outside of create_table
|
|
46
|
+
When I write to "db/migrate/01_create_users.rb" with:
|
|
47
|
+
"""
|
|
48
|
+
class CreateUsers < ActiveRecord::Migration
|
|
49
|
+
def self.up
|
|
50
|
+
create_table :users
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
"""
|
|
54
|
+
And I write to "db/migrate/02_add_attachment_to_users.rb" with:
|
|
55
|
+
"""
|
|
56
|
+
class AddAttachmentToUsers < ActiveRecord::Migration
|
|
57
|
+
def self.up
|
|
58
|
+
add_attachment :users, :avatar
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.down
|
|
62
|
+
remove_attachment :users, :avatar
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
"""
|
|
66
|
+
And I run a migration
|
|
67
|
+
Then I should have attachment columns for "avatar"
|
|
68
|
+
|
|
69
|
+
When I rollback a migration
|
|
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"
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
run_simple %(bundle exec #{runner_command} "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 #{runner_command} "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 #{runner_command} "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 #{runner_command} "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
|
+
expect(attachment_path(filename)).not_to be_an_existing_file
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
|
|
86
|
+
cd(".") do
|
|
87
|
+
columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
|
|
88
|
+
expect_columns = [
|
|
89
|
+
["#{attachment_name}_file_name", :string],
|
|
90
|
+
["#{attachment_name}_content_type", :string],
|
|
91
|
+
["#{attachment_name}_file_size", :integer],
|
|
92
|
+
["#{attachment_name}_updated_at", :datetime]
|
|
93
|
+
]
|
|
94
|
+
expect(columns).to include(*expect_columns)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
|
|
99
|
+
cd(".") do
|
|
100
|
+
columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
|
|
101
|
+
expect_columns = [
|
|
102
|
+
["#{attachment_name}_file_name", :string],
|
|
103
|
+
["#{attachment_name}_content_type", :string],
|
|
104
|
+
["#{attachment_name}_file_size", :integer],
|
|
105
|
+
["#{attachment_name}_updated_at", :datetime]
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
expect(columns).not_to include(*expect_columns)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Given /^I generate a new rails application$/ do
|
|
2
|
+
steps %{
|
|
3
|
+
When I run `bundle exec #{new_application_command} #{APP_NAME} --skip-bundle`
|
|
4
|
+
And I cd to "#{APP_NAME}"
|
|
5
|
+
And I turn off class caching
|
|
6
|
+
And I fix the application.rb for 3.0.12
|
|
7
|
+
And I write to "Gemfile" with:
|
|
8
|
+
"""
|
|
9
|
+
source "http://rubygems.org"
|
|
10
|
+
gem "rails", "#{framework_version}"
|
|
11
|
+
gem "sqlite3", "1.3.8", :platform => [:ruby, :rbx]
|
|
12
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
|
13
|
+
gem "jruby-openssl", :platform => :jruby
|
|
14
|
+
gem "capybara"
|
|
15
|
+
gem "gherkin"
|
|
16
|
+
gem "aws-sdk"
|
|
17
|
+
gem "racc", :platform => :rbx
|
|
18
|
+
gem "rubysl", :platform => :rbx
|
|
19
|
+
"""
|
|
20
|
+
And I remove turbolinks
|
|
21
|
+
And I empty the application.js file
|
|
22
|
+
And I configure the application to use "paperclip" from this project
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Given "I fix the application.rb for 3.0.12" do
|
|
27
|
+
cd(".") do
|
|
28
|
+
File.open("config/application.rb", "a") do |f|
|
|
29
|
+
f << "ActionController::Base.config.relative_url_root = ''"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Given "I allow the attachment to be submitted" do
|
|
35
|
+
cd(".") do
|
|
36
|
+
transform_file("app/controllers/users_controller.rb") do |content|
|
|
37
|
+
content.gsub("params.require(:user).permit(:name)",
|
|
38
|
+
"params.require(:user).permit!")
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Given "I remove turbolinks" do
|
|
44
|
+
cd(".") do
|
|
45
|
+
transform_file("app/assets/javascripts/application.js") do |content|
|
|
46
|
+
content.gsub("//= require turbolinks", "")
|
|
47
|
+
end
|
|
48
|
+
transform_file("app/views/layouts/application.html.erb") do |content|
|
|
49
|
+
content.gsub(', "data-turbolinks-track" => true', "")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
Given /^I attach :attachment$/ do
|
|
55
|
+
attach_attachment("attachment")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
Given /^I attach :attachment with:$/ do |definition|
|
|
59
|
+
attach_attachment("attachment", definition)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
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}"
|
|
68
|
+
if definition
|
|
69
|
+
snippet += ", \n"
|
|
70
|
+
snippet += definition
|
|
71
|
+
end
|
|
72
|
+
snippet += "\ndo_not_validate_attachment_file_type :#{name}\n"
|
|
73
|
+
cd(".") do
|
|
74
|
+
transform_file("app/models/user.rb") do |content|
|
|
75
|
+
content.sub(/end\Z/, "#{snippet}\nend")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
Given "I empty the application.js file" do
|
|
81
|
+
cd(".") do
|
|
82
|
+
transform_file("app/assets/javascripts/application.js") do |content|
|
|
83
|
+
""
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
|
|
89
|
+
step %[I successfully run `bundle exec #{generator_command} scaffold #{model_name} #{attributes}`]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
|
|
93
|
+
step %[I successfully run `bundle exec #{generator_command} paperclip #{model_name} #{attachment_name}`]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
Given /^I run a migration$/ do
|
|
97
|
+
step %[I successfully run `bundle exec rake db:migrate --trace`]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
When /^I rollback a migration$/ do
|
|
101
|
+
step %[I successfully run `bundle exec rake db:rollback STEPS=1 --trace`]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
Given /^I update my new user view to include the file upload field$/ do
|
|
105
|
+
steps %{
|
|
106
|
+
Given I overwrite "app/views/users/new.html.erb" with:
|
|
107
|
+
"""
|
|
108
|
+
<%= form_for @user, :html => { :multipart => true } do |f| %>
|
|
109
|
+
<%= f.label :name %>
|
|
110
|
+
<%= f.text_field :name %>
|
|
111
|
+
<%= f.label :attachment %>
|
|
112
|
+
<%= f.file_field :attachment %>
|
|
113
|
+
<%= submit_tag "Submit" %>
|
|
114
|
+
<% end %>
|
|
115
|
+
"""
|
|
116
|
+
}
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
Given /^I update my user view to include the attachment$/ do
|
|
120
|
+
steps %{
|
|
121
|
+
Given I overwrite "app/views/users/show.html.erb" with:
|
|
122
|
+
"""
|
|
123
|
+
<p>Name: <%= @user.name %></p>
|
|
124
|
+
<p>Attachment: <%= image_tag @user.attachment.url %></p>
|
|
125
|
+
"""
|
|
126
|
+
}
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
Given /^I add this snippet to the User model:$/ do |snippet|
|
|
130
|
+
file_name = "app/models/user.rb"
|
|
131
|
+
cd(".") do
|
|
132
|
+
content = File.read(file_name)
|
|
133
|
+
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
Given /^I add this snippet to config\/application.rb:$/ do |snippet|
|
|
138
|
+
file_name = "config/application.rb"
|
|
139
|
+
cd(".") do
|
|
140
|
+
content = File.read(file_name)
|
|
141
|
+
File.open(file_name, 'w') {|f| f << content.sub(/class Application < Rails::Application.*$/, "class Application < Rails::Application\n#{snippet}\n")}
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
Given /^I start the rails application$/ do
|
|
146
|
+
cd(".") do
|
|
147
|
+
require "./config/environment"
|
|
148
|
+
require "capybara/rails"
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
Given /^I reload my application$/ do
|
|
153
|
+
Rails::Application.reload!
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
When /^I turn off class caching$/ do
|
|
157
|
+
cd(".") do
|
|
158
|
+
file = "config/environments/test.rb"
|
|
159
|
+
config = IO.read(file)
|
|
160
|
+
config.gsub!(%r{^\s*config.cache_classes.*$},
|
|
161
|
+
"config.cache_classes = false")
|
|
162
|
+
File.open(file, "w"){|f| f.write(config) }
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
|
|
167
|
+
expected = IO.read(path)
|
|
168
|
+
actual = read_from_web(web_file)
|
|
169
|
+
expect(actual).to eq(expected)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
|
|
173
|
+
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
|
|
174
|
+
steps %{And I run `bundle install --local`}
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
|
|
178
|
+
append_to_gemfile "gem '#{gem_name}'"
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
When /^I append gems from Appraisal Gemfile$/ do
|
|
182
|
+
File.read(ENV['BUNDLE_GEMFILE']).split(/\n/).each do |line|
|
|
183
|
+
if line =~ /^gem "(?!rails|appraisal)/
|
|
184
|
+
append_to_gemfile line.strip
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
|
|
190
|
+
comment_out_gem_in_gemfile gemname
|
|
191
|
+
end
|
|
192
|
+
|
|
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
|
+
Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
|
|
200
|
+
filename = "#{directory}/#{processor}.rb"
|
|
201
|
+
cd(".") do
|
|
202
|
+
FileUtils.mkdir_p directory
|
|
203
|
+
File.open(filename, "w") do |f|
|
|
204
|
+
f.write(<<-CLASS)
|
|
205
|
+
module Paperclip
|
|
206
|
+
class #{processor.capitalize} < Processor
|
|
207
|
+
def make
|
|
208
|
+
basename = File.basename(file.path, File.extname(file.path))
|
|
209
|
+
dst_format = options[:format] ? ".\#{options[:format]}" : ''
|
|
210
|
+
|
|
211
|
+
dst = Tempfile.new([basename, dst_format])
|
|
212
|
+
dst.binmode
|
|
213
|
+
|
|
214
|
+
convert(':src :dst',
|
|
215
|
+
src: File.expand_path(file.path),
|
|
216
|
+
dst: File.expand_path(dst.path)
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
dst
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
CLASS
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def transform_file(filename)
|
|
229
|
+
if File.exist?(filename)
|
|
230
|
+
content = File.read(filename)
|
|
231
|
+
File.open(filename, "w") do |f|
|
|
232
|
+
content = yield(content)
|
|
233
|
+
f.write(content)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|