Commit Graph

15006 Commits

Author SHA1 Message Date
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
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
Jonathan Hefner
35aa5e3026
Merge pull request #49792 from stevegeek/fix_deprecation_warning_on_secrets_show_task
Fix deprecation warnings for `secrets:edit/show`
2023-10-26 11:48:48 -05:00
fatkodima
6aed3f76ac Dump schema only for a specific db for rollback/up/down tasks for multiple dbs 2023-10-26 15:26:33 +03:00
Stephen Ierodiaconou
a0a5d63fcc Fix deprecation warnings for secrets:edit/show
The warning string is `#squish`ed however `core_ext/string/filters` was
not being required. The tests were passing because the dummy test
application does a `require 'rails/all'` on boot. This is not necessarily
the case for other applications, eg ones freshly created with `rails new`.
2023-10-26 10:40:55 +02:00
Jonathan Hefner
6d00605f95 Support non-column-backed attributes for enum
Follow-up to #45734.

This re-adds support for using `enum` with non-column-backed attributes
while still guarding against typos in enum attribute names.  When using
`enum` with a non-column-backed attribute, the attribute must be
previously declared with an explicit type.  For example:

  ```ruby
  class Post < ActiveRecord::Base
    attribute :topic, :string
    enum topic: %i[science tech engineering math]
  end
  ```

Fixes #49717.
2023-10-24 12:03:59 -05:00
Xavier Noria
6f6c211f47 Update zeitwerk:check 2023-10-22 08:36:26 +02:00
Andrew Novoselac
f212fb8b83 Fix issue where bootstrap.rb overwrites the level of a BroadcastLogger's broadcasts.
In `bootstrap.rb` we set the `Rails.logger.level` to `config.log_level`. But at this point, we may have already set up a `BroadcastLogger` with multiple broadcasts that have different levels. So, calling `level=` on the `BroadcastLogger` will overwrite the level of the individual broadcasts. So instead, let's only set the `Rails.logger.level` if the logger is not a `BroadcastLogger`.
2023-10-20 10:37:54 -04:00
Akhil G Krishnan
7349b110ae Add description for error_highlight gem 2023-10-17 13:53:10 +05:30
Hartley McGuire
b62c1ac2ec
Fix extra blank line when no error_highlight
A new condition was recently [added][1] to exclude error_highlight from
the Gemfile when the Ruby version is 3.2 or greater. However, this
change leads to an extra blank line after `gem "spring"` on Ruby 3.2+.
This could also happen to new apps generated on Rubies < 3.1, but my
guess is that is less common.

This commit fixes the issue by moving the extra blank line into the
condition.

[1]: d7b395145c644434b1c2be07ef334ea5cb643b75
2023-10-16 23:55:24 -04:00
Ryuta Kamizono
2e4061666b
Merge pull request #49490 from stevepolitodesign/sp-improve-generator-logging
Improve `Rails::Generators::Actions` logging and debugging
2023-10-16 17:38:03 +09:00
Xavier Noria
ebfca905db Do not memoize auto/eager load paths in engines 2023-10-14 17:44:33 +02:00
Nikita Vasilevsky
19f8ab2e7d
[Tests only] Enable Minitest/AssertPredicate rule 2023-10-13 19:26:47 +00:00
szTheory
5a553b02e1
Docs typo: rails/railties/lib/rails/engine.rb
Small typo fix in docs for Rails engines
2023-10-13 17:38:01 +00:00
Carlos Antonio da Silva
31d66f72de
Merge pull request #48767 from c960657/mailer-preview-wrap
Prevent header wrapping in email preview
2023-10-12 18:09:34 -03:00
Petrik
b8a3efeee3 Use Thor's enum for class_options
In 11a6adc4fb6172e9af081e20c5f68ca023e3bd8a 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
Akhil G Krishnan
f953178a75 Add consistant option description for --database on rails new
Review changes added
2023-10-12 19:52:28 +05:30
Carlos Antonio da Silva
3d5b2eefa2
Merge pull request #49600 from Earlopain/filter-params-email
Add email to the list of default filter parameters

