Commit Graph

15172 Commits

Author SHA1 Message Date
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
northeastprince 8e98b614e4 Setup jemalloc in default Dockerfile 2024-02-04 10:02:51 +01:00
Jean Boussier 7c1db8db9e Always call `preload_app!` in Puma config
The puma documentation and code seem to disagree about
whether `preload_app!` is the default depending on the number
of workers.

Worst case it's the default and making it explicit is no big deal.
2024-01-31 21:45:12 +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
Hartley McGuire e5e4b80104
Change skeleton test to assert exact file output
Previously, the skeleton test would assert that every file in the
`default_files` list existed. However, since there is no requirement
that a file is added to this list when added to the generator the list
can (and has) become out of sync with the exact generated output.

This commit refactors the skeleton test to gather the full list of files
created by the generator so that it can be compared exactly to the list
of `default_files`. This ensures the generated file list must be updated
when any file is added or removed from the generator. Additionally, by
using array equality the sorting of the `default_files` list is enforced
(it was previously _mostly_ alphabetical, but not fully).

The new skeleton test assertion was written to only assert files instead
of folders for a few reasons:
- asserting that folders exist is redundant if a file exists within a
  folder (and the `default_files` list would be significantly longer
  with all folders)
- any folder generated without any files inside it will not be tracked
  by Git, so other code cannot assume these empty folders exist

Because of these reasons, this patch also includes a change to no longer
generate the `tmp/cache/assets` folder by default. The folder is an
implementation detail of Sprockets and doesn't need any special
treatment in Rails. The `Sprockets::Cache::FileStore` will create the
directory if it does not exist (which it usually won't since `tmp/cache`
is excluded from Git by the `.gitignore`), and the `tmp:cache:clear`
task already clears all subdirectories of `tmp/cache`.

Finally, some tests making assertions about the default output of the
app generator were removed as they have been made redundant by the
improvements to the skeleton test.
2024-01-28 15:03:56 -05:00
Junichi Sato 51e9074de2
Prevent rdoc task from excluding the main page
There was a bug where the main page becomes unable to be found
and this change ensures that it does not happen.

Closes https://github.com/rails/rails/issues/50871.
2024-01-26 15:05:24 +09:00
David Jensenius 49e9ec91cd
Revert help on unrecognized bare options 2024-01-25 13:56:37 -05:00
Jean Boussier 2af2b222d4
Merge pull request #50855 from Shopify/update-console-prompt-color
Display dev & test env in console prompt in blue instead of green
2024-01-24 12:55:21 +01:00
Stan Lo 7cbf06c1e8
Display dev/test env in console prompt in blue instead of green
The combination of red and blue is more color-blind friendly than red
and green.

Discussion: https://github.com/rails/rails/pull/50796#discussion_r1463670198
2024-01-24 11:07:40 +00:00
Stan Lo 0ea9748ba6
Fix prompt colorization test's setup 2024-01-24 11:07:40 +00:00
Daniel Colson 6616770ec9
Translate Trilogy syscall errors as conn failed
At GitHub we get a fair number of Trilogy `ETIMEDOUT` errors (for known
reasons that we might be able to improve somewhat, but I doubt we'll
make them go away entirely). These are very much retryable network
errors, so it'd be handy if these `ETIMEDOUT` errors were translated to
`ConnectionFailed` instead of `StatementInvalid`, making them
`retryable_connection_error`s.

ed2bc92b82/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb (L1077)

We're already translating `ECONNRESET` (via matching on the error
message) and `EPIPE` to `ConnectionFailed`. Rather than adding another
case, this commit treats all of the Trilogy `SystemCallError` subclasses
as `ConnectionFailed`.

This requires bumping trilogy 2.7 so we can get
https://github.com/trilogy-libraries/trilogy/pull/143
2024-01-23 16:20:02 -05:00
Petrik de Heus fe81d667a7
Merge pull request #50789 from p8/docs/relative-includes
Use relative includes of README's in documentation [ci-skip]
2024-01-21 18:30:07 +01:00
Stan Lo 09b2aecec5
Change Rails console prompt's format
Following the discussion in #50770, the new format will be:
`[dasherized-app-name]([colorized-env])>`

For example, if the app's module name is `MyApp`, the prompt will be:
`my-app(dev)>`, where the `dev` part will be colored.

Update railties/lib/rails/commands/console/console_command.rb

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>

Update changelog
2024-01-20 23:34:33 +00:00
Stan Lo 4d6714fcd3
Remove unnecessary nocolorize flag
Setting `TERM=dumb` is enough to disable colorization in those tests.

Mocked app should also load console helpers

Move console method extension to IRBConsole's constructor

Test IRB autocompletion control without mutating ENV

