Commit Graph

15054 Commits

Author SHA1 Message Date
Adrianna Chang
2854e378c8
Revert "Add config for validating migration timestamps" 2023-12-01 11:58:53 -05:00
Eileen M. Uchitelle
c60d064fd5
Merge pull request #50205 from rails/ac-validate-migration-timestamps
Add config for validating migration timestamps
2023-11-30 16:20:49 -05:00
Adrianna Chang
06575d1d75
Add active_record.config.validate_migration_timestamps option.
When set, validates that the timestamp prefix for a migration is in the form YYYYMMDDHHMMSS.
This is designed to prevent migration timestamps from being modified by hand.

It is turned off by default.
2023-11-30 16:04:06 -05:00
Jean Boussier
9b9468566a
Merge pull request #50188 from skipkayhil/hm-fix-ci-env
Fix test infra depending on CI=true
2023-11-30 19:13:02 +01:00
Jonathan Hefner
c05d8ed9cd Link methods for Rails::Engine [ci-skip] 2023-11-30 11:04:38 -06:00
Hartley McGuire
91dedc0436
Fix Railties tests
These tests have never run in CI due to CI using a root user. This
commit keeps that behavior without using the skip so that we can enable
raise on skips.
2023-11-30 11:11:23 -05:00
Kevin McPhillips
9b03df5626 Add some behaviour to ActiveSupport::InheritableOptions to make it quack more like a hash 2023-11-28 12:01:10 -05:00
Jonathan Hefner
11f418f17e Use --quiet for bundle install
When generating a new app, `bundle install` may be run multiple times
due to various application templates.  This can create a lot of noise
in the output log, particularly with Bundler <= 2.4.16, which displays
the full list of gems each time `bundle install` is run.

To reduce noise, this commit adds the `--quiet` flag to `bundle install`
commands.

__Before__

  ```console
  $ rails new my_cool_app --dev
        create
        create  Gemfile
           run  bundle install
  Resolving dependencies...
  Fetching gem metadata from https://rubygems.org/..........
  Bundle complete! 1 Gemfile dependency, 58 gems now installed.
  Use `bundle info [gemname]` to see where a bundled gem is installed.
           run  rails new my_cool_app --dev
         exist
        remove  Gemfile
        remove  Gemfile.lock
        create  README.md
  ...
           run  bundle install
  Fetching gem metadata from https://rubygems.org/..........
  Resolving dependencies...
  Bundle complete! 12 Gemfile dependencies, 78 gems now installed.
  Use `bundle info [gemname]` to see where a bundled gem is installed.
  ...
         rails  importmap:install
         apply  importmap-rails-1.2.3/lib/install/install.rb
  ...
           run  bundle install
  Bundle complete! 12 Gemfile dependencies, 78 gems now installed.
  Use `bundle info [gemname]` to see where a bundled gem is installed.

         rails  turbo:install stimulus:install
         apply  turbo-rails-1.5.0/lib/install/turbo_with_importmap.rb
  ...
           run  bundle install
  Bundle complete! 12 Gemfile dependencies, 78 gems now installed.
  Use `bundle info [gemname]` to see where a bundled gem is installed.
         apply  turbo-rails-1.5.0/lib/install/turbo_needs_redis.rb
    Enable redis in bundle
          gsub    Gemfile
           run    bundle install
  Fetching gem metadata from https://rubygems.org/..........
  Resolving dependencies...
  Bundle complete! 13 Gemfile dependencies, 80 gems now installed.
  Use `bundle info [gemname]` to see where a bundled gem is installed.
    Switch development cable to use redis
          gsub    config/cable.yml
           run  bundle install
  Bundle complete! 13 Gemfile dependencies, 80 gems now installed.
  Use `bundle info [gemname]` to see where a bundled gem is installed.
         apply  stimulus-rails-1.3.0/lib/install/stimulus_with_importmap.rb
  ...
           run  bundle install
  Bundle complete! 13 Gemfile dependencies, 80 gems now installed.
  Use `bundle info [gemname]` to see where a bundled gem is installed.
  ```

