Commit Graph

13532 Commits

Author SHA1 Message Date
Rafael França 890035fd4a
Merge pull request #40365 from ankurp/fix/standardize-js-package-name
Follow npm/JS standard for package name
2020-11-02 15:29:41 -05:00
Eugene Kenny 67e69e8db4
Merge pull request #38829 from cbisnett/host_authorization_exclude
Add request exclusion to Host Authorization
2020-11-02 20:22:35 +00:00
Rafael França 5f40eca4a5
Merge pull request #39832 from p8/scaffold-generator-inflection-check
Raise if camelcase inflection impossible in generator
2020-11-02 15:18:26 -05:00
Chris Bisnett 1f767407cb Add request exclusion to Host Authorization
In the same way that requests may need to be excluded from forced SSL,
requests may also need to be excluded from the Host Authorization
checks. By providing this additional flexibility more applications
will be able to enable Host Authorization while excluding requests
that may not conform. For example, AWS Classic Load Balancers don't
provide a Host header and cannot be configured to send one. This means
that Host Authorization must be disabled to use the health check
provided by the load balancer. This change will allow an application
to exclude the health check requests from the Host Authorization
requirements.

I've modified the `ActionDispatch::HostAuthorization` middleware to
accept arguments in a similar way to `ActionDispatch::SSL`. The hosts
configuration setting still exists separately as does the
hosts_response_app but I've tried to group the Host Authorization
settings like the ssl_options. It may make sense to deprecate the
global hosts_response_app if it's only used as part of the Host
Authorization failure response. I've also updated the existing tests
as the method signature changed and added new tests to verify the
exclusion functionality.
2020-11-02 20:16:29 +00:00
Eugene Kenny 56c9be11ad Tidy up comments in environment configuration files [ci skip]
https://guides.rubyonrails.org/api_documentation_guidelines.html#wording
2020-11-02 19:51:58 +00:00
Eugene Kenny b7eaaf73fb Update comment about reloading in development.rb [ci skip]
This comment predates the existence of `reload_classes_only_on_change`.
2020-11-02 19:36:26 +00:00
Edouard Chin 868866c1fd
Allow a new `server` Railtie block:
- This is similar to other railties blocks (such as `console`,
  `tasks` ...). The goal of this block is to allow the application
  or a railtie to load code after the server start.

  The use case can be to fire the webpack or react server in
  development or start some job worker like sidekiq or resque.

  Right now, all these tasks needs to be done in a separate
  shell and gem maintainer needs to add documentation on
  how to run their libraries if another program needs to run
  next to the Rails server.

  This feature can be used like this:

  ```ruby
    class SuperRailtie < Rails::Railtie
      server do
        WebpackServer.run
      end
    end
  ```
2020-11-02 18:11:41 +00:00
Rafael França d52ece70f0
Merge pull request #40492 from nateberkopec/puma5
Upgrade Puma to 5.x
2020-11-02 12:48:32 -05:00
Jonathan Hefner b38c2c1a84 Tweak generated default filter_parameters
Follow-up to #34218.

This removes some filters that could filter innocuous fields such as
`author_name`.  Filtering such fields might be surprising, especially to
people generating their first Rails app.

This commit also changes the `:password` filter to `:passw` so that it
can also filter fields such as `passwd`.
2020-11-02 10:12:32 -06:00
Nate Berkopec b8af0fd2d7
Upgrade Puma to 5.x 2020-11-01 14:50:27 -07:00
Eugene Kenny a484bd807e Avoid chdir error in bin/setup test on Ruby master
Followup to ae5ecfe26c.

`db:drop` was failing, but the test passed due to `allow_failure: true`.
2020-11-01 16:58:22 +00:00
Rafael Mendonça França 80f7fd52b2
Remove frozen_string_literal from generated file 2020-10-30 00:45:22 +00:00
Rafael França e68d39f455
Merge pull request #39746 from jonathanhefner/springy-boot
Check environment before loading Spring in boot.rb
2020-10-29 20:44:45 -04:00
Arlston Fernandes 2711dcc9a6
Customise the header name for `ActionDispatch::RequestId`
by setting `config.action_dispatch.request_id_header` to the desired value

* Ensure HTTP_X_REQUEST_ID presence to maintain compatiblility

