Commit Graph

862 Commits

Author SHA1 Message Date
Jeremy Daer fe8d41eda1
Merge pull request #42981 from ghiculescu/as-eager-more-methods-3
Active Storage eager loading: support more methods
2022-05-16 12:42:23 -07:00
Ghouse Mohamed 1a6e13d986 Adds test coverage for #attach method behaviour in activestorage 2022-05-16 12:21:19 -07:00
Jeremy Daer f24500b3ab Merge branch 'main' into as-eager-more-methods-3
* main: (746 commits)
  Address QueryCacheTest#test_query_cache_does_not_allow_sql_key_mutation failure
  Fixes ActiveStorage proxy downloads of files over 5mb in S3-like storage services
  Fixes development Action Mailbox new mail form
  Squash commits
  Include the unexpected class in InvalidParameterKey message
  Support unbounded time ranges for PostgreSQL
  Fix CHANGELOG alignment [ci-skip]
  Add ability to ignore tables by regexp for SQL schema dumps
  Improve `rails s` error message when no server could be found.
  Fix MySQL warning when creating Active Record's test databases
  Add `--js` and --skip-javascript` options to `rails new`
  Fix parsing operator classes for index columns in PostgreSQL
  Fix rails test command to handle leading dot slash
  Document that url_for can take classes
  Don't change the encoding of frozen parameters
  Update working_with_javascript_in_rails.md
  Avoid query from calculations on contradictory relation
  Fix MemoryStore#write(name, val, unless_exist: true) with expired entry
  Provide pattern matching for ActiveModel
  Stop autoclosing of PRs
  ...
2022-05-16 12:18:30 -07:00
Felipe e4eab9892f Fixes ActiveStorage proxy downloads of files over 5mb in S3-like storage services 2022-05-16 08:09:12 -03:00
Xavier Noria 2953ae5c8a Define config.enable_reloading to be !config.cache_classes
Every time I write `config.cache_classes` I have to pause for a moment to make
sure I get it right. It makes you think.

On the other hand, if you read `config.enable_reloading = true`, does the
application reload? You do not need to spend 1 cycle of brain CPU to nod.
2022-04-14 18:11:36 +02:00
Rafael Mendonça França 5c1bd20f0d
Merge pull request #44693 from ghousemohamed/fix-docs-related-gem-versions
Fix `#version` method docs and some typos [ci-skip]
2022-03-15 16:28:07 -04:00
Ghouse Mohamed 6ee6cb554b Fix #version docs and some typos 2022-03-16 01:48:37 +05:30
Matheus Richard 414394206a Extend audio_tag and video_tag to accept Active Storage attachments.
Now it's possible to write

    audio_tag(user.audio_file)
    video_tag(user.video_file)

Instead of

    audio_tag(polymorphic_path(user.audio_file))
    video_tag(polymorphic_path(user.video_file))

image_tag already supported that, so this follows the same pattern.
2022-03-14 02:05:37 -03:00
Rafael Mendonça França d6f2e17908
Make sure allowed image processing arguments are correctly loaded
If for some reason the files that defined those constants were loaded
before the `after_initialize` block, the values of the configuration
would not be applied.

With this new implementation we always use the configuration value, so
the order things are defined doesn't matter.
2022-03-11 17:45:39 +00:00
Aaron Patterson 2c21a39493
Merge pull request #44387 from piecehealth/fix_activestorage_update
fix activestorage update
2022-03-09 16:12:48 -08:00
Hartley McGuire c3844a9dc0 fix rubocop errors
Using `bundle exec rubocop -a` and visually verified
2022-03-08 15:36:24 -05:00
Zack b2ab8dd3a4
Added image trasnformation validation via configurable allow-list
ImageProcessingTransformer now offers a configurable allow-list for
transformation methods in addition to a configurable deny-list for arguments.

[CVE-2022-21831]
2022-03-08 09:28:16 -08:00
Aaron Patterson ea9f0103fd
Revert "Revert "Merge pull request #42843 from buckley-w-david/message-verifier-default-serializer""
This reverts commit fd4e63cc28.
2022-03-01 15:14:43 -08:00
Aaron Patterson fd4e63cc28
Revert "Merge pull request #42843 from buckley-w-david/message-verifier-default-serializer"
This reverts commit a40d7815ac, reversing
changes made to ad2529be4b.
2022-03-01 13:58:40 -08:00
Saba Kiaei 5256c90327 Switch ActiveSupport::MessageVerifier's default serialization to JSON 2022-03-01 13:02:17 -05:00
Rafael Mendonça França fb88db58d7
Merge pull request #44439 from ghousemohamed/patch-6
Return the blob/blobs when #attach is able to save the record
2022-02-25 16:19:01 -05:00
Ghouse Mohamed fbfb6e6885 Return blob/blobs when #attach is able to save the record and return if it is not able to 2022-02-26 02:18:51 +05:30
Koichi ITO 819871cc4e Enable `Style/MapToHash` cop
Ruby 2.6 added block argument processing to `Enumerable#to_h`.
https://bugs.ruby-lang.org/issues/15143

