Commit Graph

1056 Commits

Author SHA1 Message Date
zzak
16ff9afb2e
Merge pull request #50275 from seanpdoyle/polymorphic-rename
Provide guidance for renaming classes in polymorphic associations [ci skip]
2023-12-25 08:01:15 +09:00
Akshay Birajdar
92138c40cc Use buffered read while generating checksum for blob 2023-12-22 08:43:58 +05:30
fatkodima
f48bbff32c Expose assert_queries_match and assert_no_queries_match assertions 2023-12-21 01:30:16 +02:00
David Heinemeier Hansson
2ec0ff42be
Add webp and avif as allowed formats for active storage to serve inline (#50265) 2023-12-17 17:39:04 -08:00
Petrik
8392c54e73 Expose assert_queries and assert_no_queries assertions
To assert the expected number of queries are made, Rails internally uses
`assert_queries` and `assert_no_queries`. These assertions can be
useful in applications as well.

By extracting these assertions to a module, the assertions can be
included where required.
These assertions are added to `ActiveSupport::TestCase` when
ActiveRecord is defined.

ActiveStorage, ActionView and ActionText are using this module now as
well, instead of duplicating the implementation.
The internal ActiveRecord::TestCase, used for testing ActiveRecord,
implements these assertions as well. However, these are slighlty more
advanced/complex and use the SQLCounter class. To keep things simple,
for now this implementation isn't used.
2023-12-11 12:31:16 +01:00
Sean Doyle
0d8b3f09af Provide guidance for renaming classes in polymorphic associations [ci skip]
Add guidance to the Association Basics and `.belongs_to` method
documentation to encourage the renaming of a model's Ruby class to
coincide with updates to the existing data in the database.

Since Action Text and Active Storage rely on polymorphic associations,
add similar warnings to their guides.

Co-authored-by: Petrik de Heus <petrik@deheus.net>
Co-authored-by: Stephen Hanson <s.hanson5@gmail.com>
Co-authored-by: zzak <zzakscott@gmail.com>
2023-12-08 09:19:21 -05:00
chaadow
4ca61ffacb Take AR affixes into account for AStorage models
All of ActiveStorage database modeltable nameshave been hard coded.
Therefore, ActiveRecord::Base.(prefix|suffix) were not taken into
consideration. To fix this we remove the hard coded lines. But then we
need to also override an internal method for specifying the prefix
because of a mystical ActiveRecord/ActiveStorage sync issue
(Suffix does not appear to have the issue)

Some tests were refactored to remove hard coded table name references,
making ActiveStorage test suite compatible with ActiveRecord config.
2023-12-07 00:01:16 +01:00
Jonathan Hefner
701e17b910 Fix submit button selector for type-less buttons
Follow-up to #48290.

The `:is(button, input)[type='submit']` selector does not match `button`
elements that omit the `type` attribute in favor relying on its default
value (which is `"submit"`).

Co-authored-by: Javan Makhmali <javan@javan.us>
2023-11-24 15:36:13 -06:00
Jonathan Hefner
06f0710061 Prevent autolink to method's own class [ci-skip]
Linking to a class from within its own documentation is more confusing
than helpful.
2023-11-23 11:46:16 -06:00
chaadow
f5acef7e48 Fix AS:Representations::ProxyController returning the wrong preview
When a blob is a representable of kind `previewable`, the preview
image that's being proxied is always the original preview image,
discarding completely the `variation_key` param passed in the request.

This commit fixes this by editing `Preview` and `VariantWithRecord` to
have full synchronized API with `Variant`. this will then allow the
ProxyController to not call `representable#image` but `representable`
instead.

As all 3 classes are now 100% interchangeable, we can deprecate the use
of `Representable#image`. Users of this class won't need to call this
method as it's become obsolete. and in case of `Preview#image`
erroneous.
2023-11-21 21:00:35 +01:00
Jonathan Hefner
5d0ab554e3
Merge pull request #50107 from chaadow/fix_proxy_controller_untracked_variants
[ActiveStorage] Fix Non tracked variants not working with `ActiveStorage::Representations::ProxyController`
2023-11-20 14:46:00 -06:00
chaadow
cb3fdaf8e4 Fix representation proxy for untracked variants
`ActiveStorage::Variant`, the class used to handle untracked variants,
is lacking some methods to make it compliant with
`ActiveStorage::Representations::ProxyController#send_blob_stream`.

This commit fixes the proxying of untracked variant by adding the
missing methods.
2023-11-20 19:57:01 +01:00
Jonathan Hefner
0ad26f7890
Merge pull request #48290 from marckohlbrugge/patch-1
Support nested elements inside <button>
2023-11-20 11:25:41 -06:00
Jonathan Hefner
e514c586f1 Add CHANGELOG entry for #50082 [ci-skip] 2023-11-17 16:43:39 -06:00
chaadow
2edcda8576 Discard unrepresentable blobs while preprocessing
Preprocessing "unpresentable" blobs (neither variabe, nor previewable)
will result in a `ActiveStorage::UnrepresentableError`, which will retry
following `ActiveJob::Base` default retry logic.

This commit discards any blob that's not representable to cleanup the
job adapter queue.
2023-11-17 22:44:07 +01:00
Max Notarangelo
185c19c5ae fix typo in production initializer generator
And put "info" in quotes.
2023-11-16 15:00:07 -08:00
chaadow
eae19656fe Prevent AS::Preview#processed to generate an empty variant
if an empty hash is passed to a preview call (`blob.preview({})`)
We go through the original preview instead of regenerating a variation
based on the original preview image which would result in a performance
penalty
2023-11-15 21:01:16 +01:00
Marc Köhlbrugge
a1504f457c Support nested elements inside <button>
This change is necessary to address a potential issue that could arise when a button or an input of type submit contains child elements, such as spans, icons, or other HTML elements.

Currently, ActiveStorage's `didClick` event listener checks the target of the click event to determine if a submit button was clicked. The target property of the event refers to the specific HTML element that was clicked.

In cases where a submit button contains child elements, and one of these child elements is the element that actually gets clicked, the target would refer to this child element, not the button itself.

Since the `didClick` function checks if the target is a button or an input of type submit, this check would fail, and the button wouldn't be stored in `submitButtonsByForm`.

As a result, if the form is then submitted after a direct upload, the first submit button in the form could be incorrectly used to submit the form, even if a different button was originally clicked. This could cause unexpected behavior, as different submit buttons might be intended to trigger different actions on form submission.

By using the `event.currentTarget` instead, we'll get back the button or an input of type submit. This way we ensure that the correct button is stored in `submitButtonsByForm`, even if the click event was triggered by a child element of the button. This addresses the issue and ensures that the correct button is used to submit the form after a direct upload.

https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
2023-11-13 19:33:53 +00:00
Jonathan Hefner
a5e1fc97d2 Process preview variant when processing preview
Prior to this commit, `ActiveStorage::Preview#processed` would only
process the preview image, not the specified variant of the preview
image.  For example, `thumb = attached_pdf.preview(:thumb).processed`
would only generate the full-sized preview image, not the `:thumb`
variant of it, until e.g. `thumb.url` was called.

This commit updates `ActiveStorage::Preview#processed` to generate both
the full-sized preview image and the requested variant.

Co-authored-by: chaadow <chedli@hoggo.com>
2023-11-13 11:01:40 -06:00
Jonathan Hefner
aa47bde556 Fix strict loading for Active Storage previews
`ActiveStorage::Preview#url` delegates to the preview image's variant,
which in turn delegates to the variant's blob.  Thus when the variant
has already been processed and strict loading is enabled, the
association chain of `preview_image_attachment` => `blob` =>
`variant_records` => `image_attachment` => `blob` must be fully
pre-loaded; otherwise, `ActiveStorage::Preview#url` will raise an
`ActiveRecord::StrictLoadingViolationError`.
2023-11-13 10:58:50 -06:00
Jonathan Hefner
2ea77d6ea9 Ensure globals reset after Active Storage tests
This ensures `ActiveRecord::Base.strict_loading_by_default` and
`ActiveStorage.track_variants` are reset to their original values even
when an error (e.g. an assertion failure) is raised inside
`with_strict_loading_by_default` and `without_variant_tracking` blocks.
2023-11-13 10:52:17 -06:00
Nico Wenterodt
435a347a10 Fix #50005 transform_job not accepting previewables
The transform_job crahes if you want to preprocess a previewable files.
This commit fixes that by using the blob's `representation` method to
process variants or previews.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-11 11:21:00 -06:00
Jonathan Hefner
4dcd6ba8d3 Update .gitattributes for generated JavaScript [ci-skip]
This adds `linguist-generated` and `linguist-vendored` attributes where
appropriate to suppress the files in diffs and exclude the files from
the project's language stats on GitHub.

See https://github.com/github/linguist for more information.
2023-11-05 15:48:08 -06:00
Jonathan Hefner
28e976b6aa Update JavascriptPackageTest for Active Storage
Prior to this commit, if `app/javascript/activestorage/index.js`
contained a syntax error, `JavascriptPackageTest` would still pass
because `system "yarn build"` would simply return `false` and the
compiled output would not change.  This commit adds `exception: true` to
the `system` call so that an error will be raised if `yarn build` fails.

Also, since 6c96e1cd7bf3b7089c9b59b2ebeb35bfa6fb3f88, Active Storage
compiles an additional `app/assets/javascripts/activestorage.esm.js`
file.  This commit adds an assertion for that file as well.
2023-11-05 15:13:33 -06:00
f0a03bd899 Remove config.public_file_server.enabled from generators
Remove the option `config.public_file_server.enabled` from the generators for all environments, as the value is the same in all environments.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-03 11:34:37 -05:00
Yogesh Khater
8bf1353cae Allow accepting service as a proc
`service` kwarg in `has_one_attached` and `has_many_attached` methods accepts
only symbols as values. It allows to define a `service` at a class-level context. But in
one of our requirements, we wanted to upload files based on user's region due to
some regulations.

So in order to allow defining a `service` at instance-level context,
this PR makes the changes to accept `service` as a Proc as well.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-01 21:20:55 -05:00
Jonathan Hefner
d10c54fe3c Fix VideoAnalyzerTest with FFmpeg 6.0
FFmpeg 6.0 now reports the duration of `video_without_video_stream.mp4`
as 1.000000 instead of 1.022000.  This discrepancy was [reported][]
to the FFmpeg mailing list, and the [reply][] indicated that the change
is intentional.

For this test, the exact duration isn't significant.  We merely want to
assert that the metadata includes the duration reported by FFmpeg.
Therefore, this commit changes the assertion to accomodate the duration
reported by FFmpeg 6.0 as well as previous versions.

Fixes #49650.

[reported]: https://ffmpeg.org/pipermail/ffmpeg-user/2023-October/057067.html
[reply]: http://ffmpeg.org/pipermail/ffmpeg-user/2023-October/057083.html

Co-authored-by: Yasuo Honda <yasuo.honda@gmail.com>
2023-10-31 11:53:54 -05:00
Jonathan Hefner
dd428f1ef1 Present config.public_file_server.enabled as opt-out
Follow-up to #47137.

Since `config.public_file_server.enabled` is true by default, this
commit changes the `config/environments/production.rb` template to
present the setting as an opt-out.
2023-10-30 11:54:26 -05:00
Jean Boussier
c28e4f2434 Use double quotes more consistenly in doc and error messages
For better or worse, the Rails guide settled on double quotes
and a large part of the community also use rubocop which enforce
them by default.

So we might as well try to follow that style when providing code
snippets in the documentation or error messages.

Fix: https://github.com/rails/rails/issues/49822

I certainly didn't get them all, but consistency should be significantly
improved.
2023-10-28 11:38:49 +02:00
PD
0dfcf2fcc1
Fix typo in ActiveStorage::FixtureSet example 2023-10-27 11:48:31 -07:00
Myles Boone
13d66b1632 Add config option to not touch records
ActiveStorage::Attachment records are not directly maintained by
ActiveStorage and it may not be feasible or desired to update the record
when its attachment is saved.
2023-10-20 14:41:57 -04:00
Nikita Vasilevsky
19f8ab2e7d
[Tests only] Enable Minitest/AssertPredicate rule 2023-10-13 19:26:47 +00:00
Jonathan Hefner
6fddf2e452 Autolink ActiveStorage::Attachment [ci-skip]
This also fixes a formatting error caused by embedding `+` in the middle
of a word.
2023-10-07 11:55:35 -05:00
Rafael Mendonça França
1f0262aa2b
Separate the CI environment from the application CI environment
Right now we are using both to test the Rails applications we generate
and to test Rails itself. Let's keep CI for the app and BUILDKITE to
the framework.
2023-10-04 09:36:51 +00:00
Bart de Water
95b6fbd00f Stop building AS::Notifications::Event manually
It's possible since Rails 6 (3ea2857943dc294d7809930b4cc5b318b9c39577) to let the framework create Event objects, but the guides and docs weren't updated to lead with this example.

Manually instantiating an Event doesn't record CPU time and allocations, I've seen it more than once that people copy-pasting the example code get confused about these stats returning 0. The tests here show that - just like the apps I've worked on - the old pattern keeps getting copy-pasted.
2023-09-29 12:34:23 -04:00
Akhil G Krishnan
2e35046f61 Fix the wrong markdown hightlighting [skip ci] 2023-09-28 20:14:35 +05:30
Rafael Mendonça França
fb6c6007d0
Development of Rails 7.2 starts now
🎉
2023-09-27 03:59:11 +00:00
Rafael Mendonça França
e5386cb402
Preparing for 7.1.0.rc1 release 2023-09-27 03:08:31 +00:00
aki
1f9fbbe213
Add expires_at option to ActiveStorage::Blob#signed_id 2023-09-26 21:08:20 +00:00
Dorian Marié
94a7149a96 Actually upload the files when passed as File or Pathname
This is a follow-up to https://github.com/rails/rails/pull/45606

We were storing the file metadata in Blob and Attachment but we were not
actually uploading the files (into the file system for instance for disk
storage).

It was failing silently so I made it explicit what is accepted and what
is unexpected
2023-09-25 19:01:21 +02:00
Jean Boussier
94c90ecf20
Merge pull request #45606 from dorianmariefr/build-blob-from-file-or-pathname
Allow attaching File or Pathname to has_one_attached
2023-09-25 13:50:46 +02:00
Dorian Marié
22bacd710d Allow attaching File or Pathname to has_one_attached
### Why was this change necessary?

When creating models in tests, it's easier to pass a File or a Pathname
(from `file_fixture` for instance) to `Model.create` for instance

### How does it address the problem?

When attaching an attachable, we check if it's a File or a Pathname and
handle it appropriately.
2023-09-25 13:43:26 +02:00
Victor Mours
1bdabc1102 Clarify that the default retry strategy uses polynomial backoff and not exponential backoff 2023-09-16 00:51:14 +02:00
Shouichi Kamiya
51ac8b9f6f Enable Minitest/LiteralAsActualArgument
There are assertions that expected/actual arguments are passed in the
reversed order by mistake. Enabling the LiteralAsActualArgument rule
prevents this mistake from happening.

The existing tests were auto-corrected by rubocop with a bit of
indentation adjustment.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-09-13 10:09:32 +09:00
Rafael Mendonça França
699dfdb426
Preparing for 7.1.0.beta1 release 2023-09-13 00:36:01 +00:00
Ryuta Kamizono
099f979dc7
Merge pull request #49195 from p8/activestorage/variant-interface
Keep VariantWithRecord API consistent with Variant
2023-09-08 17:52:05 +09:00
Ryuta Kamizono
9b00c65aeb
Merge pull request #49196 from p8/activestorage/remove-unused-methods
Remove unused methods on ActiveStorage::Variant
2023-09-08 17:31:01 +09:00
Petrik
1e23fff1a1 Remove unused methods on ActiveStorage::Variant
These methods were added in b221a4dc43368a1b6f00476f7c5f6047c5c7eea4
But they don't seem to be used by Rails internally or have any tests, so
I assume they were added by accident?
As they both seem to be marked as :nodoc: on ActiveStorage::Blob, we can
remove them without a deprecation warning.

If we decide to keep these methods, they should be added to
ActiveStorage::VariantWithRecord as well. No one complaining about there
methods missing on ActiveStorage::VariantWithRecord is another reason
these methods aren't used.
2023-09-08 10:05:56 +02:00
Petrik
3e27f43dbc Keep VariantWithRecord API consistent with Variant
Similar to c18bcd582819212c0d8d5523f7918cd4c1c4d53f adds the
content_type and filename methods to VariantWithRecord.
2023-09-08 08:24:20 +02:00
Akhil G Krishnan
61a9c1a92a Ruby code block indentation issue fix
[skip ci] indentation fix

[skip ci] review changes added

[skip ci] indentation fix
2023-09-07 01:14:48 +05:30
Rafael Mendonça França
c18bcd5828
Keep VariantWithRecord API consistent with Variant
The `process` and `processed?` methods in Variant are private.
2023-08-23 19:16:39 +00:00
Rafael Mendonça França
144dd24c05
Merge pull request #48999 from higher-pixels/activestorage-transformjob-nomethoderror
Fix NoMethodError in ActiveStorage::TransformJob for untracked variants.
2023-08-23 15:05:56 -04:00
Sean Doyle
0f4ab82082 Ensure response.parsed_body support for pattern matching
Both `Nokogiri` and `Minitest` have merged the PRs mentioned to
integrate support for Ruby's Pattern matching
(https://github.com/sparklemotion/nokogiri/pull/2523 and
https://github.com/minitest/minitest/pull/936, respectively).

This commit adds coverage for those new assertions, and incorporates
examples into the documentation for the `response.parsed_body` method.

In order to incorporate pattern-matching support for JSON responses,
this commit changes the response parser to call `JSON.parse` with
[object_class: ActiveSupport::HashWithIndifferentAccess][object_class],
since String instances for `Hash` keys are incompatible with Ruby's
syntactically pattern matching.

For example:

```ruby
irb(main):001:0> json = {"key" => "value"}
=> {"key"=>"value"}
irb(main):002:0> json in {key: /value/}
=> false

irb(main):001:0> json = {"key" => "value"}
=> {"key"=>"value"}
irb(main):002:0> json in {"key" => /value/}
.../3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.7.4/lib/irb/workspace.rb:113:in `eval': (irb):2: syntax error, unexpected terminator, expecting literal content or tSTRING_DBEG or tSTRING_DVAR or tLABEL_END (SyntaxError)
json in {"key" => /value/}
             ^

        .../ruby/3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.7.4/exe/irb:9:in `<top (required)>'
        .../ruby/3.2.0/bin/irb:25:in `load'
        .../ruby/3.2.0/bin/irb:25:in `<main>'
```

When the Hash maps String keys to Symbol keys, it's able to be pattern
matched:

```ruby
irb(main):005:0> json = {"key" => "value"}.with_indifferent_access
=> {"key"=>"value"}
irb(main):006:0> json in {key: /value/}
=> true
```

[object_class]: https://docs.ruby-lang.org/en/3.2/JSON.html#module-JSON-label-Parsing+Options
2023-08-23 13:28:02 -04:00
Bryan Traywick
1d212dc357 Fix NoMethodError in ActiveStorage::TransformJob for untracked variants. 2023-08-22 13:01:44 -04:00
Hartley McGuire
bac6d8c079
Fix code blocks using + instead of <tt>
Pluses cannot be used to create code blocks when the content includes a
space.

Found using a regular expression:

```bash
$ rg '#\s[^+]*\+[^+]*\s[^+]*\S\+'
```
2023-08-10 13:05:05 -04:00
Alexandre Ruban
9d6b68446d
ActiveStorage mirror uploads should be asynchronous
Before this commit, when a file was uploaded to a mirror service,
the file upload to each service (primary and mirrors) was happening
synchronously:

```rb
def upload(key, io, checksum: nil, **options)
  each_service.collect do |service|
    io.rewind
    service.upload key, io, checksum: checksum, **options
  end
end
```

In this commit, we change this behavior to only upload the file to the
primary service synchronously and then enqueue a job to upload the
file to the mirrors asynchronously.
2023-08-04 09:08:50 +02:00
Rafael Mendonça França
379e3b4d79
Remove empty line 2023-08-03 15:41:58 -04:00
Bruno Prieto
8a88ce1943 Disable session in ActiveStorage blobs and representations proxy controller
This allows CDNs such as CloudFlare to cache files delivered by proxy by default

Fix #44136
2023-08-02 06:44:51 +02:00
Keaton Roux
dc4eb0f3b5 Add tags to audio analyzer metadata 2023-07-27 10:30:49 +02:00
Shouichi Kamiya
b1c544b1d1 Add an option to preprocessed AS variants
ActiveStorage variants are processed on the fly when they are needed but
sometimes we're sure that they are accessed and want to processed them
upfront.

`preprocessed` option is added when declaring variants.

```
class User < ApplicationRecord
  has_one_attached :avatar do |attachable|
    attachable.variant :thumb, resize_to_limit: [100, 100], preprocessed: true
  end
end
```
2023-07-03 19:36:14 +09:00
Petrik
a2ead3aaad Document generated scopes for has_one_attached and has_many_attached
`has_one_attached` and `has_many_attached` generate several scopes and
relations:

* `with_attached_*`
* `*_attachment`
* `*_attachments`
* `*_blob`
* `*_blobs`

But these are all undocumented.

We can document these methods similar to ee58c8e6be using the
`:method:` directive.
2023-07-02 11:04:08 +02:00
Russell Porter
19e0dd9773 Include variants when eager loading attachment
Fixes an explosion of active storage queries when accessing variants for multiple records.

The implementation is now consistent with that of `has_many_attached`.
2023-06-29 17:04:07 +00:00
zzak
dd89f600f7
🔗 Remove RDoc auto-link from Rails module everywhere 2023-06-23 10:49:30 +09:00
Nate Matykiewicz
dd894b2fc2
Allow an ActiveStorage attachment to be removed via a form post
Attachments can already be removed by updating the attachment to be nil such as:
```ruby
User.find(params[:id]).update!(avatar: nil)
```

However, a form cannot post a nil param, it can only post an empty string. But, posting an
empty string would result in an `ActiveSupport::MessageVerifier::InvalidSignature: mismatched digest`
error being raised, because it's being treated as a signed blob id.

Now, nil and an empty string are treated as a delete, which allows attachments to be removed via:
```ruby
User.find(params[:id]).update!(params.require(:user).permit(:avatar))

```
2023-05-29 22:58:25 -05:00
zzak
722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +09:00
zzak
073269c9b9
Merge pull request #48288 from zzak/rdoc-fixed-width-namespaces
Use short-form fixed-width RDoc form for namespaces
2023-05-25 07:14:47 +09:00
zzak
e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Jonathan Hefner
23243eb283
Merge pull request #46476 from justinperkins/fix/i18n-reserved-words-comments
Update comments in all three en.yml files relating to booleans
2023-05-24 13:58:38 -05:00
Justin Perkins
ad1d2bed4a Clarify YAML boolean caveat in en.yml template
This clarifies that the boolean interpretation (1) is due to YAML rather
than I18n, (2) is case insensitive, and (3) affects both keys and
values.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-05-24 13:35:53 -05:00
Rafael Mendonça França
61accb7dea
Merge pull request #45867 from jdufresne/show-rescuable-exceptions
Make the test environment show rescuable exceptions in responses
2023-05-24 13:45:45 -04:00
Petrik
cb14a98a06 Infer method names for :*-method: directives [ci-skip]
The :method: and :singleton-method: directives infer the method name
by looking at the token after the identifier.
So we don't need to specify them.
2023-05-18 20:51:55 +02:00
Jon Dufresne
e28f147329 Make the test environment show rescuable exceptions in responses
Background
----------

During integration tests, it is desirable for the application to respond
as closely as possible to the way it would in production. This improves
confidence that the application behavior acts as it should.

In Rails tests, one major mismatch between the test and production
environments is that exceptions raised during an HTTP request (e.g.
`ActiveRecord::RecordNotFound`) are re-raised within the test rather
than rescued and then converted to a 404 response.

Setting `config.action_dispatch.show_exceptions` to `true` will make the
test environment act like production, however, when an unexpected
internal server error occurs, the test will be left with a opaque 500
response rather than presenting a useful stack trace. This makes
debugging more difficult.

This leaves the developer with choosing between higher quality
integration tests or an improved debugging experience on a failure.

I propose that we can achieve both.

Solution
--------

Change the configuration option `config.action_dispatch.show_exceptions`
from a boolean to one of 3 values: `:all`, `:rescuable`, `:none`. The
values `:all` and `:none` behaves the same as the previous `true` and
`false` respectively. What was previously `true` (now `:all`) continues
to be the default for non-test environments.

The new `:rescuable` value is the new default for the test environment.
It will show exceptions in the response only for rescuable exceptions as
defined by `ActionDispatch::ExceptionWrapper.rescue_responses`. In the
event of an unexpected internal server error, the exception that caused
the error will still be raised within the test so as to provide a useful
stack trace and a good debugging experience.
2023-05-17 06:30:28 -07:00
zzak
f397f47212
Use double quotes for escaping yaml (re #47983) 2023-05-16 20:34:40 +09:00
Petrik
01508cac4d Document assocations and scopes on ActiveStorage::Attachment/Blob [ci-skip]
Scopes and associations aren't picked up by RDoc, but we can use
`:method` and `:singleton-method:` directives to document them.
2023-05-08 13:27:33 +02:00
Jean Boussier
22698947db
Merge pull request #47725 from pawlik/possible-bug-in-activestorage-with-rack-test-uploaded-file
Using Rack::Test::UploadedFile.new with  `StringIO` causes an exception
2023-04-26 12:07:26 +02:00
Grzegorz Pawlik
81ae40b339 Fix Rack::Test::UploadedFile.new to work with StringIO
Instantiating Rack::Test::UplaodedFile with StringIO
no longer causes an exception.
2023-04-26 09:31:45 +00:00
Josh Brito
43ec5737c7 Update comment to reference values with single quotes as opposed to double 2023-04-18 21:32:37 -07:00
Petrik
0e7cb8d327 Add missing headers to Active Storage docs [ci-skip] 2023-04-03 12:29:49 +02:00
Petrik de Heus
dc0f20595d
Merge pull request #47717 from p8/docs/include-readmes
Include READMEs in main framework pages of the API documentation
2023-03-30 16:43:14 +02:00
Rafael Mendonça França
1ed5ef6bb3
Merge pull request #47773 from Roriz/feat/custom-header-direct-upload
Safe for Direct Uploads in js Libraries or Frameworks
2023-03-27 16:37:25 -04:00
Rafael Mendonça França
71a1f61926
Merge pull request #47754 from vipulnsward/remove-mini_mime
Remove mini_mime usage in favour of marcel
2023-03-27 14:54:16 -04:00
Vipul A M
3d414f3986 Remove mini_mime usage in favour of marcel
We are using two libraries to do the same job. This commit removes the usage of mini_mime in favour of Marcel instead.

Changes are as follows:
- Replace MiniMime lookup by extension with Marcel Mimetype for lookup with extension
- Replaces usage of MiniMime lookup by content type to fetch extension with usage of Marcel Magic lookup. Marcel has multiple extentions being returned, we pick the first one. MiniMime always returns just one
- Removes specs which we specifically checking failing identification issue of MiniMine on jpeg images
- Removes mini_mime from gemspec
2023-03-27 23:24:43 +05:30
Shouichi Kamiya
7555adcff9 Use google provided library to lookup email
`google-cloud-env` (which is already a dependency of
`google-cloud-storage`) transparently handles retrying and caching for
us.
2023-03-27 10:41:12 +09:00
Radamés Roriz
a37f1d4f26
fix: add compiled js from activestorage 2023-03-26 17:05:10 -03:00
Radamés Roriz
0042a51740
fix: typo on js method 2023-03-26 15:52:15 -03:00
Radamés Roriz
26b209437b
lint: fix linter on changelog files 2023-03-26 15:51:00 -03:00
Radamés Roriz
896910fb7b
docs: change section to be more details about custom headers 2023-03-26 15:48:30 -03:00
Radamés Roriz
d81124b3bd
feat: add custom headers on direct upload js class 2023-03-26 14:43:22 -03:00
Rafael Mendonça França
febd9ab4f6
Merge PR #47150 2023-03-25 16:55:06 +00:00
Matija Čupić
c0465cf6aa
Extract sample rate in audio analyzer 2023-03-23 19:50:32 +01:00
Petrik
7c94708d24 Include READMEs in main framework pages of the API documentation
Currently when opening the main framework pages there is no introduction
to the framework. Instead we only see a whole lot of modules and the
`gem_version` and `version` methods.

By including the READMEs using the `:include:` directive each frameworks
has a nice introduction.
For markdown READMEs we need to add the :markup: directive.

[ci-skip]

Co-authored-by: zzak <zzakscott@gmail.com>
2023-03-21 21:16:28 +01:00
Andrew Novoselac
6902cbce1b Introducs TestFixtures#fixture_paths.
Multiple fixture paths can now be specified using the `#fixture_paths` accessor.
2023-03-14 19:02:56 -04:00
Yasuo Honda
78fd178512 Fix markdown format and typo
- https://github.com/rails/rails/actions/runs/4319300757/jobs/7538324353
```
Offenses:

./rails/activesupport/CHANGELOG.md:34 CHANGELOG header must start with '*' and 3 spaces
*    Remove deprecated option to passing a format to `#to_s` in `Array`, `Range`, `Date`, `DateTime`, `Time`,
^^^^
13 changelogs inspected, 1 offense detected
Error: Process completed with exit code 1.
```
Follow-up https://github.com/rails/rails/commit/e420c33

- https://github.com/rails/rails/actions/runs/4319300757/jobs/7538324760
```
./activestorage/test/models/variant_test.rb:200: ins't ==> isn't
```

Follow-up 4edaa4120b
2023-03-03 11:34:58 +09:00
Rafael Mendonça França
18e53fbb2c
Remove deprecated purge and purge_later methods from the attachments association 2023-03-03 00:38:43 +00:00
Rafael Mendonça França
c720b7eba8
Remove deprecated behavior when assigning to a collection of attachments 2023-03-03 00:38:42 +00:00
Rafael Mendonça França
0591de55af
Remove deprecated ActiveStorage::Current#host and ActiveStorage::Current#host= methods 2023-03-03 00:38:41 +00:00
Rafael Mendonça França
4edaa4120b
Remove deprecated invalid default content types in Active Storage configurations 2023-03-03 00:38:40 +00:00
Rafael Mendonça França
e78ed07e00
Merge pull request #47259 from skipkayhil/hm-regenerate-dummies
Full refresh of framework dummy applications
2023-03-01 18:08:58 -05:00
zzak
d2af670dba
Remove Copyright years (#47467)
* Remove Copyright years

* Basecamp is now 37signals... again

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>

---------

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
2023-02-23 11:38:16 +01:00
Hartley McGuire
23a459b3e5
Remove unused js files in Active Storage dummy app 2023-02-18 17:51:27 -05:00