Commit Graph

90968 Commits

Author SHA1 Message Date
Peter Berkenbosch bc6a3cc759
Fix linting error for generated system test case.
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",
```
2024-02-20 14:41:30 +01:00
Yasuo Honda fc375d63c4 Address `ApplicationTests::DBConsoleTest` failures against asserion enabled Ruby
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
$
```
2024-02-20 22:26:16 +09:00
Yasuo Honda 51ce412d1b
Merge pull request #51135 from yahonda/allow_ubuntu_default-mysql-client
Address `ApplicationTests::FrameworksTest` failure on Ubuntu 22.04
2024-02-20 20:40:11 +09:00
Yasuo Honda 22bcead5c2 Address `ApplicationTests::FrameworksTest` failure on Ubuntu 22.04
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-client
https://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
2024-02-20 19:59:36 +09:00
John Pitchko c419435b0e
Fix delegated type example
Must specify `account` parameter because of the association defined in `Entry`.
2024-02-19 21:46:14 -07:00
Jian Weihang a8bc63af54
Improve the example of ActiveSupport::Cache::Store#fetch
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
2024-02-20 12:08:39 +08:00
Roque Pinel f4f3ef7781
Add parameter filter capability for redirect locations
It uses the `config.filter_parameters` to match what needs to be
filtered. The result would be like this:

```
Redirected to http://secret.foo.bar?username=roque&password=[FILTERED]
```
2024-02-20 11:31:12 +08:00
John Pitchko 4c9a1e0d93
Add query docs for delegated type
Lint

