Commit Graph

14466 Commits

Author SHA1 Message Date
Jean Boussier b4029ba4a9
Merge pull request #46309 from skipkayhil/hm-fix-stderr-double-logs
Fix double logs if Rails.logger outputs to STDERR
2022-10-23 12:08:43 +02:00
Jean Boussier 971fa17502
Merge pull request #46279 from ghiculescu/query-tags-dupe 2022-10-23 01:22:41 +02:00
Hartley McGuire 82eb1f441d
Fix double logs if Rails.logger outputs to STDERR
Previously, configuring Rails.logger to output to STDERR would result in
double logs when running the `rails server` command. This was due to the
server command broadcasting the logger to STDOUT if it did not already
output to STDOUT.

This commit fixes the issue by checking that the logger does not output
to STDERR in addition to STDOUT before broadcasting. This aligns it with
a similar broadcast done in the Active Record railtie.
2022-10-22 19:22:24 -04:00
Alex Ghiculescu f737b5ec13 Fix double logging in `ActiveRecord::QueryLog`
Fixes https://github.com/rails/rails/issues/46103

An issue exists if you set `config.active_record.query_log_tags` to an array that includes `:controller`, `:action`, or `:job`; the relevant item will get duplicated in the log line. This occured because the relevant railties would add the item to `config.active_record.query_log_tags` again during setup. This PR fixes that by only adding those items to the config if they aren't already set.

The issue proposed more documentation to work around this, but I think it's a bug and should be fixed directly.
2022-10-22 15:53:14 -05:00
Ryuta Kamizono 4136145819 Fixup CHANGELOGs [ci-skip] 2022-10-20 18:37:48 +09:00
Petrik de Heus 1d769c6c69
Merge pull request #45475 from codergeek121/make-api-doc-link-relative [ci-skip]
Makes the  API documentation link relative
2022-10-18 21:20:16 +02:00
Jonathan Hefner 545a9908e8 Bump Puma to v6.0.0
The `Gemfile` was updated in #46106 to allow Puma 6.  Puma v6.0.0 was
released on 2022-10-14.  This commit updates `Gemfile.lock` to reflect
the new version.

This commit also updates the Puma version constraint used in generated
apps to allow Puma 6.
2022-10-16 15:43:37 -05:00
Tony Drake d6715c72c5 Scaffold destroy action returns status code 303
The default controller scaffolding currently sends back a 302 for its
destroy action.

Since Hotwire is the default for Rails going forward, this can be
problimatic. Turbo uses the fetch API internally which is particular on
how it handles redirects.

As outlined in this table in this Turbo issue,
https://github.com/hotwired/turbo/issues/84#issuecomment-862656931,
Turbo making a DELETE request (not POST + hidden _method field) and
recieving a 302 back will result in another DELETE request instead of a
GET request for the redirect.

This updates the controller template used for the scaffold generator
to send back the 303 see other status code for the destroy action.

For consistancy-sake, the Action Controller Overview guide examples
were also updated. The main Getting Started guide page already has
see other used in its example destroy action.

For non-Hotwire users, the browser will still properly redirect on
a 303 as it does with a 302.
2022-10-13 16:08:55 -04:00
Hormoz Kheradmand 4c5b478380
loading_test should not override database to :memory:
Overriding the database to :memory: results in a failing test for this
PR: https://github.com/rails/rails/pull/46097 because the database would
be reset at the start of every request in this integration test if/when
the the injected `ActiveRecord::Migration::CheckPending` middleware
re-establishes `ActiveRecord::Base.connection` between each request

I have improved a couple of issues I saw with the assertions in this
test as well, namely:

1. Asserting that the last request actually succeeded, as to avoid
   ambiguous test failures
2. Not referencing `Post` from outside the Rack application, because
   otherwise our assertion would be invalid (because referencing the
   constant actually loads it!!)
2022-10-13 12:32:06 -07:00
Sasha Stadnik 20883c46c8 use oxford comma [skip ci] 2022-10-13 12:18:06 +03:00
Jean Boussier 3b4a0835ce
Merge pull request #46141 from codergeek121/add-style-src-to-csp-nonce-directives 2022-10-12 16:55:35 +02:00
Aaron Patterson 2f36f0a2bb
Merge pull request #46171 from rails/refactor-errors
Add column information inside ERB templates
2022-10-11 15:10:40 -07:00
Aaron Patterson f52fee607e
set `keep_script_lines` in development 2022-10-11 14:41:15 -07:00
Jean Boussier d917896f45 Enable verbose mode in test and report warnings as errors
We recently let a few very easy to avoid warnings get merged.
The root cause is that locally the test suite doesn't run in
verbose mode unless you explictly pass `-w`.

On CI warnings are enabled, but there is no reason to look at the
build output unless something is failing. And even if one wanted
to do that, that would be particularly work intensive since warnings
may be specific to a Ruby version etc.

Because of this I believe we should:

  - Always run the test suite with warnings enabled.
  - Raise an error if a warning is unexpected.

We've been using this pattern for a long time at Shopify both in private
and public repositories.
2022-10-11 09:25:18 +02:00
Jonathan Hefner d240e8a986 Add Rails.application.deprecators
This adds a `Rails.application.deprecators` method that returns a
managed collection of deprecators.

