Commit Graph

13701 Commits

Author SHA1 Message Date
Tahsin Hasan
cbbaf9c19f Add support for sqlcmd instead of sqsh on sql server 2020-11-13 00:01:19 +06:00
Joel Hawksley
7cdf4020a6 Add support for stylesheets and ERB views to rails stats. 2020-11-10 09:40:18 -07:00
Jonathan Hefner
9e16bb274a Update listen gem to v3.3
Version 3.3 fixes memory leaks that occur when stopping individual
listeners (see guard/listen#476).
2020-11-10 10:06:48 -06:00
Gannon McGibbon
47a4201d8d
Merge pull request #39980 from gmcgibbon/route_append_order
Append development routes after reload hook
2020-11-09 18:19:26 -05:00
Gannon McGibbon
91247a02c6 Append development routes after reload hook
Allow appended root routes to take precedence over internal
welcome controller.
2020-11-09 18:01:50 -05:00
Haroon Ahmed
93f0cebd1d Display exception messages using simple_format for a better and clearer
exception message.
2020-11-09 21:48:24 +00:00
Eugene Kenny
bcb63fcaa8 Restore deprecation require in dbconsole command
This require was removed in 576fb33ba3c1cf0a0c3e83ffac56c46a83d7a57f,
after 8513769ad60f68d084e487550162b9d3766aea77 removed the deprecation
that originally added it in 29b16d3ff87a3da4ec4ac33a17ad9fd9540284c8.

In between however, 0983daa4aa5f6bec96254af907b9956b804faddc added
another deprecation to this file, so the require is still necessary.

Fixes #40575.
2020-11-08 19:38:43 +00:00
Jonathan Hefner
949e4587d5 Allow missing Action Cable config
Since #37850, `config_for` returns `nil` instead of an empty Hash when
a config file does not contain configuration for the specified
environment.  Thus, the return value should be converted to a Hash
before calling `with_indifferent_access`.

Fixes #40548.
2020-11-06 11:45:51 -06:00
Juan Manuel Ramallo
b43ede6b9d Increasing Puma's worker timeout in development
After Puma's version 5, a worker timeout check was added, causing all
debugging sessions (byebug, binding.irb, ...) to be terminated after a
minute is passed.

One minute timeout is fine for production environments but not for
development, when we usually debug stuff and need more than a minute to
do so.

This PR updates Puma's config template file to include a worker timeout
of one hour, only for development environments.
2020-11-06 12:57:17 -03:00
Xavier Noria
a17c5ff559
Merge pull request #34985 from schuetzm/add-note-about-application-config
Clarify that some configuration still needs to happen in config/appli…
2020-11-05 17:48:58 +01:00
stephannv
073e522578 Fix web-console version for Rails 6.1 2020-11-05 10:06:27 -03:00
Jonathan Hefner
acc837e91a Move Spring machinery back to bin files
Follow-up to #39746.

This shifts the responsibility of loading Spring from `config/boot.rb`
back to the relevant bin files.

Fixes #40518.
Closes #40521.
2020-11-03 16:35:40 -06:00
Rafael Mendonça França
8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
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 ae5ecfe26c8fdc194d5b3cd16fd13b64574bcfd3.

`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
Marc Schütz
f955cb8a66 Clarify that some configuration still needs to happen in config/application.rb [ci skip] 2020-10-27 16:48:06 +01:00
Ryuta Kamizono
154ee7b4b0 Revert "Don't enable Zeitwerk on MRI in 6.1 load_defaults"
This reverts commit 379db92364c4c212ac22a20dac72cd502156710d.

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 ddcca86f0ed5064140924c88cc5ad556d5ce32d4, 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 fedde239dcee256b417dc9bcfe5fef603bf0d952,
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
Eugene Kenny
ae5ecfe26c Avoid chdir error in Railties tests on Ruby master
5d7953f86b
https://buildkite.com/rails/rails/builds/71925#9839c015-e562-4145-932c-75b9c118bfca/1043-1055
2020-10-04 00:26:03 +01:00
Rodrigo Ramírez Norambuena
3b9f5e3f4b Remove add_gem_entry_filter from GeneratorAppBase:
The add_gem_entry_filter was introduce in
f7e0758714e645865361b5566253d3e7d896beff and doesn't work this
feature
2020-09-29 16:49:17 -03:00
Rodrigo Ramírez Norambuena
bb69d1967f Remove gemfile_entry from GeneratorAppBase:
This private method is not in used. It's introduced in 3f2230b but at the
moment there not sense to keeping this code.
2020-09-29 16:36:04 -03:00
George Claghorn
a50d2f1993 Extract ActiveStorage::Record
Permit applications to hack in custom DB config for ASt models until ASt has first-class multi-DB support:

    ActiveSupport.on_load(:active_storage_record) do
      connects_to reading: :active_storage_replica, writing: :active_storage_primary
    end

rebase
2020-09-29 11:59:14 -04:00
Rafael França
397bfb0e83
Merge pull request #40157 from adrianna-chang-shopify/dependent-destroy-async
Offer dependent: :destroy_async for associations
2020-09-25 14:50:51 -04:00
George Claghorn
4cf7559280 Destroy associations in a background job.
Sometimes cascading association deletions can cause timeouts due to
an IO issue. Perhaps a model has associations that are destroyed on
deletion which in turn trigger other deletions and this can continue
down a complex tree. Along this tree you may also hit other IO
operations. Such deep deletions can lead to server timeouts while
awaiting completion and really the user may not notice all the
changes on their side immediately making them wait unnecesarially or
worse causing a timeout during the operation.

We now allow associations supporting the `dependent:` key to take `:destroy_async`,
which schedules a background job to destroy associations.

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
Co-authored-by: Cory Gwin @gwincr11 <gwincr11@github.com>
2020-09-24 14:24:15 -04:00
Rafael França
e3bc380f0c
Merge pull request #39661 from hahmed/railties/faster-app-generator-test-for-load-defaults
Make the test AppGeneratorTest#test_new_application_load_defaults faster
2020-09-24 12:10:28 -04:00
Eileen M. Uchitelle
5abe09bba7
Merge pull request #40213 from dbussink/allow-setting-digest-class
Add an ActiveSupport option to allow setting a digest class
2020-09-23 12:09:27 -04:00
Dirkjan Bussink
0f6c9bc786
Add an ActiveSupport option to allow setting a digest class
Right now it's already possible to set a digest class manually, but this
is not through a publicly supported and approved API. With these
configuration options, it is possible to configure a digest class to use
for digests inside Rails.

The reason for this is that it allows configuring other classes in
certain conditions like running in FIPS mode. FIPS disallows MD5 and
discourages SHA1. Even though this isn't used in Rails for security
related things, using newer hash algorithms means not having to explain
it to auditors which always makes life easier.

That's not the only reason though. If today Ruby is built and running
for example in an Ubuntu 18.04 FIPS approved environment, the default
Digest classes break, see https://bugs.ruby-lang.org/issues/13681 as
well.

By allowing a class to be configured, the following can be used so that
things work properly (using the new API proposed here):

```
Rails.application.config.active_support.hash_digest_class = OpenSSL::Digest::SHA256
```

This would then use the OpenSSL certified FIPS implementation as well.
2020-09-23 17:47:35 +02:00
Kevin Deisz
da39688e26
Create a gitattributes file for templated apps
.gitattributes files are a useful way to mark certain metadata about paths in a git repository (https://git-scm.com/docs/gitattributes). This can include all kinds of information, but one of the more useful ones is that linguist (https://github.com/github/linguist, the tool that powers the language statistics/diff view of GitHub) respects certain attributes. For example:

* `linguist-vendored` paths will not be counted toward the language statistics
* `linguist-generated` paths will not have their diff shown by default

These little niceties can be really helpful over time, so we should add it to the default app generator.
2020-09-23 10:24:27 -04:00
Paul Keen
133805f1f9 Uncomment bin/yarn in bin/setup for webpacker by default
By adding installing of webpacker, `bin/setup` requires manual update in order to do cold setup. This adds extra steps to generate app and setup it.
2020-09-22 22:01:40 +03:00
Paul Keen
e1b24b04bf Restores environments before testing their settings 2020-09-22 21:43:27 +03:00
Rafael Mendonça França
7307994011
Make sure log level in development is debug
Laso make sure the tests are actually checking the log level of the app,
not the one we set in the test helper.
2020-09-22 16:12:38 +00:00
Eric Payne
229fd2a02f
Change the default log level from :debug to :info
I recently learned that Rails logs at the :debug level (not the :info
level) by default in production environments. This is a surprising
behaviour, as other popular frameworks do not log at this level
by default. It would not be surprising if a developer accidentally
logged personally identifiable information (PII) in a production
environment due to this behaviour.

I noticed that [in 2014](https://github.com/rails/rails/pull/16622), the
Rails project made an intentional decision to set the default log level
to :debug. However, the landscape around logging PII has changed since
then with the introduction of legislation like GDPR, so I thought it
prudent to reopen this discussion.
2020-09-22 15:04:44 +00:00
Rafael França
c342df62ec
Merge pull request #40119 from Shopify/rescue-db-errors-during-eager-load
Rescue Database errors during active_record.define_attribute_methods
2020-09-22 10:21:59 -04:00
Ryuta Kamizono
c848baffd2 ✂️ [ci skip]
895134bcff (diff-7789e18ec0a61c6845755a257e6eb34fR3)
ee9e308f68 (diff-5e9551294914b338d923032fa904c6beR103)
5f63c771f7 (diff-600d5368b55e46ed961abb4295977ac3R506)
48b6bacbc5 (diff-279ac5c088a3ee7e9f954bbc10d1b773R246)
49adb7f4c6 (diff-0cbe7171fdd7821fd5836896849141c0R111)
9bfe89e68e (diff-9c1c95b001e3680ba8a473cf23508b68R8)
a0f18e6090 (diff-bef0ae2c16dacf77bfd2ba099af8a330R47)
8b4d344815 (diff-09660f59aee7ec893ad609315e8843c5R18)
49d1b5a98d (diff-531e71a9d5fdc8181f38ce4416553694R107)
b674f04756 (diff-7521c0bb452244663b689e77658e63e3R98)
a9012af688 (diff-60bdcf1e1954ec56d41fc4c7bd8d3e39R512)
6380aee182 (diff-5158c234d5e19bb1cffadcbc088400f1R262)
c7820d8124 (diff-f4614e7ba8081c0c9e20fe64b6374228R60)
8df7ed3b88 (diff-0495ed68f82d1bbde593ab5491eab24aR169)
6f94260ac6 (diff-7ecb6672f3fd37dfb79c4539395d3857R28)
03e44f9300 (diff-e9234c4c6668852448059c0a35840bcaR185)
2020-09-16 09:52:10 +09:00
Akira Matsuda
47f5459138 Module#const_set is a public method 2020-09-15 17:19:37 +09:00
Vlado Cingel
d556c99687 Uniform paths joining in the code generated by rails new 2020-09-11 10:34:43 +02:00
Jonathan Hefner
be5eeb1a06 Load Rails tasks for each new Rake::Application
Follow-up to #40143.

Rails Rake tasks are loaded for each new `Rake::Application` instance
via `Rails.application.load_tasks`.  However, under the hood,
`Rails.application.load_tasks` used `require` instead of `load`, which
caused Rails tasks to be loaded for only the first `Rake::Application`
instance.

This commit changes the relevant `require` to `load`.

Fixes #40184.
2020-09-06 14:40:14 -05:00
Ryuta Kamizono
7da82b0fc3
Merge pull request #40159 from hahmed/fix-reference-to-rails-command-without-bin
Prefer bin/rails for the credentials command
2020-09-04 11:16:52 +09:00
eileencodes
ee9e308f68
Default db_config should be primary or first
The handling for single database applications has always set a schema.rb
or structure.sql files for loading the database schema. When we first
implemented multiple database support we intended to keep this for the
original, default database. Afterall Rails _has_ to connect to something
on boot. In development only one connection is connected on boot since
we don't eager load the app.

Originally we had thought that all applications should be required to
add a `primary` entry in the database configurations file. However,
this hasn't worked in practice and we have some code now that does not
assume there's a primary. The schema dumping/loading code however,
still assumed there was a "primary" in the configurations file.

We want the "default" database in any application to use the original
files even when converted to a multiple database application as this
reduces the need to make changes when implementing this functionality on
an existing application.

The changes here update Rails to ensure that we treat either "primary"
or the first database configuration for an environment as "default".
If there is a "primary" that will be used as the default configuration.
If there is no primary the configuration that is first for an
environment will be used as the default. For schema dump/load this means
that the default configuration (primary or first) will use `schema.rb`
as the filename and other configurations will use
`[CONFIGURATION_NAME]_schema.rb`.

This should also help us finish the pull request to infer migrations
paths since now we can say the first configuration is the default. This
is a natural assumption for application developers.

Followup to #39536
2020-09-03 15:55:46 -04:00
Haroon Ahmed
3119672411 Prefer bin/rails for the credentials command 2020-09-02 21:03:56 +01:00
eileencodes
e4af759bf3
Use default argument in test
We should use a default argument so that when there is only one option
we can delete the arguments instead of updating all the callers.
2020-09-01 16:26:28 -04:00
Xavier Noria
94ba417ece Move TruffleRuby check to select the autoloading mode to 6.1 defaults 2020-08-31 20:12:26 +02:00
Eugene Kenny
3d9af5a723
Merge pull request #40143 from jonathanhefner/load-rails-rake-tasks-once
Load Rails Rake tasks only once
2020-08-30 22:28:37 +01:00
Jonathan Hefner
85c5e82935 Load Rails Rake tasks only once
In #39137, a new `Rake::Application` instance was created per Rake
command invocation.  To ensure that the Rails tasks were defined for
each `Rake::Application`, `rails/tasks.rb` was loaded per instance.
However, `Rake::Application#load_rakefile` loads the application's
Rakefile, which should invoke `Rails.application.load_tasks`, which, in
turn, also loads the Rails tasks.  When a Rake task is defined more than
once, all definition blocks are executed when the task is run.  Hence,
Rails task blocks were being executed twice.

This commit removes the unnecessary load and avoids double execution.

Fixes #40136.
2020-08-30 11:34:26 -05:00
Benoit Daloze
a011422bc2 Enable Zeitwerk by default on TruffleRuby 2020-08-30 13:48:08 +02:00
Jean Boussier
36fae4bdaf Rescue Database errors during active_record.define_attribute_methods
This initializer should be best effort. If for some reason the
database in unhealthy, it is better to move forward with the
boot process than to crash.
2020-08-27 11:48:48 +02:00
Rafael França
f4ca8d53c9
Merge pull request #40114 from adrianna-chang-shopify/soft-deprecate-application-secrets
Soft deprecate Rails::Application secrets
2020-08-26 15:22:33 -04:00
Adrianna Chang
55a668db29 Remove references to secrets.yml from documentation 2020-08-26 14:59:26 -04:00
Rafael França
211564c638
Merge pull request #40001 from tgxworld/actionable_migration_not_dumping_schema
Fix ActiveRecord::PendingMigrationError action not dumping schema.
2020-08-26 14:00:41 -04:00
Adrianna Chang
e0637a5a50 Add attr_writer for credentials to Rails::Application 2020-08-26 13:30:29 -04:00
Jean Boussier
6d9d26af89 Add config.active_record.check_schema_cache_dump_version to disable schema dump version check 2020-08-26 11:53:07 +02:00
Guo Xiang Tan
17ec88ec90
Fix ActiveRecord::PendingMigrationError action not dumping schema. 2020-08-26 17:04:22 +08:00
Jack McCracken
7459672fb0 Allow a proc to be used in addition to a static value for cookies_same_site_protection
Add documentation of Proc usage for SameSite property to configuring.md

Address PR comments

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2020-08-25 14:33:48 -04:00
Chirag
84d6a0e568 Formats code blocks for better syntax highlighting 2020-08-21 15:47:32 +05:30
Gregorio Kusowski
ee117650e1 Bump minimum web-console version to 4.0.3 2020-08-20 10:45:00 +02:00
Eileen M. Uchitelle
9a36b50b84
Merge branch 'master' into combine-structure-and-schema-tasks 2020-08-17 08:47:51 -04:00
Daniel Colson
be2fd61137
Use deep_symbolize_keys instead of symbolize_names
Fixes #40031

While removing deprecated non-symbol access to nested `config_for`
hashes in #37876, we also broke `config_for` for anyone using the
[safe_yaml] gem. The problem is that `safe_yaml` patches `YAML.load` in
a way that doesn't honor the `symbolize_names` options (I believe this
is on purpose, to prevent symbol-based DOS attacks).

