Commit Graph

15255 Commits

Author SHA1 Message Date
Steve Polito
7242fd7f5c
Conditionally skip test job in ci.yml (#51289)
Skip generating a `test` job in ci.yml when a new application is
generated with the `--skip-test` option.

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2024-03-25 13:55:20 -07:00
Rafael Mendonça França
98b3183356
Merge pull request #51390 from andrewn617/devcontainer-use-ruby-feature
Devcontainer using ruby image
2024-03-25 16:43:49 -03:00
Rafael Mendonça França
cccbedf651
Merge pull request #51393 from stevepolitodesign/sp-node-lts
Bump `NODE_LTS_VERSION` to 20.11.1
2024-03-25 15:57:22 -03:00
Edouard CHIN
cac6568837
Merge pull request #51389 from lxxxvi/add-documentation-for-rails-env-local-questionmark
[ci skip] Documentation for `Rails.env.local?`
2024-03-25 15:43:35 +01:00
Carlos Antonio da Silva
61a3e61e77 Minor text / error message tweaks, fixes, and punctuation
Improve a few sentences and add punctuation to some recent changelog &
guide entries.

[ci skip]
2024-03-25 10:21:08 -03:00
Steve Polito
0f18fe1322 Bump NODE_LTS_VERSION to 20.11.1
In e8638c9a942e94f097dc8f37a3b58ac067a5ca16 we introduced a constant to
store the version of Node to be used when generating `.node-version`.

Since then, the [current LTS][LTS] version of Node is now `20.11.1` as
of [2024-02-14][date].

[LTS]: https://nodejs.github.io/nodejs.dev/en/about/releases/
[date]: https://nodejs.org/en/blog/release/v20.11.1
2024-03-25 05:27:49 -04:00
Jean Boussier
7a8e58bcb3 Put plural inverse association inference behind a configuration flag
Ref: https://github.com/rails/rails/pull/50284

While having the inverse association configured it generally positive
as it avoid some extra queries etc, infering it may break legecy code,
as evidenced by how it broke `ActiveStorage::Blob` in https://github.com/rails/rails/pull/50800

As such we can't just enable this behavior immediately, we need to provide
and upgrade path for users.
2024-03-25 10:24:21 +01:00
Andrew Novoselac
060eb5fe4a Add requires for YAML and JSON in the DB System Change generator
These were missed in rails/rails@c90a8701
2024-03-22 09:23:08 -04:00
Andrew Novoselac
5fcbc2c421 Update the Rails app devcontainer to use the Rail's orgs ruby image 2024-03-22 09:23:07 -04:00
mario
ddeb955d45 add documentation for Rails.env.local? 2024-03-22 13:16:02 +01:00
Rafael Mendonça França
5ab13c5a77
Merge pull request #51337 from fatkodima/secret_key_base-deprecation-in-development
Show warning for `secret_key_base` in development too
2024-03-18 14:37:32 -07:00
Jean Boussier
5411787a15
Merge pull request #51005 from zzak/test-runner-did-you-mean
Rails test command suggests similar test files when the given file is not found
2024-03-16 10:38:07 +01:00
zzak
346f516fa1
Rails test command suggests similar test files when the given file is not found.
For example, if you run `rails test test/models/usr_tsst.rb` and the file does not exist,
Rails will suggest `test/models/users_test.rb` as a possible file.

```
Could not load test file: test/models/usr_tsst.rb. Did you mean? test/models/user_test.rb
```

Co-authored-by: Aaron Patterson <aaron@rubyonrails.org>
2024-03-16 17:54:34 +09:00
fatkodima
b96b936a19 Show warning for secret_key_base in development too 2024-03-15 23:34:43 +02: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
Earlopain
f080d8f5d0
Fix crash for invalid Content-Type in ShowExceptions middleware 2024-03-04 09:12:35 +01:00
Jean Boussier
7263da542b Deprecate ConnectionPool#connection
Replaced by `#lease_connection` to better reflect what it does.

`ActiveRecord::Base#connection` is deprecated in the same way
but without a removal timeline nor a deprecation warning.

Inside the Active Record test suite, we do remove `Base.connection`
to ensure it's not used internally.

Some callsites have been converted to use `with_connection`,
some other have been more simply migrated to `lease_connection`
and will serve as a list of callsites to convert for
https://github.com/rails/rails/pull/50793
2024-03-01 14:32:55 +01:00
Steve Polito
59a3dd4729
Set action_mailer.default_url_options values in development and test (#51191)
* Set `action_mailer.default_url_options` values in `development` and `test`.

Prior to this commit, new Rails applications would raise
`ActionView::Template::Error` if a mailer included a url built with a
`*_path` helper.

Since we already know [new apps will be served on `localhost:3000`][new
apps], we set this as the value in `development`.

In an effort to remain consistent with existing patters, we set the
`host` to `www.example.com` in `test.

[new apps]: 47300002db/README.md (L81)

* Update railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>

---------

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-02-27 16:19:23 -05:00
Rafael Mendonça França
b6285e98f0
Make sure assert_initializer accepts a block 2024-02-23 21:54:54 +00:00
Steve Polito
fb16702fee Introduce Rails::Generators::Testing::Assertions#assert_initializer
Compliments the existing [initializer][] generator action.

```rb
assert_initializer "mail_interceptors.rb"
```

[initializer]: https://api.rubyonrails.org/classes/Rails/Generators/Actions.html#method-i-initializer
2024-02-23 10:54:25 -05:00
Jean Boussier
a918394974 Refactor InternalMetadata, MigrationContext to belong to the pool
Extracted from: https://github.com/rails/rails/pull/50793

Similar to the recent refactoring of schema caches, rather than to directly
hold a connection, they now hold a pool and checkout a connection when needed.
2024-02-22 12:46:41 +01:00
Eugene Kenny
4b9b1ef5fa Don't force controller or integration tests to load
2730f10560a9824d7cfb458fb3e78c754064fc6c replaced references to
ActionController::TestCase and ActionDispatch::IntegrationTest in this
file with lazy load hooks to avoid loading them prematurely, but these
requires meant that they were still loaded anyway.
2024-02-21 03:46:41 +00:00
Yasuo Honda
3528b9df8b
Merge pull request #51148 from yahonda/increase_timeout_for_assert_output_2
Increase assert_output timeout for `FullStackConsoleTest` and `ApplicationTests::ServerTest`
2024-02-21 09:00:31 +09:00
Yasuo Honda
790c9c5f40 Increase assert_output timeout for FullStackConsoleTest and ApplicationTests::ServerTest
This commit addresses the following failures at Rails Nightly CI with assertion enabled Ruby.
that has been built with `cppflags="-DENABLE_PATH_CHECK=0 -DRUBY_DEBUG=1" optflags="-O3 -fno-inline"`

https://buildkite.com/rails/rails-nightly/builds/191#018dc3d1-9032-4baa-ae8a-3c630889ab5f/1342-1348
https://buildkite.com/rails/rails-nightly/builds/191#018dc3d1-9033-4c0c-b61c-00f26d3a63fb/1198-1204

Related to #51140

- Failures fixed by this commit:

```
$ ruby -v
ruby 3.4.0dev (2024-02-20T11:52:09Z master c22cb960cf) [x86_64-linux]
$ bin/test test/application/console_test.rb -n test_sandbox
Run options: -n test_sandbox --seed 3666

F

Failure:
FullStackConsoleTest#test_sandbox [test/console_helpers.rb:19]:
"=> 0" expected, but got:

app-template(dev)> quapp-template(dev)> quiapp-template(dev)> quit.
Expected "\r\napp-template(dev)> quapp-template(dev)> quiapp-template(dev)> quit" to include "=> 0".

bin/test test/application/console_test.rb:142

Finished in 32.180314s, 0.0311 runs/s, 0.7458 assertions/s.
1 runs, 24 assertions, 1 failures, 0 errors, 0 skips
$
```

```
$ bin/test test/application/server_test.rb
Run options: --seed 64559

F

Failure:
ApplicationTests::ServerTest#test_restart_rails_server_with_custom_pid_file_path [test/console_helpers.rb:19]:
"Listening" expected, but got:

.
Expected "" to include "Listening".

bin/test test/application/server_test.rb:19

F

Failure:
ApplicationTests::ServerTest#test_run_+server+_blocks_after_the_server_starts [test/console_helpers.rb:19]:
"Hello world" expected, but got:

.
Expected "" to include "Hello world".

bin/test test/application/server_test.rb:43

Finished in 2.117413s, 0.9445 runs/s, 1.8891 assertions/s.
2 runs, 4 assertions, 2 failures, 0 errors, 0 skips
$
```

Note: These failures depend on assert_timeout and test environment. If these failures do not reproduce locally, setting short timeout = 1 should reproduce them.
```
$ git diff
diff --git a/railties/test/console_helpers.rb b/railties/test/console_helpers.rb
index 10d3a54602..32d333ed99 100644
--- a/railties/test/console_helpers.rb
+++ b/railties/test/console_helpers.rb
@@ -6,7 +6,7 @@
 end

 module ConsoleHelpers
-  def assert_output(expected, io, timeout = 10)
+  def assert_output(expected, io, timeout = 1)
     timeout = Time.now + timeout

     output = +""
$
```
2024-02-21 08:42:16 +09:00
Rafael Mendonça França
de139607cc
Merge pull request #51112 from dorianmariecom/dorian/to_s-for-generated-attribute
`Rails::Generators::GeneratedAttribute#to_s`
2024-02-20 17:24:50 -05:00
Rafael Mendonça França
eccc6061f4
Remove deprecated behavior that would rollback a transaction block when exited using return, break or throw. 2024-02-20 21:56:51 +00:00
Rafael Mendonça França
4bf2c4cea1
Remove deprecated behavior to support referring to a singular association by its plural name 2024-02-20 21:50:36 +00:00
Rafael Mendonça França
2af68b257f
Remove deprecated Rails.application.config.active_record.suppress_multiple_database_warning 2024-02-20 21:39:06 +00:00
Viktor Schmidt
052b5ed69a
Improve title tag for new apps (#51134)
* Fix regex for application name assertion

* Change title tag to default to a titleized app name
2024-02-20 13:32:33 -08:00
Dorian Marié
dd73f37be9
Rails::Generators::GeneratedAttribute#to_s 2024-02-20 20:57:54 +00:00
Rafael Mendonça França
c6c8d1d3c4
Merge pull request #51141 from peterberkenbosch/update-test-case-generator-to-codestyle
Fix linting error for generated system test case.
2024-02-20 15:16:12 -05:00
Rafael Mendonça França
2f10cedec7
Merge pull request #51130 from Yegorov/fix-typo-in-devcontainer
Fix typo in devcontainer
2024-02-20 12:36:44 -05:00
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
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
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
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
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
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
dhh
dd6f3e1328 Style 2024-02-14 16:02:53 -08: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
Rafael Mendonça França
acfaac6ef8
Merge pull request #50914 from andrewn617/devcontainer
Generate devcontainer files by default
2024-02-14 17:17:07 -05:00
Rafael Mendonça França
f91cb4f81f
Deprecated ENV["SCHEMA_CACHE"] in favor of schema_cache_path in the databse configuration
The config in the yaml allows for more complex configuration.
2024-02-14 22:02:29 +00:00
Rafael Mendonça França
7e04346ec4
Remove duplicated test
This is tested in:

08d724a8d6/railties/test/application/initializers/frameworks_test.rb (L263)
2024-02-14 22:02:12 +00:00
Rafael Mendonça França
cac604a992
Remove eager loading of schema cache dump
This will be eager loaded by the define_attribute_methods initializer
now that the schema cache can be automatically loaded for all
connection if the file is present on disk after #48716.
2024-02-14 22:02:10 +00:00
Rafael Mendonça França
9362dd0a3a
Use app helper to load the app
This allow us to be explicit about the environment we want to load.
2024-02-14 22:02:09 +00:00
Rafael Mendonça França
1e10794423
Add test to make sure define_attribute_methods is called on boot
Only when schema cache is present and check_schema_cache_dump_version
is false.
2024-02-14 22:02:08 +00:00