Individual deprecators can be added and retrieved from the collection:

  ```ruby
  Rails.application.deprecators[:my_gem] = ActiveSupport::Deprecation.new("2.0", "MyGem")
  Rails.application.deprecators[:other_gem] = ActiveSupport::Deprecation.new("3.0", "OtherGem")
  ```

And the collection's configuration methods affect all deprecators in the
collection:

  ```ruby
  Rails.application.deprecators.debug = true

  Rails.application.deprecators[:my_gem].debug
  # => true
  Rails.application.deprecators[:other_gem].debug
  # => true
  ```

Additionally, all deprecators in the collection can be silenced for the
duration of a given block:

  ```ruby
  Rails.application.deprecators.silence do
    Rails.application.deprecators[:my_gem].warn    # => silenced (no warning)
    Rails.application.deprecators[:other_gem].warn # => silenced (no warning)
  end
  ```
2022-10-05 14:37:27 -05:00
Jonathan Hefner bae0124ba7
Merge pull request #46193 from jonathanhefner/app_generator_test-run_app_update
Always run `rails app:update` in app update tests
2022-10-05 14:24:03 -05:00
Rafael Mendonça França b5d4172af3
Merge pull request #46180 from modulitos/set-default-query-tags-format
Set default query tags format for upcoming Rails releases
2022-10-05 14:36:21 -04:00
Niklas Haeusele e7169d5f04 Add style-src to nonce_directives in sample csp.rb to be compatible with turbo or default rails new 2022-10-05 18:50:41 +02:00
pinzonjulian f4812bf690 Allow direct uploads to work within engines 2022-10-06 00:29:27 +11:00
modulitos 36c14d9094 Set active_record.query_log_tags_format defaults
Building on the new Query Log formatting implemented in #45139, we are now setting the correct defaults for
active_record.query_log_tags_format defaults as well.

Fixes: #46179

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2022-10-05 01:04:21 -07:00
Jonathan Hefner 21f1199448 Always run `rails app:update` in app update tests
Prior to this commit, several tests in `AppGeneratorTest` were testing
app update behavior without actually running `rails app:update`.  This
meant the logic in `Rails::AppUpdater#generator_options` that detects
which frameworks and components are installed was not being tested.

Additionally, because `ENV["BUNDLE_GEMFILE"]` is set when tests are run
(by `require "bundler/setup"` in `tools/test.rb`), any tests which did
run `rails app:update` used the Rails repo Gemfile, instead of the
generated app Gemfile.  The difference becomes obvious when running
`rails app:update` after generating an app without Sprockets (as in
`test_app_update_does_not_generate_manifest_config_when_propshaft_is_used`),
because `rails app:update` will load the Sprockets railtie (due to
`Bundler.require` using the Rails repo Gemfile), and then exit with a
`Sprockets::Railtie::ManifestNeededError`.  However, if
`rails app:update` is run within a `quietly` block, such an error will
be swallowed.

This commit changes all such tests to run `rails app:update` via a
`run_app_update` helper that: (1) overrides the `BUNDLE_GEMFILE`
environment variable to point to the generated app Gemfile, (2) points
the `rails` gem in the generated app Gemfile to the Rails repo
(otherwise the `rails` gem version cannot be resolved), and (3) sets
`exception: true` so that the `system` call will raise an error if
`rails app:update` exits with an error code.

This commit also adds `jbuilder` and `web-console` to the Rails repo
Gemfile to ensure they are already installed when evaluating the
generated app Gemfile.

These changes do add a couple dozen seconds to the test suite run time,
but the thorough test coverage seems worth it.
2022-10-04 12:33:26 -05:00
Jean Boussier e15002419b
Merge pull request #46161 from eikes/use-active-support-configuration-file-in-load-database-yaml
Use ActiveSupport::ConfigurationFile in load_database_yaml
2022-10-03 22:00:42 +02:00
eileencodes 5bb357f14a
Use `adapter_class` instead of `connection_class` for adapters
In Active Record `connection_class` already means "the class in your
application that established the connection" so I would prefer it only
have that one meaning. This change swaps `connection_class` for
`adapter_class` where applicable.
2022-09-30 16:14:51 -04:00
Eike Send d9f5bfae7e
Use ActiveSupport::ConfigurationFile in load_database_yaml 2022-09-30 12:55:55 +02:00
Gannon McGibbon 4bcb8e4afb Move dbconsole logic to Active Record connection adapter.
Instead of hosting the connection logic in the command object, the
database adapter should be responsible for connecting to a console session.
This patch moves #find_cmd_and_exec to the adapter and exposes a new API to
lookup the adapter class without instantiating it.