Control IRB autocompletion without mutating ENV

Correct local variable name
2024-01-20 11:45:52 +00:00
Stan Lo 0c2898a768
Create IRBConsole to encapsulate IRB-specific setup
Add Rails-specific IRB prompt

Update changelog
2024-01-19 19:01:26 +00:00
Jonathan Hefner f21e4299d6 Fix `bin/rails -T` when no default task is defined
When Rake parses an argument string with no tasks, it sets the top-level
task as "default".  Prior to this commit, if no default task was defined
(for example, if an app was generated with `--skip-test` and didn't
define its own default task), `Rails::Command::RakeCommand` would raise
`UnrecognizedCommandError`, preventing Rake from displaying the task
list.

This commit changes `Rails::Command::RakeCommand` to let Rake handle the
"default" task.

Fixes #50700.
2024-01-18 18:10:44 -06:00
Jonathan Hefner dc85b953aa Print bin/rails help on unrecognized bare options
Prior to this commit, `bin/rails` would pass unrecognized bare options
on to Rake:

  ```console
  $ bin/rails -v
  Rails 7.2.0.alpha

  $ bin/rails -V
  rake, version 13.0.6

  $ bin/rails -s
  Running 0 tests in a single process (parallelization threshold is 50)
  ...

  $ bin/rails -S
  invalid option: -S
  ```

This commit changes `bin/rails` to print its help message when given an
unrecognized bare option:

  ```console
  $ bin/rails -v
  Rails 7.2.0.alpha

  $ bin/rails -V
  Usage:
    bin/rails COMMAND [options]

  You must specify a command. The most common commands are:
  ...

  $ bin/rails -s
  Usage:
    bin/rails COMMAND [options]

  You must specify a command. The most common commands are:
  ...

  $ bin/rails -S
  Usage:
    bin/rails COMMAND [options]

  You must specify a command. The most common commands are:
  ...
  ```

However, for backward compatibility, an exception has been made for the
`-T` / `--tasks` option:

  ```console
  $ bin/rails -T
  # Prints list of Rake tasks...
  ```

Addresses #50712.
2024-01-18 17:43:18 -06:00
Petrik 8565f45100 Use relative includes of README's in documentation [ci-skip]
The Rails documentation uses the `:include:` directive to inline the
README of the framework into the main documentation page. As the
README's aren't in the root directory from where SDoc is run we need to
add the framework path to the include:

    # :include: activesupport/README.md

This results in a warning when installing the gems as generating the rdoc for the gem is run from the gem/framework root:

    Couldn't find file to include 'activesupport/README.rdoc' from lib/active_support.rb

The `:include:` RDoc directive supports includes relative to the current
file as well:

    # :include: ../README.md

This makes sure it works for the Rails API docs and the separate gems.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2024-01-18 10:39:15 +01:00
Xavier Noria 299900f4e5 Edit pass over the railties CHANGELOG 2024-01-16 20:39:04 +01:00
Aaron Patterson eccaddba5c
Merge pull request #50758 from rails/fix-video-preview-nplus1
Eagerly load preview images (N+1)
2024-01-16 10:44:10 -08:00
Xavier Noria cb035bde4e
Merge pull request #50723 from aeroastro/feature/no-file-in-load-path
Ensure only directories exist in Rails default load paths
2024-01-16 17:48:26 +01:00
Jean Boussier 946e46ebcc Modernize method missing implementations
`...` is both simpler an more correct since the keyword argument
separation.
2024-01-16 13:17:45 +01:00
Rafael Mendonça França cddf163632
Make sure after_routes_loaded hook runs on boot
This hook was only running when routes were reloaded, but not on boot.

The goal was to run any time routes are loaded. This commit fixes it
and adds a test.

Fixes #50720.
2024-01-15 22:26:02 +00:00
Aaron Patterson 4a18e06864
use assert_operator for better error message 2024-01-15 11:41:30 -08:00
Takumasa Ochi 23cc9229ff
Ensure only directories exist in Rails default load paths
Previously, some files put under `app` directory would contaminate the load paths.
This commit removes files from the default load paths set up by the Rails framework.

Now, only directories are included as default in the following paths:

* autoload_paths
* autoload_once_paths
* eager_load_paths
* load_paths
2024-01-15 15:04:53 +09:00
Adrien POLY 88e8774844 remove deprecated yarn check 2024-01-14 22:43:46 +01:00
Xavier Noria 4fb230d214 Remove unnecessary #to_s call
The `dirs` method returns an array of strings regardless of what was
originally in the autoload paths. This type is documented:

    https://github.com/fxn/zeitwerk?tab=readme-ov-file#zeitwerkloaderdirs