In the description of #37876 there is mention of the fact that this was
the first place in Rails we used `symbolize_names`, and that
`deep_symbolize_keys` had been used in the past.

This commit switches over to `deep_symbolize_keys` to allow `config_for`
to continue working for people using [safe_yaml].

[safe_yaml]: https://rubygems.org/gems/safe_yaml
2020-08-14 23:48:16 -04:00
Eugene Kenny
e53f5ff730
Merge pull request #39851 from piecehealth/engine_skip_mailers
--skip-action-mailer option doesn't work for "rails plugin new"
2020-08-04 20:13:19 +01:00
piecehealth
1f2d0120c0 --skip-action-mailer and --skip-active_job option doesn't work for rails plugin new project_name --full or rails plugin new project_name --mountable 2020-08-04 10:48:34 +08:00
fatkodima
5488686851 Combine and deprecate rails db:structure:{dump,load} tasks into rails db:schema:{dump,load} 2020-08-03 19:08:41 +03:00
Abhay Nikam
b9879bb8ad The abstract parent class file generated via generator should not be pluralized
Currently, the file generated via the generator is pluralized
but the parent class is singluar.

example: bundle exec rails g scaffold Pet name:string --database=animals

The above command should generate: apps/models/animals_record.rb

but the pets model would inherit from: `AnimalRecord` as
`"animals".classify` would be `Animal`