Co-authored-by: Paarth Madan <paarth.madan@shopify.com>
2022-09-29 16:29:06 -05:00
Jonathan Hefner c267be43d3 Move CHANGELOG entry for #44179 to railties [ci-skip]
The CHANGELOG entry for #44179 originally focused on
`ActiveSupport::MessageVerifiers` and `ActiveSupport::MessageEncryptors`,
and made sense in `activesupport/CHANGELOG.md`.  However, prior to
merge, the focus changed to `Rails.application.message_verifiers`.
Therefore, the CHANGELOG entry should be in `railties/CHANGELOG.md`.
2022-09-29 12:08:14 -05:00
Aaron Patterson 2fb72f578f
Merge pull request #45081 from iheanyi/iheanyi/custom-query-log-tags-separators
Add ability to set the `tags_format` for `QueryLogs`
2022-09-27 17:27:16 -07:00
Aaron Patterson 08ef43ed5e
Merge pull request #46120 from rails/rescue-template-paths
Keep rescue template paths in an array
2022-09-27 15:15:06 -07:00
modulitos 6df894fd56 Add sqlcommenter formatting support on query logs
Co-authored-by: Iheanyi Ekechukwu <iekechukwu@gmail.com>
2022-09-27 14:38:35 -07:00
Eileen M. Uchitelle 5b8421f56e
Merge pull request #46134 from eikes/remove-dummy-erb-compiler
Facilitate use of any regular ERB in database.yml
2022-09-27 11:27:26 -04:00
Eike Send 5ba8aa5854
Facilitate use of any regular ERB in database.yml
Commit 37d1429ab1 introduced the DummyERB to avoid loading the environment when
running `rake -T`.

The DummyCompiler simply replaced all output from `<%=` with a fixed string and
removed everything else. This worked okay when it was used for YAML values.
When using `<%=` within a YAML key, it caused an error in the YAML parser,
making it impossible to use ERB as you would expect. For example a
`database.yml` file containing the following should be possible:

  development:
    <% 5.times do |i| %>
    shard_<%= i %>:
      database: db/development_shard_<%= i %>.sqlite3
      adapter: sqlite3
    <% end %>

Instead of using a broken ERB compiler we can temporarily use a
`Rails.application.config` that does not raise an error when configurations are
accessed which have not been set as described in #35468.

This change removes the `DummyCompiler` and uses the standard `ERB::Compiler`.
It introduces the `DummyConfig` which delegates all known configurations to the
real `Rails::Application::Configuration` instance and returns a dummy string for
everything else. This restores the full ERB capabilities without compromising on
speed when generating the rake tasks for multiple databases.

Deprecates `config.active_record.suppress_multiple_database_warning`.
2022-09-27 17:07:40 +02:00
Jonathan Hefner f05b6dd946
Merge pull request #44179 from jonathanhefner/add-message_verifiers-message_encryptors
Add `MessageVerifiers` and `MessageEncryptors` classes
2022-09-25 22:02:11 -05:00
Aaron Patterson 5c6e9d48e1
Keep rescue template paths in an array
Gotta be honest, this is so I can make some hacks.  Basically I would
like an engine to specify where to find rescue templates, and currently
there's no way to add search paths to the debug view lookup context.
This commit turns the template path in to an array (that I plan to
mutate, but nobody should do that besides me until we make an actual
good API).

I added the `dup` in `initialize` so in case the array is accidentally
mutated we don't leak memory.
2022-09-23 15:25:40 -07:00
Hartley McGuire d3ff40ee1d
Make app_name consistent between new and update
Previously, the app_name in the App Generator would behave differently
when creating a new app and updating an existing app.

When updating an app, app_name is always the Rails::Application class
name underscored. When creating a new app, app_name will use whatever
the user passes in with a few characters replaced.

This isn't necessarily an issue, but it can lead to extra noise when
running app:update. For example, an app generated with `rails new
MyWebSite` will end up with a configuration line like:

```
config.active_job.queue_name_prefix = "MyWebSite_production"
```

and running app:update will change it to

```
config.active_job.queue_name_prefix = "my_web_site_production"
```

By normalizing app_name when creating an application, the amount of
changes when updating is reduced.
2022-09-22 18:46:20 -04:00
Jonathan Hefner baade55c69 Add Rails.application.message_verifiers
Currently, `Rails.application.message_verifier(name)` returns a
`MessageVerifier` instance using a secret derived from the given `name`.
Instances created this way always generate messages using the default
options for `MessageVerifier.new`.  Also, if there are older options to
rotate for message verification, each instance created this way must be
configured individually.  In cases where Rails itself uses
`Rails.application.message_verifier` (e.g. in Active Storage),
discovering the name of the instance may require digging through
Rails' source code.

To alleviate these issues, this commit adds a `MessageVerifiers` factory
class, which acts as a central point for configuring and creating
`MessageVerifier` instances.  Options passed to `MessageVerifiers#rotate`
will be applied to `MessageVerifier` instances that `MessageVerifiers#[]`
creates.  So the following:

  ```ruby
  foo_verifier = Rails.application.message_verifier(:foo)
  foo_verifier.rotate(old_options)
  bar_verifier = Rails.application.message_verifier(:bar)
  bar_verifier.rotate(old_options)
  ```

Can be rewritten as:

  ```ruby
  Rails.application.message_verifiers.rotate(old_options)
  foo_verifier = Rails.application.message_verifiers[:foo]
  bar_verifier = Rails.application.message_verifiers[:bar]
  ```