__After__

  ```console
  $ rails new my_cool_app --dev
        create
        create  Gemfile
           run  bundle install --quiet
           run  rails new my_cool_app --dev
         exist
        remove  Gemfile
        remove  Gemfile.lock
        create  README.md
  ...
           run  bundle install --quiet
  ...
         rails  importmap:install
         apply  importmap-rails-1.2.3/lib/install/install.rb
  ...
           run  bundle install --quiet
         rails  turbo:install stimulus:install
         apply  turbo-rails-1.5.0/lib/install/turbo_with_importmap.rb
  ...
           run  bundle install --quiet
         apply  turbo-rails-1.5.0/lib/install/turbo_needs_redis.rb
    Enable redis in bundle
          gsub    Gemfile
           run    bundle install --quiet
    Switch development cable to use redis
          gsub    config/cable.yml
           run  bundle install --quiet
         apply  stimulus-rails-1.3.0/lib/install/stimulus_with_importmap.rb
  ...
           run  bundle install --quiet
  ```

Note that `bundle install` still displays any errors when using the
`--quiet` flag:

  ```console
  $ bundle install
  Could not find gem 'rails (= 9001.0)' in rubygems repository https://rubygems.org/ or installed locally.

  The source contains the following gems matching 'rails':
    * rails-0.8.0
    ...
    * rails-7.1.2
  ```
2023-11-27 13:13:02 -06:00
Jonathan Hefner
e85e574cd6
Merge pull request #50183 from jonathanhefner/app_generator-separate-lock-from-install
Separate `bundle lock` from `bundle install`
2023-11-27 12:32:03 -06:00
Jonathan Hefner
5cfff97ee7 Separate bundle lock from bundle install
When running `bundle install` for the `bin/rails app:template` command,
it is unnecessary and possibly even incorrect to also run
`bundle lock --add-platform=...` (because it could add a platform that
the user has intentionally removed).  Likewise, when running
`bundle install` to support a prerelease version of Rails, it is
unnecessary to run `bundle lock --add-platform=...`.

This commit extracts `bundle lock --add-platform=...` from `run_bundle`
into its own `add_bundler_platforms` generator task.
2023-11-27 11:52:08 -06:00
yuuji.yaginuma
1e3e013fe8 Don't add default-mysql-client when running db:system:change to Trilogy
Trilogy doesn't depend on the libmariadb / libmysqlclient library
Ref: https://github.blog/2022-08-25-introducing-trilogy-a-new-database-adapter-for-ruby-on-rails/#should-you-use-trilogy
2023-11-26 13:34:28 +09:00
Jonathan Hefner
0b02dce15f Fix generator tests on arm64 platforms
Follow-up to #47516 / #47492.

When running generator tests on `arm64` platforms, there is an extra
`lock --add-platform` command in `@bundle_commands` which causes
`assert_match %r"^exec rails ...", @bundle_commands[2]` to fail.

However, `run_generator_using_prerelease` isn't really concerned with
`lock --add-platform` commands; it is only concerned with the `install`
and `exec rails` commands, and the contents of the `Gemfile` when those
commands were executed.

Therefore, this commit removes `lock --add-platform` command-related
assertions from `run_generator_using_prerelease` and puts them into a
dedicated `test_generation_runs_bundle_lock_for_linux` test.  This
approach makes `run_generator_using_prerelease` less brittle.  This
change also fixes a technically incorrect assertion wherein the contents
of the `Gemfile` during the `lock --add-platform` command was checked
instead of the contents during the `exec rails` command.

Fixes #50168.

