Commit Graph

86481 Commits

Author SHA1 Message Date
Hartley McGuire
a42863f514
Add rake task to vendor guide javascript
The Rails guides were migrated from Turbolinks to Turbo in
0f6575a5344246d385d1a724e8b0bb3544ab6478

The PR discussion explains that the file was grabbed from unpkg, and a
decision was made to not run it through a minifier.

This commit adds a rake task to automate the process of grabbing the
turbo js file using Importmap::Packager, which is what importmap-rails
uses for `bin/importmap pin --download`.

The extra Importmap module definition is necessary because the
Importmap::Packager file uses the shorthand module syntax, meaning that
an error is thrown if the Importmap module is not previously defined.
`require "importmap-rails"` would normally define this module, but one
of its dependent requires will not load outside of a Rails application.

The turbo.css file was removed as it appears to be leftover from
Turbolinks and Turbo does not provide any css files in its dist.
2023-02-13 00:58:58 -05:00
Yasuo Honda
f838a74212
Merge pull request #46866 from ghousemohamed/change-year-2022-to-2023 2023-02-13 13:15:43 +09:00
Yasuo Honda
1766d2d3b4
Merge pull request #47371 from skipkayhil/add-config-doc-linter
Add linter for framework defaults and Rails config
2023-02-13 10:46:20 +09:00
Jonathan Hefner
7e57537bb9
Merge pull request #47326 from jonathanhefner/message_encryptor-and-message_verifier-use-throw
Use `throw` for message error handling control flow
2023-02-12 15:50:51 -06:00
Jonathan Hefner
d3917f5fdd Use throw for message error handling control flow
There are multiple points of failure when processing a message with
`MessageEncryptor` or `MessageVerifier`, and there several ways we might
want to handle those failures.  For example, swallowing a failure with
`MessageVerifier#verified`, or raising a specific exception with
`MessageVerifier#verify`, or conditionally ignoring a failure when
rotations are configured.

Prior to this commit, the _internal_ logic of handling failures was
implemented using a mix of `nil` return values and raised exceptions.
This commit reimplements the internal logic using `throw` and a few
precisely targeted `rescue`s.  This accomplishes several things:

* Allow rotation of serializers for `MessageVerifier`.  Previously,
  errors from a `MessageVerifier`'s initial serializer were never
  rescued.  Thus, the serializer could not be rotated:

    ```ruby
    old_verifier = ActiveSupport::MessageVerifier.new("secret", serializer: Marshal)
    new_verifier = ActiveSupport::MessageVerifier.new("secret", serializer: JSON)
    new_verifier.rotate(serializer: Marshal)

    message = old_verifier.generate("message")

    new_verifier.verify(message)
    # BEFORE:
    # => raises JSON::ParserError
    # AFTER:
    # => "message"
    ```

* Allow rotation of serializers for `MessageEncryptor` when using a
  non-standard initial serializer.  Similar to `MessageVerifier`, the
  serializer could not be rotated when the initial serializer raised an
  error other than `TypeError` or `JSON::ParserError`, such as
  `Psych::SyntaxError` or a custom error.

* Raise `MessageEncryptor::InvalidMessage` from `decrypt_and_verify`
  regardless of cipher.  Previously, when a `MessageEncryptor` was using
  a non-AEAD cipher such as AES-256-CBC, a corrupt or tampered message
  would raise `MessageVerifier::InvalidSignature` due to reliance on
  `MessageVerifier` for verification.  Now, the verification mechanism
  is transparent to the user:

    ```ruby
    encryptor = ActiveSupport::MessageEncryptor.new("x" * 32, cipher: "aes-256-gcm")
    message = encryptor.encrypt_and_sign("message")
    encryptor.decrypt_and_verify(message.next)
    # => raises ActiveSupport::MessageEncryptor::InvalidMessage

    encryptor = ActiveSupport::MessageEncryptor.new("x" * 32, cipher: "aes-256-cbc")
    message = encryptor.encrypt_and_sign("message")
    encryptor.decrypt_and_verify(message.next)
    # BEFORE:
    # => raises ActiveSupport::MessageVerifier::InvalidSignature
    # AFTER:
    # => raises ActiveSupport::MessageEncryptor::InvalidMessage
    ```

