Commit Graph

5047 Commits

Author SHA1 Message Date
Cadu Ribeiro f63d344ce9 Add name to DevContainer compose file
Currently when you generate a project the compose.yaml generated
file does not include the top-level name property. Not having this
top-level name property makes all containers / volumes started by
devcontainer to be prepended with the folder name, which is
`devcontainer` in the case of the .devcontainer/compose.yml` file.

This is ok if you run only one project with devcontainer but starts
to get problem if you run multiple projects. If you have one project
that runs on postgresql 15 and a new one that runs on postgresql 16 it
will fail to boot the postgresql container because both devcontainers is
using the same volume: `devcontainer_postgres-data`.

This commit fixes this by setting the top-lavel name property with
the project name, which will make the containers and volumes to be
prepended with the project name and not with `devcontainer`.
2024-05-13 14:26:46 -03:00
Koichi ITO 6afc3682ae Suppress RuboCop output when there are no offenses in code generation
Follow up #51782.

> But it's overkill for the default case where people use the default style guide,
> and it introduces both delay and console output as a cost.

When there are no offenses with the coding style generated by code generation,
outputting RuboCop results to the console was redundant.
Since RuboCop has `--format=quiet` option that suppresses console output
when there are no offenses, this PR adds that option:
https://docs.rubocop.org/rubocop/1.63/formatters.html#quiet-formatter

While this PR doesn't resolve any added execution speed by RuboCop,
the frequency of using the generator is not high within the development flow.
Therefore, depending on the execution speed, it might be possible to uncomment #51782,
but this PR respects the defaults in #51782 and doesn't address that.
2024-05-13 19:47:12 +09:00
Gannon McGibbon e97db3b395
Merge pull request #51614 from gmcgibbon/defer_route_drawing
Defer route drawing to the first request, or when url_helpers called
2024-05-12 10:17:57 -04:00
Joé Dupuis a63baa5db1
Fix test runner --fail-fast test flake
Without the sleep, the test has high variability in the amount of test
ran before stopping. With the sleep, the test is pretty stable with
negligeable impact on run time.
2024-05-10 18:58:44 -07:00
Alex Ghiculescu 2194a738c7 Active Job: Correctly use the desired test adapter in tests 2024-05-09 17:35:50 +10:00
Gannon McGibbon e54f869e43 Defer route drawing to the first request, or when url_helpers called.
Executes the first routes reload in middleware, or when the route set
url_helpers is called. Previously, this was executed unconditionally on
boot, which can slow down boot time unnecessarily for larger apps with
lots of routes.
2024-05-08 23:43:06 -04:00
Stan Lo 484c026f98
Continue including Rails::ConsoleMethods to IRB's internal
Due to some users/libs relying on Rails::ConsoleMethod to extend Rails
console, we need to keep including it to IRB's internal.

But to prevent also adding `app` and `helper` methods to the console,
which are already registered to IRB through its API, we need to remove
them from the Rails::ConsoleMethods. Additionally, we should raise
deprecation warning when users try to use Rails::ConsoleMethods in this
way.

This commit:
- Removes all methods from Rails::ConsoleMethods that are already
  registered to IRB. So it's now essentially empty.
- Raises a deprecation warning when modules are included to Rails::ConsoleMethods
  or methods are added to it.
- Adds a test to ensure that the deprecation warning is raised and the
  methods are available in the console.
2024-05-07 18:55:24 +01:00
Stan Lo beba30ba4d
Avoid setting fixed app name in console prompt
Instead, the app's name should be set via a separate IRB config, which
will allow it to be changed at runtime.

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
2024-05-07 00:02:22 +01:00
Andrew Novoselac 6e0b867a81 Improve db_system_change_generator_test.rb 2024-05-06 18:00:01 -04:00
Andrew Novoselac bd31917001 Devcontainer: Use SQLite3 feature.
This feature includes the dependencies needed for SQLite (previously we were getting these from lib-vips installation), and the SQLite3 client.
2024-05-06 17:51:04 -04:00
tompng 4b460411c7 Fix console_test to work with both IRB's RelineInputMethod and StdioInputMethod 2024-05-05 20:15:50 +09:00
Étienne Barrié d379fae6d2 Add runtime options from Thor::Actions to app:update 2024-05-02 16:53:21 +02:00
Stan Lo 4c1f7d8328
Register Rails console commands/helpers with its latest extension APIs
This will greatly increase the visibility of Rails console commands and helpers,
and stop rely on IRB's internal components.

Extension API reference: https://github.com/ruby/irb/blob/master/EXTEND_IRB.md

And because we need to create new classes to use the new APIs, I also
moved all the IRB-specific code to a new file, `irb_console.rb`.

Use IRB.conf[:BACKTRACE_FILTER] for backtrace filtering in console

This change uses the new `IRB.conf[:BACKTRACE_FILTER]` to inject the backtrace
filtering logic into IRB. This avoids the need to patch IRB's internal
WorkSpace class.

Update changelog
2024-05-01 22:14:53 +00:00
Rafael Mendonça França b35df004fd
Remove deprecated `Rails::Generators::Testing::Behaviour` 2024-05-01 20:19:21 +00:00
Rafael Mendonça França e38dfb2149
Remove deprecated `Rails.config.enable_dependency_loading` 2024-05-01 18:46:07 +00:00
Rafael Mendonça França 0c76f17f2d
Remove deprecated `Rails.application.secrets` 2024-05-01 18:46:04 +00:00
Rafael Mendonça França 0a84b72a70
Remove deprecation on calling `assert_equal` with `nil` 2024-05-01 18:45:49 +00:00
Rafael Mendonça França 38bfbcfbea
Remove deprecated support for `config.active_support.cache_format_version = 6.1` 2024-05-01 18:44:49 +00:00
fatkodima 702638291c
Fix tests without assertions in the framework 2024-04-30 23:29:30 +00:00
Andrew Novoselac 9ac526a21a Unsilence BacktraceCleaner with BACKTRACE without removing silencers
rails/rails@957a3e5 allowed the BACKTRACE env to unsilence backtraces in normals runs not just tests. However, the implementation achieves this by removing the silences in an initializer. This means that the state of backtrace silencer becomes cached by spring and the developer needs to reset spring every time they want to silence or unsilence the backtrace. It also means custom silencers added in an initializer need to be added after the :configure_backtrace_cleaner initializer or else they won't be un-silenced properly.

Instead, let's teach Rails::BacktraceCleaner to unsilence the backtrace if the BACKTRACE variable is set. ActiveSupport::BacktraceCleaner#clean already allows this by passing nil as the second argument, which just filters but does not silence the backtrace. So, in Rails::BacktraceCleaner#clean we can call super with nil in the second argument if the BACKTRACE variable is present. That way we do not need to remove the silencers in an initializer, and we don't have to reset spring to silence the backtrace.
2024-04-26 11:45:59 -04:00
Ryuta Kamizono 107fd51a22
Merge pull request #51446 from koic/fix_error_when_rails_g_rubocop_with_pretend
Fix an error for `apply_rubocop_autocorrect_after_generate!` with `--pretend`
2024-04-24 15:28:41 +09:00
John Hawthorn 734719d8af
Merge pull request #51590 from jhawthorn/backtrace_cleaner_3_4
Fix ActionView backtrace filtering on Ruby 3.4+
2024-04-22 15:33:24 -07:00
Rafael Mendonça França c05608b901
Merge pull request #50780 from zachasme/app-update-skip-sprockets
Preserve `--asset-pipeline propshaft` when running `app:update`
2024-04-22 18:42:10 -03:00
John Hawthorn 3cf6122ccc Fix ActionView backtrace filtering on Ruby 3.4+ 2024-04-22 14:07:57 -07:00
Rafael Mendonça França 270ed27cec
Merge pull request #51036 from zzak/railties/asto-integration
Add a basic railtie integration test for Active Storage
2024-04-18 18:11:44 -03:00
Rafael Mendonça França 35efaca34e
Merge pull request #51588 from duduribeiro/add-devcontainer-forward-ports
Change devcontainer.json to forward used ports for the project
2024-04-18 13:47:50 -03:00
Mike Dalessio fd1c635d2f Allow sqlite3 to float to version 2 2024-04-18 11:34:24 +02:00
Cadu Ribeiro 6a0f59a456 Change devcontainer.json to forward used ports for the project 2024-04-17 16:23:17 -03:00
Cadu Ribeiro 6b9948938c Add node and yarn to devcontainer when creating a project with Javascript 2024-04-15 23:31:50 -03:00
Rafael Mendonça França d8ca552e41
Merge pull request #51481 from andrewn617/devcontainer-user-dependency-features
Use devcontainer features for optional dependencies
2024-04-12 14:37:46 -03:00
Andrew Novoselac 765606500b Ensure that environment variables should always be strings, not booleans.
This specifically is affecting the mysql and mariadb ALLOW_EMPTY_PASSWORD flag. It seems VSCode is doing something to handle coercing these to strings, but an issue occurs when using docker-compose on this file.
2024-04-12 11:23:53 -04:00
Andrew Novoselac 16afdbea70 Use devcontainer features for optional dependencies
We have created our own features for optional Rails dependencies needed for active storage, postgres and mysql. Features provide a bit better ergonomics for adding or removing these from the devcontainer, and previously we were always installing these dependencies via the devcontainer's dockerfile, whether the app was using them or not.

With this change, when we generate the app, we just add the features we need to the devcontainer.json. And also, we swap features in and out as need when doing db:system:change.
2024-04-12 10:13:42 -04:00
Rafael Mendonça França d3b055eafd
Merge pull request #51518 from andrewn617/devcontainer-dev-mode
Make local rails available to devcontainer generated with `--dev`
2024-04-11 14:37:16 -03:00
Étienne Barrié 1dc7620b9f Respond with 406 when a browser is blocked by allow_browser
RFC 9110 specifies:

	The server MUST send an Upgrade header field in a 426 response
	to indicate the required protocol(s)

https://httpwg.org/specs/rfc9110.html#status.426

Status 406 Not Acceptable is more appropriate because it indicates the
resource

	does not have a current representation that would be acceptable
	to the user agent, according to the proactive negotiation header
	fields received in the request

https://httpwg.org/specs/rfc9110.html#status.406

With the proactive negociation section mentionining:

	implicit characteristics, such as the client's network address
	or parts of the User-Agent field.

https://httpwg.org/specs/rfc9110.html#proactive.negotiation
2024-04-11 10:50:24 +02:00
Yasuo Honda ebed327344 Address `Rails::Command::HelpIntegrationTest` failure against ruby 3.4.0dev
This commit addresses Rails Nightly CI failure
at https://buildkite.com/rails/rails-nightly/builds/391#018ec54f-a2ef-40de-9749-6cc3ecae4ebd/1368-1376

```ruby
$ ruby -v
ruby 3.4.0dev (2024-04-09T16:29:01Z master 0107954f25) [x86_64-linux]
$ bin/test test/command/help_integration_test.rb:33
Run options: --seed 3363

