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!
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>
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>
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=6312c39355e9e6
- 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=133256f3b9df50b
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>
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.
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.
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>
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>
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.
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