Rails 7 requires Ruby 2.7.0 or higher, so the new feature can use it.
`Style/MapToHash` cop will detect it. And this cop in the `Style` department,
but this seems to improve performance as follows:

```ruby
# map_to_hash.rb
require 'benchmark/ips'

ARRAY = (1..100).to_a
HASH = {foo: 1, bar: 2}

Benchmark.ips do |x|
  x.report('array.map.to_h') { ARRAY.map { |v| [v, v * 2] }.to_h }
  x.report('array.to_h')     { ARRAY.to_h { |v| [v, v * 2] } }

  x.compare!
end

Benchmark.ips do |x|
  x.report('hash.map.to_h') { HASH.map { |k, v| [k.to_s, v * 2] }.to_h }
  x.report('hash.to_h')     { HASH.to_h { |k, v| [k.to_s, v * 2] } }

  x.compare!
end
```

```console
% ruby map_to_hash.rb
Warming up --------------------------------------
      array.map.to_h     9.063k i/100ms
          array.to_h     9.609k i/100ms
Calculating -------------------------------------
      array.map.to_h     89.063k (± 3.9%) i/s -    453.150k in  5.096572s
          array.to_h     96.449k (± 1.7%) i/s -    490.059k in  5.082529s

Comparison:
          array.to_h:    96448.7 i/s
      array.map.to_h:    89063.4 i/s - 1.08x  (± 0.00) slower

Warming up --------------------------------------
       hash.map.to_h   106.284k i/100ms
           hash.to_h   149.354k i/100ms
Calculating -------------------------------------
       hash.map.to_h      1.102M (± 2.2%) i/s -      5.527M in   5.019657s
           hash.to_h      1.490M (± 0.9%) i/s -      7.468M in   5.013264s

Comparison:
           hash.to_h:  1489707.0 i/s
       hash.map.to_h:  1101561.5 i/s - 1.35x  (± 0.00) slower
```

`Style/MapToHash` cop ... https://docs.rubocop.org/rubocop/1.25/cops_style.html#stylemaptohash
2022-02-26 04:31:03 +09:00
Ghouse Mohamed 49b4af8b3d Return blob/blobs when #attach is able to save the record and return false if it is not able to 2022-02-23 02:03:25 +05:30
Jonathan Hefner 07bee949c4 Replace backticks with RDoc markup [ci-skip]
RDoc does not support backticks the way that Markdown does.  Instead,
inline code must be wrapped with `+` or `<tt>`.
2022-02-21 11:11:11 -06:00
Jean Boussier e26372b713 Implicitly assert no exception is raised in `assert_queries` & al
Fix: https://github.com/rails/rails/pull/44397
Ref: https://github.com/rails/rails/pull/37313
Ref: https://github.com/rails/rails/pull/42459

This avoid mistakes such as:

```ruby
assert_raise Something do
  assert_queries(1) do
    raise Something
  end
end
```

Co-Authored-By: Alex Coomans <alexc@squareup.com>
2022-02-19 09:11:14 +01:00
piecehealth ead3f67e88 fix activestorage update 2022-02-10 18:01:09 +08:00
Gannon McGibbon aaa64687e8
Revert #38957 (#44287)
* Revert "Pass service_name param to DirectUploadsController"

This reverts commit 193289dbbe.

* Revert "Multi-service direct uploads in Action Text attachment uploads"