Additionally, `Rails.application.message_verifiers` supports a
`:secret_key_base` option, so old `secret_key_base` values can be
rotated:

  ```ruby
  Rails.application.message_verifiers.rotate(secret_key_base: "old secret_key_base")
  ```

`MessageVerifiers` memoizes `MessageVerifier` instances.  This also
allows `MessageVerifier` instances to be overridden entirely:

  ```ruby
  Rails.application.message_verifiers[:foo] = ActiveSupport::MessageVerifier.new(other_secret)
  ```

For parity, this commit also adds a `MessageEncryptors` factory class,
which fulfills the same role for `MessageEncryptor` instances.
2022-09-22 16:21:31 -05:00
Rafael Mendonça França fa7b3feaaa
Merge pull request #46074 from skipkayhil/fix-app-plugin-generation-2
Fix plugin generation inside applications
2022-09-21 14:20:38 -04:00
Yasuo Honda 859af30e3b
Merge pull request #45216 from yahonda/rubocop_minitest_020_enables_skip_ensure_cop
Do not run tests that have `ensure` instead of `skip`
2022-09-21 08:09:32 +09:00
Hartley McGuire 3dfa9b9e29
Fix plugin generation inside applications
Previously, generating a plugin inside an application would throw an
error when trying to create a dummy_app due to the generator trying to
reuse the application's name.

This is fixed by extracting the logic used to determine the source of an
application's name, and then only using the existing name as the source
for the app:update task.
2022-09-20 17:11:13 -04:00
Hartley McGuire 25c468bdd3
Fix being able to pass --force to db:system:change
Running db:system:change will always prompt to overwrite database.yml,
so being able to --force it seems expected
2022-09-20 17:02:20 -04:00
Yasuo Honda 1b736a8720 Do not run tests that have `ensure` instead of `skip`
Even if tests are "skipped" by `Minitest::Assertions#skip`
`ensure` is executed because tests methods are Ruby methods.

Adding conditions outside of the test methods, entire test methods are
executed only when they are necessary.
2022-09-20 22:12:20 +09:00
Takashi Kokubun 24fbbe06d2
Improve error messages on bin/setup
`system(.., exception: true)` gives you more information on how the
command failed, e.g.

```
bin/setup:8:in `system': Command failed with exit 1: bundle install (RuntimeError)

bin/setup:8:in `system': No such file or directory - bundle (Errno::ENOENT)
```
2022-09-19 15:48:21 +09:00
Petrik c328ac5c86 Use `sslmode` option instead of `ssl_mode` for MySQL command connections
In f36c261a44 support for the ssl-mode option was added for MySQL when
using the dbconsole command and MySQLDatabaseTasks.
However, the mysql2 gem uses `ssl_mode` instead of `sslmode`:

ba4d46551d/lib/mysql2/client.rb (L51)

As `ssl_mode` is what should be used in the database.yml configuration
for MySQL we should use it as well for the dbconsole command and
MySQLDatabaseTasks.

Co-authored-by: Chris Gunther <chris@room118solutions.com>
2022-09-17 18:53:54 +02:00
Petrik d14662a5ae Tiny copy fix in CHANGELOGs [ci-skip] 2022-09-17 12:54:43 +02:00
John Bampton 3a32915bbc Fix word case. `json` -> `JSON` 2022-09-17 04:11:36 +10:00
Jean Boussier f33a1b902d Add `assert_error_reported` and `assert_no_error_reported`
Allows to easily asserts an error happened but was handled

