Commit Graph

480 Commits

Author SHA1 Message Date
Maurice Kühlborn
455a122ef0 Add progressive JPG to default variable content types 2018-11-21 23:21:01 +01:00
Gannon McGibbon
e74fdbe00c Amend CVE note and security guide section wordings
Reword first sentence of dep management and CVE section of
security guide. Also, reword and move gemspec notes above deps.

[ci skip]
2018-11-06 18:06:57 -05:00
Gannon McGibbon
1c11688b56 Add CVE note to security guide and gemspecs
[ci skip]
2018-11-06 14:25:36 -05:00
Kyle Keesling
79e086efc4
update activestorage attachment model documentation reflect recent behavior changes 2018-10-24 09:08:45 -04:00
Rob Jonson
d8707e0dfc enable_fragment_cache_logging
fragment caching was refactored in (I think 5.2) and by default doesn't log cache info

this is confusing in development where rails dev:cache now turns on caching, but doesn't show any different logging output

better to enable debugging by default for dev - and let people turn it off if preferred
2018-10-09 11:48:40 +01:00
Donnie Propst
b4e827d80a Point to requiring the ASt engine in the installation instructions [ci skip] 2018-10-08 11:26:51 -04:00
Graham Conzett
bba5ecc923 Use content_mime_type 2018-10-08 09:50:51 -04:00
Graham Conzett
1986048d27 Fix issue ActiveStorage direct upload disk
Fix an issue in ActiveStorage where a direct upload to disk storage
would fail due to a content type mismatch if the file was uploaded using
a mime-type synonym.
2018-10-07 16:07:09 -04:00
David Heinemeier Hansson
4838c1716a
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps

* Stop including coffee-rails by default

* Drop using a js_compressor by default

* Drop extra test for coffeescript inclusion by default

* Stick with skip_javascript to signify skipping webpack

* Don't install a JS runtime by default any more

* app/javascript will be the new default directory for JS

* Make it clear that this is just for configuring the default Webpack framework setup now

* Start using the Webpack tag in the default layout

* Irrelevant test

* jQuery is long gone

* Stop having asset pipeline compile default application.js

* Add rails-ujs by default to the Webpack setup

* Add Active Storage JavaScript to application.js pack by default

* Consistent quoting

* Add Turbolinks to default pack

* Add Action Cable to default pack

Need some work on how to set the global consumer that channels will
work with. @javan?

* Require all channels by default and use a separate consumer stub

* Channel generator now targets Webpack style

* Update task docs to match new generator style

* Use uniform import style

* Drop the JS assets generator

It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!

* Add app/javascript to the stats directories

* Simpler import style

Which match the other imports.

* Address test failures from dropping JS compilation (and compression)

* webpacker-default: Modify `AssetsGeneratorTest`

Before:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201

F

Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10

.

Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```

After:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571

..

Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```

* webpacker-default: Modify `ChannelGeneratorTest`

Before:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986

.F

Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34

.F

Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22

E

Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60

F

Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80

F

Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68

Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```

After:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857

.......

Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```

* Fix shared generator tests.

* webpacker-default: Modify `ControllerGeneratorTest`

The JS assets generator was dropped. ref. 46215b1794

* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.

This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.

* require webpacker in test app