This will throw the `uninitialized constant AnimalRecord Did you mean? AnimalsRecord`
error.
2020-08-02 22:25:57 +05:30
Jonathan Hefner
f24347031f Load plugin VERSION constant by default
For example, for a plugin like `my_plugin`, this makes the
`MyPlugin::VERSION` constant available to all consumers by default.

This commit also replaces the default generated test with a test that
the developer is less likely to delete.
2020-07-31 15:43:34 -05:00
Eugene Kenny
6b359cef39
Merge pull request #39959 from jonathanhefner/plugin-test-class-naming-convention
Follow naming conventions in generated plugin test
2020-07-31 21:31:50 +01:00
Jonathan Hefner
0098088fc1 Follow naming conventions in generated plugin test
This commit ensures that a generated test file like "foo/bar_test.rb"
defines the class `Foo::BarTest` rather than `Foo::Bar::Test`.
2020-07-31 10:01:48 -05:00
André Luis Leal Cardoso Junior
a636aa940b Adds db:migrate:redo:NAME support for multidbs
On current master with multiple DBs configured, calling db:migrate:redo fails when trying to run db:rollback.

Before:

```
» bin/rails db:migrate:redo
rake aborted!
You're using a multiple database application. To use `db:rollback` you must run the namespaced task with a VERSION. Available tasks are db:rollback:primary and db:rollback:secondary.
Tasks: TOP => db:rollback
(See full trace by running task with --trace)
```

