Commit Graph

91188 Commits

Author SHA1 Message Date
Rosa Gutierrez
71a74ad035
Preserve encoding on truncate_bytes (#51313)
String.new with no arguments returns the empty string with ASCII-8BIT
encoding. Then, depending on each grapheme cluster of the string and
on the omission string, the resulting string might keep the ASCII-8BIT
encoding. With this change, we preserve the encoding of the original
string instead.

Note that String.new accepts an `encoding` keyword argument, like
```
String.new(encoding: Encoding::UTF_8)
```
However, instead of using that, we rely on `force_encoding` to set the
original encoding. This is so that String subclasses don't need to
preserve this keyword argument. For example, SafeBuffer doesn't.
Thanks to @jeremy for catching this!
2024-03-12 15:39:21 -07:00
Rafael Mendonça França
d79da7bd5e
Merge pull request #51299 from ElvinEfendi/support-custom-blob-key-in-compose
Support custom blob key in ActiveStorage::Blob#compose similar to other Blob APIs
2024-03-12 17:28:21 -04:00
Matheus Richard
7fe58410a6
Fix error message for unknown template local variable
This was likely a copy/paste error.
2024-03-12 17:22:53 -03:00
Hartley McGuire
4c2c8f8193
Merge pull request #51312 from debashiscodes/improve-layout-and-rendering-doc
Improve the documentation for layout and rendering(layouts_and_rendering.md).
2024-03-12 19:09:58 +00:00
Debashis Biswal
b09c8621b1
[ci skip] Improve the documentation for layout and rendering.
Update guides/source/layouts_and_rendering.md

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2024-03-12 15:08:28 -04:00
Aditya Pandit
bf48b1515c Updated the pull request template, grammatical and general wordings 2024-03-12 22:17:17 +05:30
Nikita Vasilevsky
99acf3e784
Do not build View watcher until the first updated? check
Currently initialization of every Rails::Engine leads to the creation
of a new View watcher when the engine prepends its paths.
This contributes to the time it takes to perform the first cold request
on a lazy loaded application.

This change delays the initialization of the View watcher until the first
`updated?` check is performed.

Co-Authored-By: Gannon McGibbon <gannon.mcgibbon@gmail.com>
2024-03-12 16:30:29 +00:00
Elvin Efendiev
64178f998e Support custom blob key in ActiveStorage::Blob#compose similar to other Blob APIs 2024-03-11 17:27:19 -04:00
bhumi1102
4d3e2910c6
Review Active Record Basics Guide [ci-skip] (#51226)
Add more code examples and update existing examples to be more consistent across the board.
Make the connection between Active Record and Active Model clearer.
Update Intro language to be more friendly, less jargon-y, clearly explain terms like ORM.
Expand some sections like how to generate namespaces models.

Co-authored-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
2024-03-11 16:16:44 -03:00
Eileen M. Uchitelle
da7f51a447
Merge pull request #51296 from seanpdoyle/follow-up-51258
`ActiveRecord::Migration.verbose` documentation [ci skip]
2024-03-11 10:37:12 -04:00
Sean Doyle
c2ca7594dc ActiveRecord::Migration.verbose documentation [ci skip]
Follow-up to [#51258][]

Re-write `ActiveRecord::Migration.verbose` documentation to incorporate
[review feedback][] from [#51258][].

[#51258]: https://github.com/rails/rails/pull/51258
[review feedback]: https://github.com/rails/rails/pull/51258#discussion_r1519637097
2024-03-11 09:44:59 -04:00
Vipul A M
bf96dcfa0d
Merge pull request #51258 from seanpdoyle/migration-verbose-class-attribute
Emphasize mention of `Migration.verbose` [ci skip]
2024-03-10 13:30:23 -04:00
Eileen M. Uchitelle
029d31ca31
Merge pull request #51267 from flavorjones/flavorjones-51246-rails-html-sanitizer
railties: configure sanitizer vendor in 7.1 defaults more robustly
2024-03-08 11:43:08 -05:00
Yasuo Honda
82e3252f18
Merge pull request #51286 from yahonda/wl_13325_mysql_8019
MySQL 8.0.19 introduces aliases in the VALUES and SET clauses of INSERT INTO ... ON DUPLICATE KEY UPDATE statement
2024-03-09 00:53:34 +09:00
Yasuo Honda
52353c8bf5 MySQL 8.0.19 introduces aliases in the VALUES and SET clauses of INSERT INTO ... ON DUPLICATE KEY UPDATE statement
This commit addresses the following errors against MySQL 8.0.18 or lower version of MySQL 8.0.

- Steps to reproduce

```ruby
git clone https://github.com/rails/rails
cd rails
git clone https://github.com/rails/buildkite-config .buildkite/
RUBY_IMAGE=ruby:3.3 docker-compose -f .buildkite/docker-compose.yml build base &&
  CI=1 MYSQL_IMAGE=mysql:8.0.18 docker-compose -f .buildkite/docker-compose.yml run mysqldb runner activerecord 'rake db:mysql:rebuild test:mysql2'
```

- Actual behavior

```ruby
... snip ...
Error:
InsertAllTest#test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_false_but_overridden:
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `ships_values` ON DUPLICATE KEY UPDATE updated_at=(CASE WHEN (`ships`.`name`<' at line 1
    /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `_query'
    /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `block in query'
    /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:150:in `handle_interrupt'
    /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:150:in `query'
    lib/active_record/connection_adapters/mysql2/database_statements.rb:104:in `block (2 levels) in raw_execute'
    lib/active_record/connection_adapters/abstract_adapter.rb:997:in `block in with_raw_connection'
    /rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
    /rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
    /rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
    /rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
    lib/active_record/connection_adapters/abstract_adapter.rb:969:in `with_raw_connection'
    lib/active_record/connection_adapters/mysql2/database_statements.rb:102:in `block in raw_execute'
    /rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
    lib/active_record/connection_adapters/abstract_adapter.rb:1112:in `log'
    lib/active_record/connection_adapters/mysql2/database_statements.rb:101:in `raw_execute'
    lib/active_record/connection_adapters/abstract_mysql_adapter.rb:237:in `execute_and_free'
    lib/active_record/connection_adapters/mysql2/database_statements.rb:23:in `internal_exec_query'
    lib/active_record/connection_adapters/abstract/database_statements.rb:171:in `exec_insert_all'
    lib/active_record/connection_adapters/abstract/query_cache.rb:26:in `exec_insert_all'
    lib/active_record/insert_all.rb:55:in `execute'
    lib/active_record/insert_all.rb:13:in `block in execute'
    lib/active_record/connection_adapters/abstract/connection_pool.rb:384:in `with_connection'
    lib/active_record/connection_handling.rb:270:in `with_connection'
    lib/active_record/insert_all.rb:12:in `execute'
    lib/active_record/persistence.rb:363:in `upsert_all'
    test/cases/insert_all_test.rb:561:in `block in test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_false_but_overridden'
    test/cases/insert_all_test.rb:809:in `with_record_timestamps'
    test/cases/insert_all_test.rb:560:in `test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_false_but_overridden'

bin/rails test /rails/activerecord/test/cases/insert_all_test.rb:557

E
... snip ...
8856 runs, 25842 assertions, 1 failures, 52 errors, 41 skips
```

Follow up #51274

Refer to these release notes, WL and commits for MySQL 8.0.19 and 8.0.20.

- MySQL 8.0.19 supports aliases in the VALUES and SET clauses of INSERT INTO ... ON DUPLICATE KEY UPDATE statement
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-19.html

> MySQL now supports aliases in the VALUES and SET clauses of INSERT INTO ... ON DUPLICATE KEY UPDATE statement
> for the row to be inserted and its columns. Consider a statement such as this one:

https://dev.mysql.com/worklog/task/?id=6312
c39355e9e6

- MySQL 8.0.20 deprecates the old `VALUES()` syntax in INSERT ... ON DUPLICATE KEY UPDATE statements

https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-20.html
> The use of VALUES() to access new row values in INSERT ... ON DUPLICATE KEY UPDATE statements
> is now deprecated, and is subject to removal in a future MySQL release.
> Instead, you should use aliases for the new row and its columns as implemented in MySQL 8.0.19 and later.

https://dev.mysql.com/worklog/task/?id=13325
6f3b9df50b
2024-03-09 00:03:39 +09:00
Yasuo Honda
608c1bfe17
Merge pull request #51281 from fatkodima/fix-flaky-insert_all-test 2024-03-08 12:03:39 +09:00
fatkodima
3c61c3d4f8 Fix flaky upsert test 2024-03-08 01:56:08 +02:00
Rafael Mendonça França
83702d64c8
Fix header formatting in configuring.md 2024-03-07 22:04:36 +00:00
Rafael Mendonça França
247c892150
Move load hooks section to the configuration guide
Those also applies to applications, so they should not be in a guide
specific for engines.
2024-03-07 22:03:04 +00:00
Rafael Mendonça França
8922180af5
Merge pull request #51270 from skipkayhil/hm-fix-bold-label-list
Fix md label-lists rendering incorrectly [ci-skip]
2024-03-07 16:19:49 -05:00
Rafael Mendonça França
033acf8bc3
Merge pull request #51279 from gabriel-amaral/gabriel-amaral/form_path-fix-fragment
Handling relative paths with extra URI parts.
2024-03-07 15:36:15 -05:00
Gabriel Amaral
2cd7460152 Making code branches explicit
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-03-07 20:20:25 +00:00
Gabriel Amaral
b8e4640d72 Handling relative paths with extra URI parts. 2024-03-07 19:44:32 +00:00
Ridhwana
6e0b89c533
[RF DOCS] Active Model Basics Documentation [ci-skip] (#51210)
Review the Active Model Basics guide.

Add `Attributes` and `AttributeAssignment` sections.

Update the rest of the sections by trying to provide more information, be more clear, and include more examples. In some parts, it references the API where more information about the methods can be provided.

Expand `ActiveModel::API` and `ActiveModel::Model`, reorganize sections to a more sensible order.

Co-authored-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
2024-03-07 14:17:56 -03:00
Jean Boussier
7f349f8ad7
Merge pull request #51274 from fatkodima/fix-mysql-upsert-warning 2024-03-07 15:12:08 +01:00
fatkodima
0e7826e10e Fix upsert warning for MySQL 2024-03-07 15:35:14 +02:00
Hartley McGuire
6640b85b69
Fix md label-lists rendering incorrectly
When converting docs from RDoc to Markdown, some label-lists ended up
not rendering properly. This appears to be due to RDoc's Markdown
parser not recognizing label-list labels if the label has additional
markup around it (in this case, bold markers `**`).

Additionally, the markdown label-list was missing newlines between list
items which also caused the label-list to not render correctly.

This commit fixes both of these issues for cases where the RDoc
originally used <b> tags in a label-list label. Since label-list labels
will already be bolded, there is no reason to also use `**` on the
labels.
2024-03-06 18:11:14 -05:00
Sean Doyle
0faae8af77 Emphasize mention of Migration.verbose [ci skip]
The API documentation for `ActiveRecord::Migration` mentions controlling
the level of log output through a `.verbose` class attribute. The line
isn't wrapped in `<tt>`, `+`, or backticks, so isn't emphasized as if it
were code.

This commit visually emphasizes that line so that it's more obviously
code.
2024-03-06 17:12:55 -05:00
Mike Dalessio
8957ba58d5
Fix sanitizer vendor config with 7.1 defaults
rails-html-santizer is a dependency of Action View and a transitive
dependency of Action Text (via Action Pack), but may not be loaded
until after railties sets configuration defaults.

This change `require`s rails-html-sanitizer immediately before it's
needed, and avoids the possibly-incorrect assumption that
Rails::HTML::Sanitizer is already defined.

Closes #51246

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2024-03-06 16:54:16 -05:00
Carlos Antonio da Silva
2fa3294618
Merge pull request #51263 from buncis/update-delegate-type-doc
[ci skip] update delegated type doc to make it less confusing and in sync with rails guide
2024-03-06 13:22:44 -03:00
Petrik de Heus
8b4432125a
Merge pull request #51239 from jherdman/tweak-tag-helper-docs [ci-skip]
More complicated tag helper example
2024-03-06 17:17:13 +01:00
James Herdman
09e8eb4f0b More complicated tag helper example [ci skip]
Illustrate tag helper attribute usage with the block form.
2024-03-06 09:34:34 -05:00
buncis
1c54153dc6
update docs to make it less confusing and in sync with rails guide 2024-03-06 20:31:34 +07:00
Rafael Mendonça França
f7353283fd
Merge pull request #51248 from Earlopain/ar-guides-links
Add mention that methods can also skip callbacks to the AR Validations Guide [ci-skip]
2024-03-05 12:05:24 -05:00
Rafael Mendonça França
08b49f18eb
Merge pull request #51247 from Earlopain/fix-51228
Fix crash for invalid Content-Type in ShowExceptions middleware
2024-03-05 10:18:13 -05:00
Carlos Antonio da Silva
d514a31eed Remove WIP from Action Mailbox & Action Text guides [ci skip]
These have been reviewed recently by the Rails Foundation team working
on the guides:

Action Mailbox: https://github.com/rails/rails/pull/50973
Action Text: https://github.com/rails/rails/pull/50977
2024-03-05 11:48:06 -03:00
Earlopain
d3f16a7de1
Encourage the user to check method docs in AR Callback/Validation Guides 2024-03-05 13:31:39 +01:00
Yasuo Honda
917b6b2908
Merge pull request #51252 from yahonda/diag_247
Add missing :author_addresses in `OrderTest`
2024-03-05 14:58:52 +09:00
Yasuo Honda
3a7d96c485 Add missing :author_addresses in OrderTest
This commit addresses this CI failure https://buildkite.com/rails/rails-nightly/builds/247#018e0bea-7a88-45eb-94fa-be4155aeeeca/1164-1173

- Error without this commit
```ruby
$ bin/test test/cases/relation/order_test.rb test/cases/fixtures_test.rb -n "/^(?:OrderTest#(?:test_order_desc)|FixturesWithForeignKeyViolationsTest#(?:test_does_not_raise_if_no_fk_violations))$/" --seed 31115
Using sqlite3
Run options: -n "/^(?:OrderTest#(?:test_order_desc)|FixturesWithForeignKeyViolationsTest#(?:test_does_not_raise_if_no_fk_violations))$/" --seed 31115

.E

Error:
FixturesWithForeignKeyViolationsTest#test_does_not_raise_if_no_fk_violations:
RuntimeError: Foreign key violations found in your fixture data. Ensure you aren't referring to labels that don't exist on associations. Error from database:

Foreign key violations found: authors, authors, authors
    lib/active_record/fixtures.rb:704:in `rescue in check_all_foreign_keys_valid!'
    lib/active_record/fixtures.rb:701:in `check_all_foreign_keys_valid!'
    lib/active_record/fixtures.rb:688:in `block (2 levels) in insert'
    lib/active_record/connection_adapters/abstract/connection_pool.rb:384:in `with_connection'
    lib/active_record/fixtures.rb:685:in `block in insert'
    lib/active_record/fixtures.rb:676:in `each'
    lib/active_record/fixtures.rb:676:in `insert'
    lib/active_record/fixtures.rb:662:in `read_and_insert'
    lib/active_record/fixtures.rb:607:in `create_fixtures'
    test/cases/fixtures_test.rb:893:in `block (2 levels) in test_does_not_raise_if_no_fk_violations'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:49:in `assert_nothing_raised'
    test/cases/fixtures_test.rb:892:in `block in test_does_not_raise_if_no_fk_violations'
    test/cases/fixtures_test.rb:906:in `with_verify_foreign_keys_for_fixtures'
    test/cases/fixtures_test.rb:891:in `test_does_not_raise_if_no_fk_violations'

bin/test test/cases/fixtures_test.rb:884

Finished in 0.084771s, 23.5930 runs/s, 94.3720 assertions/s.
2 runs, 8 assertions, 0 failures, 1 errors, 0 skips
$
```

Refer to #43873 that has the same reason why it gets error.
2024-03-05 14:23:20 +09:00
Earlopain
17662a4876
Link to API docs in AR Callbacks/Validations guide 2024-03-04 11:26:35 +01:00
Earlopain
f080d8f5d0
Fix crash for invalid Content-Type in ShowExceptions middleware 2024-03-04 09:12:35 +01:00
Yasuo Honda
db30dd6fe7
Merge pull request #51240 from yahonda/follow_up_51204
Use `ActiveRecord::Base.lease_connection` for uncached dirties tests
2024-03-04 08:39:52 +09:00
Yasuo Honda
a556be5ddc Use ActiveRecord::Base.lease_connection for uncached dirties tests
This commit addresses these errors since #51192 renames `.connection` into `.lease_connection`

Follow up #51204

```ruby
$ cd activerecord
$ bin/test test/cases/query_cache_test.rb -n /uncached_dirties/
Using sqlite3
Run options: -n /uncached_dirties/ --seed 57207

E

Error:
QueryCacheTest#test_query_cache_uncached_dirties:
NoMethodError: undefined method `connection' for class ActiveRecord::Base
    lib/active_record/dynamic_matchers.rb:22:in `method_missing'
    test/cases/query_cache_test.rb:712:in `block (2 levels) in test_query_cache_uncached_dirties'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes'
    test/cases/query_cache_test.rb:712:in `block in test_query_cache_uncached_dirties'
    test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap'
    test/cases/query_cache_test.rb:771:in `block in middleware'
    test/cases/query_cache_test.rb:720:in `test_query_cache_uncached_dirties'

bin/test test/cases/query_cache_test.rb:709

E

Error:
QueryCacheTest#test_query_cache_connection_uncached_dirties:
NoMethodError: undefined method `connection' for class ActiveRecord::Base
    lib/active_record/dynamic_matchers.rb:22:in `method_missing'
    test/cases/query_cache_test.rb:726:in `block (2 levels) in test_query_cache_connection_uncached_dirties'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes'
    test/cases/query_cache_test.rb:726:in `block in test_query_cache_connection_uncached_dirties'
    test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap'
    test/cases/query_cache_test.rb:771:in `block in middleware'
    test/cases/query_cache_test.rb:734:in `test_query_cache_connection_uncached_dirties'

bin/test test/cases/query_cache_test.rb:723

E

Error:
QueryCacheTest#test_query_cache_uncached_dirties_disabled_with_nested_cache:
NoMethodError: undefined method `connection' for class ActiveRecord::Base
    lib/active_record/dynamic_matchers.rb:22:in `method_missing'
    test/cases/query_cache_test.rb:740:in `block (2 levels) in test_query_cache_uncached_dirties_disabled_with_nested_cache'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:194:in `assert_changes'
    test/cases/query_cache_test.rb:740:in `block in test_query_cache_uncached_dirties_disabled_with_nested_cache'
    test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap'
    test/cases/query_cache_test.rb:771:in `block in middleware'
    test/cases/query_cache_test.rb:757:in `test_query_cache_uncached_dirties_disabled_with_nested_cache'

bin/test test/cases/query_cache_test.rb:737

Finished in 0.134429s, 22.3166 runs/s, 0.0000 assertions/s.
3 runs, 0 assertions, 0 failures, 3 errors, 0 skips
$
```
2024-03-03 23:37:54 +09:00
Donal McBreen
5d528ba0c8
Add dirties option to uncached (#51204)
This adds a `dirties` option to `ActiveRecord::Base.uncached` and
`ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.

Setting `dirties` to `false`, means database writes to the connection
pool will not mark any query caches as dirty.

The option defaults to `true` which retains the existing behaviour and
clears query caches on all connection pools used by the current thread.

Co-authored-by: Jeremy Daer <jeremy@rubyonrails.org>
2024-03-02 19:01:24 -08:00
Jeremy Daer
5cedb8745c Illustrator files are previewable with Poppler as well
Extends #51235's MuPDF support to Poppler.

Add test coverage for Blob previews and representation.
2024-03-01 13:04:27 -08:00
Jeremy Daer
bf8e0f5f61 Illustrator .ai files are previewable as PDFs
This happened to work with Marcel 1.0.2 and earlier since magic byte
sniffing sees that Illustrator files are PDFs internally, causing these
files to be treated as `application/pdf` despite having a declared
content type of `application/illustrator` and an `.ai` file extension.

Marcel 1.0.3 corrected this to the more specific `application/illustrator`
subtype of `application/pdf`, but the MuPDF previewer only accepts the
parent `application/pdf` type.

Changing it to accept PDF and any child types allows the previewer to
explicitly work with Illustrator files again, which was only a happy
accident previously.
2024-03-01 10:55:48 -08:00
Jeremy Daer
4f0f3448cd Marcel 1.0.4
Update tests to clarify content type detection heuristic after exposing
a regression in Marcel 1.0.3 that wasn't caught by its test suite:

1. magic bytes
2. declared content type, unless it's binary
3. filename extension
4. binary: application/octet-stream
2024-03-01 09:29:24 -08:00
Jean Boussier
1c0982d88a
Merge pull request #51232 from Shopify/refactor-insert-all
Refactor InsertAll not to permanently lease a connection
2024-03-01 17:30:03 +01:00
Hartley McGuire
7d008fee70
Merge pull request #51229 from Earlopain/update-bin-rails-test-help-output
Update output of `bin/rails test -h` in testing guide [ci-skip]
2024-03-01 15:37:14 +00:00
Jean Boussier
ec7deca7ee Refactor InsertAll not to permanently lease a connection
Extracted from: https://github.com/rails/rails/pull/50793
2024-03-01 15:33:45 +01:00