Note also that the #to_s call was not tested (you could not).
2024-01-13 00:00:46 +01:00
Rafael Mendonça França 524faa9466
Add test for after_routes_loaded
Related to #50720.
2024-01-12 19:18:32 +00:00
Takumasa Ochi 5853ff19eb
Fix failing test due to the relative path output of minitest
minitest has been updated to output relative paths for failures at v5.21.0

e410bade17

This patch fixes test to pass regardless of minitest versions.
2024-01-13 01:01:28 +09:00
Alex Ghiculescu ad7abf37a7
Fix indenting in SQLite database.yml 2024-01-12 08:40:30 +10:00
Takumasa Ochi d7e2575082
Prevent unnecessary application reloads in development
Previously, the Rails application would reload due to changes
in some files outside the autoload paths.
For instance, editing `app/README.md` would trigger a reload,
even though the reloaded classes and modules were identical
to those loaded previously.

This commit fixes this issue by ensuring the application reloads correctly
according to `Rails.autoloaders.main.dirs`, thereby preventing unnecessary reloads.

https://github.com/rails/rails/issues/37011#issuecomment-1322560651
2024-01-11 21:35:47 +09:00
Jean Boussier 9dab3e4184 Fix a typo in puma.rb.tt 2024-01-10 18:42:14 +01:00
Jean Boussier 06d614ada9 Update the default Puma configuration
The main change is the default number of threads
is reduced from 5 to 3 as discussed in https://github.com/rails/rails/issues/50450

Pending a potential future "Rails tuning" guide, I tried
to include in comments the gist of the tradeoffs involved.

I also removed the pidfile except for development.
It's useful to prevent booting the server twice there
but I don't think it makes much sense in production,
especially [since Puma no longer supports daemonization
and instead recommend using a process
monitor](99f83c50fb/docs/deployment.md (should-i-daemonize)).
And it makes even less sense in a PaaS or containerized
world.
2024-01-10 10:13:59 +01:00
Akhil G Krishnan de3a9a1d41 Ignore docker and git related files in dockerignore
Ignore docker and git related files in dockerignore

Ignore docker and git related files in dockerignore
2024-01-10 11:22:19 +05:30
Jean Boussier 2d6b02bad6
Merge pull request #50632 from skipkayhil/hm-move-chunk-test-to-actionpack
Move Transfer-Encoding chunked test to Action Pack
2024-01-09 14:35:50 +01:00
Akhil G Krishnan dbdc26858a Fix extra blank line on CI when skipping brakeman
Fix extra blank line on CI when skipping brakeman

Fix extra blank line on CI when skipping brakeman
2024-01-09 12:26:17 +05:30
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
Igor Alexandrov 34aca28757 Moved --no-pager exec option to CI only config 2024-01-08 21:18:00 +04:00
Igor Alexandrov 0550b02c63 Made Brakeman CI config stricter 2024-01-08 21:14:29 +04:00
Jonathan Hefner 3bbf21c343 Use verb form of "fallback"
"Fallback" is a noun, whereas "fall back" is a verb.
2024-01-07 17:27:23 -06:00
Jonathan Hefner ff9b62417f Prepend `$` to example CLI commands [ci-skip]
This allows the syntax highlighter to recognize the code as CLI commands.
2024-01-07 17:27:23 -06:00
Jonathan Hefner d1411b2018 Split up code blocks for multi-file examples [ci-skip]
RDoc treats consecutive indented lines as a single code block.  For code
examples that span multiple files / languages, this confuses the syntax
highlighter and makes the examples harder to read.  Unfortunately, RDoc
doesn't provide syntax to prevent this, and it ignores multiple
consecutive blank lines.  However, by inserting an empty tag such as
`<code></code>`, we can force RDoc to recognize separate code blocks.
2024-01-07 17:27:23 -06:00
Hartley McGuire a03a854193
Move Transfer-Encoding chunked test to Action Pack
While working on [another PR][1], I found that removing the
Transfer-Encoding conditionals did not result in any failing tests in
Action Pack. This was surprising to me until I found that there was a
test for this behavior in Railties. However, nothing about the test
really depends on having a full Rails application or the Railties test
suite.

This commit moves the test into Action Pack to simplify/speedup the test
(no need to build a full app) as well as keeping the test closer to the
actual behavior being tested.

[1]: 0c334b48fdc5d70b0c8406ba184fbfd26750b049
2024-01-07 14:33:25 -05:00
David Heinemeier Hansson 0ecbb16939
Add default svg icon in generated application layout (#50629)
* SVG icon is support by Chrome/Firefox

So prefer that over PNG.

* Also included

* No need for a size when we only have one
2024-01-07 12:32:43 -05:00