F

Failure:
Rails::Command::HelpIntegrationTest#test_prints_help_via_`X:help`_command_when_running_`X`_and_`X:X`_command_is_not_defined [test/command/help_integration_test.rb:37]:
--- expected
+++ actual
@@ -1,4 +1,5 @@
-"Commands:
+"/home/yahonda/.rbenv/versions/trunk/lib/ruby/gems/3.4.0+0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34: warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.
+Commands:
   bin/rails dev:cache           # Toggle development mode caching on/off
   bin/rails dev:help [COMMAND]  # Describe available commands or one specific...

bin/test test/command/help_integration_test.rb:33

Finished in 0.738986s, 1.3532 runs/s, 1.3532 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
$
```

This commit can be reverted once both rack and jbuilder take care of it.

Related to
https://github.com/rack/rack/pull/2166
https://github.com/rails/jbuilder/issues/561
2024-04-10 17:57:40 +09:00
fatkodima 041de49399 Remove usage of `OpenStruct` 2024-04-09 21:35:08 +03:00
eileencodes 50515fb45f
Add more ostruct requires
`ostruct` was being implictly required by the `json` gem. But once it
was upgraded, these tests failed to initialize `OpenStruct`.

While we're trying to remove `ostruct` usage in #51510, CI is currently
failing so I'm pushing these in the mean time.
2024-04-09 11:34:44 -04:00
Andrew Novoselac ab17a6cec5 When generating an app with the --dev flag, mount the local rails repo in the devcontainer
This is useful for testing changes to how the devcontainer is generated, and will be necessary for creating a CI workflow for testing the devcontainer setup.
2024-04-08 15:30:04 -04:00
Jean Boussier 40d6385123 Stop generating files with `git_source(:github)`
This has been built-in in Bundler for years now, and the
builtin version is much better as it allows to point to a PR
directly.
2024-04-04 15:04:16 +02:00
Andrew Novoselac bc9c66583e Allow Actionable Errors encountered when running tests to be retried.
If running in an interactive console, the user will be given the option to correct the error and re-run the tests.

Co-authored-by: Gannon McGibbon <gannon.mcgibbon@gmail.com>
2024-04-03 19:32:34 -04:00
Koichi ITO 33c63f0559 Fix an error for `apply_rubocop_autocorrect_after_generate!` with `--pretend`
## Motivation / Background

An issue was identified where an error occurs when executing `apply_rubocop_autocorrect_after_generate!` with `--pretend` option,
according to feedback from https://github.com/rubocop/rubocop-rails/pull/1263.

## Details

This PR fixes the following error when executing `apply_rubocop_autocorrect_after_generate!` with `--pretend` option:

```console
$ bin/rails g migration create_users -p
```

### Before

An `Errno::ENOENT` error occurs:

```console
invoke  active_record
create    db/migrate/20240329060627_create_users.rb
/Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/bundler/gems/rails-8e46af8c9396/railties/lib/rails/configuration.rb:138:in
`system': No such file or directory - bin/rubocop (Errno::ENOENT)
```

