Commit Graph

7253 Commits

Author SHA1 Message Date
Étienne Barrié
da740d63b2 Stop setting RAILS_ENV when test_unit railtie is loaded
Because the TestUnit::Runner is used to run the tests from Rake test
tasks, we don't need to set the Rails environment based on the name of
the task anymore.

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2021-02-01 16:00:05 -05:00
Kasper Timm Hansen
51bab5927c
Merge pull request #41000 from jonathanhefner/dark-mode-css
Tweak dark mode CSS
2021-01-29 03:26:16 +01:00
Kasper Timm Hansen
aada36fa31
Merge pull request #41132 from etiennebarrie/rake-test-tasks
Ensure test rake commands run immediately
2021-01-28 02:13:46 +01:00
Rafael Mendonça França
033706b2dc
Rename the config to make clear it is a boolean 2021-01-27 00:31:16 +00:00
Rafael Mendonça França
8405513071
ActionDispatch::Request#content_type now returned Content-Type header as it is 2021-01-27 00:28:54 +00:00
André Luis Leal Cardoso Junior
2fafcd84f4 Remove media=all from stylesheet_link_tag on generators 2021-01-22 21:27:47 -03:00
André Luis Leal Cardoso Junior
1280620767 Remove legacy media=screen default from stylesheet_link_tag.
If the media attribute is omitted, the default for web browsers is "all", meaning that by default links apply to all media.

Before:

```ruby
> stylesheet_link_tag "style"
=> <link href="/assets/style.css" media="screen" rel="stylesheet" />
```

After:

```ruby
> stylesheet_link_tag "style"
=> <link href="/assets/style.css" rel="stylesheet" />

```

The current behavior is not going to change for existing applications.

For newly built applications, the media attribute is not going to be added by default. Which can be configured using the following:

```
Rails.application.config.action_view.stylesheet_media_default = false
```
2021-01-22 20:42:22 -03:00
Jonathan Hefner
ad25006216 Resolve default annotation tags after config loads
`Rails::SourceAnnotationExtractor::Annotation.tags` may be modified by
app configuration.  Therefore, resolve default annotation tags after
loading the app configuration.

This fixes errors like https://buildkite.com/rails/rails/builds/74268#240d60bc-baa7-4b6e-ad21-b3172095f939/1083-1092
resulting from erikhuda/thor@0222fe52ed.
2021-01-21 14:56:19 -06:00
Jonathan Hefner
982b14fb2b Search for yarn.cmd and yarn.ps1 in bin/yarn
Follow-up to #40950.

On Windows, Yarn actually uses `yarn.cmd` and `yarn.ps1` for PowerShell.
2021-01-21 12:28:22 -06:00
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
Étienne Barrié
9aac3cb1d2 Ensure test rake commands run immediately
Before this commit, Rails test Rake tasks only load the test files, and
the tests only run in an at_exit hook via minitest/autorun.

This prevents conditionally running tasks only when tests pass, or even
more simply in the right order. As a simple example, if you have:

task default: [:test, :rubocop]

The rubocop task will run after the test task loads the test files but
before the tests actually run.

This commit changes the test Rake tasks to shell out to the test runner
as a new process.

This diverges from previous behavior because now, any changes made in
the Rakefile or other code loaded by Rake won't be available to the
child process. However this brings the behavior of `rake test` closer to
the behavior of `rails test`.

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2021-01-16 14:38:30 -05: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
b2db22204d Tweak dark mode CSS
Follow-up to #40960.

This fixes a few different visual issues with links and table rows when
using dark mode.

Co-authored-by: Chris Seelus <chris@imeos.com>
2021-01-02 13:21:48 -06: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