* Use req.headers[] to fetch header rather than ENV methods

* Update configuration doc to match existing descriptions

* Add changelog entry for action_dispatch.request_id_header
2020-10-30 00:31:09 +00:00
Rafael Mendonça França 576fb33ba3
Remove unneeded requires 2020-10-30 00:26:11 +00:00
Rafael Mendonça França 3c18a0cca8
Remove deprecated required option on the model generators 2020-10-30 00:26:10 +00:00
Rafael Mendonça França 8992a7d0c2
Remove deprecated `rake initializers` tasks 2020-10-30 00:26:09 +00:00
Rafael Mendonça França e152f83c64
Remove deprecated `rake routes` tasks 2020-10-30 00:26:08 +00:00
Rafael Mendonça França 01f0020a55
Remove deprecated `rake dev:cache` tasks 2020-10-30 00:26:08 +00:00
Rafael Mendonça França c0728ad321
Remove deprecated support for using the `HOST` environment variable to specify the server IP 2020-10-30 00:26:07 +00:00
Rafael Mendonça França 5a7028a1a5
Remove deprecated `server` argument from the rails server command 2020-10-30 00:26:06 +00:00
Rafael Mendonça França 6204651412
Remove deprecated `SOURCE_ANNOTATION_DIRECTORIES` ENV 2020-10-30 00:26:06 +00:00
Rafael Mendonça França 8513769ad6
Remove deprecated `connection` option in the `rails dbconsole` command 2020-10-30 00:26:05 +00:00
Rafael Mendonça França 227d04f46a
Remove depreated `rake notes` tasks 2020-10-30 00:26:04 +00:00
Rafael Mendonça França 4bd56f4428
Remove deprecated fallback to `I18n.default_local` when `config.i18n.fallbacks` is empty 2020-10-30 00:25:50 +00:00
Rafael Mendonça França 64efe502f3
Change `ActionDispatch::Response#content_type` to return the full Content-Type header
And deprecate the config to keep the previous behavior.
2020-10-30 00:25:49 +00:00
Rafael Mendonça França fd24cf1c5d
Return `false` when enqueuing a job is aborted 2020-10-30 00:25:31 +00:00
Rafael Mendonça França 71ddfd78d4
Remove deprecated finalize_compiled_template_methods 2020-10-30 00:25:16 +00:00
Eugene Kenny 12ce3e7723
Merge pull request #40478 from eugeneius/undeprecate_use_sha1_digests
Improve config.active_support.use_sha1_digests deprecation message
2020-10-30 00:10:29 +00:00
Omri Gabay 43d83e96c9
Add option to mute multiple database yaml warning
Adds an option to silence the warning that database configurations can
throw when it's unparsable.
2020-10-29 16:57:57 -04:00
Eugene Kenny a03a2c4188 Improve use_sha1_digests deprecation message
We now provide the full setting that maintains the existing behaviour.
2020-10-29 18:46:21 +00:00
eileencodes 31461d8a79
Implement granular role and shard swapping
This change allows for a connection to be swapped on role or shard for a
class. Previously calling `connected_to` would swap all the connections
to a particular role or shard. Granular connection swapping is useful
for swapping one connection to reading while leaving all other
connection classes on writing.

The public methods on connection handler have been updated to behave the
same as they did previously on the different handlers. The difference
however is instead of calling
`ActiveRecord::Base.connection_handlers[:reading].clear_all_connections!`
you now call
`ActiveRecord::Base.connection_handler.clear_all_connections!` which
will clear based on current role set by a `connected_to` block. Outside
the context of a `connected_to` block, `clear_all_connections!` can take
an optional parameter to clear specific connections by role.

The major changes in this PR are:

* We introduced a `legacy_connection_handling` configuration option that
is set to true by default. It will be set to `false` for all new
applications.
* In the new connection handling there will be one only connection
handler. Previously there was a connection handler for each role. Now
the role is stored in the `PoolManager`. In order to maintain backwards
compatibility we introduced a `LegacyPoolManager` to avoid duplicate
conditionals. See diagram in PR body for changes to connection
management.
* `connected_to` will now use a stacked concurrent map to keep track of
the connection for each class. For each opened block the `class`,
`role`, and `shard` will be added to the stack, when the block is exited
the `class`, `role`, `shard` array will be removed from the stack.
* With these changes `ActiveRecord::Base.connected_to` will remain
global. If called all connections in the block will use the `role` and
`shard` that was switched to. If called with a parent class like
`AnimalsRecord.connected_to` only models under `AnimalsRecord` will be
switched and everything else will remain the same.