### After

No errors.
2024-03-29 15:15:23 +09:00
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
Andrew Novoselac 5fcbc2c421 Update the Rails app devcontainer to use the Rail's orgs ruby image 2024-03-22 09:23:07 -04: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
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
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
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 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 2f10cedec7
Merge pull request #51130 from Yegorov/fix-typo-in-devcontainer
Fix typo in devcontainer
2024-02-20 12:36:44 -05: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
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
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
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
Rafael Mendonça França 75d5308f81
Temporarily remove `ruby` from Gemfile
See 707b5cb606 for more details.
2024-02-14 21:53:52 +00:00
Andrew Novoselac c90a8701e5
Generate a .devcontainer folder and its contents when creating a new app.
The .devcontainer folder includes everything needed to boot the app and do development in a remote container.

The container setup includes:
 - A redis container for Kredis, ActionCable etc.
 - A database (SQLite, Postgres, MySQL or MariaDB)
 - A Headless chrome container for system tests
 - Active Storage configured to use the local disk and with preview features working

If any of these options are skipped in the app setup they will not be included in the container configuration.

These files can be skipped using the `--no-devcontainer` option.

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-02-14 20:59:48 +00:00
Rafael Mendonça França 707b5cb606
Revert "Merge pull request #49360 from skipkayhil/hm-gemfile-ruby-file"
This reverts commit 6985c3bedf, reversing
changes made to 3163bb7351.

