Commit Graph

7242 Commits

Author SHA1 Message Date
Mike Rogers
83f2f9fd24 Changing 'rails new' --master to be --main
Renaming test containing flag

Updating other test referencing master branch

Add notice that --master is deprecated, but still working the same as --main

Only set @main if it's nil

Making warn wildcard

I think a hidden aliaes would be just as good

Improving description & fixing rubocop error

Forgot comma

Deprecation warning was kind of hard - so just doing alias for now

rubocop -a
2021-01-19 21:07:40 +00:00
Rafael Mendonça França
077c66d5d6
Rename master to main in all code references 2021-01-19 20:46:33 +00:00
Christian Schmidt
25f388b0f0
Explicit check for html and text parts
Attachments should not trigger format selector
2021-01-18 11:44:08 +01:00
Kasper Timm Hansen
2afc9059c9
Merge pull request #41026 from santib/use-4xx-for-validations-errors-responses
Use 422 instead of 200 as the status code for form submission error responses
2021-01-11 00:03:32 +01:00
Rafael França
88b432c221
Merge pull request #41043 from dbussink/default-sha256-digest
Change the default digest for new apps to SHA256
2021-01-08 18:01:38 -05:00
Rafael Mendonça França
1e6d25caaa
Merge PR #41055
Closes #41055.
2021-01-08 22:40:26 +00:00
bogdanvlviv
4a401ca73a
Make config.action_view.button_to_generates_button_tag work
In https://github.com/rails/rails/pull/40747 we added `ActionView::Helpers::UrlHelper.button_to_generates_button_tag`.

- `config.action_view.button_to_generates_button_tag` should configure `ActionView::Helpers::UrlHelper.button_to_generates_button_tag`
  - Added test cases