Examples:

Given an application we have a `User` model that inherits from
`ApplicationRecord` and a `Dog` model that inherits from
`AnimalsRecord`. `AnimalsRecord` and `ApplicationRecord` have writing
and reading connections as well as shard `default`, `one`, and `two`.

```ruby
ActiveRecord::Base.connected_to(role: :reading) do
  User.first # reads from default replica
  Dog.first # reads from default replica

  AnimalsRecord.connected_to(role: :writing, shard: :one) do
    User.first # reads from default replica
    Dog.first # reads from shard one primary
  end

  User.first # reads from default replica
  Dog.first # reads from default replica

  ApplicationRecord.connected_to(role: :writing, shard: :two) do
    User.first # reads from shard two primary
    Dog.first # reads from default replica
  end
end
```

Things this PR does not solve:

* Currently there is no API for swapping more than one but not all
connections. Apps with many primaries may want to swap 3 but not all 10
connections. We plan to build an API for that in a followup PR.
* The middleware remains the same and is using the global switching
methods. Therefore at this time to use this new feature applications
must manually switch connections. We will also address this in a
followup PR.
* The `schema_cache` is currently on the `PoolConfig`. We plan on trying
to move this up to the `PoolManager` or elsewhere later on so each
`PoolConfig` doesn't need to hold a reference to the `schema_cache`.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-10-28 15:11:35 -04:00
Eugene Kenny 9d1f3b7d52 Fix a typo in new_framework_defaults_6_1.rb 2020-10-27 23:44:58 +00:00
Ryuta Kamizono 154ee7b4b0 Revert "Don't enable Zeitwerk on MRI in 6.1 load_defaults"
This reverts commit 379db92364.

Reason: 94ba417ece (r41923157)
2020-10-25 15:51:36 +09:00
Eugene Kenny 379db92364 Don't enable Zeitwerk on MRI in 6.1 load_defaults
It's already handled by loading the 6.0 defaults two lines up.
2020-10-24 02:14:58 +01:00
Loren Norman 1f9a5dd36b fix broken handling of unknown http methods 2020-10-23 23:34:58 +01:00
Jonathan Hefner 72d10e218b Check environment before loading Spring in boot.rb
In #39632, `boot.rb` was changed to load `bin/spring`, with the
intention of adding a check to Spring itself that would prevent Spring
from running in production environments.  However, in a production
environment, the Spring gem may not be installed.  Furthermore,
`bin/spring` may raise an error other than `LoadError` if it has been
overwritten by e.g. `bundle binstubs` as part of the deployment process.
Therefore, this commit adds the environment check to `boot.rb`.