Reason: While we want to apply this change, it make bundle being more
strict about the ruby version. This is particularly problematic for
the devcontainer images that don't support defining which patch
version of ruby to install.

Right now, you can only say you want Ruby 3.2, which could mean
3.2.3 or 3.2.0. If for some reason the devcontainer image doesn't
match the patch version on `.ruby-version` it will fail to install.

We are planning to solve this problem by publishing our own
ruby images that allow defining the patch level, but until that
we can't apply this change.
2024-02-14 20:53:47 +00:00
Hartley McGuire a1c6e27baf
Use `ruby file: ".ruby-version"` for new apps
Previously, new apps would have a Ruby version set in both the Gemfile
and the .ruby-version file. This duplication makes it more difficult to
quickly change an application's ruby version as users must remember to
update multiple files.

This commit updates the app generator's Gemfile to read the Ruby version
from the .ruby-version file. Since this feature was introduced in the
latest version of Bundler, it will only be enabled if a supported version
of Bundler is used.

Alternatively, another solution mentioned on the original PR adding
.ruby-version was that the .ruby-version file could be removed once
rvm/rbenv support reading the Ruby version from the Gemfile. This has a
downside that many other tools like chruby do not have plans to support
reading a Ruby version from the Gemfile, and so users of those tools
would have a worse experience if the .ruby-version file is removed.

