Commit Graph

92632 Commits

Author SHA1 Message Date
Rafael Mendonça França 5a0b2fa5a3
Merge pull request #52680 from MatheusRich/action-text-attachment-events
Dispatch direct-upload events on attachment uploads
2024-08-26 21:20:59 -03:00
Rafael Mendonça França 48aaffd050
Merge pull request #52709 from ghiculescu/at-store-if-blank-validation
Make Action Text `store_if_blank` work for `presence` validation
2024-08-26 17:02:16 -03:00
Matheus Richard 8f0b9117b7 Dispatch direct-upload events on attachment uploads
When using Action Text's rich textarea,  it's possible to attach files to the
editor. Previously, that action didn't dispatch any events, which made it hard
to react to the file uploads. For instance, if an upload failed, there was no
way to notify the user about it, or remove the attachment from the editor.

This commits adds new events - `direct-upload:start`, `direct-upload:progress`,
and `direct-upload:end` - similar to how Active Storage's direct uploads work.

Closes #37793
Supersedes #37794

Co-authored-by: Brad Rees <github@bradleyrees.com>
2024-08-26 16:15:35 -03:00
Rafael Mendonça França 9558f00f59
Merge pull request #52713 from bopm/patch-1
Fixes shellcheck SC2144, replace glob with find.
2024-08-26 15:37:51 -03:00
Rafael Mendonça França 534b4ab2a6
Merge pull request #52354 from zachasme/sqlite-virtual-tables
Add support for SQLite3 full-text-search and other virtual tables
2024-08-26 14:49:10 -03:00
Rafael Mendonça França 1c0b912069
Merge pull request #52700 from ngan/fix-db-prepare-schema-dump
Dump schema only once after database prepare
2024-08-26 14:48:11 -03:00
Sergey Moiseev c10edc8409
Changes due to review 2024-08-26 20:34:41 +03:00
Rafael Mendonça França 8c7754dfdf
Merge pull request #52703 from jonathanhefner/fix-52607
Resolve model attribute types on schema load
2024-08-26 14:07:21 -03:00
Sergey Moiseev 567853e805
Fixes shellcheck SC2144
Currently, this code only works if there is only one match. If for any reason there will be more than one, it'll fail.
See https://github.com/koalaman/shellcheck/wiki/SC2144
2024-08-26 18:47:18 +03:00
Rafael Mendonça França 10924d3c96
Merge pull request #52706 from p8/railties/stats-register_directory
Rename `CodeStatistics.add_directory` to `CodeStatistics.register_directory`
2024-08-26 12:15:49 -03:00
Jean Boussier d369c194e8
Merge pull request #52712 from adityapandit17/query_log_fixes
No need for explicit return of handlers
2024-08-26 10:05:31 +02:00
Aditya Pandit 2aa1790500 No need for explicit return of handler 2024-08-26 13:22:24 +05:30
Alex 36b167c440 Make Action Text `store_if_blank` work for `presence` validation
Makes this work: https://github.com/rails/rails/pull/52573/files#r1730329576
2024-08-26 09:13:02 +10:00
Petrik cb8fd483fe Rename CodeStatistics.add_directory to CodeStatistics.register_directory
`register_*` seems a more common pattern in Rails, especially for third
party hooks. For example:

    Rails::SourceAnnotationExtractor::Annotation.register_directories("spec", "another")

Other examples:

    ActionMailer::Base.register_preview_interceptor
    MimeType.register
    MimeType.register_alias
    ActiveModel::Type.register
2024-08-25 11:09:10 +02:00
Ryuta Kamizono c6e3336cfd
Merge pull request #52701 from p8/railties/namespace-code-statistics
Namespace CodeStatistics and CodeStatisticsCalculator to Rails
2024-08-25 16:14:16 +09:00
Jonathan Hefner 49a65a81ef Revert "Revert "Merge pull request #49769 from jonathanhefner/active_record-enum-non-column-backed""
This reverts commit b5fe9ec57b.
2024-08-24 14:11:58 -05:00
Jonathan Hefner 4902a982d9 Resolve model attribute types on schema load
When running tests in parallel, a new database is created for each test
worker (via `ActiveRecord::TestDatabases.create_and_load_schema`).  Each
of these databases use different OID numbers for custom defined types
such as enums.  If model schemas are loaded before forking -- as done in
`railties/lib/rails/testing/maintain_test_schema.rb` when `eager_load`
is true -- Rails will hold on to the OID numbers from the original
database.  Thus each test worker does not recognize the OID numbers when
resolving model attribute types.