After:

```
» bin/rails db:migrate:redo
rake aborted!
You're using a multiple database application. To use `db:migrate:redo` you must run the namespaced task with a VERSION. Available tasks are db:migrate:redo:primary and db:migrate:redo:secondary.
Tasks: TOP => db:migrate:redo
(See full trace by running task with --trace)
```

Running the namespaced version:

```
» bin/rails db:migrate:redo:secondary
== 20200728162820 CreateAnimals: reverting ====================================
-- drop_table(:animals)
   -> 0.0025s
== 20200728162820 CreateAnimals: reverted (0.0047s) ===========================

== 20200728162820 CreateAnimals: migrating ====================================
-- create_table(:animals)
   -> 0.0028s
== 20200728162820 CreateAnimals: migrated (0.0029s) ===========================
```
2020-07-30 22:15:22 -03:00
Abhay Nikam
db5c619541 Fixed typo AnimalsRecrd -> AnimalsRecord [ci skip] 2020-07-30 12:56:54 +05:30
eileencodes
261cbcd2a8
Generate abstract class when generating scaffold in another database
This PR ensures that when you're generating a scaffold or model and that
model should belong to another database it will create an abstract class
if it doesn't already exist.

The new abstract class will ensure that the new model inherits from that
class, but will not be deleted if the scaffold is deleted. This is
because Rails can't know if you have other models inheriting from that
class so we don't want to revoke that if the scaffold is destroyed.

If the abstract class already exists it won't be created twice. If the
options for `parent` are set, the generator will use that as the
abstract class instead of creating one. The generated abstract class
will add the writing connection automatically, users need to add the
reading connection themselves as Rails doesn't know which is the reading
connection.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-07-29 12:43:45 -04:00
Eugene Kenny
4560c36da2
Merge pull request #39933 from exterm/engines-are-not-applications
Correct engine generator docs
2020-07-28 23:19:05 +01:00
Jonathan Hefner
adfa417fbb Use standard config/application.rb in plugin dummy
The `config/application.rb` file of a plugin test dummy app should be
the same as in a standard Rails app, with the exception of an additional
`require` statement to load the plugin itself.  However, prior to this
commit, the plugin generator used a specialized template for a portion
of this file, which tended to drift out-of-sync with the standard app
generator's template.  Specifically, this drift could result in missing
`require` statements of newer Rails frameworks when the plugin generator
was run with any `--skip-xxxx` option.

This commit changes the plugin generator to insert its additional
`require` statement into the standard `config/application.rb` file
generated by the app generator.
2020-07-28 14:33:40 -05:00
Philip Müller
dee804345d
[ci skip] Correct engine generator docs
Engines are not applications, indeed 'Application < Engine', so it's the other way round.
The difference can be confusing anyway, so we should make sure the documentation is clear.
2020-07-27 10:22:29 -04:00
Eugene Kenny
c418fb9fe9
Merge pull request #39708 from jonathanhefner/finish_template-goes-last
Ensure principle tasks go before finish_template
2020-07-18 23:49:24 +01:00
Eugene Kenny
aa85c4ba0c
Merge pull request #39829 from tgxworld/remove_protect_from_forgery_from_application_controller_template
Remove `protect_from_forgery` in rails plugin template.
2020-07-17 00:12:27 +01:00
Chris Oliver
12afb7fb4b
Allow passing URL params to conductor form for inbound emails 2020-07-14 14:02:43 -04:00
Petrik
f72294fdc0 Raise if camelcase inflection impossible in generator
When passing a camelcased model name to a generator sometimes it's
impossible to inflect the casing.  For example "BFF" will generate a
route for the controller BffsController, but the controller generated is
BfFsController.