Co-authored-by: zzak <zzakscott@gmail.com>
2023-11-25 16:42:10 -06:00
Rafael Mendonça França
2a761d23d2
Remove deprecated primitive serializer for BigDecimal arguments 2023-11-22 22:13:03 +00:00
Rafael Mendonça França
43e42c1ea8
Remove deprecated comparison between ActionController::Parameters and Hash 2023-11-22 22:12:07 +00:00
Rafael Mendonça França
2bd6cf5177
Remove deprecated config.action_mailer.preview_path 2023-11-22 22:11:31 +00:00
Jean Boussier
2f19782dce ErrorReporter#unexpected to report in production but raise in development
It's a common useful pattern for situation where something isn't
supposed to happen, but if it does we can recover from it.

So in such situation you don't want such issue to be hidden
in development or test, as it's likely a bug, but do not want to
fail a request if it happens in production.

In other words, it behaves like `#record` in development and test
environments, and like `raise` in production.

Fix: https://github.com/rails/rails/pull/49638
Fix: https://github.com/rails/rails/pull/49339

Co-Authored-By: Andrew Novoselac <andrew.novoselac@shopify.com>
Co-Authored-By: Dustin Brown <dbrown9@gmail.com>
2023-11-20 09:42:56 +01:00
Kevin McPhillips
77df3d50aa Delay validation of registered Active Record adapters. Allow adapter aliasing. 2023-11-19 10:13:08 -05:00
Joshua Young
8174f94e16 Improve AdapterNotFound error message 2023-11-19 19:56:26 +09:00
fatkodima
c00932949f Fix rails console to work with DATABASE_URL for PostgreSQL 2023-11-18 00:52:52 +02:00
Max Notarangelo
185c19c5ae fix typo in production initializer generator
And put "info" in quotes.
2023-11-16 15:00:07 -08:00
Jean Boussier
009c7e7411 Refactor lookup of connection adapters
Right now adapters have to expose a rather byzantine API:

  - They must be defined in `active_record/connection_adapters/<name>_adapter`
  - They must define `ConnectionHandling.<name>_adapter_class`
  - They must define `ConnectionHandling.<name>_connection`

All this is not very DRY and a bit annoying. Additionally it makes
it very hard to define aliases (e.g. `mysql` => `trilogy`), or to
substitute a default adapter for a specialized one.

This refactor aims at making all this easier by exposing a simple
`register` method, that third party adapters can call from a Railtie.
2023-11-16 09:07:44 +01:00
Akhil G Krishnan
b9273fe97c Add missing closing backtick 2023-11-11 12:30:30 +05:30
Rafael Mendonça França
fd20970d65
Merge pull request #49839 from skipkayhil/hm-skb-deprecation
Fix config.secret_key_base warning about secrets
2023-11-10 13:43:17 -05:00
Jonathan Hefner
a409c63541 Fix typo [ci-skip] 2023-11-09 13:27:57 -06:00
Hartley McGuire
c8e1fe9981
Fix running db:system:change with no Dockerfile
The db:system:change command was [updated][1] to include support for
changing the database packages installed in the Dockerfile. However, it
never checks that the Dockerfile exists before trying to perform a
substitution and will raise an error when its missing:

```
/home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/actions/file_manipulation.rb:272:in `binread': No such file or directory @ rb_sysopen - /home/hartley/test/dev_minimal/Dockerfile (Errno::ENOENT)
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/actions/file_manipulation.rb:272:in `gsub_file'
        from /home/hartley/src/github.com/skipkayhil/rails/railties/lib/rails/generators/rails/db/system/change/change_generator.rb:47:in `edit_dockerfile'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:134:in `block in invoke_all'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:134:in `each'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:134:in `map'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:134:in `invoke_all'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/group.rb:232:in `dispatch'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/base.rb:584:in `start'
        from /home/hartley/src/github.com/skipkayhil/rails/railties/lib/rails/commands/db/system/change/change_command.rb:20:in `perform'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
        from /home/hartley/src/github.com/skipkayhil/rails/railties/lib/rails/command/base.rb:178:in `invoke_command'
        from /home/hartley/.cache/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
        from /home/hartley/src/github.com/skipkayhil/rails/railties/lib/rails/command/base.rb:73:in `perform'
        from /home/hartley/src/github.com/skipkayhil/rails/railties/lib/rails/command.rb:71:in `block in invoke'
        from /home/hartley/src/github.com/skipkayhil/rails/railties/lib/rails/command.rb:149:in `with_argv'
        from /home/hartley/src/github.com/skipkayhil/rails/railties/lib/rails/command.rb:69:in `invoke'
        from /home/hartley/src/github.com/skipkayhil/rails/railties/lib/rails/commands.rb:18:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'
