Fixes:
```
Offenses:
test/application_system_test_case.rb:9:49: C: [Correctable] Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
url: "http://#{ENV["SELENIUM_HOST"]}:4444",
```
https://buildkite.com/rails/rails-nightly/builds/191#018dc3d1-902c-4b01-a82c-b662ebdbe567/1182-1188
Increasing timeout value from 10 to 100 for assert_output method addresses these failures.
- Ruby built with debug options that takes more than 20 seconds and gets failed
Here, the Ruby is built with these options:
```
cppflags="-DENABLE_PATH_CHECK=0 -DRUBY_DEBUG=1" optflags="-O3 -fno-inline"
```
```ruby
$ ruby -v
ruby 3.4.0dev (2024-02-20T11:52:09Z master c22cb960cf) [x86_64-linux]
$ time bin/test test/application/dbconsole_test.rb
Run options: --seed 5685
F
Failure:
ApplicationTests::DBConsoleTest#test_use_value_defined_in_environment_file_in_database_yml [test/console_helpers.rb:19]:
"sqlite>" expected, but got:
.
Expected "" to include "sqlite>".
bin/test test/application/dbconsole_test.rb:21
F
Failure:
ApplicationTests::DBConsoleTest#test_respect_environment_option [test/console_helpers.rb:19]:
"sqlite>" expected, but got:
.
Expected "" to include "sqlite>".
bin/test test/application/dbconsole_test.rb:43
Finished in 10.105668s, 0.1979 runs/s, 0.3958 assertions/s.
2 runs, 4 assertions, 2 failures, 0 errors, 0 skips
real 0m21.031s
user 0m8.665s
sys 0m2.286s
$
```
- Ruby built without debug options that finishes within second.
```ruby
$ ruby -v
ruby 3.4.0dev (2024-02-20T11:52:09Z master c22cb960cf) [x86_64-linux]
$ time bin/test test/application/dbconsole_test.rb
Run options: --seed 1479
..
Finished in 5.463076s, 0.3661 runs/s, 1.0983 assertions/s.
2 runs, 6 assertions, 0 failures, 0 errors, 0 skips
real 0m9.942s
user 0m2.288s
sys 0m2.173s
$
```
This commit address Rails Nightly failure at
https://buildkite.com/rails/rails-nightly/builds/191#018dc3d1-8fb2-4c35-ad1d-bd3891757361/1310-1318
This issue reproduces when the `default-mysql-client` apt package installs `mysql-client-8.0`
that raises `CR_CONN_HOST_ERROR` which is mapped to `ActiveRecord::DatabaseConnectionError`
while `mariadb-client` raises `CR_CONNECTION_ERROR` error which is mapped to `ActiveRecord::ConnectionNotEstablished`.
In this test, whichever exception `ActiveRecord::ConnectionNotEstablished` or `DatabaseConnectionError` is fine
as long as the connection is invalid.
- Steps to reproduce
Run this step at Linux box on Ubuntu Jammy or whatever `default-mysql-client` installs MySQL client, not MariaDB one.
```
git clone https://github.com/rails/rails
cd rails/railties
bundle install
bin/test test/application/initializers/frameworks_test.rb:285
```
- Failure fixed by this commit
```ruby
$ bin/test test/application/initializers/frameworks_test.rb:285
Run options: --seed 32832
F
Failure:
ApplicationTests::FrameworksTest#test_expire_schema_cache_dump_if_the_version_can't_be_checked_because_the_database_is_unhealthy [test/application/initializers/frameworks_test.rb:285]:
Expected /Failed to validate the schema cache because of ActiveRecord::ConnectionNotEstablished/ to match "Failed to validate the schema cache because of ActiveRecord::DatabaseConnectionError: There is an issue connecting with your hostname: 127.0.0.1.\n\nPlease check your database configuration and ensure there is a valid connection to your database.\n".
bin/test test/application/initializers/frameworks_test.rb:263
Finished in 6.299418s, 0.1587 runs/s, 0.6350 assertions/s.
1 runs, 4 assertions, 1 failures, 0 errors, 0 skips
```
- `default-mysql-client` package used by Rails CI
3158d00b48/Dockerfile (L91)
`default-mysql-client` installs different package per distribution, Ja
https://packages.ubuntu.com/jammy/default-mysql-clienthttps://packages.debian.org/bookworm/default-mysql-client
- Each error message are defined in these lines by these commits:
-- MariaDB
eeba940311/sql-common/errmsg.c (L32)9075973dbf
-- MySQL
824e2b4064/libmysql/errmsg.cc (L39)964d5fdb02
The original example has race condition issue that the output of the example isn't conistent, see https://github.com/rails/rails/issues/43588.
The change improves the example by removing unnecessary thread and add detailed comments.
In the new example, there will be race condition only if `ActiveSupport::Cache::MemoryStore` took longer than 0.1 second to extend expiry but that's unlikely to happen.
Close#43588
Follow-up to [#48798][]
Reverts [#47837][]
The `capture_broadcasts` helper was introduced in [#48798][] to remove
the return value from the `assert_broadcasts` call. The behavior was
changed, but the corresponding documentation for the `assert_broadcasts`
method did not revert the changes added in [#47837][].
This change should probably also get backported to `7-1-0-stable`.
[#47837]: https://github.com/rails/rails/pull/47837
[#48798]: https://github.com/rails/rails/pull/48798
Co-authored-by: Matheus Richard <matheusrichardt@gmail.com>
* Prevent extra newlines after table generation block in shema.rb file when there are no foreign keys or indexes. This will produce valid code without linting issues (issue: Trailing whitespace detected)
* fix linting issues
* fix linting
Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
In `4067c9565a5da78a72e375a2d959000147f02c34` `ActionDispatch::Executor`
started to report all errors, even the ones that were "handled" by the application.
This leads to errors like `ActionController::RoutingError` polluting error trackers
while not being actionable since they do not represent an exceptional situation.
This commit changes the behavior to only report errors that are not
considered "handled" based on the `ActionDispatch::ExceptionWrapper.rescue_responses` list.
* Support encrypting binary columns
ActiveRecord Encryption doesn't prevent you from encrypting binary
columns but it doesn't have proper support for it either.
When the data is fed through encrypt/decrypt it is converted to a
String. This means that the the encryption layer is not transparent
to binary data - which should be passed as Type::Binary::Data.
As a result the data is not properly escaped in the SQL queries or
deserialized correctly after decryption.
However it just happens to work fine for MySQL and SQLite because the
MessageSerializer doesn't use any characters that need to be encoded.
However if you try to use a custom serializer that does then it breaks.
PostgreSQL on the other hand does not work - because the Bytea type
is passed a String rather than a Type::Binary::Data to deserialize, it
attempts to unescape the data and either mangles it or raises an error
if it contains null bytes.
The commit fixes the issue, by reserializing the data after
encryption and decryption. For text data that's a no-op, but for binary
data we'll convert it back to a Type::Binary::Data.
* Extract decrypt_as_text/encrypt_as_text
* Handle serialized binary data in encrypted columns
Calling `serialize` is not always possible, because the column type
might not expect to be serializing a String, for example when declared
as serialzed or store attribute.
With binary data the encryptor was passed an
`ActiveModel::Type::Binary::Data`` and returned a `String``. In order to
remain transparent we need to turn the data back into a
`ActiveModel::Type::Binary::Data` before passing it on.
We'll also rename `serialize`` to `text_to_database_type` to be a bit
more descriptive.
Another refactoring in relation to https://github.com/rails/rails/pull/50793
But it makes sense even without it.
Rather than each connection to have its own `BoundSchemaReflection`,
we can instead have `BoundSchemaReflection` hold a `ConnectionPool`,
from which it can checkout a connection to perform queries when needed.
If the current thread already leased a connection, it will be used.
This simplifies the interface quite a bit.
Some tests do leak connections, which cause some other tests to stall
for a very long time when they call `clear_all_connections`.
Each leaked connection takes 5 seconds to be cleared because of the
checkout timeout.
So on teardown to inspect all pools to make sure nothing was leaked
and if some connections were leaked we cleanup the state.
Follow-up to [49856][]
Follow-up to [49194][]
The introduction of memoization as an optimization posed a backwards
incompatible change to View tests that call `render` multiple times.
This commit changes the `@rendered` instance variable from a `String` to
an instance of the `RenderedViewContent` specialized `String` subclass.
The end result is that there is no memoization to reset, and the
memoization optimization side-effect is preserved after rendering for
test cases where `rendered` (or parser methods like `rendered.html`)
might be invoked more than once.
[49856]: https://github.com/rails/rails/pull/49856#issuecomment-1945039015
[49194]: https://github.com/rails/rails/pull/49194/files#diff-ce84a807f3491121a5230d37bd40454bb1407fcca71179e1a2fa76d4c0ddfa2aR293
This constant is referenced in
actionpack/lib/action_dispatch/testing/assertions/routing.rb,
which doesn't directly depend on ActionController::TestCase.