This commit sidesteps the problem by resolving model attribute types on
schema load.  This does not address the conflicting OID numbers, but
each test worker will inherit properly resolved attribute types.

Fixes #52607.
2024-08-24 14:11:58 -05:00
Ngan Pham 175bf8259a
Dump schema only once after database prepare 2024-08-24 06:56:39 -07:00
Petrik 8c19758136 Namespace CodeStatistics and CodeStatisticsCalculator to Rails
CodeStatistics and CodeStatisticsCalculator are currenltly top-level
constants, while almost everything in `railties/lib/rails` is namespaced
to `Rails`. These have probably never conflicted with other top-level
constants, but Rails should not pollute the top-level namespace if it's
not necessary.
2024-08-24 09:59:58 +02:00
Rafael Mendonça França ec667e5f11
Cleanup the assets before generating the guides
This will fix the issue that digest were being included into
digest paths.
2024-08-24 00:28:35 +00:00
Zacharias Knudsen 1ecb91bb38
Add support for SQLite3 full-text-search and other virtual tables.
Previously, adding sqlite3 virtual tables messed up `schema.rb`.

Now, virtual tables can safely be added using `create_virtual_table`.
2024-08-23 22:13:00 +00:00
John Hawthorn c1d04cc092
Merge pull request #52696 from jhawthorn/cached_row_count
Add :row_count in cached sql.active_record payload
2024-08-23 14:39:43 -07:00
Rafael Mendonça França 11f1f35b0a
Merge pull request #52694 from aidanharan/perform-query-batch-option
Include batch option in the abstract adapters `perform_query` method signature
2024-08-23 18:19:41 -03:00
Rafael Mendonça França 667a2063ed
Merge pull request #52226 from p8/railties/deprecate-stats-directories
Fix third party hook for `rails stats` Thor command
2024-08-23 18:10:48 -03:00
Rafael Mendonça França 411edaf54e
Merge pull request #52695 from excid3/strip-encrypted-content-file
Strip encrypted file contents
2024-08-23 18:07:46 -03:00
Rafael Mendonça França 824b225300
Merge pull request #52689 from Shopify/remove-redundant-requires
Remove redundant requires
2024-08-23 18:01:56 -03:00
John Hawthorn 31309b8b3f Add :row_count in cached sql.active_record payload
Previously we added :row_count to the instrumentation payload for
sql.active_record, but only for uncached queries. This adds the same
information on queries which are cached.
2024-08-23 12:30:14 -07:00
Étienne Barrié 6b7b019e07 Remove redundant requires 2024-08-23 20:22:46 +02:00
Chris Oliver f07a4f824a
Strip encrypt file contents
If a newline accidentally gets added to the encrypted content file, it
is unable to be decrypted.

