Commit Graph

90545 Commits

Author SHA1 Message Date
Stan Lo 4d6714fcd3
Remove unnecessary nocolorize flag
Setting `TERM=dumb` is enough to disable colorization in those tests.

Mocked app should also load console helpers

Move console method extension to IRBConsole's constructor

Test IRB autocompletion control without mutating ENV

Control IRB autocompletion without mutating ENV

Correct local variable name
2024-01-20 11:45:52 +00:00
Jean Boussier 30cb7a6221
Merge pull request #50796 from Shopify/implement-#50770
Add customized prompt for Rails console
2024-01-19 20:11:51 +01:00
Stan Lo 0c2898a768
Create IRBConsole to encapsulate IRB-specific setup
Add Rails-specific IRB prompt

Update changelog
2024-01-19 19:01:26 +00:00
Edouard Chin 21eceb7db2
Merge pull request #50808 from m-nakamura145/actionpack/modules_for_helpers-example
Add example to modules_for_helpers documentation [ci-skip]
2024-01-19 16:59:37 +01:00
m-nakamura145 930649598f
Add example to modules_for_helpers documentation [ci-skip] 2024-01-20 00:48:59 +09:00
Jean Boussier 2ddbca3e6a
Merge pull request #50809 from Shopify/freeze-cached-strings
Freeze and dedup `quote_column_name` and `quote_table_name` caches
2024-01-19 15:23:55 +01:00
Petrik de Heus 25d03be267
Merge pull request #50810 from m-nakamura145/activesupport/duration-parts-example
Add example to parts documentation [ci-skip]
2024-01-19 15:10:24 +01:00
m-nakamura145 a5af0a9118
Add example to parts documentation [ci-skip] 2024-01-19 22:05:59 +09:00
Jean Boussier 44ef49c2d0
Merge pull request #50804 from joshuay03/consistently-raise-an-error-for-nested-attributes-args
[Fix #50803] Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer
2024-01-19 13:29:01 +01:00
Jean Boussier 9d4a44d049 Freeze and dedup `quote_column_name` and `quote_table_name` caches
Avoid corrupting the cache by mutating the return value, and also
sligthly reduce memory usage when the quoting format often return
an unmodified string.
2024-01-19 12:42:02 +01:00
Joshua Young 1eab83a0a8 [Fix #50803] Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer 2024-01-19 20:34:33 +10:00
Jonathan Hefner 9c3ffab47c Fix RateLimitingTest assertion for :by option
Follow-up to #50788.

This test wasn't actually asserting that the `:by` option worked.
2024-01-18 18:43:43 -06:00
Jonathan Hefner c8bfd6870d
Merge pull request #50799 from jonathanhefner/command-fix-task-list-when-no-default-task
Fix `bin/rails -T` when no default task is defined
2024-01-18 18:43:18 -06:00
Eugene Kenny 36cc7c560b Remove unsupported values for config.action_dispatch.show_exceptions [ci skip]
Support for `true` and `false` was removed in
ec2c2666c2.
2024-01-19 00:21:26 +00:00
Jonathan Hefner f21e4299d6 Fix `bin/rails -T` when no default task is defined
When Rake parses an argument string with no tasks, it sets the top-level
task as "default".  Prior to this commit, if no default task was defined
(for example, if an app was generated with `--skip-test` and didn't
define its own default task), `Rails::Command::RakeCommand` would raise
`UnrecognizedCommandError`, preventing Rake from displaying the task
list.

This commit changes `Rails::Command::RakeCommand` to let Rake handle the
"default" task.

Fixes #50700.
2024-01-18 18:10:44 -06:00
Jonathan Hefner a18aa26f0c
Merge pull request #50798 from jonathanhefner/command-handle-unrecognized-bare-option
Print `bin/rails` help on unrecognized bare options
2024-01-18 18:10:23 -06:00
Jonathan Hefner dc85b953aa Print bin/rails help on unrecognized bare options
Prior to this commit, `bin/rails` would pass unrecognized bare options
on to Rake:

  ```console
  $ bin/rails -v
  Rails 7.2.0.alpha

  $ bin/rails -V
  rake, version 13.0.6

  $ bin/rails -s
  Running 0 tests in a single process (parallelization threshold is 50)
  ...

  $ bin/rails -S
  invalid option: -S
  ```

This commit changes `bin/rails` to print its help message when given an
unrecognized bare option:

  ```console
  $ bin/rails -v
  Rails 7.2.0.alpha

  $ bin/rails -V
  Usage:
    bin/rails COMMAND [options]

  You must specify a command. The most common commands are:
  ...

  $ bin/rails -s
  Usage:
    bin/rails COMMAND [options]

  You must specify a command. The most common commands are:
  ...

  $ bin/rails -S
  Usage:
    bin/rails COMMAND [options]

  You must specify a command. The most common commands are:
  ...
  ```

However, for backward compatibility, an exception has been made for the
`-T` / `--tasks` option:

  ```console
  $ bin/rails -T
  # Prints list of Rake tasks...
  ```

Addresses #50712.
2024-01-18 17:43:18 -06:00
Eugene Kenny 78fd6b7816 Remove outdated comment in ExceptionsWrapper#show? [ci skip]
Support for `true` and `false` was removed in
ec2c2666c2.
2024-01-18 21:31:32 +00:00
Jean Boussier 4816684c85
Merge pull request #50737 from skipkayhil/hm-further-optimize-tag-builder
Optimize TagBuilder tag generation
2024-01-18 19:19:27 +01:00
Jean Boussier 0a30d2bb3a
Merge pull request #50794 from Shopify/test-trigger-pk-population-against-more-dbs
[Tests only] Expand trigger populated PK test case to run against more DBs
2024-01-18 19:17:00 +01:00
Nikita Vasilevsky 24570678d6
[Tests only] Expand trigger populated PK test case to run against more DBs 2024-01-18 17:28:12 +00:00
Rafael Mendonça França 57034632f5
Merge pull request #50775 from mockdeep/rf-thread_fix
Fix threading issue with strict locals
2024-01-18 11:57:25 -05:00
Jean Boussier 8e0a702bf3
Merge pull request #50788 from Shopify/cleanup-file-store
`RateLimiting` Cleanups
2024-01-18 17:54:44 +01:00
Eileen M. Uchitelle 33aa383c20
Merge pull request #50783 from Shopify/append-pk-to-returning-columns-if-returning-is-empty
Always request `primary_key` in `RETURNING` if no other columns requested
2024-01-18 11:45:40 -05:00
Jean Boussier 4530a56e0f `RateLimiting` Cleanups
Followup: https://github.com/rails/rails/pull/50781

Some small issues I failed to address in the original PR.
2024-01-18 10:11:43 +01:00
Jean Boussier 8f386d7321
Merge pull request #50778 from fatkodima/fix-caching-async-queries
Fix async queries to work with query cache and other cached async queries
2024-01-17 20:44:38 +01:00
fatkodima 63ad11ab20 Fix async queries to work with query cache and other cached async queries 2024-01-17 21:32:14 +02:00
Nikita Vasilevsky c2c861f98a
Always request `primary_key` in `RETURNING` if no other columns requested
Prior 7.1 Rails always included `primary_key` in `RETURNING` clause on
record creation. This was changed in 7.1 to include more auto-populated
columns if such columns exist. This change lead to situations where
no columns were requested in `RETURNING` clause, even the `primary_key`.

This change brings back the old behavior of always requesting the
`primary_key` in `RETURNING` clause if no other columns are requested.
2024-01-17 18:19:40 +00:00
Jean Boussier 194ce13228 More AC::RateLimiting documentation fixes 2024-01-17 18:01:22 +01:00
Jean Boussier 10a34b7621 Touch up the AC::RateLimiting documentation 2024-01-17 17:59:49 +01:00
Jean Boussier 1205a751c5
Merge pull request #50781 from Shopify/as-cache-limitter
Refactor `ActionController::RateLimiting` to use `AS::Cache`
2024-01-17 17:49:27 +01:00
Jean Boussier d839ddb71a Refactor `ActionController::RateLimiting` to use `AS::Cache`
Given that the limiter implementation provided by Kredis is a simple
increment with a limit, all `ActiveSupport::Cache` already provide that
same capability, with a wide range of backing stores, and not just Redis.

This even allow to use SolidCache has a backend if you so desire.

If we feel particularly fancy, we could also accept a more generic
limiter interface to better allow users to swap the implementation
for better algorithms such as leaky-bucket etc.
2024-01-17 15:40:49 +01:00
Jean Boussier b54a287f9d Ensure all Cache store have consistent TTL behavior on increment
Make sure they all increment the counter but don't update the TTL.
2024-01-17 15:40:16 +01:00
Jean Boussier 25b7f64074
Merge pull request #50733 from yash/yk/fix-mysql-escapes-on-default-generated
Fix single quote escapes on default generated MySQL columns
2024-01-17 13:48:03 +01:00
Yash Kapadia 0702c24e7b Fix single quote escapes on default generated MySQL columns
MySQL 5.7.5+ supports generated columns, which can be used to create a column that is computed from an expression. This commit fixes the escaping of the default value for such expressions if a single quote is included.

See the following for more: https://dev.mysql.com/blog-archive/generated-columns-in-mysql-5-7-5/
2024-01-17 07:12:27 -05:00
Jean Boussier a9562e28c4
Merge pull request #50779 from Shopify/debug-ar-time
Fix `ActiveSupport::Notifications.publish_event` to preserve units
2024-01-17 13:07:32 +01:00
Jean Boussier de779f2bf7 Fix `ActiveSupport::Notifications.publish_event` to preserve units
Ref: https://github.com/rails/rails/pull/43502
Fix: https://github.com/rails/rails/pull/50767
Fix: https://github.com/rails/rails/pull/50493

When republishing a an event into a `start, finish` tuple, we need
to convert the timestamps back into seconds.
2024-01-17 12:53:40 +01:00
Yasuo Honda 2fb05958a6
Merge pull request #50756 from Angy-h/getting-started-update-screenshot
Update the screenshot in the section 8.4 of Getting Started with Rails [ci skip]
2024-01-17 18:11:47 +09:00
Akira Matsuda a71e0aabe3
Merge pull request #46872 from amatsuda/fast_string_to_time_bug
TZ offset minute has to be negated in the Western Hemisphere
2024-01-17 17:55:38 +09:00
Akira Matsuda d10d5aedce
TZ offset minute has to be negated in the Western Hemisphere
When the TZ in the given string contains minus offset, both hour and minute
value has to be negated, but the current code negates hour only.
Hence, for instance in Newfoundland Time Zone (UTC−03:30), it used to return
1 hour advanced value.

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2024-01-17 17:25:37 +09:00
Robert Fletcher 929f9fd3fe Fix threading issue with strict locals
Fixes #50774

When the server boots up, 2 threads hit the same `UnboundTemplate`
instance before it has set up `@templates`. Both threads get past the
`unless template = @templates[locals]` check because
`@templates[locals]` isn't set yet. However, with `@write_lock`, one
thread waits while the other one proceeds, setting `@templates` to a
frozen hash. The second thread then gets the write lock and tries to
modify `@templates` but it has been frozen.
2024-01-16 16:27:58 -08:00
Rafael Mendonça França 473fd597f6
Merge pull request #50769 from p8/actiontext/eager-load-with-includes
Use `includes` instead of `eager_load` for `with_all_rich_text`
2024-01-16 18:28:38 -05:00
Rafael Mendonça França 474ee0a014
Merge pull request #50773 from skipkayhil/hm-fix-another-compat-issue
Fix t.references validating options on Rails < 7.1
2024-01-16 18:09:33 -05:00
Hartley McGuire 597b56cde0
Optimize TagBuilder tag generation
Currently there's about a 35% difference between tags generated using
the `TagBuilder` and tags generated by passing a positional argument to
`#tag`.

This commit optimizes `TagBuilder` to reduce that difference down to 13%.

The first change is to perform less hash allocations by not splatting
the options twice in the `TagBuilder` (one at the `tag.a` invocation,
and one at `tag_string`). The extra splat for `tag_string` was moved
into `method_missing` since that is the only other caller of this
private method.

The other change is to only escape the content in `tag_string` if it a
non-empty.

Additionally, a test was tweaked to ensure that passing `options` to a
`self_closing_element` is tested as it was previously not.

Benchmark:

```
require "action_view"
require "benchmark/ips"

class Foo
  include ActionView::Helpers
end

helpers = Foo.new

Benchmark.ips do |x|
  x.report("tag") { helpers.tag("a", href: "foo") }
  x.report("tag_builder") { helpers.tag.a(href: "foo") }
  x.compare!
end
```

Before:

```
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
                 tag    67.180k i/100ms
         tag_builder    50.267k i/100ms
Calculating -------------------------------------
                 tag    673.064k (± 0.4%) i/s -      3.426M in   5.090520s
         tag_builder    504.971k (± 0.4%) i/s -      2.564M in   5.076842s

Comparison:
                 tag:   673063.7 i/s
         tag_builder:   504971.4 i/s - 1.33x  slower
```

After:

```
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
                 tag    67.374k i/100ms
         tag_builder    59.702k i/100ms
Calculating -------------------------------------
                 tag    670.837k (± 0.4%) i/s -      3.369M in   5.021714s
         tag_builder    592.727k (± 1.3%) i/s -      2.985M in   5.037088s

Comparison:
                 tag:   670836.6 i/s
         tag_builder:   592726.7 i/s - 1.13x  slower
```

Co-authored-by: Sean Doyle <seanpdoyle@users.noreply.github.com>
2024-01-16 17:51:21 -05:00
Hartley McGuire 327f28b65f
Fix t.references validating options on Rails < 7.1
Option validation was [added][1] for 7.1+ Migration classes, and a
compatibility layer was added to ensure that previous Migration versions
do not have their options validated. However, the `t.references` method
was missing in the compatibility layer which results in pre 7.1
Migrations validating options passed to `t.references`.

This commit fixes the issue by adding t.references to the compatibility
layer.

See also a [similar fix][2] for `add_reference`

[1]: e6da3ebd6c
[2]: 71b4e22301
2024-01-16 17:21:22 -05:00
Petrik 3b49e47ce8 Use `includes` instead of `eager_load` for `with_all_rich_text`
`eager_load` performs a single query using a `LEFT OUTER JOIN` to load
the associations. Loading the associations in a join can result in many
rows that contain redundant data and it performs poorly at scale.

With `includes` a separate query is performed for each association,
unless a join is required by conditions.

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-01-16 22:06:19 +01:00
Xavier Noria 299900f4e5 Edit pass over the railties CHANGELOG 2024-01-16 20:39:04 +01:00
Aaron Patterson eccaddba5c
Merge pull request #50758 from rails/fix-video-preview-nplus1
Eagerly load preview images (N+1)
2024-01-16 10:44:10 -08:00
Aaron Patterson 7e9b5889cc
update changelog 2024-01-16 09:36:44 -08:00
Aaron Patterson f2f50c904e
Fix N+1 on scope with non-image previews 2024-01-16 09:36:43 -08:00