This commit allows passing a custom `purpose:` keyword argument to both
`find_signed!` and `signed_id`. This matches the signature of the
`super` methods in ActiveRecord, and it is already possible with the
non-bang [`find_signed`][find_signed] method, since that one doesn't
have an override in ActiveStorage (although perhaps it should, to set
the default :blob_id purpose)
This is useful in cases where you want to further isolate different
types of blobs, for example if they have different levels of
authorization.
[find_signed]: be11d1b6e8/activerecord/lib/active_record/signed_id.rb (L42-L48)
Generating a video preview by capturing only the first frame of a video
is problematic for videos that begin with a fade in from black. By
using keyframe and scene detection that is built in to FFmpeg, we can
generate a more representative preview.
`Minitest.plugin_rails_init` sets `Minitest.backtrace_filter` to
`Rails.backtrace_cleaner` right before tests are run, overwriting the
value set in test_helper.rb.
`Rails.backtrace_cleaner` silences backtrace lines that do not start
with `Rails.root` followed by e.g. "lib/" or "test/". Thus when
`Rails.root` is a subdirectory of the project directory -- for example,
when testing a plugin that has a dummy app -- all lines of the backtrace
are silenced.
This commit adds a fallback such that when all backtrace lines are
silenced, the original `Minitest.backtrace_filter` is used instead.
Additionally, this commit refactors and expands existing test coverage.
The `linguist-vendored` attribute excludes the specified file from the
project's language stats on GitHub. The `linguist-generated` attribute
does the same, and also suppresses that file in diffs on GitHub.
See https://github.com/github/linguist for more information.
Permit applications to hack in custom DB config for ASt models until ASt has first-class multi-DB support:
ActiveSupport.on_load(:active_storage_record) do
connects_to reading: :active_storage_replica, writing: :active_storage_primary
end
rebase
When a PDF is used for both printing and displaying. It will most likely
contain a crop box in order to hide print margins when displaying the PDF.
Use Poppler's parameter to automatically use the crop box (visible box)
rather than the media box (printable box) in order to remove those margins
when drawing the PDF.
See https://manpages.debian.org/testing/poppler-utils/pdftoppm.1.en.html
Guard against the case where ActiveStorage.verifier isn't yet initialized at load time.
Yes, you're not supposed to load AR models in initializers, but it's easy to do accidentally as long as we don't prevent it. We should be resilient against it wherever practical.
Some video formats, such as WebM, do not store duration information at
the level of the video stream. Instead, the duration is stored as part
of the container format information.
This commit modifies `VideoAnalyzer` to use the duration from the video
container when the duration from the video stream is not available.
Fixes#40130.
An Active Storage `Blob` must be identified before it can be reliably
validated. For direct uploads, a `Blob` is identified when it is
attached, rather than when it is created.
Before this commit, the sequence of events when attaching a `Blob` was:
1. Find the `Blob`.
2. Assign the `Blob` to an `Attachment`.
3. Save the owner record.
4. Save the `Attachment`.
5. Identify the `Blob`'s true `content_type` from its file.
6. Save the `Blob`.
This meant that the owner record's validations might not see the
`Blob`'s true `content_type`.
After this commit, the sequence of events will be:
1. Find the `Blob`.
2. Identify the `Blob`'s true `content_type` from its file.
3. Assign the `Blob` to an `Attachment`.
4. Save the owner record.
5. Save the `Attachment`.
6. Save the `Blob`.
Thus the `Blob`'s true `content_type` will be available when running the
owner record's validations.
This commit fixes the "resized variation of BMP blob" test.
By default `create_file_blob` use "image/jpeg" as content type,
since this test does not specify the correct `content_type` for
a `*.bmp` image ("image/bmp") the `ActiveStorage::Variant#specification`
consider the blob as a web image which causes the variant to return a
`*.bmp` URL and a "BMP" type, this is an incorrect behavior since if you
upload a `*.bmp` image the variant will have a PNG format with "image/png"
as content type.
After this change the test will cover the current activestorage behavior.
Changes:
* Specify correct `content_type` on "resized variation of BMP blob" test.
* Change asserts to cover the current activestorage behavior.
Currently `delete` is used on the `purge` and `purge_later` methods,
that prevent any callbacks to be triggered which causes the parent
model to not be updated when an attachment is purged. This behaviour
cause issues on some caching strategies as reported here: https://github.com/rails/rails/issues/39858
Changes:
* Add `record&.touch` on `attachment#purge`
* Add `record&.touch` on `attachment#purge_later`
* Remove extra blank line on attachment.rb
* Add tests which are failing before this change and pass after the change
Error entries appear in the log when we request ActiveStorage
controllers (`ActiveStorage::Representations::ProxyController#show`,
`ActiveStorage::Blobs::ProxyController#show`).
These entries look like: "Couldn't find template for digesting:
active_storage/representations/proxy/show".
These controllers use the method
`ActionController::ConditionalGet#http_cache_forever`,
and therefore `ActionController::ConditionalGet#combine_etags` method,
and therefore `ActionController::EtagWithTemplateDigest` module via
`etaggers` array.
`ActionController::EtagWithTemplateDigest` module requires a template
(view).
We have no views in ActiveStorage, so `EtagWithTemplateDigest` is
now turned off in ActiveStorage controllers by
`etag_with_template_digest` class attribute.
This change swaps the CommonJS require() syntax in the Webpacker
application.js pack template file and in documentation examples with ES
module import syntax.
Benefits of this change include:
Provides continuity with the larger frontend community: Arguably, one of
the main draws in adopting Webpacker is its integration with Babel to
support ES module syntax. For a fresh Rails install with Webpacker, the
application.js file will be the first impression most Rails developers
have with webpack and Webpacker. Most of the recent documentation and
examples they will find online for using other libraries will be based
on ES module syntax.
Reduces confusion: Developers commonly add ES imports to their
application.js pack, typically by following online examples, which means
mixing require() and import statements in a single file. This leads to
confusion and unnecessary friction about differences between require()
and import.
Embraces browser-friendliness: The ES module syntax forward-looking and
is meant to be supported in browsers. On the other hand, require()
syntax is synchronous by design and not browser-supported as CommonJS
originally was adopted in Node.js for server-side JavaScript. That
webpack supports require() syntax is merely a convenience.
Encourages best practices regarding optimization: webpack can statically
analyze ES modules and "tree-shake", i.e., strip out unused exports from
the final build (given certain conditions are met, including
`sideEffects: false` designation in package.json).
Fixes that calling e.g. `url_for @user.avatar` would return an incorrect URL resulting in a 404. The Active Storage URL helper ends up calling ActiveStorage::Attachment#signed_id, which previously delegated to ActiveStorage::Blob#signed_id but changed to return a signed *attachment* ID in 1a3dc42.
The Active Storage controllers pass signed IDs to ActiveStorage::Blob.find_signed, so we need signed blob IDs.
Prior to this commit, a `dup`ed record and its originating record would
share the same `Attached` proxy objects. Those proxy objects, in turn,
would point to the same `Attachment` associations, causing changes made
through the proxy interface to affect both records.
- Add the configuration option for annotating templates with file names to the generated app.
- Add `annotate_rendered_view_with_filenames` option to configuring guide.