Co-authored-by: Takumi Shotoku <sinsoku.listy@gmail.com>
2024-02-14 12:28:31 -05:00
David Heinemeier Hansson 6260b6b0c8
Allow .test by default in development (#51087)
This ensures out-of-the-box compatibility with puma-dev
2024-02-14 08:28:25 -08:00
Rafael Mendonça França f8ffd46ccc
Merge pull request #51063 from anonychun/speedup-docker-build-time
Speedup Docker Build Time
2024-02-13 18:17:05 -05:00
Edouard CHIN ce9f13c97e Don't load `*_test.rb` file from the "fixtures" folder:
- If an application has files named `*_test.rb` in the
  "fixtures/files" folder, they were picked up to be loaded.
  In most cases this would result in a LoadError as its likely
  those files include code that can't be loaded.
2024-02-13 19:01:14 +01:00
Achmad Chun Chun bdb8a6dcf7 change from deploy to base 2024-02-13 22:19:12 +07:00
Achmad Chun Chun 78061ebfe8 speedup docker build time 2024-02-13 20:26:14 +07:00
maximerety d997c554b3
[Fix #50604] Restore compatibility of ARE configs with eager loading mode
Configure ActiveRecord::Encryption (ARE) on ActiveRecord::Base (AR)
loading, so that ARE configs are ready before AR models start using
`encrypts` to declare encrypted attributes.

This means that you can add ARE configurations in initializers, as long
as you don't trigger the loading of ActiveRecord::Base or your AR models
in prior initializers.
2024-02-12 17:57:56 +01:00
Jean Boussier a8d6d477c7
Merge pull request #50999 from Shopify/refactor-transactional-fixtures
Decouple transactional fixtures and active connections
2024-02-12 09:54:39 +01:00
zzak f7424890c0
Add a basic railtie integration test for Active Storage 2024-02-10 18:29:43 +09:00
Rafael Mendonça França cd053bcedc
Merge pull request #50992 from KJTsanaktsidis/ktsanaktsidis/persist_logger_tags_until_as_event
Don't pop logger tags in Rails::Rack::Logger until request is finished
2024-02-09 18:38:55 -05:00
Eileen M. Uchitelle 45ecdce495
Merge pull request #51006 from kddnewton/parse-with-prism
Parse tests with prism
2024-02-09 16:43:22 -05:00
Kevin Newton 105e05e891
Parse tests with prism
This changes TestParser to parse with prism instead of ripper if it
is available for the current version of Ruby. It's within the margin
for the speed, and its significantly less code that is easier to
read and should be easier to maintain.
2024-02-09 10:54:20 -05:00
Jean Boussier 1dcb411429 Decouple transactional fixtures and active connections
Ref: https://github.com/rails/rails/pull/50793

Transactional fixtures are currently tightly coupled with the pool
active connection. It assumes calling `pool.connection` will memoize
the checked out connection and leverage that to start a transaction
on it and ensure all subsequent accesses will get the same connection.

To allow to remove checkout caching (or make it optional), we first
must decouple transactional fixtures to not rely on it.

The idea is to behave similarly, but store the connection in
the pool as a special "pinned" connection, and not as the regular
active connection.

This allows to always return the same pinned connection,
but without necessarily assigning it as the active connection.

Additionally, this pinning impact all threads and fibers, so
that all threads have a consistent view of the database state.
2024-02-09 12:59:40 +01:00
Adrianna Chang 06b7e345af
Add `active_record.config.validate_migration_timestamps` config option.
When set, an `ActiveRecord::InvalidMigrationTimestampError` will be raised if the timestamp
prefix for a migration is more than a day ahead of the timestamp associated with the current time.
This is done to prevent forward-dating of migration files, which can impact migration generation
and other migration commands.

It is turned off by default, but will be turned on for applications starting in Rails 7.2.
2024-02-08 12:14:26 -05:00
Kevin Newton 11a97e6bca
Parse tests using prism 2024-02-07 23:14:04 -05:00
KJ Tsanaktsidis 5faeb7007d
Don't pop logger tags in Rails::Rack::Logger until request is finished
At the moment, Rails::Rack::Logger tags the logger (if it's
ActiveSupport::TaggedLogging) for the duration of the @app.call, but
only fires the request.action_dispatch event later, on body close. That
means anything logged in request.action_dispatch handlers won't have the
same tags as the rest of the request.

Fix this by deferring the popping of tags into
finish_request_instrumentation, in the same way that finishing the
instrumentation handle is deferred.
2024-02-07 14:12:07 +11:00
Jean Boussier 932af452e8 Implement `Rails::TestUnitReporter#prerecord`
This is invoked by Minitest before invoking the test, allowing
to print the test name in advance.

This is useful to debug slow and stuck tests by turning on verbose
mode. This way the stuck test name is printed before the process
deadlock.

Otherwise you have to resort to dirty tricks to figure out which
test is not returning.

This is also how the default Minitest reporter works in verbose
mode.
2024-02-06 16:41:48 +01:00
fatkodima a87668a238 Support `:source_location` tag option for query log tags 2024-02-06 00:52:57 +02:00
Jean Boussier bbc7ec49fb Improve routes source location detection
Followup: https://github.com/rails/rails/pull/50923

Instead of stopping on the first frame that isn't in
Action Dispatch, we should return the first frame that
isn't filtered by the backtrace cleaner.
2024-02-05 16:37:37 +01:00
fatkodima b8585b3b3a Fix loading schema cache when all databases have disabled database tasks 2024-01-30 13:49:05 +02:00
Rafael Mendonça França 4d1d7d3d1b
Unify the logic to determine the default schema cache path for a database configuration
When the application has more than one database configuration, only
the primary was being loaded by default on boot time. All the other
connection pools were loading the schema cache lazily.

This logic can be found in:

351a8d9bc9/activerecord/lib/active_record/connection_adapters/pool_config.rb (L13)
351a8d9bc9/activerecord/lib/active_record/railtie.rb (L149-L178)

The lazy code path wasn't using the same logic to determine the name
of the default schema cache file that the Railties uses, so it
was loading the schema cache of the primary config to all the other
configs. If no table name coincided nothing bad would happen, but if
table names coincided, the schema would be completly wrong in all
non-primary connections.
2024-01-29 18:18:15 +00:00
Willian Tenfen W 35f132e7ee
Support comment symbol '#' on .railsrc file
Commented out lines in .rc file should not be treated as arguments when
using rails new generator command. [Fix #50899]
2024-01-29 17:56:24 +00:00
Rafael Mendonça França 5606783097
Merge pull request #50903 from skipkayhil/hm-exact-generator-assertions
Change skeleton test to assert exact file output
2024-01-29 12:54:38 -05:00
Ruy R. 4ddf6ccad0
Skip CSS when creating APIs.
Update CHANGELOG.

Address requested changes.
2024-01-29 06:42:01 -03:00
Hartley McGuire c278684ae1
Assert exact file output for plugins too
In a [previous commit][1], the App Generator skeleton test was updated
to verify the exact file output when generating a new application. This
commit applies the same change to the Plugin Generator.

At first, I was hesitant to add the list of dummy app files to the
`default_files` for the Plugin Generator test, however it quickly became
apparent that it was a good idea. Making this change exposed that recent
file additions to the App Generator were added to the plugin's dummy app
as well. Things like CI files, rubocop configuration, and a brakeman
command should not be created for a dummy app, and are now properly
excluded.

Similar to the App Generator commit, this change also removes tests that
are now redundant due to the skeleton test verifying the exact list of
files generated.

[1]: e5e4b80104
2024-01-28 16:08:46 -05:00