Email addresses are considered personal data. While not quite on the same level of sensitivity as the other parameters in the list any application that implements signup through email without SSO inadvertently logs this information.
2023-10-12 09:12:59 -03:00
Earlopain
5af6d285fd
Add email to the list of default filter parameters 2023-10-12 13:39:57 +02:00
Frank Groeneveld
2b3782ed8f Fix documentation for credentails server start command 2023-10-12 10:21:23 +02:00
Rafael Mendonça França
60fc83f4e1
Merge pull request #49535 from t27duck/check_rails_new_options
Disallow invalid values for rails new options
2023-10-11 22:55:12 +02:00
Rafael Mendonça França
452c9f6c71
Merge pull request #49538 from akhilgkrishnan/capitalize-framework-names
Capitalize framework names [skip ci]
2023-10-11 17:04:27 +02:00
Akhil G Krishnan
80a5fb50c2 Update postgres naming to PostgreSQL 2023-10-10 13:44:20 +05:30
Tony Drake
11a6adc4fb Disallow invalid values for rails new options
The `--database`, `--asset-pipeline`, `--css`, and `--javascript` flags for
`rails new` can all take different options. However, only `--database` has
a check to make sure the correct option is given.

If someone where to fat-finger a value, for example `--javascript=esbuiild`,
they most likely would be left with either importmaps used or some other
undefined behavior.

This change adds similar checks as the `--database` flag for the other four
options to make sure the user enters the correct value.
2023-10-09 16:35:10 -04:00
Akira Matsuda
254b655932
Merge pull request #49548 from amatsuda/contraller_generator_route_string_literal
Let controller generator generate double-quoted routes
2023-10-10 04:04:00 +09:00
Jean Boussier
70c28cfcbf
Merge pull request #49525 from abhaynikam/fix-app-generated-dockerfile-to-use-correct-ruby-version
Ensures the Rails generated Dockerfile uses correct ruby version and matches Gemfile
2023-10-09 18:46:44 +02:00
Akira Matsuda
b669023dac
Let controller generator generate double-quoted routes 2023-10-09 12:47:27 +09:00
Abhay Nikam
af2b246f48 Ensures app install generated dockerfile uses correct ruby version 2023-10-08 11:47:27 +05:30
Akhil G Krishnan
c96695dfcf Capitalize framework names 2023-10-08 11:34:21 +05:30
Jonathan Hefner
0f535a8f35 Clean up docs for Rails::Generators::ActiveModel [ci-skip]
Without additional formatting, these method docs render as a single
line.  For example,

  ```ruby
  # GET show
  # GET edit
  # PATCH/PUT update
  # DELETE destroy
  ```

renders as

  ```html
  <p>GET show GET edit PATCH/PUT update DELETE destroy</p>
  ```
2023-10-07 12:26:33 -05:00
Mohit Sindhwani
1040355fb3
Adds DOCTYPE html to the response from up on the HealthController 2023-10-07 17:18:02 +08:00
Rafael Mendonça França
a731dbdfb8
Only check the schema when the table exists on CI
The goal of this code since the beginning was only to check invalid
attributes, not missing tables.

We can assume that if the person didn't create the table yet but
they do use it, some other test would fail.

Fixes #49500.
2023-10-06 13:32:54 +00:00
Steve Polito
2b4909b817 Improve generator logging and debugging
This commit is a follow-up to #49448, with regards to [this comment][].

Prior to this commit, logging and debugging for
[Rails::Generators::Actions][] was limited even when enabling
`RAILS_LOG_TO_STDOUT`. This was because the private `action` method in
the corresponding test was capturing `$stdout`.