```ruby
report = assert_error_reported(IOError) do
  # ...
end
assert_equal "Oops", report.error.message
assert_equal "admin", report.context[:section]
assert_equal :warning, report.severity
assert_predicate report, :handled?
```
2022-09-16 10:04:26 +02:00
Yasuo Honda 8c619c3096
Merge pull request #46008 from p8/activerecord/ssl-verify-connection
Add ssl-mode option to dbconsole command and MySQLDatabaseTasks
2022-09-16 16:51:51 +09:00
Yasuo Honda 7536fe4eac
Merge pull request #46043 from yahonda/remove_rubinius_code
Drop Rubinius code
2022-09-15 23:03:06 +00:00
Donapieppo d5124b2522
Add puma app server to Gemfile in order to start test/dummy (#45950)
* Add puma app server to Gemfile in order to start test/dummy

* Fix Could not find server '' error for plugin dummy apps
by adding a web server to plugin Gemfile.

In order to run the test/dummy application we add
puma (web_server_gemfile_entry as defined in
`railties/lib/rails/generators/app_base.rb`)
to the engine Gemfile.

* No more need to add puma to Gemfile.

Back to the previous version of the engine guide as
the web server is now present in Gemfile after
`rails plugin new`

[Donapieppo + Rafael Mendonça França]
2022-09-15 13:28:42 -04:00
Petrik ed3b92b38f Add ssl-mode option to dbconsole command and MySQLDatabaseTasks
According to the MySQL documentation, database connections default to
ssl-mode=PREFERRED. But PREFERRED doesn't verify the server's identity:

    The default setting, --ssl-mode=PREFERRED, produces an encrypted
    connection if the other default settings are unchanged. However, to
    help prevent sophisticated man-in-the-middle attacks, it is
    important for the client to verify the server’s identity. The
    settings --ssl-mode=VERIFY_CA and --ssl-mode=VERIFY_IDENTITY are a
    better choice than the default setting to help prevent this type of
    attack. VERIFY_CA makes the client check that the server’s
    certificate is valid. VERIFY_IDENTITY makes the client check that
    the server’s certificate is valid, and also makes the client check
    that the host name the client is using matches the identity in the
    server’s certificate.

https://dev.mysql.com/doc/refman/8.0/en/using-encrypted-connections.html

However both the Rails::DBConsole command and the MySQLDatabaseTasks
ignore the ssl-mode option, making the connection fallback to PREFERRED.

Adding ssl-mode to the forwarded options makes sure the expected mode is
passed to the connection.
2022-09-15 19:20:16 +02:00
Yasuo Honda 349a66ebed Drop Rubinius code
Rubinius has not been maintained since May 2020 and based on the
discussion at https://github.com/rails/rails/pull/44984 ,
I think we can remove Rubinius specific code from Rails.
2022-09-15 23:43:51 +09:00
Rafael Mendonça França e6d4ac0e50
Merge pull request #46009 from johnnyshields/bundler-use-windows-platform
Bundler should use platform :windows instead of :mingw, etc.
2022-09-14 22:35:59 -04:00
Rafael Mendonça França 3d1f38fa30
Merge pull request #45546 from skipkayhil/decaffeinate-ujs
Convert rails-ujs to ES2015 modules
2022-09-14 18:59:58 -04:00
Gannon McGibbon ab67599c47
Merge pull request #45999 from gmcgibbon/clarify_edge_option_doc
Clarify --edge points to latest stable branch of rails
2022-09-13 12:31:32 -05:00
Gannon McGibbon 5f97bd460e Clarify --edge points to latest stable branch of rails
The --edge option points or the latest stable branch of a release of
rails (eg. rails _7.1_ new my_app --edge would point to 7-1-stable).
When using a prerelease of Rails, main is used instead.
2022-09-13 12:00:56 -05:00
johnnyshields b7e809a96e Bundler should use platform :windows instead of :mingw, :mswin, :x64_mingw, :mswin64. This is a recently added feature to bundler/rubygems in v3.3.22. 2022-09-13 16:45:59 +09:00
Rafael Mendonça França 46bfabcfd4
Merge pull request #44547 from skipkayhil/fix-incorrect-assertions
fix remaining asserts that should be assert_equal
2022-09-12 20:32:42 -04:00
eileencodes 93ddf338a0
Move InternalMetadata to an independent object
Followup to #45908 to match the same behavior as SchemaMigration

Previously, InternalMetadata inherited from ActiveRecord::Base. This is
problematic for multiple databases and resulted in building the code in
AbstractAdapter that was previously there. Rather than hacking around
the fact that InternalMetadata inherits from Base, this PR makes
InternalMetadata an independent object. Then each connection can get it's
own InternalMetadata object. This change required defining the methods
that InternalMetadata was depending on ActiveRecord::Base for (ex
create!). I reimplemented only the methods called by the framework as
this class is no-doc's so it doesn't need to implement anything beyond
that. Now each connection gets it's own InternalMetadata object which
stores the connection.

This change also required adding a NullInternalMetadata class for cases
when we don't have a connection yet but still need to copy migrations
from the MigrationContext. Ultimately I think this is a little weird -
we need to do so much work to pick up a set of files? Maybe something to
explore in the future.

Aside from removing the hack we added back in #36439 this change will
enable my work to stop clobbering and depending directly on
Base.connection in the rake tasks. While working on this I discovered
that we always have a ActiveRecord::InternalMetadata because the
connection is always on Base in the rake tasks. This will free us up
to do less hacky stuff in the migrations and tasks.

Both schema migration and internal metadata are blockers to removing
`Base.connection` and `Base.establish_connection` from rake tasks, work
that is required to drop the reliance on `Base.connection` which will
enable more robust (and correct) sharding behavior in Rails..
2022-09-12 09:17:02 -04:00
Josef Šimánek b0fdca4fbc Rescue Rack::QueryParser::ParamsTooDeepError in HTTP request.
- render HTTP 400
- needs Rack 2.2.4+
2022-09-11 01:40:28 +02:00
Yasuo Honda df9ae739ed Ruby 3.2 `FileUtils.rm_f` raises `Errno::EISDIR` to remove directories
This commit addresses the following error.

```
% cd rails/railties
% rm ../Gemfile.lock
% bundle install
$ bin/test test/application/test_runner_test.rb -n test_load_fixtures_when_running_test_suites

E

Error:
ApplicationTests::TestRunnerTest#test_load_fixtures_when_running_test_suites:
Errno::EISDIR: Is a directory @ apply2files - test/models
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:2300:in `unlink'
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:2300:in `block in remove_file'
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:2305:in `platform_support'
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:2299:in `remove_file'
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:1449:in `remove_file'
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:1189:in `block in rm'
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:1188:in `each'
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:1188:in `rm'
    /home/yahonda/.rbenv/versions/3.2.0-preview2/lib/ruby/3.2.0+2/fileutils.rb:1211:in `rm_f'
    /home/yahonda/src/github.com/rails/rails/railties/test/application/test_runner_test.rb:254:in `block (2 levels) in test_load_fixtures_when_running_test_suites'
    /home/yahonda/src/github.com/rails/rails/railties/test/application/test_runner_test.rb:254:in `chdir'
    /home/yahonda/src/github.com/rails/rails/railties/test/application/test_runner_test.rb:254:in `block in test_load_fixtures_when_running_test_suites'
    /home/yahonda/src/github.com/rails/rails/railties/test/application/test_runner_test.rb:250:in `each'
    /home/yahonda/src/github.com/rails/rails/railties/test/application/test_runner_test.rb:250:in `test_load_fixtures_when_running_test_suites'

bin/test test/application/test_runner_test.rb:246

Finished in 2.319535s, 0.4311 runs/s, 0.8622 assertions/s.
1 runs, 2 assertions, 0 failures, 1 errors, 0 skips
$ ruby -v
ruby 3.2.0preview2 (2022-09-09 master 35cfc9a3bb) [x86_64-linux]
```

Fix #45983
2022-09-10 23:06:30 +09:00
Gannon McGibbon bd919163ed
Merge pull request #45974 from gmcgibbon/improve_plugin_generator_docs
Improve plugin generator docs
2022-09-09 22:40:45 -05:00
Hartley McGuire c62dcf54eb
fix remaining asserts that should be assert_equal
Found using Minitest/AssertWithExpectedArgument.

Also enabled the rule per feedback and fixed 29 additional violations
2022-09-09 19:22:21 -04:00
Gannon McGibbon a90cf09862 Improve plugin generator docs
- Explain what plugin means (it is either railtie or engine gem).
- Minor formatting changes
- Adds more examples with common options
2022-09-09 17:47:37 -05:00
Oscar Romero d80e619385
Corrected hyperlink address in help manual -h, -c option by removing the unnecessary bracket. (#45989)
* Corrected hyperlink address by removing the unneccesary bracket

* Update railties/lib/rails/generators/rails/app/app_generator.rb

This correction should work regardless of which hyperlink parser or terminal being used.

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

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2022-09-09 18:15:06 -04:00
Rafael Mendonça França cbf4290f0e
Merge pull request #45987 from igorkasyanchuk/main
Added ability to download `.eml` file for the email preview.
2022-09-09 17:39:59 -04:00
Igor Kasyanchuk 9f0a064fde
Added ability to download `.eml` file for the email preview. 2022-09-10 00:05:32 +03:00
Gannon McGibbon ed81896765
Merge pull request #45973 from gmcgibbon/improve_app_generator_docs
Improve app generator docs
2022-09-09 16:03:38 -05:00
Kevin Newton 514ef0b8a5
Extract annotations using a parser for Ruby files
When you're looking for annotations, it's possible (albeit extremely unlikely) for it to pick up things that aren't comments (see the added test for an example). If we instead use a parser like ripper, we can filter down to just the comments and only try to extract the annotations from the source file's comments.
2022-09-09 15:46:54 -04:00
Rafael Mendonça França dbe0c342ea
Merge pull request #45979 from deivid-rodriguez/support-prerelease-rubies-in-ruby-gemfile-dsl
Support prerelease rubies in Gemfile template
2022-09-09 15:44:19 -04:00
Eileen M. Uchitelle 923eefd773
Merge pull request #45955 from gjtorikian/patch-1
Fix grammatical issue
2022-09-09 13:49:43 -04:00
Garen Torikian fa2242a7ee
Fix grammatical issue 2022-09-09 10:35:36 -07:00
Gannon McGibbon 739bfa9ace Improve app generator docs
- Minor formatting changes
- Adds more examples with common options
2022-09-09 11:35:59 -05:00
Gannon McGibbon 2b42bbc8a2
Merge pull request #45975 from gmcgibbon/application_record_generator_usage
Delegate application record generator description to orm hooked generator.
2022-09-09 12:32:31 -04:00
Eileen M. Uchitelle 063db854bb
Merge pull request #45908 from rails/redo-schema-migration
Move SchemaMigration to an independent object
2022-09-09 10:18:01 -04:00
David Rodríguez 10b95e2008
Support prerelease rubies in Gemfile template
Recent Bundler version have fixed version matching of the `ruby` Gemfile
DSL and now prereleases like `Ruby 3.2.0.preview2` will no longer match
Gemfiles specifying exact constraints like `ruby "3.2.0"`.

For the default Gemfile to support prerelease rubies, it needs to use
an exact constraint that considers prereleases, for example, with
`Gem.ruby_version`. Alternatively, the requirement could be relaxed, but
I believe the intention here is to restrict the Gemfile to the exact
Ruby version generating it.
2022-09-09 12:26:56 +02:00
Gannon McGibbon f54cbe1f4a Delegate application record generator description to orm hooked generator. 2022-09-08 18:19:51 -05:00
Rafael Mendonça França bf1fe42918
Add regression test for broken filter
In 7690290, the filter was not finding the end of the methods defined
using the `test do` syntax. This would cause more than 1 test to be
selected depending on the line number passed as argument.

The previous test wasn't failing because the two tests asked to run
where one after the other and the filter, even broken would only
run those two tests. By changing the test definition order we trigger
the bug introduced by that commit.
2022-09-08 21:09:53 +00:00
Rafael Mendonça França ff9739217d
Revert "Replace `method_source` gem with stdlib equivalent" 2022-09-08 16:58:52 -04:00
Jonathan Hefner bee6167977
Merge pull request #45935 from the-spectator/add_bcc_to_mailer_preview
Show BCC field in mailer preview
2022-09-08 12:00:26 -05:00
eileencodes 436277da88
Move SchemaMigration to an independent object
Previously, SchemaMigration inherited from ActiveRecord::Base. This is
problematic for multiple databases and resulted in building the code in
AbstractAdapter that was previously there. Rather than hacking around
the fact that SchemaMigration inherits from Base, this PR makes
SchemaMigration an independent object. Then each connection can get it's
own SchemaMigration object. This change required defining the methods
that SchemaMigration was depending on ActiveRecord::Base for (ex
create!). I reimplemented only the methods called by the framework as
this class is no-doc's so it doesn't need to implement anything beyond
that. Now each connection gets it's own SchemaMigration object which
stores the connection. I also decided to update the method names (create
-> create_version, delete_by -> delete_version, delete_all ->
delete_all_versions) to be more explicit.

This change also required adding a NullSchemaMigraiton class for cases
when we don't have a connection yet but still need to copy migrations
from the MigrationContext. Ultimately I think this is a little weird -
we need to do so much work to pick up a set of files? Maybe something to
explore in the future.

Aside from removing the hack we added back in #36439 this change will
enable my work to stop clobbering and depending directly on
Base.connection in the rake tasks. While working on this I discovered
that we always have a `ActiveRecord::SchemaMigration` because the
connection is always on `Base` in the rake tasks. This will free us up
to do less hacky stuff in the migrations and tasks.
2022-09-08 11:32:32 -04:00
Koichi ITO eeeb0b1b7a Enable `Minitest/AssertRaisesWithRegexpArgument` cop
This PR enables `Minitest/AssertRaisesWithRegexpArgument` cop
and it suppresses the new warning below.

```console
% bundle exec rubocop
(snip)

Offenses:

activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb:111:9: C: Minitest/AssertRaisesWithRegexpArgument:
Do not pass regular expression literals to assert_raises. Test the resulting exception.
assert_raises(ActiveRecord::StatementInvalid, /TypeError/) do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb:628:9: C: Minitest/AssertRaisesWithRegexpArgument:
Do not pass regular expression literals to assert_raises. Test the resulting exception.
assert_raises(ActiveRecord::StatementInvalid, /SQLite3::ReadOnlyException/) do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
railties/test/application/rake/multi_dbs_test.rb:307:13: C: Minitest/AssertRaisesWithRegexpArgument:
Do not pass regular expression literals to assert_raises. Test the resulting exception.
assert_raises RuntimeError, /You're using a multiple database application/ do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
railties/test/application/rake/multi_dbs_test.rb:311:13: C: Minitest/AssertRaisesWithRegexpArgument:
Do not pass regular expression literals to assert_raises. Test the resulting exception.
assert_raises RuntimeError, /You're using a multiple database application/ do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
railties/test/application/rake/multi_dbs_test.rb:336:13: C: Minitest/AssertRaisesWithRegexpArgument:
Do not pass regular expression literals to assert_raises. Test the resulting exception.
assert_raises RuntimeError, /You're using a multiple database application/ do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
railties/test/application/rake/multi_dbs_test.rb:361:13: C: Minitest/AssertRaisesWithRegexpArgument:
Do not pass regular expression literals to assert_raises. Test the resulting exception.
assert_raises RuntimeError, /You're using a multiple database application/ do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

The last argument of `assert_raises` is a custom message string to help explain failures.
So, it's not the argument that `exception.message` is compared to.
`assert_raises` returns a raised exception and can be used to match against a regular expression.

And it updates the dependency version of rubocop-minitest in the Gemfile.
Because `Minitest/AssertRaisesWithRegexpArgument` cop was introduced in minitest 0.22.
https://github.com/rubocop/rubocop-minitest/releases/tag/v0.22.0
2022-09-08 17:44:40 +09:00
Akshay Birajdar f44362b140 Show BCC recipients in mailer preview 2022-09-08 11:36:45 +05:30
Jonathan Hefner 9a439f6332
Merge pull request #45938 from ttanimichi/patch-2
The description of `--api` option doesn't make sense
2022-09-05 17:26:09 -05:00
Tsukuru Tanimichi f0b087efb0 Clarify description of --api option
"Indicates when to generate api" doesn't make sense:

```
$ bin/rails g scaffold | grep api
      [--api], [--no-api]                                    # Indicates when to generate api
```

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-09-05 16:55:36 -05:00
Tsukuru Tanimichi 3ee754e102 Clarify description of --force-plural option
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-09-05 16:34:42 -05:00
Jean Boussier e4c237e014 Add missing documentation for Rails.error
The functionality itself is documented, but not the accessor
2022-09-02 09:15:58 +02:00
Trevor Turk 0ae0ab7e3f Add raise_on_invalid_cache_expiration_time config to ActiveSupport::Cache::Store 2022-08-30 10:10:28 -05:00
Carl Brasic 7690290068 Replace `method_source` gem with stdlib equivalent
The `method_source` gem was added in
https://github.com/rails/rails/pull/19216. It was used to determine the
last line number of a given test method to support running tests by line
number. But this is not something that requires an external dependency:
Ripper can do this easily, and it has the added advantage of not using
repeated calls to `eval` to do it.

Drop `method_source` and replace it with a simple handler for Ripper's
`on_def` parser event.

I don't believe that there are any mainstream rubies at this point that
can run Rails and don't support Ripper but correct me if I'm wrong.
2022-08-30 08:52:11 -05:00
Rafael Mendonça França eb0e8807b7
Revert "Remove `Rails::Application` `assets` accessor" 2022-08-28 19:06:39 -04:00
fatkodima 3158bbb9f6 Update `rubocop-performance` and enable more performance-related cops 2022-08-26 15:07:11 +03:00
Orhan Toy 930e36f10b Extend `routes --grep` to also filter routes by matching against path 2022-08-25 08:33:51 +00:00
Eileen M. Uchitelle 61733bde03
Merge pull request #45875 from tekin/rails-runner-spots-missing-files
Better rails runner output for missing files
2022-08-24 09:38:43 -04:00
Étienne Barrié 73d96c4947 Remove Rails::Application#assets accessor
It was used to store a Sprockets::Environment in
3e7985c9c1 but then it ended up being
monkey-patched from sprockets-rails in
78519dca00
2022-08-24 11:07:30 +02:00
Yusuke Endoh 3beb2aff3b Use error_highlight gem to locate the columns where an error was raised
This change incorporates to Rails a feature called error_highlight that
has been available since Ruby 3.1. This allow Rails' error report screen
to display the fine-grained location where an error occurred (not only a
line number but also beginning and end column numbers of the code
fragment).

For ErrorHighlight, see https://bugs.ruby-lang.org/issues/17930 in
detail.

To use error_highlight, ExceptionWrapper now prefers
`Exception#backtrace_locations` (since Ruby 2.1), which returns an array
of `Thread::Backtrace::Location`s, instead of `Exception#backtrace`.
This is because error_highlight requires `Thread::Backtrace::Location`
to locate the column where an error was raised.

Co-Authored-By: John Hawthorn <john@hawthorn.email>
Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
2022-08-24 00:28:50 +09:00
Tekin Süleyman 7088003d19
Better rails runner output for missing files
This updates The Rails runner command to give a more helpful error
message when given a path as input but the file does not exist.

Instead of the cryptic "undefined local variable or method" the user is
told that the file could not be found.

I've gone for the simplest approach I could think of to identify when
the input is likely a file path: it ends with `".rb"`. This isn't a
perfect approach – there's nothing stopping someone passing a script
without an extension, and it's also possible to have valid Ruby syntax
that ends in `".rb" – but it does feel "good enough" and will make the
Rails runner slightly more user-friendly for those working with file
paths without negatively impacting those that are passing in Ruby
code.
2022-08-23 17:06:19 +02:00
Jean Boussier bc4c3ef969 Replace MutexHook by MonitorHook to allow reentrancy
Ref: https://github.com/rails/rails/pull/43550

If `executor_around_test_case` is enabled, all hooks must be
reentrant. However `allow_concurrency = false` register a
`MutexHook` that isn't reentrant.

So this commit replace it by a `Monitor` which does allow
reentrancy.
2022-08-19 13:18:26 +02:00
John Hawthorn 85db5be358 Fix "unmarshalable" test for minitest 5.16.3 2022-08-18 09:47:50 -07:00
eileencodes 2efb06d1dd
Define and raise error if `legacy_connection_handling=` is called from an app
I deprecated `legacy_connection_handling` setter in 7.0 but then removed
it without setting it to false by default upgraded apps might have this
set to false in their config and still be getting an error. This
confusing behavior came up with one of our apps at work.

To make it less confusing I've redefined `legacy_connection_handling`
setter and am raising an argument error if called. I didn't redefine the
getter because that shouldn't be in a config, it's not useful in that
context.
2022-08-16 16:28:00 -04:00
Jonathan Hefner 542d3f11fe Improve use_big_decimal_serializer documentation
Follow-up to #45618.

This fixes a few typos and clarifies the wording.
2022-08-10 12:45:52 -05:00
Jonathan Hefner 95fa021465
Merge pull request #45719 from bensheldon/subpath_engine_route_helpers
Allow Mounted Engine url_helpers to use config.relative_url_root
2022-08-09 14:49:39 -05:00
Rafael Mendonça França 95066e5fbd
Merge pull request #31595 from fatkodima/mailer-preview_paths
Support multiple preview paths for mailers
2022-08-09 16:20:18 -03:00