Update activerecord/lib/active_record/delegated_type.rb

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-02-19 14:12:16 -07:00
Artem Yegorov 5919152ad0
Improve the names of variables for devcontainer tests 2024-02-19 22:13:10 +03:00
Artem Yegorov 39056cc457
Fix typo in network name for devcontainer 2024-02-19 22:04:17 +03:00
bhumi1102 554e71af0b
[RF DOCS] Add documentation for `perform_all_later` to Active Job Basics guide [ci-skip] (#51004)
Add documentation related to perform_all_later for bulk enqueuing jobs.

Co-authored-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
2024-02-19 13:56:15 -03:00
Hartley McGuire 5cc11f761d
Merge pull request #51126 from seanpdoyle/action-cable-assert-broadcasts-documentation
Action Cable `assert_broadcasts` API docs [ci skip]
2024-02-19 10:49:28 -05:00
Sean Doyle cfab11c959 Action Cable `assert_broadcasts` API docs [ci skip]
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>
2024-02-19 10:39:43 -05:00
Christian Schmidt d518457ca3 Rubocop 2024-02-19 13:43:59 +01:00
Christian Schmidt 3aa7d79418 Support filenames in Logger.logger_outputs_to? 2024-02-19 13:39:48 +01:00
Hartley McGuire cd4a5b0733
Merge pull request #51042 from lsglucas/docs/security
docs: Outdated CORS initializer [ci-skip]
2024-02-18 12:10:42 -05:00
Hartley McGuire b3208eff05
Merge pull request #51120 from skipkayhil/hm-aj-q-links
Add links to config.active_job.default_queue_name
2024-02-18 11:58:32 -05:00
Hartley McGuire d212c0bd34
Add links to config.active_job.default_queue_name
[ci-skip]
2024-02-18 11:43:51 -05:00
Hartley McGuire e18203e40f
Merge pull request #51113 from ghiculescu/patch-12
Document missing active storage queue configs
2024-02-18 11:34:14 -05:00
fatkodima 6dfe92b23f Pass `connection_pool` to more database-related exceptions raisings 2024-02-18 01:05:40 +02:00
Jean Boussier 057563a888
Merge pull request #51038 from fatkodima/debug-ci
Rewrite connection reaper test with timeout
2024-02-17 21:32:03 +01:00
fatkodima 4880ec66b9 Rewrite connection reaper test with timeout 2024-02-17 20:55:56 +02:00
Alex Ghiculescu 419599e107
Document missing active storage queue configs
ref https://github.com/rails/rails/pull/51030#discussion_r1491915873
2024-02-17 13:11:59 +10:00
Rafael Mendonça França 44db6bbfcb
Merge pull request #51043 from jasl/ac-expose-close-args
ActionCable: allow to pass websocket.close args
2024-02-16 17:13:46 -05:00
Jun Jiang d5786b2e9d ActionCable: Use `...` to passthrough args 2024-02-17 05:28:42 +08:00
Jun Jiang 08cb349a4b ActionCable: avoid potential nil error 2024-02-17 05:28:42 +08:00
Jun Jiang 0df0947b70 ActionCable: Allow pass code and reason when closing a WebSocket connection 2024-02-17 05:28:42 +08:00
Rafael Mendonça França b8de2534f2
Merge pull request #51107 from Shopify/report-handled-action-dispatch-errors-differently
Do not report rendered errors except 500
2024-02-16 14:35:25 -05:00
Klemen Nagode 89addc7a6e
Prevent extra newlines after table generation block in shema.rb (#48731)
* 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>
2024-02-16 14:27:44 -05:00
Nikita Vasilevsky a8d1d927e8
Do not report rendered errors except 500
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.
2024-02-16 19:19:47 +00:00
Rafael Mendonça França 23db60b8ec
Merge pull request #51104 from tiramizoo/ignore-devcontainer
Ignore devcontainer files in docker image
2024-02-16 12:09:34 -05:00
Rafael Mendonça França 1400447ff6
Fix quote 2024-02-16 17:08:53 +00:00
Donal McBreen 50e322962b
Add MessagePackMessageSerializer for binary data (#51102) 2024-02-16 09:07:25 -08:00
Wojciech Wnętrzak eb9b98f0c4
Ignore devcontainer files in docker image
Follow up to https://github.com/rails/rails/pull/50914
2024-02-16 16:48:16 +01:00
Jean Boussier c676398d5e
Merge pull request #51101 from Shopify/ruby-head-backtrace-fix
Update test suite for compatibility with Ruby 3.4-dev
2024-02-16 12:32:23 +01:00
Jean Boussier 50daadaa71 Update test suite for compatibility with Ruby 3.4-dev
https://bugs.ruby-lang.org/issues/19117 and https://bugs.ruby-lang.org/issues/16495
slightly change how backtrace are rendered which makes a few tests fail.
2024-02-16 11:55:44 +01:00
Rafael Mendonça França 9e01d93547
Merge pull request #51053 from ghiculescu/dont-redefine-call_app
Refactor `Rails::Rack::Logger` to avoid adding a new param to `call_app`
2024-02-15 12:56:48 -05:00
Alex 363abead17
Refactor `Rails::Rack::Logger` to avoid adding a new param to `call_app`
ref: https://github.com/rails/rails/pull/50992#issuecomment-1939865460

This refactors the implementation from that PR so that we don't need a new param on the `call_app` method. This means we don't break any gems or apps that have overridden it.
2024-02-15 17:26:27 +00:00
Donal McBreen 7d4a39cc6f
Support encrypting binary columns (#50920)
* 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.
2024-02-15 08:45:56 -08:00
Jean Boussier ed76d0fbc7
Merge pull request #51091 from Shopify/pool-schema-cache
Refactor SchemaCache to hold a ConnectionPool
2024-02-15 14:09:56 +01:00
Jean Boussier 1af13c645a Refactor SchemaCache to hold a ConnectionPool
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.
2024-02-15 13:56:32 +01:00
Jean Boussier 024f2def01
Merge pull request #51097 from Shopify/test-connection-leak
ActiveRecord::TestCase: reap all leaked connection on teardown
2024-02-15 13:45:11 +01:00
Jean Boussier 85330030b3 ActiveRecord::TestCase: reap all leaked connection on teardown
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.
2024-02-15 13:31:34 +01:00
Eugene Kenny 9aeb1de245
Merge pull request #51093 from seanpdoyle/action-view-rendered-memoization
Action View Test Case `rendered` memoization
2024-02-15 02:52:07 +00:00
Sean Doyle 01502fe239 Remove Upgrade Guidance 2024-02-14 20:41:08 -05:00
Sean Doyle 520cd8f0e3 Action View Test Case `rendered` memoization
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
2024-02-14 20:37:47 -05:00
dhh dd6f3e1328 Style 2024-02-14 16:02:53 -08:00
Rafael Mendonça França e2c522b4b2
Merge pull request #51016 from javierav/optimistic-locking-doc
Document that lock_version column is integer
2024-02-14 18:55:48 -05:00
dhh 99d3b52774 Use consistent ENV.fetch style
There are no expensive computations here, so no need for a block.
2024-02-14 15:54:34 -08:00
Eugene Kenny 53079761a5 Add autoload for ActionController::TestRequest
This constant is referenced in
actionpack/lib/action_dispatch/testing/assertions/routing.rb,
which doesn't directly depend on ActionController::TestCase.
2024-02-14 23:42:31 +00:00