The casing is impossible to inflect if both:
- a camelcased model name is passed to a generator
- `name.pluralize.underscore.singularize != name.underscore.singularize`

If this happens we raise an error. The error message explains the user
can either us an underscored name or add an inflection instead.
2020-07-13 22:02:13 +02:00
Guo Xiang Tan
85316f7bbe
Remove protect_from_forgery in rails plugin template.
`protect_from_forgery` is added to `ActionController::Base` by default
since ec4a836919c021c0a5cf9ebeebb4db5e02104a55
2020-07-13 14:39:30 +08:00
Guo Xiang Tan
f1e53be508
Change default HTTP status to 308 for ActionDispatch::SSL.
308 status code introduced in https://tools.ietf.org/html/rfc7538
preserves the request method unlike 301 status code which would convert
POST requests to GET.
2020-07-06 14:51:24 +08:00
Eugene Kenny
1f1e45630e
Merge pull request #39671 from hahmed/railties/speed-up-test-skip-webpack-install
Speed up railties test test_skip_webpack_install currently ~10s
2020-06-29 23:56:21 +01:00
Jean Boussier
12f3f11f61 Use URI::DEFAULT_PARSER rather than instantiate a new one 2020-06-29 23:06:34 +02:00
Jonathan Hefner
a6e1be7148 Ensure principle tasks go before finish_template
This fixes a regression of #13637, and adds a regression test.
2020-06-23 23:31:47 -05:00
Haroon Ahmed
46045e35ed Speed up test_skip_webpack_install from ~10s to < 5s by avoiding the call to bundler, I also added an assertion for webpacker which was needed for this test 2020-06-22 21:15:12 +01:00
Haroon Ahmed
a20d5bd1e3 Remove unknown_asset_fallback check from test_new_application_load_defaults as it adds no value to the generator tests, this speeds up the test from ~5s to ~0.1s. The unknown_asset_fallback test has been moved into the configuration_test.rb 2020-06-19 12:25:15 +01:00
Javan Makhmali
664e94989e
Merge pull request #39521 from rossta/patch/use-import-syntax-in-application-js-template
Use ES module import syntax in application js template
2020-06-18 07:43:09 -04:00
Ross Kaffenberger
04cbaa1475 Use ES module syntax for application.js.tt and docs
This change swaps the CommonJS require() syntax in the Webpacker
application.js pack template file and in documentation examples with ES
module import syntax.

Benefits of this change include:

Provides continuity with the larger frontend community: Arguably, one of
the main draws in adopting Webpacker is its integration with Babel to
support ES module syntax. For a fresh Rails install with Webpacker, the
application.js file will be the first impression most Rails developers
have with webpack and Webpacker.  Most of the recent documentation and
examples they will find online for using other libraries will be based
on ES module syntax.

Reduces confusion: Developers commonly add ES imports to their
application.js pack, typically by following online examples, which means
mixing require() and import statements in a single file. This leads to
confusion and unnecessary friction about differences between require()
and import.

Embraces browser-friendliness: The ES module syntax forward-looking and
is meant to be supported in browsers. On the other hand, require()
syntax is synchronous by design and not browser-supported as CommonJS
originally was adopted in Node.js for server-side JavaScript. That
webpack supports require() syntax is merely a convenience.

Encourages best practices regarding optimization: webpack can statically
analyze ES modules and "tree-shake", i.e., strip out unused exports from
the final build (given certain conditions are met, including
`sideEffects: false` designation in package.json).
2020-06-16 15:12:12 -04:00
Henrik Nyh
63824f9ffb
setup.tt comment: "at anytime" -> "at any time"
https://www.grammarly.com/blog/anytime-any-time/
2020-06-16 16:19:27 +01:00
Rafael França
acf87b4ed2
Merge pull request #39632 from jonathanhefner/springy-boot
Move Spring machinery to boot.rb
2020-06-15 22:42:07 -04:00
Jonathan Hefner
a6c958b3a7 Move Spring machinery to boot.rb
This partially reverts #39225, and folds `boot_with_spring.rb` into
`boot.rb`.

Fixes #39622.
2020-06-15 17:32:55 -05:00
Jonathan Hefner
f67e4cb7e5 Ensure times-called assertions are evaluated
If an assertion is inside a method stub, it may never be evaluated.
This is particularly problematic when asserting a method is called a
non-zero number of times.

This commit moves such assertions outside their method stubs.
2020-06-15 02:10:58 -05:00
Ryuta Kamizono
528b62e386 Address to false negative for Performance/DeletePrefix,DeleteSuffix
Follow up to c07dff72278fb7f2a3c4c71212a0773a2b25c790.

Actually it is not the cop's fault, but we mistakenly use `^`, `$`, and
`\Z` in much places, the cop doesn't correct those conservatively.

I've checked all those usage and replaced all safe ones.
2020-06-14 13:04:47 +09:00
Josef Šimánek
a49dfe38ae
Introduce Rails::TestUnitReporter.app_root to inject app_root when needed. 2020-06-14 00:02:49 +02:00
Josef Šimánek
32aebc76cb
Use COMPONENT_ROOT as app_root when present in test unit reporting. 2020-06-13 20:30:25 +02:00
Étienne Barrié
cf3736dce8
Add application config for URL-safe Base64 CSRF tokens
This allows applications to safely upgrade to Rails 6.1 without
breaking tokens while the deploy is still being rolled out.
2020-06-11 11:39:37 -04:00
Kasper Timm Hansen
4654f4aab6
Merge pull request #39541 from jonathanhefner/silence-rake-task-backtraces
Silence Rake task backtraces
2020-06-05 12:54:11 +02:00
Jonathan Hefner
7ba531be74 Silence Rake task backtraces
Silence Rake task backtraces, similar to Rails::BacktraceCleaner.
Application lines are preserved, but all other lines are hidden.

