Commit Graph

811 Commits

Author SHA1 Message Date
TangRufus 4c5b6008ba
Add `oven-sh/setup-bun` to GitHub CI when generating an app with bun 2024-01-08 19:50:21 +00:00
Hans Schnedlitz 482330d156
Do not generate pidfile in production environments (#50644)
* Remove pidfile in production

* Update changelog

* Update activestorage/test/dummy/config/puma.rb

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

* Update template and other dummy files

---------

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-01-08 14:47:25 -05:00
Adrian 475bb4b1ed default annotate_rendered_view_with_filenames to true in development
remove whitespaces

remove whitespaces
2024-01-04 21:24:37 +02:00
Alex Ghiculescu 957a3e5e55 Add BACKTRACE env variable to turn off backtrace for normal running, not just tests 2024-01-04 07:25:12 +10:00
Sean Doyle 9a58f7eccd Raise `ArgumentError` when reading from `config.x` with arguments
The flexibility provided by `config.x` supports arbitrarily defining new
configuration objects on-the-fly. Each new intermediate configuration
object is constructed during chaining from its ancestor through a method
invocation made without arguments.

Conversely, writing to leaf configuration values occurs when the invoked
method's name ends with `=`, and the new configuration value is assigned
to whatever that method's arguments are.

There are no cases when reading from a `config.x` value or building the
intermediate values involves arguments.

Prior to this commit, a read invoked with a method arguments would
ignore those arguments. While this is robust and error-free, it's
possible to obscure misuse.

For example, consider a line like:

```ruby
config.x.my_config.enabled = true
config.x.my_config.enabled #=> true
```

Now consider that first line with a typo that omits the `=`:

```ruby
config.x.my_config.enabled true
config.x.my_config.enabled #=> nil
```

This commit aims to provide more direct feedback for scenarios like the
one above. There aren't legitimate use cases for invoking `#enabled`
with arguments, so raise a `ArgumentError` when encountering a read with
arguments.
2024-01-03 15:08:40 -05:00
David Heinemeier Hansson bb5e2791e0
Add default pwa manifest and service worker file (#50528)
* Add default pwa manifest and service worker file

* Update CHANGELOG.md
2024-01-03 13:07:12 +01:00
Akhil G Krishnan 9bc4536d47 Add changelog entry for #50512 2024-01-01 09:35:54 +05:30
David Heinemeier Hansson 08a792be84
Default to creating GitHub CI files (#50508)
* Default to creating GitHub CI files
2024-01-01 00:37:12 +01:00
Vipul A M 813afbdd74
Add brakeman to new Rails applications (#50507)
It can be skipped with the `--skip-brakeman` flag.

Closes #50501
2023-12-31 19:09:47 +01:00
zzak 0fb5f67ac4
Add rubocop-rails-omakase to new Rails applications (#50486)
* Add rubocop to new rails app generator

This setups a basic rubocop config for new rails apps using the `rubocop-rails-omakase` gem:
https://github.com/rails/rubocop-rails-omakase

It can be skipped with the `--skip-rubocop` flag.
2023-12-30 21:13:13 +01:00
Ben Sheldon [he/him] a9c4699751
Add runner option to disable Executor wrap 2023-12-08 09:36:33 -08:00
Chedli Bourguiba 0fe286339a Make engines aware of AR::Base table name prefix 2023-12-06 20:09:18 +01: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]: ac9f08d1c3
2023-11-09 11:26:51 -05: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
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
Adrian Hirt 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
Ivan Fedotov 7ff33d8b3c
Use numeric UID and GID in Dockerfile template 2023-10-31 07:54:13 +00:00
Petrik b8a3efeee3 Use Thor's enum for class_options
In 11a6adc4fb custom code was added to
restrict values for some `rails new` options.
We don't need to implement this when it's already supported by Thor.

This also adds `none` as an option to the asset_pipeline as used in:
`railties/test/generators/shared_generator_tests.rb:320`.
2023-10-12 21:01:53 +02:00
Steve Polito e659f46da1
Conditionally print `$stdout` when invoking `run_generator` (#49448)
* Conditionally print `$stdout` when invoking `run_generator`

In an effort to improve the developer experience when debugging
generator tests, we add the ability to conditionally print `$stdout`
instead of capturing it.

This allows for calls to `binding.irb` and `puts` work as expected.

```sh
PRINT_STDOUT=true ./bin/test test/generators/actions_test.rb
```

* Update railties/CHANGELOG.md

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

* Rename environment variable

* Update generators guides.

* Update guides

---------

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2023-10-03 07:01:16 -04:00
Rafael Mendonça França fb6c6007d0
Development of Rails 7.2 starts now
🎉
2023-09-27 03:59:11 +00:00
Rafael Mendonça França e5386cb402
Preparing for 7.1.0.rc1 release 2023-09-27 03:08:31 +00:00
Matt Brictson 39ccb97e3c
Fix uninitialized constant error on Puma boot
Before, using the default `puma/config.rb` generated by `rails new`,
Puma would fail to boot in production with this error:

```
./config/puma.rb:16:in `block in _load_from': uninitialized constant Puma::DSL::Concurrent (NameError)
	from ./config/puma.rb:16:in `fetch'
	from ./config/puma.rb:16:in `_load_from'
```

This was because `Concurrent.physical_processor_count` was being
referenced before the `Concurrent` constant was initialized.

Fix by requiring `concurrent-ruby` just before the `Concurrent` constant
is needed.

Fixes #49323
2023-09-20 06:54:30 -07:00
Akhil G Krishnan 0d3a4ca7e9
Add missing dollar sign for bash script [skip ci] 2023-09-14 17:48:20 +00:00
Petrik 99b1316fd9 Raise error when generating attribute with dangerous name
Generating a model with attributes named `hash` or `save` should raise
an error, instead of generating a migration with an invalid attribute.
2023-09-14 12:58:36 +02:00
fatkodima e4206c64d9 Add changelog entry for profiling slow tests
The change was added in #49082.
[skip ci]
2023-09-13 21:41:50 +03:00
Rafael Mendonça França 699dfdb426
Preparing for 7.1.0.beta1 release 2023-09-13 00:36:01 +00:00
Jason Meller 274bc97d63
Add Bun support (#49241)
* Add Bun support to `rails new -j` generator

* Add additional generation consideration for Bun

* Use development gems to test the whole workflow

* Remove custom gems from local testing

* Revert lock

* Revert errant custom gem declaration

* Fix linting errors

* Fix remnants of bad merge

* Always use latest bun

* Update actioncable/lib/rails/generators/channel/channel_generator.rb

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>

* Update guides/source/working_with_javascript_in_rails.md

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

* Only use the latest bun if nothing is specified

* Hardcode known good version

---------

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2023-09-12 16:55:27 -04:00
Cadu Ribeiro 9a98235ced Make bin/setup work with bun 2023-09-11 21:11:06 -03:00
Xavier Noria b16adcd4e4 Generate config.autoload_lib(...) for new apps 2023-08-25 09:22:25 +02:00
Akhil G Krishnan 0f7f9e3d5e [skip ci] Moved sh to bash and added missing $ 2023-08-24 18:48:20 +05:30
Shouichi Kamiya b8decf79d8 Add an option to start rails console in sandbox mode by default
To avoid accidental writing to the production database, I always start
rails console in sandbox mode. I only start rails console in non-sandbox
mode when I'm sure I want to write to the production database.

`sandbox_by_default` option is added to start rails console in sandbox
mode by default. With this option turned on, `--no-sandbox` must be
specified to start rails in non-sandbox mode.

Note that this option is ignored when rails environment is development
or test.
2023-08-22 09:23:52 +09:00
Sean Doyle 9a53234695 Omit `webdrivers` gem from `Gemfile` template
As of Selenium 4.6, [the Selenium Manager is capable of managing Chrome
Driver installations and integrations][readme]. As of Selenium 4.11, the
Selenium Manager is capable of [capable of resolving the Chrome for
Testing installation][] path.

By omitting the `gem` declaration from the `Gemfile.tt`, newly generated
applications and applications updating their `Gemfile` in lockstep with
newer Rails versions can shed the dependency and avoid test failures
introduced by newly released Chrome versions (like, for example,
[titusfortner/webdrivers#247][]).

[readme]: 43f8ac436c (update-selenium-manager)
[titusfortner/webdrivers#247]: https://github.com/titusfortner/webdrivers/issues/247
[capable of resolving the Chrome for Testing installation]: https://github.com/rails/rails/pull/48847#issuecomment-1656756862

Co-authored-by: Titus Fortner <titusfortner@users.noreply.github.com>
2023-08-01 09:22:08 -04:00
Shouichi Kamiya 5931a68158 Support filtering tests by line ranges
The new syntax allows you to filter tests by line ranges. For example, the
following command runs tests between line 10 to 20.

```bash
$ rails test test/models/user_test.rb:10-20
```

Co-authored-by: Seonggi Yang <seonggi.yang@gmail.com>
Co-authored-by: Ryohei UEDA <ueda@anipos.co.jp>
Co-authored-by: oljfte <oljfte@gmail.com>
2023-07-26 15:00:08 +09:00
Guillermo Iguaran 5ed37b35d6 Update default scaffold templates to set 303 (See Other) as status code on redirect for the update action
XHR requests other than GET or POST have issues when using 302
(e.g browsers trying to follow the redirect using the
original request method resulting in double PATCH/PUT)

This should be reverted when / if
https://github.com/rails/rails/pull/45393 is merged
2023-06-30 21:52:49 -07:00
Xavier Noria 0568bc9a90 Introduce config.autoload_lib_once(ignore:) 2023-06-29 09:15:17 +02:00
Guillermo Iguaran 10b4bd597f
Merge branch 'main' into hm-config-exception-level 2023-06-26 19:07:08 -07:00
Matthew Hirst 00ebbbd746
This allows Rails projects with multiple databases to specify which database they would like the migrations to be copied to. 2023-06-26 19:27:47 +02:00
Hartley McGuire 519577ecc3
Make the log level in DebugExceptions configurable
This middleware has been logging at a FATAL level since the first
[commit][1] in Rails (the code originally lived in
actionpack/lib/action_controller/rescue.rb). However, FATAL is
documented in the Ruby Logger [docs][2] as being for "An unhandleable
error that results in a program crash.", which does not really apply to
this case since DebugExceptions is handling the error. A more
appropriate level would be ERROR, which the Ruby Logger docs describe as
"A handleable error condition."

This commit introduces a new configuration for the DebugExceptions log
level so that new apps will have it set to ERROR by default and ERROR
can eventually be made the default.

[1]: db045dbbf6
[2]: https://ruby-doc.org/3.2.1/stdlibs/logger/Logger/Severity.html
2023-06-25 23:11:39 -04:00
Xavier Noria e1321a291f Introduce config.autoload_lib 2023-06-25 10:17:08 +02:00
Petrik eaa190169f Don't show secret_key_base for `Rails.application.config#inspect`
When calling `Rails.application.config#inspect` it will show all
attributes, including @secret_key_base after 21c3455054

By overriding the `inspect` method to only show the class name we can
avoid accidentally outputting sensitive information.

Before:

```ruby
Rails.application.config.inspect
"#<Rails::Application::Configuration:0x00000001132b02a0 @root=... @secret_key_base=\"b3c631c314c0bbca50c1b2843150fe33\" ... >"
```

After:

```ruby
Rails.application.config.inspect
"#<Rails::Application::Configuration:0x00000001132b02a0>"
```
2023-06-16 15:11:31 +02:00
Petrik 9f9b540cb5 Deprecate calling `Rails.application.secrets`.
Rails `secrets` have been deprecated in favor of `credentials`.
Calling `Rails.application.secrets` should show a deprecation warning.
2023-06-15 08:41:23 +02:00
Petrik 21c3455054 Store `secret_key_base` in `Rails.config` for local environments.
Rails `secrets` have been deprecated in favor of `credentials`.
For the local environment the `secret_key_base` is now be stored in
`Rails.config.secret_key_base` instead of the deprecated
`Rails.application.secrets.secret_key_base`.
2023-06-14 16:37:23 +02:00
Justin Searls 3b83758680 Enable force_ssl=true in production by default
I will admit to deploying an app into production and leaving it there for weeks before realizing that authenticated traffic was being transported un-secured HTTP. I'd been operating under the false assumption that `config.force_ssl` would be `true` in production by default for new apps.

Suggesting this change to gauge interest and start a conversation. Since this option was introduced, the state of the web has really changed with Let's Encrypt certificates, and HTTPS has become table stakes for most hosting services. It feels like the time is right to enable Strict-Transport-Security by default for new apps.

Co-authored-by: Aaron Patterson <aaron@rubyonrails.org>
Co-authored-by: Guillermo Iguaran <guilleiguaran@gmail.com>
Co-authored-by: vinibispo <vini.bispo015@gmail.com>
2023-06-09 16:27:10 -07:00
Gannon McGibbon f9eea790a5 Add engine draw_paths to app
Allows engine draw paths to be accessible under the application route set.
2023-06-05 20:07:28 -05:00
Summer ☀️ a062d182c3 Support `VISUAL` env var, and prefer it over `EDITOR` 2023-06-01 20:55:27 -06:00