* Add webpacker without making the build hang/timeout. (#33640)

* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required

* no longer need to have webpacker in env templates as webpacker moved this config to yml file

* Fix rubocop violation

* Got the test passing for the running scaffold

* update expected lines of code

* update middleware tests to account for webpacker

* disable js in plugins be default to get the tests passing (#34009)

* clear codeclimate report issues

* Anything newer than currently released is good

* Use Webpacker development version during development of Rails

* Edge should get development webpacker as well

* Add changelog entry for Webpacker change
2018-09-30 22:31:21 -07:00
Rafael Mendonça França
f679933daa
Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
Kasper Timm Hansen
ed56a03104
Merge pull request #33829 from mtsmfm/encode-filename
Encode Content-Disposition filenames on send_data and send_file
2018-09-23 19:43:06 +02:00
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
bogdanvlviv
be0d22a8e1
Raise ActiveRecord::InvalidForeignKey in before_destroy for a blob if attachments exist
The issue #32584 was fixed in #33405 by adding foreign key constraint
to the `active_storage_attachments` table for blobs.
This commit implements fix on app-level in order to ensure that users
can't delete a blob with attachments even if they don't have the foreign key constraint.
See a related discussion in the Campfire:
https://3.basecamp.com/3076981/buckets/24956/chats/12416418@1236718899

Note that, we should backport it to `5-2-stable` too.

Related to #33405
2018-09-16 22:44:30 +03:00
Chris Bisnett
7dd9916c0d Configure Active Storage route prefix
Applications can configure the route prefix prepended to the Active
Storage routes. By default this maintains the previous prefix
`/rails/active_storage` but supports custom prefixes.

Before this change the route for serving blobs is fixed to
`/rails/active_storage/blobs/:signed_id/*filename`. After this change
it's possible to configure the route to something like
`/files/blobs/:signed_id/*filename`.
2018-09-14 10:40:18 -04:00
Fumiaki MATSUSHIMA
890485cfce Encode Content-Disposition filenames on send_data and send_file 2018-09-13 21:38:46 +09:00
Xavier Noria
f589e20b0a use "minitest" consistently
The name of the minitest library is spelled that way: regular font, and
lowercase. Lowercase is used even at the beginning of sentences, see

    http://docs.seattlerb.org/minitest/

I double-checked this with @zenspider too (thanks!).
2018-09-11 23:57:25 +02:00
Marcelo Perini Veloso
0d4ba40688 Fix zero-byte files upload 2018-09-06 20:04:21 -03:00
Cameron Bothner
aae56c3529 Handle only specifically relevant Azure HTTPErrors
The Azure gem uses `Azure::Core::Http::HTTPError` for everything:
checksum mismatch, missing object, network unavailable, and many more.
(https://www.rubydoc.info/github/yaxia/azure-storage-ruby/Azure/Core/Http/HTTPError).
Rescuing that class obscures all sorts of  configuration errors. We
should check the type of error in those rescue  blocks, and reraise when
needed.
2018-08-23 23:36:43 -04:00
George Claghorn
3868648cae Revert "Merge pull request #33667 from cbothner/azure-service-swallowing-all-errors"
This reverts commit b204d167c5cfebd59f771d406178e371811ac43a, reversing
changes made to de6a200f82a3de399fa685d583503bc88dbc5e9f.
2018-08-23 19:07:29 -04:00
Cameron Bothner
6acf2fa363 Handle only specifically relevant Azure HTTPErrors
The Azure gem uses `Azure::Core::Http::HTTPError` for everything:
checksum mismatch, missing object, network unavailable, and many more.
(https://www.rubydoc.info/github/yaxia/azure-storage-ruby/Azure/Core/Http/HTTPError).
Rescuing that class obscures all sorts of  configuration errors. We
should check the type of error in those rescue  blocks, and reraise when
needed.
2018-08-23 17:54:35 -04:00
George Claghorn
dc001dbd58
Merge pull request #33666 from cbothner/fail-gracefully-from-activestorage-file-not-found
Fail more gracefully from ActiveStorage missing file exceptions
2018-08-22 22:56:10 -04:00
Cameron Bothner
22efb2ec49 Respond with 404 in ActiveStorage::DiskController#show when file missing
`ActiveStorage::DiskController#show` generates a 404 Not Found response when
the requested file is missing from the disk service. It previously raised
`Errno::ENOENT`.
2018-08-21 15:35:58 -04:00
Cameron Bothner
5cd2d07bdc Translate service-specific missing object exceptions into a generic one
`ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
`ActiveStorage::FileNotFoundError` when the corresponding file is missing
from the storage service. Services translate service-specific missing
object exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service
and `Errno::ENOENT` for the disk service) into
`ActiveStorage::FileNotFoundError`.
2018-08-21 15:31:14 -04:00
bogdanvlviv
0e77706dc5
activestorage: yarn build
Context https://github.com/rails/rails/pull/33413#issuecomment-414137587
2018-08-19 19:33:16 +03:00
George Claghorn
093d8d3953 Retry ActiveStorage::AnalyzeJobs on download integrity check failures 2018-08-19 01:19:51 -04:00
George Claghorn
116fae6ef9 Remove superfluous test
This test no longer covers the behavior of ActiveStorage::PurgeJob. Attached blobs are ignored by ActiveStorage::Blob#purge as of 934fccd, which includes an equivalent model test.
2018-08-19 01:10:50 -04:00
Chris Seelus
880f977925 Enable multiple submit buttons for Active Storage forms 2018-08-18 19:31:39 +02:00
George Claghorn
e33c3cd8cc Extract ActiveStorage::SetCurrent
Provide a handy concern for custom Active Storage controllers that can't inherit from ActiveStorage::BaseController.
2018-08-16 01:41:15 -04:00
George Claghorn
2d3a28b949 Document all Active Storage error classes [ci skip] 2018-08-10 18:38:28 -04:00
George Claghorn
18425b8371 Add a generic base class for Active Storage exceptions
Closes #33292.

[Andrei Makarov & George Claghorn]
2018-08-10 18:35:49 -04:00
George Claghorn
697f4a93ad Extract transformers 2018-08-10 12:42:14 -04:00
George Claghorn
10129fbf57 DRY up web image checks in ActiveStorage::Variant 2018-08-09 19:53:12 -04:00
George Claghorn
79573b3aff Camelize instead of classifying
Avoid mangling service names that end in S:

    "GCS".classify # => "GC"
    "GCS".camelize # => "GCS"
2018-08-06 22:23:47 -04:00
Joel Taylor
3082786be6 Improve ActiveStorage service adapter error handling 2018-08-06 18:17:49 -07:00
George Claghorn
bd680dd59a Fix uploading Tempfiles to Azure Storage
Closes #32530.
2018-08-03 22:41:19 -04:00
George Claghorn
bba4d2dd8c Remove another unused require 2018-08-02 14:38:33 -04:00
George Claghorn
bd01f9831c Remove unused require 2018-08-01 09:59:04 -04:00
George Claghorn
fee7fba893 Retry ActiveStorage::PurgeJobs on DB deadlock 2018-07-31 19:29:23 -04:00
George Claghorn
cd2fe237f7 Guard against missing blobs caused by concurrent purges 2018-07-30 21:42:20 -04:00
George Claghorn
362042c0d7 Ignore concurrently-deleted files when deleting by prefix from GCS 2018-07-30 13:13:00 -04:00
George Claghorn
6a0b0154e3 Update ActiveStorage::Previewer docs
PDFPreviewer became MuPDFPreviewer in 0b717c2. Previewers are simple enough that we can just provide a single example.
2018-07-29 11:48:11 -04:00
George Claghorn
046bd75b0e Clarify condition
&& binds tighter than || in JavaScript, but we ought not expect readers to remember language trivia.
2018-07-27 00:20:47 -04:00
George Claghorn
195463736c Fix directly uploading zero-byte files
Closes #33450.
2018-07-27 00:11:22 -04:00
George Claghorn
e03add2248 Log streaming downloads 2018-07-26 18:48:04 -04:00
Jasper Martin
934fccd522 Ignore ActiveRecord::InvalidForeignKey in ActiveStorage::Blob#purge
Do nothing instead of raising an error when it’s called on an attached blob.
2018-07-26 09:24:31 -04:00
Matthew Draper
ec387c6dd9
Merge pull request #33229 from albertoalmagro/albertoalmagro/prefer-rails-command-over-bin-rails
Prefer rails command over bin/rails
2018-07-25 04:10:29 +09:30
George Claghorn
0f57f75008 Remove unused attribute 2018-07-21 14:21:14 -04:00
George Claghorn
6c45b04a73 Discard ActiveStorage::PurgeJobs on ActiveRecord::InvalidForeignKey 2018-07-20 11:18:37 -04:00
George Claghorn
562ec3dcd1 Test that ActiveStorage::Blob#purge fails when attachments exist 2018-07-20 10:28:14 -04:00
George Claghorn
2ae3a29508 Add a foreign-key constraint to the attachments table for blobs 2018-07-19 20:43:33 -04:00
George Claghorn
3f53296f18 Delete attachment before purging blob 2018-07-19 20:26:56 -04:00
George Claghorn
07ecaa614b Destroy blob record before deleting stored data 2018-07-19 20:26:40 -04:00
George Claghorn
3ccec9b80d Link between ActiveStorage::Blob#purge, #purge_later, and #delete [ci skip] 2018-07-18 22:06:15 -04:00
George Claghorn
ac6e6c6b99 Clarify the ActiveStorage::Attachment#purge and #purge_later docs
Link to the corresponding ActiveStorage::Blob methods, whose docs more accurately describe their effects. [ci skip]
2018-07-18 21:59:31 -04:00
George Claghorn
af02b9b78f Remove unnecessary tap 2018-07-17 16:23:53 -04:00
George Claghorn
e13e16f5ad Fix replacing many attachments via assign and attach 2018-07-17 09:33:48 -04:00
George Claghorn
379d98dcd4 Correct test name 2018-07-16 15:59:17 -04:00
George Claghorn
36ec5428bf Fix that successive ActiveStorage::Attached::Many#attach calls would overwrite previous attachments 2018-07-16 15:57:43 -04:00
George Claghorn
1d13de4e39 Test removing attachments via #attach 2018-07-16 08:59:23 -04:00
George Claghorn
94f2558f6a Restore inadvertently-removed fallback 2018-07-15 20:12:53 -04:00
George Claghorn
390097531b Support HTTP Range downloads from disk
Closes #32193.
2018-07-15 19:58:14 -04:00
George Claghorn
bd5eba1adf Clear attachment changes on reload 2018-07-13 14:48:45 -04:00
George Claghorn
28db8ba60e Implement ActiveStorage::Attached::{One,Many}#attach in terms of changes 2018-07-13 13:29:33 -04:00
George Claghorn
d20d6c7326 Fix that detaching could purge 2018-07-13 12:17:33 -04:00
George Claghorn
63951072af Fix analyzing new blobs from uploaded files on attach 2018-07-13 06:33:45 -04:00
George Claghorn
16f435f931 Discard ActiveStorage::PurgeJobs for missing blobs 2018-07-11 22:09:23 -04:00
George Claghorn
a1735a0dde Remove overly-broad retry in ActiveStorage::PurgeJob
We've never intentionally tripped this retry in production. Add retries for specific errors as needed.
2018-07-11 22:04:42 -04:00
George Claghorn
0b85123cd8 Raise an ArgumentError instead of a RuntimeError 2018-07-08 11:35:27 -04:00
George Claghorn
e8682c5bf0
Store newly-uploaded files on save rather than assignment 2018-07-07 23:25:33 -04:00
George Claghorn
03afddd2eb Fix that models can clobber each others' attachment reflections
Consider the following model definitions:

    class User < ApplicationRecord
      has_one_attached :avatar
    end

    class Group < ApplicationRecord
      has_one_attached :avatar
    end

If you attempt to reflect on the User model's avatar attachment via User.reflect_on_attachment, you could receive a reflection for the Group model's avatar attachment. Fix this by ensuring that each model class uses its own Hash object to track attachment reflections.
2018-07-07 17:09:31 -04:00
Alberto Almagro
40b209db53 Recommend use of rails over bin/rails
As discussed in #33203 rails command already looks for, and runs,
bin/rails if it is present.

We were mixing recommendations within guides and USAGE guidelines,
in some files we recommended using rails, in others bin/rails and
in some cases we even had both options mixed together.
2018-07-06 22:46:35 +02:00
Bibek Shrestha
637a8cde59 Remove vestigial require on ActiveStorage GCSService
The file `filename.rb` as mentioned in `require "active_storage/filename"`
belongs to the `app` folder while GCSService belongs to the lib folder.

Looking at the git blame, it was added in commit ccac681122 (diff-bda6a610ef1575b2c8458c96b7f12578)
where ActiveStorage::Filename was actually used. But it is no longer
required on master and therefore can be removed.

This allows anyone to use GCSService directly without enabling
ActiveStorage engine.
2018-07-04 17:04:26 -04:00
utilum
875ef6e748 Tweak Previewer::PopplerPDFPreviewer#pdftoppm_exists?
Does not warn `instance variable @pdftoppm_exists not initialized`.
2018-06-29 07:58:28 +02:00
George Claghorn
56b9d0fd3a Generate a new key for each service test
Sidestep Google Cloud Storage's restrictive per-object rate limit.
2018-06-25 18:49:26 -04:00
ishanray
d3715e67f1
Update service.rb 2018-06-24 00:09:31 -04:00
George Claghorn
b21f50d8ae Permit configuring the default service URL expiry 2018-06-21 11:06:32 -04:00
yuuji.yaginuma
38dbc8e2b8 Fix "warning: Net::HTTPResponse#header is obsolete"
Ref: cc77a81129/lib/net/http/response.rb (L138-L155)
2018-06-17 21:35:07 +09:00
utilum
d70bd73f05 Update ffmpeg -> FFmpeg, mutools|mupdf -> muPDF
[ci skip]
2018-06-08 11:28:11 +02:00
bogdanvlviv
8bc9062aee
Refactor activestorage/test/models/attached_test.rb
Don't include `ActiveJob::TestHelper` since there is no test that uses it.

Ensure removing of overridden User's methods.

Related to https://github.com/rails/rails/pull/33085#issuecomment-395548563
Module#remove_method is private in Ruby 2.4.

Related to fd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9
2018-06-07 23:29:03 +03:00
George Claghorn
d3e0a9f110 Exclude upload time from instrumented preview time 2018-06-03 20:24:51 -04:00
Rafael França
c1844477a1
Merge pull request #33018 from kddeisz/defined-attachments
ActiveStorage reflection
2018-06-01 14:24:06 -04:00
Kevin Deisz
6c7e6abfaa
Ensure reflection_class_for is private 2018-05-31 21:15:51 -04:00
Kevin Deisz
ce337d1757
Move ActiveStorage reflection logic entirely into ActiveStorage 2018-05-31 09:33:46 -04:00
George Claghorn
bd7ebf61fb Remove errant debugger call 2018-05-30 20:09:30 -04:00
George Claghorn
a6d80e164f Include blob ID in tempfile name for debugging convenience 2018-05-30 20:05:39 -04:00
Kevin Deisz
bc3b6ea461
Reflection for attachments
Add the ability to reflect on the attachments that have been defined using ActiveRecord::Reflection.
2018-05-30 13:28:22 -04:00
George Claghorn
cfb493a3a3 Fix reference 2018-05-28 16:30:26 -04:00
George Claghorn
1bdaccc0b8 Verify integrity after chunked download 2018-05-28 16:28:46 -04:00
utilum
39192e39ad Hide Active Storage migration installation task (#33007)
Resolves #33006
2018-05-28 18:09:38 +02:00
George Claghorn
097650c194
Merge pull request #32968 from utilum/shadowing_outer_variable
Avoid 2.6 warning: shadowing outer local variable - list
2018-05-23 21:56:33 -04:00
utilum
f6f8fc2ca0 Avoid 2.6 warning: shadowing outer local variable - list 2018-05-23 23:48:32 +02:00
utilum
a48f6a5d9f Enable warnings in all test tasks
Also normalize AJ task use t, like all other Rails test tasks.
2018-05-23 23:05:03 +02:00
Javan Makhmali
b60ee86d94 Change video preview format from PNG to JPG 2018-05-23 14:32:34 -04:00
George Claghorn
bdd8b6843c
Merge pull request #32144 from kazu9su/master
Add ActiveStorage::Service::DiskService#url_for_direct_upload test
2018-05-22 17:34:19 -04:00
Jacob Smith
0210ac0b43 Disable variant options when false or nil present
In response to https://github.com/rails/rails/issues/32917

In the current implementation, ActiveStorage passes all options to the underlying processor,
including when a key has a value of false.

For example, passing:

```
avatar.variant(resize: "100x100", monochrome: false, flip: "-90")
```

will return a monochrome image (or an error, pending on ImageMagick configuration) because
it passes `-monochrome false` to the command (but the command line does not allow disabling
flags this way, as usually a user would omit the flag entirely to disable that feature).

This fix only passes those keys forward to the underlying processor if the value responds to
`present?`. In practice, this means that `false` or `nil` will be filtered out before going
to the processor.

One possible use case would be for a user to be able to apply different filters to an avatar.
The code might look something like:

```
  variant_options = {
    monochrome: params[:monochrome],
    resize:     params[:resize]
  }

  avatar.variant(*variant_options)
```

Obviously some sanitization may be beneficial in a real-world scenario, but this type of
configuration object could be used in many other places as well.

- Add removing falsy values from varaints to changelog

- The entirety of #image_processing_transformation inject block was wrapped in `list.tap`
 to guard against the default `nil` being returned if no conditional was called.

- add test for explicitly true variant options
2018-05-21 10:38:15 -04:00
George Claghorn
9f95767979 Permit opening a blob in a custom tempdir 2018-05-17 19:14:11 -04:00
Josh Susser
fd0bd1bf68 Generate getter and setter methods in mixin
Generated attachment getter and setter methods are created within
the model's `GeneratedAssociationMethods` module to allow overriding
and composition using `super`.

Includes tests for new functionality.

Co-authored-by: Josh Susser <josh@hasmanythrough.com>
Co-authored-by: Jamon Douglas <terrildouglas@gmail.com>
2018-05-17 14:51:15 -07:00
Ryuta Kamizono
16c0cd1870 Fix formatting of author credit [ci skip] 2018-05-17 21:01:11 +09:00
lucfranken
8cc79f502e
Active storage: Image variant options not correct
### Steps to reproduce

Using Rails 5.2.0

When following this example:

http://api.rubyonrails.org/classes/ActiveStorage/Variant.html

`avatar.variant(resize: "100x100", monochrome: true, flip: "-90")`

### Expected behavior

Image should be rendered as flipped.

### Actual behavior

I get an error:

> failed with error: gm mogrify: Unrecognized option (-90).

### Fix:

According to: https://github.com/minimagick/minimagick the option should be called rotate:

`avatar.variant(resize: "100x100", monochrome: true, rotate: "-90")`

So **flip** changed to **rotate**.

### System configuration
**Rails version**: 5.2.0

**Ruby version**: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
2018-05-17 12:49:11 +02:00
Ryuta Kamizono
a1f9fe8bdd Remove unused require "active_support/core_ext/string/filters" 2018-05-17 15:30:49 +09:00