This also affects unrecognized tasks, causing the backtrace to be hidden
entirely.  Closes #39524.

Co-authored-by: Petrik <petrik@deheus.net>
2020-06-05 02:26:46 -05:00
Ryuta Kamizono
c07dff7227 Auto-correct for delete_prefix/delete_suffix
Follow up to #39409.
2020-06-05 12:40:39 +09:00
Eileen M. Uchitelle
e95edb3d6d
Merge pull request #39536 from eileencodes/remove-assumption-that-primary-exists
Remove assumption that a primary config exists
2020-06-04 16:03:03 -04:00
eileencodes
e7b1e118b9
Fix schema cache load and corresponding test
This test was incorrect. `primary` was winning for the schema cache load
but when you boot an application it's actually the first configuration
that wins (in a multi db app).

The test didn't catch this because I forgot to add a migrations_paths to
the configuration.

We updated the schema cache loader railtie as well because any
application that didn't have a `primary` config would not be able to use
the schema cache. Originally we thought we'd enforce a `primary`
configuration but no longer feel that's correct. It's simpler to say
that the first wins in a 3-tier rather than implementing a solution to
require `primary` and / or allow aliases.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>
2020-06-04 15:12:12 -04:00
eileencodes
7b4fdf3ce7
Remove assumption that a primary config exists
Applications may not have a primary configuration so we should not
assume there is one. In both these cases we can get the right connection
without that.

For the databases.rake file we want to re-establish a connection for the
environment we're in. The first config defined under an environment for
a multi-db app will win. This is already the case on application boot so
we should be consistent.

For the info.rb file we already have a connection so we can lookup the
adapter from the connection's db_config. If a primary hadn't existed
this would have thrown an exception.