[this comment]: https://github.com/rails/rails/pull/49448#issuecomment-1743061538
[Rails::Generators::Actions]: https://api.rubyonrails.org/v7.0.8/classes/Rails/Generators/Actions.html
2023-10-05 09:11:33 -04:00
Earlopain
8ed54084a8
Remove whitespace from filter parameter template [ci-skip] 2023-10-05 13:57:59 +02:00
Rafael Mendonça França
fed3125ea1
Merge pull request #49470 from rails/rm-eager-load-model-schema
Load the model schema when running test in eager load context
2023-10-04 05:51:39 -04:00
Rafael Mendonça França
1f0262aa2b
Separate the CI environment from the application CI environment
Right now we are using both to test the Rails applications we generate
and to test Rails itself. Let's keep CI for the app and BUILDKITE to
the framework.
2023-10-04 09:36:51 +00:00
Rafael Mendonça França
aa4e713fc0
Extract public file to maintain test schema so RSpec can use as well
Since `load_schema` is private API, we don't want it to be explicitly
called by RSpec.

This feature can be used by RSpec by exposing it in
`rails/testing/maintain_test_schema` so they don't need to reimplement
the same thing.
2023-10-03 14:07:54 +00:00
Rafael Mendonça França
70843ff7b2
Load the model schema when running test in eager load context
Some protections like the one that checks if an enum is pointing to
a valid column in the table only works when the database schema is
loaded to the model.

Before this change, if schema cache wasn't present and the right
combinations of configurations were not set, developers would only see
this exception in production.

With this change, those errors would be caught on CI, as soon the
tests are loaded.
2023-10-03 13:20:40 +00: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
71fd543d4b
Merge pull request #49460 from matteeyah/main
Check first two arguments in docker entrypoint
2023-10-03 06:47:00 -04:00
Edouard CHIN
c577cc950b Handle case when config.logger is already a BroadcastLogger:
- This commit avoids having `Rails.logger` be a two level nested
  BroadcastLogger. Side note that Nesting BroadcastLogger works and is
  supported by the implementation but we shouldn't do it in that
  case as it's confusing for the user.
2023-10-03 00:21:01 +02:00
Matija Čupić
7aaea30dd5
Check first two arguments in docker entrypoint
This allows passing parameters as the Docker command when running this
container, e.g. `./bin/rails server -b 0.0.0.0`.
2023-10-02 20:55:28 +02:00
Jean Boussier
02e679ba75 Get rid of the jruby_skip test helper
The last test calling it actually passes on latest
JRuby.
2023-10-02 13:01:44 +02:00
Takuya Noguchi
5f3c0d6bee Avoid Action Cable config in dev templates on --skip-action-cable
rails new --skip-aciton-cable now generates config/environments/development.rb
without Action Cable configurations.

Follows up PRs 22586 and 24169

Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
2023-09-30 00:33:03 +00:00
Rafael Mendonça França
d7b395145c
Merge pull request #49428 from uxxman/main
No need to include error_highlight when ruby version >= 3.2
2023-09-29 16:00:37 -04:00
Rafael Mendonça França
db2ef1d250
Merge pull request #49417 from Edouard-chin/ec-logger-fix
Fix the BroadcastLogger being initialized too late:
2023-09-29 15:45:03 -04:00
Edouard CHIN
40cb50e06e Fix the BroadcastLogger being initialized too late:
- An oversight of #48615 is that it changes the `Rails.logger` to be
  a broadcast logger after the app is booted. Anything referencing
  `Rails.logger` during the boot process will get a simple logger and
  ultimately resulting in logs not being broadcasted.

  For example `ActionController::Base.logger.info("abc")` would
  just output logs in the `development.log` file, not on STDOUT.

  ----

  The only solution I could think of is to create a BroadcastLogger
  earlier at boot, and add logger to that broadcast when needed (instead
  of modiyfing the `Rails.logger` variable).
2023-09-29 15:42:47 +02:00
Usman
24b99910cf No need to include error_highlight when ruby version >= 3.2 2023-09-29 09:05:06 +00:00
Jean Boussier
2da1852ac9 Delay Adapter#check_version to #configure_connection
Ideally we should be able to checkout an Adapter instance without
triggering a connection to the server.

For some adapters like Trilogy that is the case today, but only if
you have a schema cache loaded, otherwise `check_version` will trigger
a query.

I think this check can be delayed to when we actually use the connection.
2023-09-29 08:53:16 +02:00