* Support `nil` original value when using `MessageVerifier#verify`.
  Previously, `MessageVerifier#verify` did not work with `nil` original
  values, though both `MessageVerifier#verified` and
  `MessageEncryptor#decrypt_and_verify` do:

    ```ruby
    encryptor = ActiveSupport::MessageEncryptor.new("x" * 32)
    message = encryptor.encrypt_and_sign(nil)

    encryptor.decrypt_and_verify(message)
    # => nil

    verifier = ActiveSupport::MessageVerifier.new("secret")
    message = verifier.generate(nil)

    verifier.verified(message)
    # => nil

    verifier.verify(message)
    # BEFORE:
    # => raises ActiveSupport::MessageVerifier::InvalidSignature
    # AFTER:
    # => nil
    ```

* Improve performance of verifying a message when it has expired and one
  or more rotations have been configured:

    ```ruby
    # frozen_string_literal: true
    require "benchmark/ips"
    require "active_support/all"

    verifier = ActiveSupport::MessageVerifier.new("new secret")
    verifier.rotate("old secret")

    message = verifier.generate({ "data" => "x" * 100 }, expires_at: 1.day.ago)

    Benchmark.ips do |x|
      x.report("expired message") do
        verifier.verified(message)
      end
    end
    ```

  __Before__

    ```
    Warming up --------------------------------------
         expired message     1.442k i/100ms
    Calculating -------------------------------------
         expired message     14.403k (± 1.7%) i/s -     72.100k in   5.007382s
    ```

  __After__

    ```
    Warming up --------------------------------------
         expired message     1.995k i/100ms
    Calculating -------------------------------------
         expired message     19.992k (± 2.0%) i/s -    101.745k in   5.091421s
    ```

Fixes #47185.
2023-02-12 15:16:25 -06:00
Hartley McGuire
630b1ff128
Add linter for framework defaults and Rails config
This linter parses the Rails::Application::Configuration file and
ensures that
- all configurations are listed alphabetically in Configuring guide
- all framework defaults are listed alphabetically in Configuring guide
- all framework defaults are included in the new_framework_defaults_x_x
  template
2023-02-12 14:49:02 -05:00
Vipul A M
21a3b52ba0
Merge pull request #47356 from GeoffTidey/activestorage-security-docs-update
Adjust guide to explain you *should* disable the ActiveStorage default routes when implementing authenticated routes [ci skip]
2023-02-12 20:06:57 +05:30
Vipul A M
8b6b7c79f4
Merge pull request #47366 from dpedoneze/patch-1
Fix S3 CORS example
2023-02-12 20:04:31 +05:30
Petrik de Heus
672df5b923
Merge pull request #47368 from vipulnsward/fix-missing-bash-signs
Fix all missing $ signs in all bash commands in guides
2023-02-12 10:42:43 +01:00
Petrik de Heus
9030c0653d
Merge pull request #47308 from p8/activerecord/improve-eager-loading-docs2
Clarify how `eager_load` and `preload` works [ci-skip]
2023-02-12 10:01:01 +01:00
Guillermo Iguaran
4973c07d9e Move comment about TestInput to the header of class definition to make clear the purpose of the class 2023-02-11 22:42:04 -08:00
Guillermo Iguaran
097ead29d9
Merge pull request #47336 from pedro108/fix-raw-post-for-chunked-request
Fix request.raw_post empty bug when the Transfer-Encoding header is present
2023-02-11 17:16:18 -08:00
Vipul Amler
8db4161f58 Fix missing $ signs in all bash commands in guides 2023-02-12 05:49:43 +05:30
David Pedoneze
554e94ad82
Fix S3 CORS example
Update keys to match latest AWS using ExposeHeaders and MaxAgeSeconds
2023-02-11 16:31:56 -03:00
Vipul A M
b6ecefddac
Merge pull request #47364 from hachi8833/fix_active_support_core_extension_sample
[ci-skip] fix sample code for *bytes methods in Active Support Guide
2023-02-11 18:49:38 +05:30
hachi8833
70010dfa79 [ci-skip] fix sample code for *bytes methods 2023-02-11 21:45:18 +09:00
Pedro de Jesus
c426e46d76 Add body_stream.rewind before reading it on ActionPack::Request 2023-02-10 19:02:19 +00:00
Pedro de Jesus
75126b8dd4 Fix issue #46784 2023-02-10 17:27:49 +00:00
Geoff Tidey
7880b76d7b Adjust guide to explain you *should* disable the ActiveStorage default routes when implementing authenticated routes [ci skip] 2023-02-10 17:00:23 +00:00
Jonathan Hefner
c88ca3b720
Merge pull request #47242 from skipkayhil/hm-rm-extra-engine-require
Remove unneeded require in plugin application.rb
2023-02-10 10:18:08 -06:00
Jonathan Hefner
f6cccfc380
Merge pull request #47339 from fatkodima/optimize-highlight-helper
Optimize `TextHelper.highlight` for large inputs