- Fixed new_framework_defaults_6_2.rb.tt (See https://github.com/rails/rails/pull/40747#discussion_r542946805, https://github.com/rails/rails/pull/40747#discussion_r542947538, cc @kaspth)
- Added the option to the configuring guide
  - Documented
  - Added to "6.2 defaults section
  - Added to "Baseline defaults" section (see ff881137a8ceab951211a66afa2389ae599b2ce7)
2021-01-08 16:33:30 +02:00
bogdanvlviv
5e0d451966
Unite Active Storage configs in load_defaults '6.1' into one if-section
When I was comparing 'defaults' for 6.1 in this method and our configuring
guide, I was confused that some active_storage options are missing.

This change doesn't bring any implementation changes and feels like
a cosmetic change. Please feel free to close this if you think so and don't
see that we could benefit this change.
2021-01-08 15:30:36 +02:00
Dirkjan Bussink
ba9207f301
Change the default digest for new apps to SHA256
As mentioned in
https://github.com/rails/rails/pull/40770#issuecomment-748347066 we
should default to SHA256 where SHA1 is used today. This switches over
the ActiveSupport::Digest to use SHA256 for new applications.

It also updates the constants to always refer to and use the OpenSSL
constants as well, as also discussed in that PR.
2021-01-08 12:07:20 +01:00
Rafael Mendonça França
c7fca843a5
Add key_generator_hash_digest_class to the new frameworks default file
And document how to do the key rotation.
2021-01-07 23:34:54 +00:00
Dirkjan Bussink
447e28347e
Allow configuration of the digest class used in the key generator
This change allows for configuration of the hash digest that is used in
the key generator for key derivation.

SHA1 is an outdated algorithm and security auditors tend to frown on
its usage. By allowing this to be configured, it becomes possible to
move to a more up to date hash mechanism.

While I don't think this has any current relevant security implications,
especially not with a proper random secret base, moving away from SHA1
makes conversations with auditors and FIPS compliance checks easier
since the best answer is always that an approved algorithm is used.

A rotation can be built using this change with an approach like the
following for encrypted cookies:

```ruby
Rails.application.config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256

Rails.application.config.action_dispatch.cookies_rotations.tap do |cookies|
  salt = Rails.application.config.action_dispatch.authenticated_encrypted_cookie_salt
  secret_key_base = Rails.application.secrets.secret_key_base

  key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000, hash_digest_class: OpenSSL::Digest::SHA1)
  key_len = ActiveSupport::MessageEncryptor.key_len
  secret = key_generator.generate_key(salt, key_len)

  cookies.rotate :encrypted, secret
end
```

This turns the default into using SHA256 but also still accepts secrets
derived using SHA1.

The defaults for new apps is here changed to use SHA256. Existing apps
will keep using SHA1.
2021-01-07 14:28:01 +01:00
Santiago Bartesaghi
e83d7dcb2f Use 4XX instead of 2XX for validation errors responses 2021-01-06 00:10:26 -03:00
Jonathan Hefner
2e6dae1a26 Populate ARGV for app template
In #38495, `ARGV` was isolated to prevent commands from depending on its
contents, which might be indeterminate.  However, app templates may
depend on `ARGV`, so populate it before evaluating them.

Fixes #40945.
2021-01-01 11:28:08 -06:00
Rafael França
156fe36885
Merge pull request #39567 from jonathanhefner/credentials-diff-disenroll
Add `credentials:diff --disenroll`
2020-12-29 18:12:31 -05:00
Rafael França
4ed00c4d9a
Merge pull request #38733 from roramirez/remove-gemlist-entry
Remove gemfile_entry from GeneratorAppBase:
2020-12-29 18:05:52 -05:00
Jonathan Hefner
eb7fe0b293 Add credentials:diff --disenroll
This allows users to undo `credentials:diff --enroll` without having to
know the details of its implementation.
2020-12-29 16:46:13 -06:00
Jonathan Hefner
a2c41ca5e3 Rename Diffing methods to increase specificity
Because `Diffing` is a module included in a larger context, rename
several of its methods to increase their specificity.
2020-12-29 16:09:01 -06:00
Sean Doyle
9af9458396 Consistently render button_to as <button>
Prior to this commit, the
[ActionView::Helpers::UrlHelper#button_to][button_to] helper rendered
`<input type="submit">` elements when passed its contents as a String
argument, and rendered `<button type="submit">` elements when passed its
contents as a block.

This difference is subtle, and might lead to surprises.

Additionally, a `<form>` element's submitter can encode a `name`/`value`
pairing, which will be submitted as part of the request. When
`button_to` renders an `<input type="submit">` element, the "button"
content is rendered as a `[value]` attribute, which prevents any
meaningful data from being encoded.

Since it's a single `<button>` or `<input type="submit">` within a
`<form>`, missing out on that opportunity to encode information might
not be a show stopper, but ensuring that a `<button>` element is
rendered _without_ a default `[value]` attribute enables applications to
encode additional information that can be accessed JavaScript as
`element.value`, instead of a workaround like
`element.getAttribute("data-value")`.

Support rendering `input` elements with button_to
---

To support the original behavior of `button_to` rendering `<input
type="submit">` elements when invoked _without_ a block, expose the
`app.config.button_to_generates_button_tag` configuration flag.

By default, it's set to `true` and ensures that all `button_to` calls
render `<button>` elements. To revert to the original behavior, set it
to `false`.

[button_to]: https://api.rubyonrails.org/v6.0/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to

Co-authored-by: Dusan Orlovic <duleorlovic@gmail.com>
2020-12-28 19:33:05 -05:00
Rafael França
05e694536c
Merge pull request #40215 from vlado/file_path_joining_in_generator
Uniform paths joining in the code generated by `rails new`
2020-12-28 19:23:53 -05:00
Rafael França
d73ddc6469
Merge pull request #40913 from jonathanhefner/handle-spring-not-installed
Handle when Spring is not installed
2020-12-28 19:09:41 -05:00
Jonathan Hefner
2a4fa7ed5f Handle when Spring is not installed
Spring is not in the default `:test` gem group, and may not be installed
in some testing environments, such as CI.

Fixes #40911.
2020-12-28 10:55:58 -06:00
Eugene Kenny
b4abba3f1e
Merge pull request #40952 from jonathanhefner/plugin-dummy-skip-spring
Skip Spring in plugin dummy apps
2020-12-27 23:09:15 +00:00
Jonathan Hefner
c05078be77 Skip Spring in plugin dummy apps
Since #39746, the Spring binstub can be generated without having to run
`bundle install` first, and thus the `skip_bundle` option does not
prevent the Spring binstub from being generated.  Therefore, explicitly
set the `skip_spring` option for plugin dummy apps.
2020-12-27 16:45:13 -06:00
Jonathan Hefner
6bfb5820fb Search for yarn.exe in bin/yarn
Since #40646, `bin/yarn` manually searches `PATH` for the `yarn`
executable.  In Windows environments, executables have an `.exe` file
extension, so we must search for `yarn.exe` as well.

Fixes #40942.
2020-12-27 15:17:33 -06:00
Andrew White
71bc41477d
Merge pull request #40882 from rails/add-preload-links-header-config
Add `config.action_view.preload_links_header` option
2020-12-21 06:41:13 +00:00
Kevin Jalbert
8859978b43
Fix RDoc code formatting for Railtie [ci skip]
Fixes an indention issue which results in ill-formatted RDoc code rendering.
2020-12-19 14:18:04 -05:00
Andrew White
200083c232
Add config.action_view.preload_links_header option
PR #39939 added support for the `Link` header being generated
automatically when using `stylesheet_link_tag` and
`javascript_include_tag`. However not everything should be
preloaded, e.g. a link to a legacy IE stylesheet has no need to be
preloaded because IE doesn't support the header and in some browsers it
will trigger the preload even though it's not used since it's inside an
IE conditional comment. This leads to increased bandwith costs and
slower application performance.

To allow more flexibility for sites that may have complex needs for the
`Link` header this commit adds a configuration option that disables it
completely and leaves it up to the application to decide how to handle
generating a `Link` header.
2020-12-19 05:24:09 +00:00
Jonathan Hefner
50a39e24be Load most recent version of Bundler in bin/spring
Because Bundler is a default gem, `require "bundler"` by itself will
load the default version of the gem, instead of the most recent version.
This can cause Rails commands to produce warnings like the following:

> Warning: the running version of Bundler (2.1.4) is older than the
> version that created the lockfile (2.2.2). We suggest you to upgrade
> to the version that created the lockfile by running
> `gem install bundler:2.2.2`.

Adding `gem "bundler"` allows the most recent version of the gem to be
loaded.
2020-12-18 11:29:58 -06:00
Rafael França
002e802ce0
Merge pull request #40785 from Stellenticket/yarn_command_with_spaces
Allow spaces in path to Yarn binstub and only run on precompile if needed
2020-12-16 19:07:38 -05:00
Artur Beljajev
0be9a266b0
Update api_functional_test.rb.tt
Replace magic number with named constant
2020-12-14 14:27:56 +02:00
Markus Doits
87e9ae053d
Only run yarn:install before assets:precompile if bin/yarn present
Based on discussion in https://github.com/rails/rails/issues/40795, it
looks like `yarn:install` is *always* run, even if the Rails project
disabled javascript and there is no `bin/yarn`.

Check for the existence of `bin/yarn` to decide if `yarn:install` should
be run or not.

The check for this is taken from `railties/lib/rails/app_updater.rb`,
where it does the same:

```ruby
         options[:skip_javascript] = !File.exist?(Rails.root.join("bin", "yarn"))
```
2020-12-11 15:54:29 +01:00
Markus Doits
01801281ca
Add an error message in case bin/yarn is missing
One reason why it could be missing because Rails was upgraded but `rails
app:update` was not run.

Running `rails app:update:bin` should create it.

refs #40795
2020-12-11 11:14:11 +01:00
Markus Doits
f4265aebc8
put yarn binary in quotes to allow spaces in path to it 2020-12-10 18:13:02 +01:00
Markus Doits
bd4d8fdfce
check yarn version and run correct install command 2020-12-08 22:58:25 +00:00
Rafael França
45d1efab51
Merge pull request #40766 from rafaelfranca/rm-queue-defaults
Change default queue name of all the internal jobs to be the job adapter's default
2020-12-08 22:47:47 +00:00
Rafael França
35b706bc0a
Merge pull request #40734 from semaperepelitsa/benchmarkable
Add benchmark method that can be called from anywhere
2020-12-08 15:02:49 -05:00
KapilSachdev
a908d06c85
feat(rubocop): Add Style/RedundantRegexpEscape
- This cop will help in removing unnecessary escaping inside Regexp literals.
2020-12-08 18:57:09 +00:00
Simon Perepelitsa
1911673e67 Add benchmark method that can be called from anywhere 2020-12-04 15:52:10 +03:00
Rafael Mendonça França
c1528c905c
Fix the cop violation 👮 2020-12-03 23:14:28 +00:00
Rafael Mendonça França
ee647d4b0a
Impove the RoutesReloader to not expose internal API
We don't need a callback and we should not expose the attribute to the
API given this is only internal.

I also removed the CHANGELOG entry because this is a bugfix for a change
that was not released yet.
2020-12-03 23:01:53 +00:00
Rafael França
bcb3383256
Merge pull request #40742 from dotLou/development_only_execute_route_reloader_once
Only execute route reloads once on boot for development environment
2020-12-03 17:29:34 -05:00
Rafael Mendonça França
028faabc5f
Align all the assigments 2020-12-03 22:28:45 +00:00
Louis Cloutier
796e7129e6
Only execute route reloads once on boot for development environment
Signed-off-by: Louis Cloutier <louis.cloutier@shopify.com>
2020-12-03 15:55:41 -05:00
Ryunosuke Sato
78e0e183c5
Fix to handle missing yarn environment in bin/yarn
When we use `bin/yarn` without original yarn,
the following error will be occurred:
```
bin/yarn:12:in `initialize': no implicit conversion of nil into String (TypeError)
```

This means `executable_path` is `nil`.

To handle missing yarn correctly, checking `executable_path` seems good.
This is a result of my local without yarn.
```
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
rake aborted!
```

This commit follows up https://github.com/rails/rails/pull/40646.
2020-12-03 22:27:43 +09:00
Rafael França
855e782979
Merge pull request #40717 from cindygshopify/remove_sprockets_related_files
removed sprocket related files
2020-12-02 20:51:06 -05:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Cindy Gao
d620f068c2 removed sprocket related files manifest.js and application.css from generated rails app when --skip-sprockets flag passed into rails new and app:update 2020-12-02 14:52:46 -05:00
Petrik
0a583c73c1 Change form_with to generate non remote forms by default
`form_with` would generate a remote form by default.
This confused users because they were forced to handle remote requests.

All new 6.1 applications will generate non-remote forms by default.
When upgrading a 6.0 application you can enable remote forms by default by
setting `config.action_view.form_with_generates_remote_forms` to `true`.
2020-12-01 21:14:37 +01:00
Rafael França
363cd6d5c0
Merge pull request #40503 from juanmanuelramallo/increase-worker-timeout-in-development
Increasing Puma's worker timeout in development
2020-11-30 18:43:05 -05:00
Alex Ghiculescu
76e432341c Always recommend config.asset_host in examples 2020-11-30 16:33:51 -06:00