This commit also changes the app generator to generate `bin/spring`
directly, instead of delegating to `bundle exec spring binstub`.  This
addresses an issue with the `--skip-bundle` flag.  Previously,
`--skip-bundle` caused `bin/spring` to not be generated. Thus the user
had to manually run `bundle exec spring binstub` later, though that was
not documented nor explained.  Now, `bin/spring` is always generated.
Additionally, by guaranteeing that `bin/stub` is generated, we avoid the
need for `rescue LoadError` in `boot.rb`.
2020-10-22 12:25:06 -05:00
Jonathan Hefner b653778169 Rewrite test_spring_no_fork
The previous version of the test was fragile, and it skipped running on
JRuby even though its purpose is to test environments like JRuby.
2020-10-22 09:41:52 -05:00
Jonathan Hefner 20e8314273 Rewrite test_after_bundle_callback
The previous version of the test was fragile due to over-specificity.
2020-10-22 09:41:52 -05:00
Nick Wolf 7cc2b57b8d
Refactor railsrc file location to be xdg compliant (#39411)
* Refactor railsrc file location to be xdg compliant

The XDG Base Directory Specification (which is currently used by
FOSS projects such as Git, Tmux, Pry, Rspec) provides a default
location for various file formats, including config/rc files.

This comment refactors app_generator.rb to load railsrc from
XDG_CONFIG_HOME if both XDG_CONFIG_HOME is set and rails/railrc
exists within the XDG_CONFIG_HOME location.

To maintain backwards compatibility it defaults back to ~/.railsrc
if either XDG_CONFIG_HOME is not set or there is no rails/railsrc.

* Refactor default_rc_file based on jonathanhefner PR feedback

* Update generators/rails/app/USAGE to explain railsrc XDG compliance

* Refactor default_rc_file based on sinsoku PR feedback

* Add test for ARGVScrubber.default_rc_file method

fileutils is required because tmpdir does not allow you to create a new
temp directory with a set title 'inside' another temporary directory, a
file is created for railsrc because tempfile creates a custom and unique
name preventing the specification of a file called 'railsrc'

Currently this test is failing because the ARGVScrubber class seems to
be loading directly from the gem (which still has the previous code)
rather than from the file itself. (loading the code in a pry session
and using show-method ARGVScrubber.default_rc_file reveals it is coming
from
gems/railties-6.0.3.3/lib/rails/generators/rails/app/app_generator.rb:536
instead of
railties/lib/rails/generators/rails/app/app_generator.rb

* Switch to double quote strings

* Add file deletion for argv_scrubber test

* Refactor test_xdg_config_no_custom_rc with jonathanhefner feedback

* Add Changelog for railsrc xdg-specification compliance

* Apply backtick and whitespace refactoring suggestsions from jonathanhefner

* Apply jonathanhefner suggested Changelog refactoring

[Rafael Mendonça França + Nick Wolf + Jonathan Hefner]
2020-10-21 01:21:07 -04:00
Ankur Patel e22bcc2409 Follow npm/JS standard for package name
Currently when a new rails app is created it uses the app name as it and puts
it in the package.json name. According to npm and JS standards package names
do not have capital letters and should not be using the PascalCase that is
used in Rails app name. This change is to convert app name to using snake case
but with dashes
2020-10-11 07:42:01 -04:00
Rafael França 9492339979
Merge pull request #38443 from jonathanhefner/plugin-fix-stack-traces
Fix stack traces when testing plugins
2020-10-08 19:06:40 -04:00
Jonathan Hefner 33fdae0584 Fix backtraces for generated plugin tests
`Minitest.plugin_rails_init` sets `Minitest.backtrace_filter` to
`Rails.backtrace_cleaner` right before tests are run, overwriting the
value set in test_helper.rb.

`Rails.backtrace_cleaner` silences backtrace lines that do not start
with `Rails.root` followed by e.g. "lib/" or "test/".  Thus when
`Rails.root` is a subdirectory of the project directory -- for example,
when testing a plugin that has a dummy app -- all lines of the backtrace
are silenced.

This commit adds a fallback such that when all backtrace lines are
silenced, the original `Minitest.backtrace_filter` is used instead.

Additionally, this commit refactors and expands existing test coverage.
2020-10-07 15:40:56 -05:00
Eugene Kenny 81317b077a Fix pending migration actionable error test
Since ddcca86f0e, omitting the location
parameter causes the actionable error request to fail.
2020-10-07 20:17:02 +01:00
Akira Matsuda c01aace309 If it respond_to a method, the method should be public_sendable 2020-10-07 11:25:26 +09:00
Akira Matsuda 6c5e07a462 Both update_config_files and update_bin_files are public methods 2020-10-07 11:25:26 +09:00
Akira Matsuda 0bfa02aba3 This kind of wrapper should better not be able to call private methods 2020-10-07 11:12:02 +09:00
Akira Matsuda a412e4da64 Get rid of unnecessary meta programming
Each stacked operation is a Proc object instead of operation name since fedde239dc,
and so we can now simply inline the target method for each operation
2020-10-07 11:12:02 +09:00
Akira Matsuda 87dfa8617c attr_reader methods are public methods 2020-10-07 11:12:01 +09:00
Rafael Mendonça França 0c8df42b50
Decorate Rails' backtrace cleaner before passing to minitest
The minitest database cleaner never returns empty traces so we need to
make sure ours also have the same behavior before passing to minitest.
2020-10-07 00:28:02 +00:00