```

This commit fixes the issue by checking first whether the Dockerfile
exists before trying to perform any substitution on it.

[1]: ac9f08d1c354baab6362d7050a3c9e43db09689c
2023-11-09 11:26:51 -05:00
Rafael Mendonça França
ee42128bc1
Merge pull request #49765 from andrewn617/configurable-inspect
Make the output of `ActiveRecord::Core#inspect` configurable.
2023-11-08 15:08:36 -05:00
Andrew Novoselac
e50182a42c Make the output of ActiveRecord::Core#inspect configurable.
By default, calling `inspect` on a record will yield a formatted string including just the `id`.

```ruby
Post.first.inspect #=> "#<Post id: 1>"
```

The attributes to be included in the output of `inspect` can be configured with
`ActiveRecord::Core#attributes_for_inspect`.

```ruby
Post.attributes_for_inspect = [:id, :title]
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
```

With the `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.

```ruby
Post.attributes_for_inspect = :all
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
```
2023-11-08 14:23:16 -05:00
Jonathan Hefner
8b8cef49a9
Merge pull request #49967 from p8/railties/test-env-show-exceptions-comment
Update description for show_exceptions in environments/test.rb
2023-11-08 10:58:47 -06:00
Petrik
155ec680bb Update description for show_exceptions in environments/test.rb
In e28f147329330e7ae55606e62ecc3de328431f0b the `show_exceptions`
default was updated to `:rescuable` in environments/test.rb.
The description still described the old default value (`false`), instead
of `:rescuable`.
2023-11-08 13:58:58 +01:00
Christian Schmidt
ff2e38ccc5 List inline attachments separately in AM previews
This commit separates inline attachments from normal attachments when
listing attachments in Action Mailer previews.  For example, attachments
that were previously listed like

  > Attachments: logo.png file1.pdf file2.pdf

will now be listed like

  > Attachments: file1.pdf file2.pdf (Inline: logo.png)

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-07 15:58:44 -06:00
Christian Schmidt
e5481edb8b Only show SMTP-To if different from To+Cc+Bcc
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-07 11:44:55 -06:00
Jean Boussier
d53ef2c180
Merge pull request #49948 from ghiculescu/patch-12
Fix grammer in railties changelog
2023-11-07 10:59:53 +01:00
Jean Boussier
7f8a413a93 Delete duplicated file 2023-11-07 10:59:23 +01:00
Alex Ghiculescu
644ee2fb0b
Fix grammer in railties changelog
cc @byroot
2023-11-07 19:31:09 +10:00
Jean Boussier
c29cda2fec Enable YJIT by default if running Ruby 3.3+
There was many public reports of 15-25% latency improvements for Rails
apps that did enable Ruby 3.2 YJIT, and in 3.3 it's even better.

Following https://github.com/ruby/ruby/pull/8705, in Ruby 3.3 YJIT
is paused instead of disabled by default, allowing us to enable it
from an initializer.
2023-11-07 09:26:29 +01:00
sampatbadhe
f4a9b40639 ActionMailer Email Preview - show date header when present or fallback to Time.current.rfc2822
Resolves #49788
2023-11-04 16:29:23 -05:00
f0a03bd899 Remove config.public_file_server.enabled from generators
Remove the option `config.public_file_server.enabled` from the generators for all environments, as the value is the same in all environments.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-03 11:34:37 -05:00
Jean Boussier
296664d59e Fix formatting in railties/CHANGELOG.md 2023-11-03 10:30:43 +01:00
Katsuhiko YOSHIDA
6cd4de4a8a Non-zero exit status on migration file creation errors 2023-11-01 11:25:37 +01:00
Guillaume Wrobel
638c0b0864 Reset indentation of equals assignation 2023-10-31 20:52:18 -05:00
Jean Boussier
5a47bb840e
Merge pull request #49859 from zzak/railties-schema-cache-dump-check-errors
Cover railties check_schema_cache_dump_version errors
2023-10-31 09:09:35 +01:00
Jean Boussier
f2088bec18
Merge pull request #49742 from ivanfed0t0v/dockerfile-numeric-uid-gid
Make Dockerfile template compatible with Kubernetes rootless pods
2023-10-31 09:02:39 +01:00
Ivan Fedotov
7ff33d8b3c
Use numeric UID and GID in Dockerfile template 2023-10-31 07:54:13 +00:00
zzak
08035898ec
Quiet check_schema_cache_dump_version errors:
* "Ignoring db/schema_cache.yml because it has expired."

Before:

```
bin/test test/application/rake/multi_dbs_test.rb -n "schema_cache is loaded on primary db in multi-db app"
Run options: -n "schema_cache is loaded on primary db in multi-db app" --seed 13139