Like the key file, this ensures that the content is stripped of newlines
before decryption.
2024-08-23 13:04:32 -05:00
Rafael Mendonça França 92e9b23472
Merge pull request #52686 from adityapandit17/guide-block-alignment-fixes
Fixed significant styling issue [ci skip]
2024-08-23 13:47:50 -03:00
Donal McBreen 6f79f25321
Decryption casting v2 revert (#52693)
* Revert "Switch back to DelegateClass(ActiveModel::Type::Value)"

This reverts commit 91745df899.

* Revert "Update docs and changelog"

This reverts commit b234a94e56.

* Revert "Nest encrypted attribute types within serialized types"

This reverts commit 6a27e7b2f9.

* Revert "Encryption casting with `encrypts` before `serialize`"

This reverts commit 4dd2b22efe.

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2024-08-23 08:27:49 -07:00
Aidan Haran 180d173c6e Include batch option in the `perform_query` method signature 2024-08-23 16:25:30 +01:00
bhumi1102 b6fcd661db
[RF-DOCS] Rails Routing Guide [ci-skip] (#52521)
Here are some of the things addressed from this Guide.

- [X] We mention Rack application right away, good place to link to the [Rack guide](https://edgeguides.rubyonrails.org/rails_on_rack.html).
- [X] Would it make sense to link "CRUD operation" to something like the [AR Basics CRUD](https://edgeguides.rubyonrails.org/active_record_basics.html#crud-reading-and-writing-data) section? We don't _always_ need to tie CRUD to database, it's more about the concept.
- [X] Under Path and URL helpers, it might make sense to turn that list into a table to make it easier to scan?
- [X] Singular resources starts with examples of using get, maybe it should be specific to resource and leave get to Non-Resourceful Routes section? That section doesn't start with "simple" examples.
- [X] "Because you might want to use the same controller for a singular route (/account) and a plural route (/accounts/45), singular resources map to plural controllers." => I've never seen this be the case, I think this can be reworded to explain that singular resources map to plural controllers, without this idea of "use the same controller".
- [X] Under shallow nesting, there's a long example with three child resources to demonstrante that "all get the same shallow behavior"... maybe that'd be better with just 2 so that the table doesn't get so big/long.
- [X] Under creating paths and URLs from objects, it explains how to create paths from objects (i.e. polymorphic routing), that may be a good segway to show that it uses the route key / singular route key from ActiveModel::Naming to figure that out. (could be a note/tip of sorts for example, just thought it'd be good to make that connection somewhere) Also ActiveModel::Conversion#to_param would be used to convert the IDs.
- [X] member and collection are explained under "Adding more RESTful actions", but there's not a good clarification of what the terms represent, i.e. that member refers to routes acting on a single element, much like show/update/destroy, and collection referes to routes acting on multiple (or a collection of) elements like index. Is it worth clarifying further?
- [X] Consider: Constraints could be a main section rather than live under non-resourceful routes, because generally speaking, they can be applied anywhere, even for resources. The only specific one would be match...via:
--> Good point. Tried to move the 3 or 4 sub-sections related to constraints, but couldn't decide where they fit, after non-resource routes or before, and how to transition into them...leaving it as is for now.
- [X] Under Route Globbing and Wildcard Segments there's a waning about passing format: false related to "old 3.0.x behavior" which can either be explained better (what's the meaning of passing format: false), and/or potentially removed (at least the mention to "3.0.x behavior" could be removed) 
- [X] When explaining about using draw to break down very large route files, that subsection could be a caution/warning of sorts to call more attention to the fact that most people shouldn't need it.
- [X] We could explain how to check routes via console with Rails.application.routes.url_helpers under inspecting routes.
- [X] Document the somewhat recent `--unused` option to rails routes. ([Reference](https://github.com/rails/rails/pull/51316#issuecomment-1994428608))

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
Co-authored-by: Matheus Richard <matheusrichardt@gmail.com>
Co-authored-by: Bartosz Łęcki <bart.lecki@gmail.com>
Co-authored-by: Lucas Fernandes <lsfernandes92@gmail.com>
Co-authored-by: Ruy Rocha <108208+ruyrocha@users.noreply.github.com>
Co-authored-by: Hrishi Mittal <hrishimittal@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2024-08-23 17:14:58 +02:00
Rafael Mendonça França 0af9459f6e
Merge pull request #52688 from Shopify/require-parallelize-executor
Require testing/parallelize_executor in testing/isolation
2024-08-23 10:51:49 -03:00
Eileen M. Uchitelle d36df7aced
Merge pull request #52687 from neilvcarvalho/nc-unpin-sqlite3-bug-report
Unpin sqlite3 version in bug_report_templates
2024-08-23 09:42:21 -04:00
Étienne Barrié 3a2386d058 Require testing/parallelize_executor in testing/isolation
The constant is referred to by this file but might not be loaded.
2024-08-23 15:37:16 +02:00
Neil Carvalho 313582b92a
Unpin sqlite3 version in bug_report_templates
Reverts #51591 as it is not necessary anymore.
All the Rails currently supported versions (>= 7.1
as of now) support `sqlite3` 2.0, while edge Rails
requires `sqlite3` 2.0 or higher.
2024-08-23 10:24:14 -03:00
Petrik 271467b013 Deprecate `STATS_DIRECTORIES` in favor of `CodeStatistics.add_directory`
`STATS_DIRECTORIES` is used by third parties to add directories to the
statistics output. It's a global constant defined in a Rake file, that
gets loaded anytime the Rake commands get loaded.

For example Rspec Rails adds these in a prepended Rake task:
8c17b4e502/lib/rspec/rails/tasks/rspec.rake (L43)

Rake tasks only get loaded if no matching Thor task has been found. This
means `STATS_DIRECTORIES` is only available when the Rake commands have
loaded.

As the stats command has now been moved to a Thor task, calling
`bin/rails stats` will no longer add directories to `STATS_DIRECTORIES`,
as the Rake commands don't get loaded anymore.

To remove the dependency on Rake and avoid a global constant we can add
an API to add directories: `CodeStatistics.add_directory`.
`STATS_DIRECTORIES` is deprecated.

`deprecate_constant` couldn't be used here as that doesn't seem to work
for the root namespace.

Co-authored-by: Earlopain <14981592+Earlopain@users.noreply.github.com>
2024-08-23 14:59:14 +02:00
Aditya Pandit 55116d3750 Fixed significant styling issue 2024-08-23 16:34:40 +05:30
Jean Boussier 0794abb6bb
Merge pull request #52684 from Shopify/error-subscriber-backtrace
ActiveSupport::ErrorReporter#report assigns a backtrace to unraised exceptions
2024-08-23 12:34:14 +02:00
Jean Boussier b1d8cf59d9 ActiveSupport::ErrorReporter#report assigns a backtrace to unraised exceptions
Previously reporting an un-raised exception would result in an error report without
a backtrace. Now it automatically generates one.
2024-08-23 10:17:56 +02:00
Ryuta Kamizono ca05b17c99 Fix sqlite3 link http://www.sqlite.org to https://www.sqlite.org
[ci skip]
2024-08-23 16:41:25 +09:00
Yasuo Honda bc4912f4cf
Merge pull request #52682 from yahonda/suppress_rfc3986_parser_warning
Allow `URI::RFC3986_PARSER` warnings
2024-08-23 15:28:53 +09:00
Yasuo Honda 4bd2c306f0 Allow `URI::RFC3986_PARSER` warnings
This pull request allows `URI::RFC3986_PARSER` warnings appeared since https://buildkite.com/rails/rails-nightly/builds/931

This warning has been implemented to Ruby master branch via b41d79962a
and the original pull request for URI is https://github.com/ruby/uri/pull/114

We are not able to just replace `URI::DEFAULT_PARSER` with `URI::RFC2396_PARSER`
because `URI::RFC2396_PARSER` gets `uninitialized constant URI::RFC2396_PARSER (NameError)` with Ruby 3.3.4 as reported https://github.com/ruby/uri/issues/118

We can revert this commit and replace `URI::DEFAULT_PARSER` with `URI::RFC2396_PARSER` once `URI::RFC2396_PARSER` is available for uri bundled with Ruby 3.3.4 or older versions.

- This commit allows the warning below and let Rails CI against Ruby master branch run

```
$ RAILS_STRICT_WARNINGS=1 bin/test test/abstract/callbacks_test.rb
/home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:2063: warning: URI::RFC3986_PARSER.escape is obsoleted. Use URI::RFC2396_PARSER.escape explicitly.
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/strict_warnings.rb:35:in 'ActiveSupport::RaiseWarnings#warn': /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:2063: warning: URI::RFC3986_PARSER.escape is obsoleted. Use URI::RFC2396_PARSER.escape explicitly. (ActiveSupport::RaiseWarnings::WarningError)
        from <internal:warning>:54:in 'Kernel#warn'
        from /home/yahonda/.rbenv/versions/trunk/lib/ruby/3.4.0+0/uri/rfc3986_parser.rb:156:in 'URI::RFC3986_Parser#escape'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:2063:in 'ActionDispatch::Routing::Mapper::Resources#add_route'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:2038:in 'ActionDispatch::Routing::Mapper::Resources#decomposed_match'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:2002:in 'block in ActionDispatch::Routing::Mapper::Resources#map_match'
        from <internal:array>:53:in 'Array#each'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:1996:in 'ActionDispatch::Routing::Mapper::Resources#map_match'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:1739:in 'ActionDispatch::Routing::Mapper::Resources#match'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:798:in 'ActionDispatch::Routing::Mapper::HttpHelpers#map_method'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/mapper.rb:741:in 'ActionDispatch::Routing::Mapper::HttpHelpers#get'
        from /home/yahonda/src/github.com/rails/rails/actionpack/test/abstract_unit.rb:71:in 'block (2 levels) in <top (required)>'
        from /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/deprecation/reporting.rb:43:in 'ActiveSupport::Deprecation::Reporting#silence'
        from /home/yahonda/src/github.com/rails/rails/actionpack/test/abstract_unit.rb:70:in 'block in <top (required)>'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/route_set.rb:479:in 'BasicObject#instance_exec'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/route_set.rb:479:in 'ActionDispatch::Routing::RouteSet#eval_block'
        from /home/yahonda/src/github.com/rails/rails/actionpack/lib/action_dispatch/routing/route_set.rb:461:in 'ActionDispatch::Routing::RouteSet#draw'
        from /home/yahonda/src/github.com/rails/rails/actionpack/test/abstract_unit.rb:69:in '<top (required)>'
        from /home/yahonda/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:75:in 'Kernel.require'
        from /home/yahonda/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:75:in 'block (2 levels) in Kernel#replace_require'
        from /home/yahonda/src/github.com/rails/rails/actionpack/test/abstract/callbacks_test.rb:3:in '<top (required)>'
        from /home/yahonda/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:75:in 'Kernel.require'
        from /home/yahonda/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:75:in 'block (2 levels) in Kernel#replace_require'
        from /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:62:in 'block in Rails::TestUnit::Runner.load_tests'
        from <internal:array>:53:in 'Array#each'
        from /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:60:in 'Rails::TestUnit::Runner.load_tests'
        from /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:52:in 'Rails::TestUnit::Runner.run'
        from /home/yahonda/src/github.com/rails/rails/tools/test.rb:18:in '<top (required)>'
        from bin/test:5:in 'Kernel#require_relative'
        from bin/test:5:in '<main>'
$
```
2024-08-23 12:26:10 +09:00
Rafael Mendonça França a59ddc714f
Merge pull request #52656 from tsvallender/db-specify-cmd
Allow use of alternative database interfaces
2024-08-22 14:58:17 -03:00
Trevor Vallender 4b2174d674
Allow use of alternative database interfaces
The CLI tool used as a database interface is now specified and
customisable via ActiveRecord.database_cli.

This specifies the current defaults but allows them to be overridden by
users. It continues to accept array values to allow fallback options.
2024-08-22 17:20:37 +00:00
Rafael Mendonça França d4df3d5f81
Merge pull request #50475 from waymondo/postgres-partition-options
support dumping PostgreSQL inheritance & partitioning options to `schema.rb`
2024-08-22 14:08:25 -03:00
justin talbott fba7ef0369
support dumping PostgreSQL partitioning options to `schema.rb` 2024-08-22 16:23:06 +00:00
Stephen Margheim c3f5eba1ad
Update the description of when SQLite might make sense as the configured database [ci skip] (#52639)
* Update the description of when SQLite might make sense as the configured database

* Update configuring.md

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2024-08-22 08:48:41 -07:00
Rafael Mendonça França b5fe9ec57b
Revert "Merge pull request #49769 from jonathanhefner/active_record-enum-non-column-backed"
This reverts commit 121e0ad015, reversing
changes made to d68e43922b.

Fixes #52607.

But this reintroduce #49717. Since enum not backed by columns are
less common, we can live with that for now.
2024-08-22 15:17:02 +00:00