This reverts commit 0b69ad4de6.
2022-01-29 14:27:45 +01:00
Abhay Nikam 5c7468dba8 Fixes active storage changelog entry(#44244) formatting [ci skip] 2022-01-28 16:32:56 +05:30
Luke Lau 7e61f808c6 Don't stream redirect controller responses
They don't need to be streamed and by including
ActiveStorage::Streaming, they spin up new threads which can cause
problems with connection pools as detailed in #44242
2022-01-26 12:04:40 +00:00
jlestavel 2197814074
Allow app to opt out of precompiling activestorage js assets (#43967) 2022-01-18 18:19:30 +01:00
weavermedia bc9060a22a Improve ActiveStorage analyzer error message for missing ffprobe. Add mention to guides. 2022-01-07 10:32:03 -08:00
Nando Vieira 865a01d87c
Export assets. 2022-01-06 13:51:46 -08:00
Nando Vieira a75cf1f1f0
Export other ActiveStorage JavaScript modules. 2022-01-06 09:24:36 -08:00
Rafael Mendonça França c97dee313c
Require shellwords where it is used
Ruby 3.1 doesn't require this by default anymore.
2022-01-06 00:19:11 +00:00
Ryuta Kamizono 65766ebcc8 Bump license years to 2022 [ci-skip] 2022-01-01 15:22:15 +09:00
Rafael Mendonça França a17629e393
Fix image_processing link
[ci skip]
2021-12-29 21:36:51 +00:00
Rafael Mendonça França dae7e46db4
Remove CHANGELOG entry that is already in 7-0-stable 2021-12-15 00:55:18 +00:00
Sean Doyle 4f191b9754 ActiveStorage: support empty attachments submits
The background
---

Configuration for replacing a collection was introduced in
[rails/rails#36716][].

However, since [rails/rails#42596][] has been merged, Rails 7.1 and
beyond will default to _replacing_ an Active Storage `has_many_attached`
relationship, as opposed to _appending to it_.

The problem
---

With replacement as the established precedent, it's currently a
challenge to replace an existing collection with an empty one.

The solution
---

This commit makes two changes.

The first is to Action View and its form building helpers. The change
draws inspiration from how an `<input type="checkbox">` field (or
collection of fields) is paired with an `<input type="hidden">` field to
represent the unchecked value. The change pairs any `<input type="file"
multiple="multiple">` elements with an `<input type="hidden">` element
to represent an empty collection. Like the [check_box][] form builder
method, the `file_field`  method accepts an `include_hidden:` option to
skip the creation of the hidden element.

The second is to how Active Storage generates attribute assignment
methods through `has_many_attached`. With the possibility of an `<input
type="file">` field being paired with an `<input type="hidden"
value="">` field, the backing models need to be able to coerce an
"empty-ish" value into an empty list. For example:

```ruby
@user.highlights = [""]
@user.highlights        # => []
```

When combined, these changes enable consumer applications to submit
"empty" collections to blank out existing attachments.

Support is configured through the
`config.active_storage.multiple_file_field_include_hidden` configuration
value, which defaults to `false`.

[check_box]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box
[rails/rails#36716]: https://github.com/rails/rails/pull/36716
[rails/rails#42596]: https://github.com/rails/rails/pull/42596
2021-12-14 18:40:35 -05:00
Rafael Mendonça França 8b6342e341
Use `if_not_exists` instead of `table_exists?` 2021-12-08 23:25:02 +00:00
Rafael Mendonça França 6172f541d8
Merge pull request #43776 from lifeiscontent/patch-1
Update 20191206030411_create_active_storage_variant_records.rb
2021-12-08 18:24:08 -05:00
Alex Ghiculescu 675264a449 Active Storage eager loading: support more methods
As noted at https://github.com/rails/rails/pull/40842#issuecomment-895231378, the current implementation works great with the `processed` method, but doesn't work with other methods such as `key`. This PR fixes that.

Why is this fix necessary? Currently when you call `VariantWithRecord#key`, `key` gets called on `VariantWithRecord` -> `Attached::One` -> `Attachment` -> `Blob`. This results in n+1 calls to load the `Attachment`. But for this purpose we shouldn't need to load it, as the `VariantWithRecord` already knows about it relevant `Blob`. So this PR changes the method to call directly to that blob.
2021-12-08 13:54:37 -06:00
Jonathan Hefner 4917ee9df6 Use dynamic Rails version in framework dummy apps
This matches what we currently generate for plugin dummy apps.
2021-12-08 11:31:49 -06:00
Rafael Mendonça França 83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
Rafael Mendonça França b37c02e027
✂️ 2021-12-06 22:39:44 +00:00
Rafael Mendonça França 47fc79ca2b
Merge pull request #43637 from alxjrvs/blob-representation-disposition
Fix Rails 7 Regression - ActiveStorage Content Disposition
2021-12-06 17:39:14 -05:00
Rafael Mendonça França aa55566bcf
Merge pull request #42599 from santib/use-rails-guides-instead-of-edge-guides
Use rails guides instead of edge guides [ci skip]
2021-12-06 17:36:52 -05:00
Aaron Reisman 6ed63abecd
Update 20191206030411_create_active_storage_variant_records.rb
In the cast of bootstrapping a project for the first time without active storage, when running `rails app:update` this migration would result in trying to create the table twice.
2021-12-03 19:55:01 -08:00
Kasper Timm Hansen 1df9b01fe6 Pass an array through our stack, don't bother converting back & forth
Users aren't likely to pass non-array values here anyway.
2021-12-04 02:25:42 +01:00
Kasper Timm Hansen f34fcac88f [ci skip] compose no longer returns the checksum, remove comment 2021-12-04 02:19:19 +01:00
Kasper Timm Hansen 1c309b6bbd compose is primarily meant to take blobs so make them a positional argument 2021-12-04 02:14:48 +01:00
Kasper Timm Hansen 14f190f337 Flip blob question to allow us to exit early 2021-12-04 01:20:05 +01:00
David Heinemeier Hansson 6c828836c1 Distribute both ESM and CJS version
And make sure module refers to the ESM version.
2021-12-03 11:12:07 +01:00
Jean Boussier b30148a2e8 Typo in Active Storage: custom_metadatata -> custom_metadata
Introduced in https://github.com/rails/rails/pull/43294
2021-11-30 11:31:52 +01:00
Gannon McGibbon 79a5e0b759 Add ActiveStorage::Blob.compose 2021-11-25 19:37:57 -05:00