Ignoring db/schema_cache.yml because it has expired. The current schema version is 20231017102756, but the one in the schema cache file is 20231017102755.
.
```

Added test cases for this error and "Failed to validate schema cache" in `test/application/rake/dbs_test.rb`.
2023-10-31 14:47:09 +09:00
Aashish Saini
d8b3c557e9 Use cannonical form of library names 2023-10-30 12:51:35 -05:00
Jonathan Hefner
dd428f1ef1 Present config.public_file_server.enabled as opt-out
Follow-up to #47137.

Since `config.public_file_server.enabled` is true by default, this
commit changes the `config/environments/production.rb` template to
present the setting as an opt-out.
2023-10-30 11:54:26 -05:00
Hartley McGuire
1abd331ff8
Fix config.secret_key_base warning about secrets
Using `config.secret_key_base` currently raises a deprecation warning
when used in production because `config.secret_key_base` gets merged
into the `secrets` hash instead of being looked up specifically in
the `secret_key_base` method.

This commit addresses this by not raising a deprecation warning if
`secrets.secret_key_base` and `config.secret_key_base` are the same
object (meaning `config.secret_key_base` was merged into `secrets).

Additionally, an improved deprecation warning is added for apps that
continue to set `secret_key_base` in their secrets. The current warning
is not great because it isn't directly actionable for users. Currently
they will see the warning, not see `secrets` being referenced in their
app, and potentially end up confused. The new warning helps users
understand the actual change they need to make: not removing a reference
to `secrets` but moving `secret_key_base` out of `secrets`.
2023-10-29 19:00:46 -04:00
Jonathan Hefner
820fbd9102
Merge pull request #45530 from skipkayhil/rm-add-sprockets-during-update
Remove adding sprockets during app:update
2023-10-29 16:38:19 -05:00
Jean Boussier
c28e4f2434 Use double quotes more consistenly in doc and error messages
For better or worse, the Rails guide settled on double quotes
and a large part of the community also use rubocop which enforce
them by default.

So we might as well try to follow that style when providing code
snippets in the documentation or error messages.

Fix: https://github.com/rails/rails/issues/49822

I certainly didn't get them all, but consistency should be significantly
improved.
2023-10-28 11:38:49 +02:00
zzak
e2169f5778
Railties TestHelper remove_from_config should remove all occurrences 2023-10-27 10:59:12 +09:00