Co-authored-by: Matthew Draper <matthew@trebex.net>
Co-authored-by: John Hawthorn <john@hawthorn.email>
2023-02-10 10:08:34 -06:00
Eileen M. Uchitelle
9057668711
Merge pull request #47320 from jessicajoly88/jj/the_right_branch
Fix state leakage between tests
2023-02-10 10:49:40 -05:00
Eileen M. Uchitelle
ca13681f3b
Merge pull request #47351 from markhallen/add-regression-test-for-timestamped-before-save-callback-mutations
Add missing test for timestamp on before_save
2023-02-10 10:37:40 -05:00
Jessica Joly
68aceb5946 [Fix #47203]Fix state leakage between tests
The state that leaks comes from the table schema cache because the cache never gets cleared when the table gets dropped in a test scenario.

We now clear the schema cache every time a table is dropped in a test scenario.

Co-authored-by: Frederic Ma <frederic.ma@shopify.com>
2023-02-10 15:26:32 +00:00
Mark Allen
7d1615ef89 Add regression test for timestamp on before_save
Related to #45389

Guard against the omission of touching the `updated_at` timestamp in the scenario where attributes are changed by `before` callbacks, but no attributes are changed outside of the callbacks.
2023-02-10 13:49:46 +00:00
fatkodima
f2cb36f1bc Optimize TextHelper.highlight for large inputs
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-02-10 12:47:14 +02:00
Petrik
2b5ee8db3d Clarify how eager_load and preload works [ci-skip]
This tries to improve the documentation by:
* Explaining what types of queries will be created;
* Explaining the benefits of using separate queries over a simple join;
* Showing the SQL that will be generated.

Co-authored-by: zzak <zzakscott@gmail.com>
2023-02-10 10:50:46 +01:00
zzak
e184d33dfc
Merge pull request #47349 from rails/revert-47348-revert-47263-revert-47261-rdoc-configure
Revert "Revert "Revert "Configure RDoc in Task#new"""
2023-02-10 17:32:49 +09:00
zzak
d40d4958da
Revert "Revert "Revert "Configure RDoc in Task#new""" 2023-02-10 17:31:25 +09:00
zzak
0e25d8e01b
Merge pull request #47348 from rails/revert-47263-revert-47261-rdoc-configure
Revert "Revert "Configure RDoc in Task#new""
2023-02-10 17:28:58 +09:00
zzak
0607e5d5a6
Revert "Revert "Configure RDoc in Task#new"" 2023-02-10 17:26:31 +09:00
Hartley McGuire
1d241f0f0b
Remove unneeded require in plugin application.rb
This require was added in cfcea1d53ae5ce38a7cbeb41e05958dc009988b0, but
at that time the generated Gemfile did not resolve using the gemspec.
gemspec was added to the plugin's generated Gemfile later in
a74e4736f95befa7a22c208019bf11a155ff7543. Since then, the
Bundler.require in the plugin's generated config/application.rb will
require the plugin and the extra require is unneeded.

The replaced test was added in adfa417fbbf6f670c3d10ed2c32c58bc1dc92c2e
when the plugin generator's application.rb was replaced with the app
generator's. Since the test is only concerned with the file content and
not whether that content is useful, the test was replaced with an
attempt to run the plugin's test, since this would verify that the
plugin can be loaded within the dummy app.

The plugin helpers are added because the generated Gemfile is now used
for resolution instead of Rails'. This makes the tests more accurate
because real plugins will be resolving against their own Gemfiles.
However, this also leads to a few issues solved by the new helpers:
- gemspecs are generated with TODOs that have to be fixed
- commands run in the plugin must have their Bundler environment reset
because processes spawned in Rails' tests inherit BUNDLE_GEMFILE

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-02-09 20:44:44 -05:00
Rafael Mendonça França
8231a4c61e
Merge pull request #47344 from ggmichaelgo/main
maintain html_safe? on sliced HTML safe strings
2023-02-09 16:24:08 -05:00
Michael Go
2e52d0a39d [Fix #47343] maintain html_safe? on sliced HTML safe strings 2023-02-09 16:51:22 -04:00
Petrik de Heus
6ab16868ff
Merge pull request #47342 from p8/guides/code-blocks
Improve code block examples in plugins guide [ci-skip]
2023-02-09 21:41:37 +01:00
Petrik
58616c8c7e Improve code block examples in plugins guide [ci-skip]
Remove obsolete indentation and mark as test output as bash code.
2023-02-09 21:38:53 +01:00
Jonathan Hefner
1bb9f0e616
Merge pull request #47309 from 4geru/railties/infinitive-form-descriptions-again
Use infinitive form for all task descriptions verbs

Co-authored-by: Petrik <petrik@deheus.net>
2023-02-09 10:56:41 -06:00
Eileen M. Uchitelle
ee43a8fe6c
Merge pull request #47330 from skipkayhil/add-metadata-default-to-guide
Add use_message_serializer_for_metadata to guide [ci skip]
2023-02-09 10:37:41 -05:00
Carlos Antonio da Silva
643c2cbbff Fix changelog example in actionpack
`full_path` is actually `fullpath`, as described in the line above.
`filtered_path` exists only in the `request` object, not `response`.

[ci skip]
2023-02-09 09:08:17 -03:00
Carlos Antonio da Silva
99bbbf26c4 Move strict_loading_violation event down and add info about config
`sql.active_record` should be more commonly used than this more specific
`strict_loading_violation.active_record` one, so move it down in the
guide and leave the `sql` one first.

Also add an info message about that event only being emitted in case the
relevant config is set, otherwise it defaults to raising an error and no
event is instrumented.

[ci skip]
2023-02-09 09:00:49 -03:00
zzak
813f978747
Merge pull request #47333 from zzak/re-c7792a0
Document option section style for API guidelines
2023-02-09 17:24:20 +09:00
zzak
70494a608c
Document option section style for API guidelines 2023-02-09 17:20:55 +09:00
zzak
52689f1353
Merge pull request #47332 from zzak/re-46760
Add a note about ENV["SECRET_KEY_BASE_DUMMY"] to asset_pipeline guide
2023-02-09 16:21:18 +09:00
zzak
4a4665375c
Add a note about ENV["SECRET_KEY_BASE_DUMMY"] to asset_pipeline guide 2023-02-09 16:17:49 +09:00
Petrik de Heus
cafd92dbe9
Merge pull request #47305 from skipkayhil/update-deprecation-event-guide
Update deprecation.rails hook in guides [ci skip]
2023-02-09 07:48:47 +01:00
zzak
5315d8d04d
Merge pull request #47331 from zzak/re-47317
🌶️ Spice up new Mailer preview for all headers
2023-02-09 14:53:41 +09:00
zzak
b3d64e0112
🌶️ Spice up new Mailer preview for all headers 2023-02-09 14:50:47 +09:00
Hartley McGuire
26e54be048
Add use_message_serializer_for_metadata to guide
It was added in 91bb5da5fc3a121a56464aada5b6b38655eb6b0f
2023-02-09 00:05:01 -05:00
zzak
7f4245c336
Merge pull request #47329 from zzak/re-46296
RE: defer and async options in javascript_include_tag
2023-02-09 13:09:51 +09:00
zzak
78be186970
RE: defer and async options in javascript_include_tag
Combines #46296 and #46793 PRs.

Co-authored-by: Paulo Fidalgo <paulo.fidalgo.pt@gmail.com>
Co-authored-by: OKURA Masafumi <masafumi.o1988@gmail.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
Co-authored-by: Alex Ghiculescu <alex@tanda.co>
2023-02-09 13:02:21 +09:00