Followup to https://github.com/rails/rails/pull/39535 which removed the
assumption there was a primary config from the schema cache load
railtie.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-06-04 15:08:59 -04:00
Aaron Patterson
35fe9bc0aa
Merge pull request #39477 from p8/improve-inspect
Make custom inspect methods more consistent
2020-06-03 10:43:35 -07:00
Eugene Kenny
751d46af4f
Merge pull request #39523 from p8/rename-stubs-out-to-generate
Replace 'Stubs out' with 'Generates' in generator USAGE's [ci skip]
2020-06-03 10:40:40 +01:00
Petrik
2b09948637 Replace 'Stubs out' with 'Generates' in generator USAGE's [ci skip]
Generators generate things, but what is meant by 'Stubbing out' might
confuse beginners and non-native English speakers.
While generated tests are stubs that should have an implementation, a
generated model is a valid model that doesn't require any changes.
2020-06-03 08:51:47 +02:00
Haroon Ahmed
7a321d8429
rails new --minimal gives you a minimal rails stack. (#39282) 2020-06-02 13:29:02 -07:00
Petrik
c7a3894667 Fix test name that no longer raises exception 2020-06-02 10:01:30 +02:00
Jonathan Hefner
08aeb01b0f Lazily build path regex in PathParser
Eagerly building the path regex can exclude handlers which are added on
Action View load.

Fixes #39492.
2020-05-31 15:28:24 -05:00
jasl
34adebd4a7 Don't inline run webpacker:install on rails new 2020-05-30 05:44:04 +08:00
Petrik
74cb9a6f38 Make inspect look more like regular Object#inspect
Move the # outside the < > just like regular Object#inspect
2020-05-29 21:53:35 +02:00
fatkodima
2156226e6e Do not swallow unknown configuration options for ActiveJob 2020-05-29 17:48:51 +03:00
Ryuta Kamizono
c65864cdca Prefer no allocation start/end_with? over String#[] == 2020-05-29 10:20:13 +09:00
Eugene Kenny
0ebc720a04 Set retry_jitter to 0.0 for upgraded applications
The point of new framework defaults is that they're opt-in for upgraded
applications, but the default for this option applied the new behaviour.
2020-05-27 22:15:19 +01:00
John Hawthorn
db543ba728
Merge pull request #39361 from jhawthorn/path_parser
Introduce Resolver::PathParser
2020-05-26 20:16:18 -07:00
John Hawthorn
a70ad604cf Add railties test of custom handlers and formats 2020-05-26 19:27:38 -07:00
Ryuta Kamizono
dc94a753d1 require "active_support/core_ext/symbol/starts_ends_with" for Ruby 2.6
And use `Symbol#[]` to strip suffix to avoid intermediate string
allocation.
2020-05-25 05:24:44 +09:00
Jonathan Hefner
a2ca8f062c Utilize Symbol#start_with? and #end_with?
Follow-up to #39155.

Thanks to Symbol#start_with? and #end_with?, these calls no longer need
to be prefixed with `.to_s`.
2020-05-24 14:46:12 -05:00
fatkodima
e24d6ecbfd Update rubocop-performance gem and enable Performance/DeletePrefix and Performance/DeleteSuffix cops 2020-05-24 12:51:35 +03:00
John Hawthorn
096d143c8c Clear cache after setting Template::Types delegate
details_cache_key already references Template::Types.symbols and view
resolvers cache based on default_formats and other values. This
previously wasn't an issue because no views had been looked up before
this was set. Now that we are building a regex from the values of
Template::Types.symbols we need to clear cache after changing this
setting.
2020-05-21 22:43:13 -07:00
George Claghorn
e4b6c719cd Update Railties tests for 7e52d0a 2020-05-21 13:00:56 -04:00
Ryan Davis
c07bcd6573 Fixed up error output tests and added a missing failure output test.
Errors *should* output their stack. Somehow these tests were passing
before. This clarifies all states (skip/fail/error) and works against
@tenderlove's patch.
2020-05-20 15:54:28 -07:00
Aaron Patterson
43ed3c7939
This is causing problems in master wrt backtraces
Before #39304 was merged, backtraces would look like this:

```
$ be ruby -I lib:test test/controller/request_forgery_protection_test.rb -n test_ignores_trailing_slash_during_generation
Run options: -n test_ignores_trailing_slash_during_generation --seed 22205

E

Error:
PerFormTokensControllerTest#test_ignores_trailing_slash_during_generation:
NoMethodError: undefined method `have_cookie_jar?' for #<Object:0x00007f9ce19b9620>
    /Users/aaron/git/rails/actionpack/lib/action_controller/test_case.rb:522:in `ensure in process'
    /Users/aaron/git/rails/actionpack/lib/action_controller/test_case.rb:542:in `process'
    /Users/aaron/git/rails/actionpack/lib/action_controller/test_case.rb:395:in `get'
    test/controller/request_forgery_protection_test.rb:1005:in `test_ignores_trailing_slash_during_generation'

rails test test/controller/request_forgery_protection_test.rb:1004

Finished in 0.213230s, 4.6898 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
```

After #39304 was merged they look like this:

```
$ be ruby -I lib:test test/controller/request_forgery_protection_test.rb -n test_ignores_trailing_slash_during_generation
Run options: -n test_ignores_trailing_slash_during_generation --seed 62892

E

Error:
PerFormTokensControllerTest#test_ignores_trailing_slash_during_generation:
NoMethodError: undefined method `have_cookie_jar?' for #<Object:0x00007fa6d60193c8>

rails test test/controller/request_forgery_protection_test.rb:1004

Finished in 0.211953s, 4.7180 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
```

This patch reverts the part of #39304 that removes the backtrace.
2020-05-20 08:42:36 -07:00
fatkodima
6c4f3be929 Unify raise_on_missing_translations for views and controllers 2020-05-20 02:42:59 +03:00
Rafael França
a80115b7c5
Merge pull request #39204 from prathamesh-sonpatki/template-annotation
Add the configuration option for annotating templates with file names to the generated app
2020-05-19 19:11:31 -04:00
Prathamesh Sonpatki
a673ce69e7
Rename annotate_template_file_names to annotate_rendered_view_with_filenames
- Add the configuration option for annotating templates with file names to the generated app.
- Add `annotate_rendered_view_with_filenames` option to configuring guide.
2020-05-19 09:28:14 +05:30
Ryuta Kamizono
a2a861d357 ✂️ trailing spaces [ci skip] 2020-05-18 07:16:18 +09:00
Vinicius Stock
98a3644be0
Create update yarn task (#39314)
* Use app:binstub:yarn in Action Text install generator
2020-05-17 19:51:32 +02:00
David Heinemeier Hansson
f4c9d0b014
Add default ENV variable option with BACKTRACE to turn off backtrace cleaning (#39220)
* Add default ENV variable option with BACKTRACE to turn off backtrace cleaning when debugging framework code

* Use runner as the example

Although I think we should consider dropping -b in tests and just relying on this more general option for sidestepping the backtrace cleaner.
2020-05-17 08:52:05 -07:00
Xavier Noria
838d3f73dd The warning for autoloaded constants on boot includes a solution 2020-05-17 10:12:15 +02:00
Xavier Noria
524d678a03 Document how to reload at boot time [ci skip]
Co-authored-by: Haroon Ahmed <haroon.ahmed25@gmail.com>
2020-05-17 10:11:41 +02:00
Kasper Timm Hansen
03e82e2f0d
Merge pull request #39245 from paul-mannino/unload-app
Don't load app environment when running encrypted commands
2020-05-16 23:55:21 +02:00
David Heinemeier Hansson
c6bdfd133f
Use explicit spring boot loader (#39225) 2020-05-16 13:57:45 -07:00
Ryan Davis
d0060f1206 Fix failure in reporter_test.rb
I'm not sure about this one. The gist is, minitest's
UnexpectedError#message includes a backtrace but the reporter tests
here expect there not to be one in inline output.

Personally, I think that's wrong as it removes information you'd want
to debug, but this might be a philosophical difference with the rails
test ethos... or it might just be aesthetic.

I am happy to back out this change and fix the tests if you'd rather.
2020-05-15 16:42:27 -07:00
Haroon Ahmed
9c886c18bc fix wording in rail/engine class 2020-05-14 08:51:27 +01:00
Eileen M. Uchitelle
d08f2d41a1
Merge pull request #39257 from eileencodes/revert-job-deprecation
Revert "Remove deprecated `ActionMailer::DeliveryJob` and `ActionMailer::Parameterized::DeliveryJob`
2020-05-12 19:12:42 -04:00
Eugene Kenny
96a1a2a37c Use binread instead of setting file mode manually
Followup to b31022052a54ef76f347973e23519ba86ffc94ff.
2020-05-13 00:05:32 +01:00
eileencodes
336a07b9a4
Revert "Remove deprecated ActionMailer::DeliveryJob and ActionMailer::Parameterized::DeliveryJob"
This reverts commit 0f9249c93f402d276730fcfaba1ed1b876ee7c26.

Reverted because this wasn't warning in custom jobs and therefore
applications may have not seen the deprecation. We'll need to fix the
deprecation to warn for custom jobs so that applications can migrate.
2020-05-12 15:20:07 -04:00
Paul Mannino
4e8650f8b1 Don't load app environment when running encrypted commands
This extends the fix made by a39aa99c814 to the EncryptedCommand class
which suffers from the exact same issue.
2020-05-12 12:06:05 -05:00
Xavier Noria
0dc3f5146d adds credit to CHANGELOG item [ci skip] 2020-05-12 08:16:41 +02:00
Xavier Noria
e9c585096e deprecates the classic autoloader 2020-05-12 08:12:05 +02:00
Jonathan Fleckenstein
dfb5a82b25
Active Storage: allow serving files by proxying 2020-05-11 16:21:58 -04:00
Niklas Häusele
9488712365
Adds a rails test:all rake task (#39221)
* Adds a rails test:all rake task

This task runs all tests, including system tests.

* Better placement + slight tweak of the comment

Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
2020-05-10 17:22:49 -07:00
Ryuta Kamizono
1165401ee9 Remove unused require "active_support/core_ext/kernel/singleton_class"
`singleton_class` is in Ruby 1.9.2, and there is no use singleton class
eval in the files.
2020-05-10 03:20:02 +09:00
yuuji.yaginuma
fde100d18e Add config.generators.after_generate for processing to generated files
Register a callback that will get called right after generators has
finished.

This is useful if users want to process generated files.
For example, can execute an autocorrect of RuboCop for generated files
as like following.

```ruby
config.generators.after_generate do |files|
  system("bundle exec rubocop --auto-correct " + files.join(" "), exception: true)
end
```
2020-05-08 21:06:04 +09:00
Kasper Timm Hansen
f1c7a32e90
Merge pull request #39001 from jonathanhefner/test-runner-recognize-windows-paths
Recognize Windows-style paths in test runner
2020-05-07 22:48:23 +02:00
Kasper Timm Hansen
d143154147
Merge pull request #39036
Closes #39036
2020-05-07 01:05:58 +02:00
Jorge Manrubia
a0f18e6090
Make test file patterns configurable via Environment variables
This makes test file patterns configurable via two environment variables:
`DEFAULT_TEST`, to configure files to test, and `DEFAULT_TEST_EXCLUDE`,
to configure files to exclude from testing.

These values were hardcoded before, which made it difficult to add
new categories of tests that should not be executed by default (e.g:
smoke tests).

It uses environment variables instead of regular Rails config options
because Rails environment is not available when the Runner builds the
list of files to test (unless using Spring). A nicer solution would be
making sure that the Rails environment is always loaded when the runner
starts. This is a first simple step to make these paths configurable for
now

This way at least you could override defaults in `config/boot.rb`:

```ruby
ENV["DEFAULT_TEST_EXCLUDE"] = "test/{dummy,smoke,system}/**/*_test.rb
```

Co-authored-by: Jeremy Daer <jeremydaer@gmail.com>
2020-05-07 01:04:01 +02:00
Ryuta Kamizono
98a1405f07 Dogfooding "active_support/core_ext/symbol/starts_ends_with"
Any missing thing would be found such like #39159.
2020-05-06 14:19:25 +09:00
Ryuta Kamizono
55e038cf17
Merge pull request #39152 from kamipo/deprecate_starts_ends_with
Deprecate `starts_with?` and `ends_with?` for String core extensions
2020-05-05 22:33:30 +09:00
Ryuta Kamizono
3f883b69a7 Relax required rack-mini-profiler version 2.0.x to 2.x 2020-05-05 17:22:26 +09:00
Ryuta Kamizono
6a4395f466 Deprecate starts_with? and ends_with? for String core extensions
In the past, we sometimes hit missing `Symbol#start_with?` and
`Symbol#end_with?`.

63256bc5d7
a8e812964d

So I proposed `Symbol#start_with?` and `Symbol#end_with?` to allow duck
typing that methods for String and Symbol, then now it is available in
Ruby 2.7.

https://bugs.ruby-lang.org/issues/16348

Using `String#starts_with?` and `String#ends_with?` could not be gained
that conveniency, so it is preferable to not use these in the future.
2020-05-05 15:51:24 +09:00
Rafael Mendonça França
bd87b37d4f
Remove unneeded test after force_ssl removal 2020-05-05 01:13:46 -04:00
Rafael Mendonça França
0f9249c93f
Remove deprecated ActionMailer::DeliveryJob and ActionMailer::Parameterized::DeliveryJob 2020-05-05 00:31:14 -04:00
Brandon Fish
b4ccdcb73a Include parallelize :threads option when fork is not available 2020-05-04 20:26:24 -05:00
Jonathan Hefner
68a3f679d9 Support reentrant calls to RakeCommand.perform
Rake stores the current top-level task and arguments in global state.
Invoking another top-level task within the same process requires
overwriting this state.  Doing so indiscriminately can cause incorrect
behavior, such as infinitely repeating the original task.  In
particular, this is a problem when running one task from another via
`rails_command "...", inline: true`.

The solution is to save and restore the global state in each call to
`RakeCommand.perform` using the `Rake.with_application` method.

Fixes #39128.
2020-05-03 19:28:15 -05:00
Alberto Almagro
8bae32ba2c Add mention to shared section in config_for docs [ci skip]
37913 added the possibility to deeply merge configurations by grouping
them within a shared section. This powerful alternative was not reflected
in any documentation, which made my team think it was not possible until
I found out this feature after looking at the source code.

This patch reflects this change in the documentation so that it is
easier for other developers to know about this behavior.
2020-05-01 15:25:14 +02:00
Ryuta Kamizono
ca3579ad29
Merge pull request #39064 from kamipo/pg-1.1
Update pg gem required version to 1.1
2020-05-01 09:19:30 +09:00
Xavier Noria
92d03850f3 files -> directories in zeitwerk:check warning [skip ci] 2020-04-29 11:12:46 +02:00
Xavier Noria
cd2d1cf731
Merge pull request #38374 from peterb/improve_zeitwerk_check_warning_message
Improve zeitwerk:check warning message [CI skip]
2020-04-29 11:08:17 +02:00