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.
This commit is meant to accomplish two things:
- update gems with precompiled C extensions (nokogiri) so that Rails'
lockfile can be `bundle install`d on Ruby 3.3
- remove some Gemfile conditionals for Ruby < 3 now that 3.1 is the
minimum version
Additionally, a requirement is added to ignore mdl 0.13.0 because it
raises false positive warnings. The commit introducing those warnings
has been reverted but there has not been a release since the revert.
Also perform two autocorrects with `bundle exec rubocop -A`:
- fixes a new case of [`Style/RedundantReturn`][1]
- fixes a new case of [`Performance/StringInclude`][2]
[1]: 146b1c2e33
[2]: 3158bbb9f6
Co-authored-by: David Heinemeier Hansson <david@basecamp.com>
Follow-up to #50507.
Since `brakeman` is now included in generated apps by default, it must
be installed before running Rails tests that invoke `bin/rails` for
generated apps.
This fixes CI failures such as:
```
Error:
AppGeneratorTest#test_app_update_does_not_change_app_name_when_app_name_is_hyphenated_name:
RuntimeError: Command failed with exit 1: yes | bin/rails app:update
test/generators/app_generator_test.rb:1304:in `system'
test/generators/app_generator_test.rb:1304:in `block (2 levels) in run_app_update'
test/generators/app_generator_test.rb:1304:in `block in run_app_update'
test/generators/app_generator_test.rb:1299:in `chdir'
test/generators/app_generator_test.rb:1299:in `run_app_update'
test/generators/app_generator_test.rb:430:in `test_app_update_does_not_change_app_name_when_app_name_is_hyphenated_name'
```
This fixes the following error for the guides build:
```
Traceback (most recent call last):
13: from bug_report_templates/action_controller.rb:5:in `<main>'
12: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/inline.rb:42:in `gemfile'
11: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler.rb:403:in `with_unbundled_env'
10: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler.rb:649:in `with_env'
9: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler.rb:403:in `block in with_unbundled_env'
8: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/inline.rb:51:in `block in gemfile'
7: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/settings.rb:142:in `temporary'
6: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/inline.rb:66:in `block (2 levels) in gemfile'
5: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/runtime.rb:24:in `setup'
4: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/runtime.rb:24:in `map'
3: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/spec_set.rb:165:in `each'
2: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/spec_set.rb:165:in `each'
1: from /usr/local/bundle/gems/bundler-2.4.22/lib/bundler/runtime.rb:25:in `block in setup'
/usr/local/bundle/gems/bundler-2.4.22/lib/bundler/runtime.rb:304:in `check_for_activated_spec!': You have already activated psych 5.1.1.1, but your Gemfile requires psych 5.1.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
```
This is similar to #45052. Eventually, this should be fixed permanently
by either rubygems/rubygems#5529 or rubygems/rubygems#5535.
This commit addresses the Rails CI using Ruby master branch failure
because Rails CI enables `RAILS_STRICT_WARNINGS` to raise RuntimeError for warnings.
https://buildkite.com/rails/rails/builds/102621#018c49df-e3de-4c2f-aeb7-6d8f08997da9/1102-1107
```ruby
/rails/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb:4: warning: bigdecimal/util is found in bigdecimal, which will no longer be part of the default gems since Ruby 3.4.0. Add bigdecimal to your Gemfile or gemspec. (RuntimeError)
```
According to https://bugs.ruby-lang.org/issues/20058 ,
This failure has been triggered since cc9826503d
and it will be addressed once the bigdecimal 3.1.5 is available at rubygems.org .
In the meantime, we can workaround this issue by logking `bigdecimal` version to 3.1.4 or lower.
This commit should be reverted when the `bigdecimal` 3.1.5 is available at rubygems.org .
It breaks various `rails console` related integration tests:
```
Failure:
FullStackConsoleTest#test_sandbox [test/application/console_test.rb:123]:
"> " expected, but got:
(END).
Expected "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n--More--\r \r(END)" to include "> ".
```
I tried to figure out a fix, but ran out of time, so in order
to fix CI we can lock IRB for now.
On the first call it can be a bit slow because it needs to load
a bunch of data. It's also better to do it as part of boot
so that some of that data is shared via Copy-on-Write
This commit addresses the following CI failure
https://buildkite.com/rails/rails/builds/101658#018ba903-f8d8-4187-929c-fc7996bb17f3
- Without this fix
```
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ cd guides/bug_report_templates
$ ruby action_controller_gem.rb
... snip
/home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:308:in `check_for_activated_spec!': You have already activated timeout 0.3.1, but your Gemfile requires timeout 0.4.1. Since timeout is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports timeout as a default gem. (Gem::LoadError)
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:25:in `block in setup'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/spec_set.rb:155:in `each'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/spec_set.rb:155:in `each'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:24:in `map'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:24:in `setup'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/inline.rb:66:in `block in gemfile'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/settings.rb:131:in `temporary'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/inline.rb:50:in `gemfile'
from action_controller_gem.rb:5:in `<main>'
$
```
Ruby 3.3.0 is going to start warning for racc not being specififed as a
dependency, and Ruby 3.4.0 will raise if it is not specified.
This commit prevents those issues by adding racc to the Action Pack
gemspec, since `racc/parser` is a runtime dependency of the Journey
parser.
It used to be stdlib but is being extracted in modern rubies.
Overall its usefulness is dubious. In all cases it is included in
Rails, it's only for the `synchronize` method, but end up exposing
a dozen other useless methods.
In the end just using a Mutex is clearer and simpler.
In some cases we can even get away with a single mutex in a constant.
This commit addresses action_controller_gem.rb failure by updating psych as follows.
`$ bundle update psych --conservative`
Refer to https://buildkite.com/rails/rails/builds/100884#018b3a84-f1c5-4461-839c-5cfbe26ee001/1092-1125
- Without this commit
```
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ cd guides/bug_report_templates
$ ruby action_controller_gem.rb
Fetching gem metadata from https://rubygems.org/...........
... snip ...
Using rails 7.1.1
/home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:308:in `check_for_activated_spec!': You have already activated psych 5.1.0, but your Gemfile requires psych 5.1.1.1. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:25:in `block in setup'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/spec_set.rb:155:in `each'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/spec_set.rb:155:in `each'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:24:in `map'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:24:in `setup'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/inline.rb:66:in `block in gemfile'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/settings.rb:131:in `temporary'
from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/inline.rb:50:in `gemfile'
from action_controller_gem.rb:5:in `<main>'
$
```
## Motivation / Background
Follow up 1c93288f8b.
This PR adds bigdecimal to runtime dependency of Active Support to suppress the following Ruby 3.3.0dev's warning.
> /Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/bundler/gems/rails-a8871e6829e5/activesupport/lib/
> active_support/core_ext/object/json.rb:5: warning: bigdecimal will be not part of the default gems since Ruby 3.4.0.
> Add bigdecimal to your Gemfile. Also contact author of to add bigdecimal into its gemspec.
The grep yields the following results:
```console
$ git grep 'require.*bigdecimal'
activejob/lib/active_job/arguments.rb:3:require "bigdecimal"
activejob/lib/active_job/serializers/big_decimal_serializer.rb:3:require "bigdecimal"
activejob/test/cases/argument_serialization_test.rb:3:require "bigdecimal"
activemodel/lib/active_model/type/decimal.rb:3:require "bigdecimal/util"
activemodel/lib/active_model/validations/numericality.rb:5:require "bigdecimal/util"
activemodel/test/cases/validations/numericality_validation_test.rb:8:require "bigdecimal"
activerecord/test/cases/adapters/sqlite3/quoting_test.rb:4:require "bigdecimal"
activerecord/test/cases/arel/visitors/to_sql_test.rb:4:require "bigdecimal"
activerecord/test/cases/migration_test.rb:5:require "bigdecimal/util"
activesupport/lib/active_support/core_ext/big_decimal/conversions.rb:3:require "bigdecimal"
activesupport/lib/active_support/core_ext/big_decimal/conversions.rb:4:require "bigdecimal/util"
activesupport/lib/active_support/core_ext/object/json.rb:5:require "bigdecimal"
activesupport/lib/active_support/message_pack/extensions.rb:3:require "bigdecimal"
activesupport/lib/active_support/xml_mini.rb:5:require "bigdecimal"
activesupport/lib/active_support/xml_mini.rb:6:require "bigdecimal/util"
activesupport/test/core_ext/hash_ext_test.rb:4:require "bigdecimal"
activesupport/test/core_ext/object/duplicable_test.rb:4:require "bigdecimal"
activesupport/test/hash_with_indifferent_access_test.rb:4:require "bigdecimal"
activesupport/test/json/encoding_test_cases.rb:3:require "bigdecimal"
```
By adding only to Active Support as a dependency, it should resolve the issue due to the dependency.
## Detail
The warning is confirmed in the following step:
```ruby
$ cat generic_main.rb
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
end
require 'active_support'
require 'minitest/autorun'
# These gems will be bundled gems in Ruby 3.4
require 'bigdecimal'
```
Run generic_main.rb with Ruby 3.3.0dev below.
```console
$ ruby -v
ruby 3.3.0dev (2023-08-25T17:47:04Z master 7d32011399) [x86_64-darwin22]
$ ruby generic_main.rb
Fetching gem metadata from https://rubygems.org/.......
Resolving dependencies...
/Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/bundler/gems/rails-a8871e6829e5/activesupport/lib/
active_support/core_ext/object/json.rb:5: warning: bigdecimal will be not part of the default gems since Ruby 3.4.0.
Add bigdecimal to your Gemfile. Also contact author of to add bigdecimal into its gemspec.
Run options: --seed 39015
# Running:
Finished in 0.001313s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
```
## Additional information
It is essentially the same as https://github.com/rails/rails/pull/48907.
This `#use_puma?` check was [introduced][1] because Rails could
potentially display the wrong server URL in development if another host
or port is configured in `config/puma.rb`.
However, in Rack 3 the the name of the server class changed from
`Rack::Handler::Puma` to `Rackup::Handler::Puma`, which means that the
served_url is being logged again.
This commit fixes the check to accept either version of the class.
Additionally, puma was updated in Gemfile.lock because Puma 6.0.x prints
a deprecation warning about Rack::Handler that's fixed in 6.1.0.
[1]: 29648ff60e
This commit adds `drb`, `mutex_m` and `base64` to `activesupport/activesupport.gemspec`
because 3.3.0dev shows warnings if bundled gem candidates are required
like `mutex_m will be not part of the default gems since Ruby 3.4.0. Add it to your Gemfile.`
- Example
```
$ ruby -v ; ruby generic_main.rb
ruby 3.3.0dev (2023-08-07T23:09:02Z master 0e5da05a32) [x86_64-linux]
Fetching https://github.com/rails/rails.git
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/.......
/home/yahonda/.rbenv/versions/trunk/lib/ruby/gems/3.3.0+0/bundler/gems/rails-2942958827f1/activesupport/lib/active_support/notifications/fanout.rb:3: warning: mutex_m will be not part of the default gems since Ruby 3.4.0. Add it to your Gemfile.
/home/yahonda/.rbenv/versions/trunk/lib/ruby/gems/3.3.0+0/bundler/gems/rails-2942958827f1/activesupport/lib/active_support/message_encryptor.rb:4: warning: base64 will be not part of the default gems since Ruby 3.4.0. Add it to your Gemfile.
generic_main.rb:16: warning: drb will be not part of the default gems since Ruby 3.4.0. Add it to your inline Gemfile.
$
```
- generic_main.rb
```
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
end
require "active_support"
require "minitest/autorun"
require "drb"
require "base64"
require "mutex_m"
```
These gems are chosen as follows.
- Bundled gems candidates for Ruby 3.4
```ruby
$ ruby -v ; ruby -e 'pp Gem::BUNDLED_GEMS::SINCE.select { |k,v| v == "3.4.0" }'
ruby 3.3.0dev (2023-08-07T23:09:02Z master 0e5da05a32) [x86_64-linux]
{"abbrev"=>"3.4.0",
"observer"=>"3.4.0",
"getoptlong"=>"3.4.0",
"resolv-replace"=>"3.4.0",
"rinda"=>"3.4.0",
"nkf"=>"3.4.0",
"syslog"=>"3.4.0",
"drb"=>"3.4.0",
"mutex_m"=>"3.4.0",
"csv"=>"3.4.0",
"base64"=>"3.4.0"}
$
```
- `drb`, `mutex_m` and `base64` are required by Rails
- "drb"
```ruby
$ git grep 'require "drb"'
activesupport/lib/active_support/testing/parallelization.rb:require "drb"
activesupport/lib/active_support/testing/parallelization/server.rb:require "drb"
```
- "mutex_m"
```ruby
$ git grep 'require "mutex_m"'
actionpack/lib/action_controller/metal/params_wrapper.rb: require "mutex_m"
activerecord/lib/active_record/attribute_methods.rb:require "mutex_m"
activerecord/lib/active_record/relation/delegation.rb:require "mutex_m"
activesupport/lib/active_support/notifications/fanout.rb:require "mutex_m"
```
- "base64" usage
```ruby
$ git grep 'require "base64"'
actioncable/Rakefile:require "base64"
actionmailer/lib/action_mailer/inline_preview_interceptor.rb:require "base64"
actionpack/lib/action_controller/metal/http_authentication.rb:require "base64"
actionview/Rakefile:require "base64"
activerecord/lib/active_record/encryption/message_serializer.rb:require "base64"
activerecord/lib/active_record/fixture_set/render_context.rb:require "base64"
activerecord/test/cases/encryption/message_serializer_test.rb:require "base64"
activesupport/lib/active_support/message_encryptor.rb:require "base64"
activesupport/lib/active_support/message_verifier.rb:require "base64"
activesupport/lib/active_support/xml_mini.rb:require "base64"
railties/test/application/mailer_previews_test.rb:require "base64"
```
- Dependency between Rails related modules
- "drb" is only required by Active Support
- "mutex_m" is required by Action Pack, Active Record and Active Support
Action Pack and Active Record depend on Active Support. Therefore, adding dependency to Active Support is fine.
2942958827/actionpack/actionpack.gemspec (L36)2942958827/activerecord/activerecord.gemspec (L38)
- "base64" is required by Action Cable, Action Mailer, Action Pack, Action View,
Active Record, Active Support and Raillties.
Action Cable, Action Mailer, Action Pack, Action View and Active Record and Railties depend
on Active Support. Therefore, adding dependency to Active Support is fine.
2942958827/actioncable/actioncable.gemspec (L35)2942958827/actionmailer/actionmailer.gemspec (L36)2942958827/actionpack/actionpack.gemspec (L36)2942958827/actionview/actionview.gemspec (L36)2942958827/actionpack/actionpack.gemspec (L36)2942958827/railties/railties.gemspec (L40)
Refer to:
https://bugs.ruby-lang.org/issues/19776https://github.com/ruby/ruby/pull/8126https://github.com/rubygems/rubygems/pull/6840
* `supports_json?` always return false on mariadb so the test needs to
stub.
* to_a(as: :hash) is not supported on trilogy. And we should be dealing
with ActiveRecord::Result objects anyway.
As of Selenium 4.6, [the Selenium Manager is capable of managing Chrome
Driver installations and integrations][readme]. As of Selenium 4.11, the
Selenium Manager is capable of [capable of resolving the Chrome for
Testing installation][] path.
By omitting the `gem` declaration from the `Gemfile.tt`, newly generated
applications and applications updating their `Gemfile` in lockstep with
newer Rails versions can shed the dependency and avoid test failures
introduced by newly released Chrome versions (like, for example,
[titusfortner/webdrivers#247][]).
[readme]: 43f8ac436c (update-selenium-manager)
[titusfortner/webdrivers#247]: https://github.com/titusfortner/webdrivers/issues/247
[capable of resolving the Chrome for Testing installation]: https://github.com/rails/rails/pull/48847#issuecomment-1656756862
Co-authored-by: Titus Fortner <titusfortner@users.noreply.github.com>
Fix: https://github.com/rails/rails/issues/45017
Ref: https://github.com/rails/rails/pull/29333
Ref: https://github.com/ruby/timeout/pull/30
Historically only raised errors would trigger a rollback, but in Ruby `2.3`, the `timeout` library
started using `throw` to interupt execution which had the adverse effect of committing open transactions.
To solve this, in Active Record 6.1 the behavior was changed to instead rollback the transaction as it was safer
than to potentially commit an incomplete transaction.
Using `return`, `break` or `throw` inside a `transaction` block was essentially deprecated from Rails 6.1 onwards.
However with the release of `timeout 0.4.0`, `Timeout.timeout` now raises an error again, and Active Record is able
to return to its original, less surprising, behavior.