Commit Graph

15205 Commits

Author SHA1 Message Date
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
707b5cb606
Revert "Merge pull request #49360 from skipkayhil/hm-gemfile-ruby-file"
This reverts commit 6985c3bedf0d85c180d8b86a2fcd6b19e7251bd3, reversing
changes made to 3163bb735189eddd7c152a1e72bed7b4d052f7d4.

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
Rafael Mendonça França
53deefaff9
Remove extra new line in the generated Gemfile 2024-02-14 19:53:00 +00:00
dhh
e98bbd0943 Better flow for puma.rb 2024-02-14 10:32:02 -08:00
Rafael Mendonça França
85b30040ce
Merge pull request #51084 from anonychun/dont-override-ld-preload
Dont override LD_PRELOAD value
2024-02-14 12:58:56 -05: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
David Heinemeier Hansson
270eaa0565
Suggest puma-dev configuration in bin/setup (#51088) 2024-02-14 08:26:19 -08:00
Achmad Chun Chun
74a532ccc3 Remove duplicate value 2024-02-14 20:19:55 +07:00
Achmad Chun Chun
600fb54f21 Don't override LD_PRELOAD value if already set 2024-02-14 20:06:12 +07: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
9940dc879d docker-entrypoint: export LD_PRELOAD
Otherwise it won't applied to the execed process.

Fix: https://github.com/rails/rails/pull/50943#issuecomment-1936443319
2024-02-12 14:15:16 +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
Lewis Buckley
a15f5b837f
Add note about imagemagick / libvips support being required 2024-02-09 23:45:18 +00:00
Lewis Buckley
f3e3f82e7d
Add WebP as a new framework default image type
Follows https://github.com/rails/rails/pull/38918 and
https://github.com/rails/rails/pull/38988

At the time, webp browser support was limited. Now 96% of browsers
support webp: https://caniuse.com/?search=webp
2024-02-09 23:44:51 +00: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
Rafael Mendonça França
3079e8b0f8
Merge pull request #51033 from jasonkarns/patch-3
.gitignore template references git's default instead of custom config
2024-02-09 17:08:14 -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
Jason Karns
ff9248a4d4
Prefer to reference git's default configuration, not bespoke
Prefer references to git's default configuration, rather than encouraging customized configurations.

`git config core.excludesFile` defaults to `${XDG_CONFIG_HOME:-~/.config}/git/ignore`. This updates the .gitignore template to suggest the default location for git's global gitignore rather than a customized location.
2024-02-09 14:37:39 -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
1ca8c8ea34 Improve the docker-entrypoint comments
Co-Authored-By: Joshua Young <djry1999@gmail.com>
2024-02-06 16:59:50 +01: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
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]: e5e4b801046bceb1067ffb316edd1ad704b6596d
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