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.
Previously, using Rack::Sendfile would result in the following warning:
```
/usr/local/bundle/gems/rack-3.0.7/lib/rack/sendfile.rb:114: warning: assigned but unused variable - status
```
and this would print more than 150 times when running
test/application/configuration_test.rb in Railties. This commit fixes
the warnings by updating rack to 3.0.8 where the warning was fixed.
Encrypted keys were updated [previously][1] to restrict other users from
reading the file by default. However, there is a brief period of time
between an encrypted key being created and its permissions being set to
0600. This means that it is possible for another user to read that file
during that time.
This commit fixes that issue by setting the desired permissions when the
file is created. The ability to use the `perm` option was added in Thor
1.2.2 so the minimum version was updated in the Railties gemspec.
[1]: 4c6c3575c6
Address these Rails CI failures:
https://buildkite.com/rails/rails/builds/96301#01880117-acb1-4d77-935a-4a1de13c8609/1093-1101
Refer to
https://bugs.ruby-lang.org/issues/19616https://github.com/ruby/ruby/pull/7781
```ruby
$ ruby -v
ruby 3.3.0dev (2023-05-09T19:40:26Z master e1c84e8ee6) [x86_64-linux]
$ cd railties
$ bin/test test/application/console_test.rb
... snip ...
.F
Failure:
FullStackConsoleTest#test_environment_option_and_irb_option [/home/yahonda/src/github.com/rails/rails/railties/test/application/console_test.rb:133]:
"> " expected, but got:
Loading test environment (Rails 7.1.0.alpha)
Switch to inspect mode.
▽.
Expected # encoding: ASCII-8BIT
"Loading test environment (Rails 7.1.0.alpha)\r\nSwitch to inspect mode.\r\n\e[1G\xE2\x96\xBD\e[6n" to include "> ".
bin/test test/application/console_test.rb:167
^[[30;2RF
Failure:
FullStackConsoleTest#test_sandbox [/home/yahonda/src/github.com/rails/rails/railties/test/application/console_test.rb:133]:
"> " expected, but got:
Loading development environment in sandbox (Rails 7.1.0.alpha)
Any modifications you make will be rolled back on exit
▽.
Expected # encoding: ASCII-8BIT
"Loading development environment in sandbox (Rails 7.1.0.alpha)\r\nAny modifications you make will be rolled back on exit\r\n\e[1G\xE2\x96\xBD\e[6n" to include "> ".
bin/test test/application/console_test.rb:139
^[[30;2R......
Finished in 66.153595s, 0.1360 runs/s, 0.2872 assertions/s.
9 runs, 19 assertions, 2 failures, 0 errors, 0 skips
$
```
`ActiveSupport::MessagePack` is a serializer that integrates with the
`msgpack` gem to serialize a variety of Ruby objects. `AS::MessagePack`
supports several types beyond the base types that `msgpack` supports,
including `Time` and `Range`, as well as Active Support types such as
`AS::TimeWithZone` and `AS::HashWithIndifferentAccess`.
Compared to `JSON` and `Marshal`, `AS::MessagePack` can provide a
performance improvement and message size reduction. For example, when
used with `MessageVerifier`:
```ruby
# frozen_string_literal: true
require "benchmark/ips"
require "active_support/all"
require "active_support/message_pack"
marshal_verifier = ActiveSupport::MessageVerifier.new("secret", serializer: Marshal)
json_verifier = ActiveSupport::MessageVerifier.new("secret", serializer: JSON)
asjson_verifier = ActiveSupport::MessageVerifier.new("secret", serializer: ActiveSupport::JSON)
msgpack_verifier = ActiveSupport::MessageVerifier.new("secret", serializer: ActiveSupport::MessagePack)
ActiveSupport::Messages::Metadata.use_message_serializer_for_metadata = true
expiry = 1.year.from_now
data = { bool: true, num: 123456789, string: "x" * 50 }
Benchmark.ips do |x|
x.report("Marshal") do
marshal_verifier.verify(marshal_verifier.generate(data, expires_at: expiry))
end
x.report("JSON") do
json_verifier.verify(json_verifier.generate(data, expires_at: expiry))
end
x.report("AS::JSON") do
asjson_verifier.verify(asjson_verifier.generate(data, expires_at: expiry))
end
x.report("MessagePack") do
msgpack_verifier.verify(msgpack_verifier.generate(data, expires_at: expiry))
end
x.compare!
end
puts "Marshal size: #{marshal_verifier.generate(data, expires_at: expiry).bytesize}"
puts "JSON size: #{json_verifier.generate(data, expires_at: expiry).bytesize}"
puts "MessagePack size: #{msgpack_verifier.generate(data, expires_at: expiry).bytesize}"
```
```
Warming up --------------------------------------
Marshal 1.206k i/100ms
JSON 1.165k i/100ms
AS::JSON 790.000 i/100ms
MessagePack 1.798k i/100ms
Calculating -------------------------------------
Marshal 11.748k (± 1.3%) i/s - 59.094k in 5.031071s
JSON 11.498k (± 1.4%) i/s - 58.250k in 5.066957s
AS::JSON 7.867k (± 2.4%) i/s - 39.500k in 5.024055s
MessagePack 17.865k (± 0.8%) i/s - 89.900k in 5.032592s
Comparison:
MessagePack: 17864.9 i/s
Marshal: 11747.8 i/s - 1.52x (± 0.00) slower
JSON: 11498.4 i/s - 1.55x (± 0.00) slower
AS::JSON: 7866.9 i/s - 2.27x (± 0.00) slower
Marshal size: 254
JSON size: 234
MessagePack size: 194
```
Additionally, `ActiveSupport::MessagePack::CacheSerializer` is a
serializer that is suitable for use as an `ActiveSupport::Cache` coder.
`AS::MessagePack::CacheSerializer` can serialize `ActiveRecord::Base`
instances, including loaded associations. Like `AS::MessagePack`, it
provides a performance improvement and payload size reduction:
```ruby
# frozen_string_literal: true
require "benchmark/ips"
require "active_support/message_pack"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.string :body
t.timestamps
end
create_table :comments, force: true do |t|
t.integer :post_id
t.string :body
t.timestamps
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
post = Post.create!(body: "x" * 100)
2.times { post.comments.create!(body: "x" * 100) }
post.comments.load
cache_entry = ActiveSupport::Cache::Entry.new(post)
Rails70Coder = ActiveSupport::Cache::Coders::Rails70Coder
CacheSerializer = ActiveSupport::MessagePack::CacheSerializer
Benchmark.ips do |x|
x.report("Rails70Coder") do
Rails70Coder.load(Rails70Coder.dump(cache_entry))
end
x.report("CacheSerializer") do
CacheSerializer.load(CacheSerializer.dump(cache_entry))
end
x.compare!
end
puts "Rails70Coder size: #{Rails70Coder.dump(cache_entry).bytesize}"
puts "CacheSerializer size: #{CacheSerializer.dump(cache_entry).bytesize}"
```
```
Warming up --------------------------------------
Rails70Coder 329.000 i/100ms
CacheSerializer 492.000 i/100ms
Calculating -------------------------------------
Rails70Coder 3.285k (± 1.7%) i/s - 16.450k in 5.008447s
CacheSerializer 4.895k (± 2.4%) i/s - 24.600k in 5.028803s
Comparison:
CacheSerializer: 4894.7 i/s
Rails70Coder: 3285.4 i/s - 1.49x slower
Rails70Coder size: 808
CacheSerializer size: 593
```
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
The [Trilogy database client][trilogy-client] and corresponding
[Active Record adapter][ar-adapter] were both open sourced by GitHub last year.
Shopify has recently taken the plunge and successfully adopted Trilogy in their Rails monolith.
With two major Rails applications running Trilogy successfully, we'd like to propose upstreaming the adapter
to Rails as a MySQL-compatible alternative to Mysql2Adapter.
[trilogy-client]: https://github.com/github/trilogy
[ar-adapter]: https://github.com/github/activerecord-trilogy-adapter
Co-authored-by: Aaron Patterson <tenderlove@github.com>
Co-authored-by: Adam Roben <adam@roben.org>
Co-authored-by: Ali Ibrahim <aibrahim2k2@gmail.com>
Co-authored-by: Aman Gupta <aman@tmm1.net>
Co-authored-by: Arthur Nogueira Neves <github@arthurnn.com>
Co-authored-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Ashe Connor <kivikakk@github.com>
Co-authored-by: Brandon Keepers <brandon@opensoul.org>
Co-authored-by: Brian Lopez <seniorlopez@gmail.com>
Co-authored-by: Brooke Kuhlmann <brooke@testdouble.com>
Co-authored-by: Bryana Knight <bryanaknight@github.com>
Co-authored-by: Carl Brasic <brasic@github.com>
Co-authored-by: Chris Bloom <chrisbloom7@github.com>
Co-authored-by: Cliff Pruitt <cliff.pruitt@cliffpruitt.com>
Co-authored-by: Daniel Colson <composerinteralia@github.com>
Co-authored-by: David Calavera <david.calavera@gmail.com>
Co-authored-by: David Celis <davidcelis@github.com>
Co-authored-by: David Ratajczak <david@mockra.com>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Eileen Uchitelle <eileencodes@gmail.com>
Co-authored-by: Enrique Gonzalez <enriikke@gmail.com>
Co-authored-by: Garrett Bjerkhoel <garrett@github.com>
Co-authored-by: Georgi Knox <georgicodes@github.com>
Co-authored-by: HParker <HParker@github.com>
Co-authored-by: Hailey Somerville <hailey@hailey.lol>
Co-authored-by: James Dennes <jdennes@gmail.com>
Co-authored-by: Jane Sternbach <janester@github.com>
Co-authored-by: Jess Bees <toomanybees@github.com>
Co-authored-by: Jesse Toth <jesse.toth@github.com>
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Co-authored-by: John Barnette <jbarnette@github.com>
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: John Nunemaker <nunemaker@gmail.com>
Co-authored-by: Jonathan Hoyt <hoyt@github.com>
Co-authored-by: Katrina Owen <kytrinyx@github.com>
Co-authored-by: Keeran Raj Hawoldar <keeran@gmail.com>
Co-authored-by: Kevin Solorio <soloriok@gmail.com>
Co-authored-by: Leo Correa <lcorr005@gmail.com>
Co-authored-by: Lizz Hale <lizzhale@github.com>
Co-authored-by: Lorin Thwaits <lorint@gmail.com>
Co-authored-by: Matt Jones <al2o3cr@gmail.com>
Co-authored-by: Matthew Draper <matthewd@github.com>
Co-authored-by: Max Veytsman <mveytsman@github.com>
Co-authored-by: Nathan Witmer <nathan@zerowidth.com>
Co-authored-by: Nick Holden <nick.r.holden@gmail.com>
Co-authored-by: Paarth Madan <paarth.madan@shopify.com>
Co-authored-by: Patrick Reynolds <patrick.reynolds@github.com>
Co-authored-by: Rob Sanheim <rsanheim@gmail.com>
Co-authored-by: Rocio Delgado <rocio@github.com>
Co-authored-by: Sam Lambert <sam.lambert@github.com>
Co-authored-by: Shay Frendt <shay@github.com>
Co-authored-by: Shlomi Noach <shlomi-noach@github.com>
Co-authored-by: Sophie Haskins <sophaskins@github.com>
Co-authored-by: Thomas Maurer <tma@github.com>
Co-authored-by: Tim Pease <tim.pease@gmail.com>
Co-authored-by: Yossef Mendelssohn <ymendel@pobox.com>
Co-authored-by: Zack Koppert <zkoppert@github.com>
Co-authored-by: Zhongying Qiao <cryptoque@users.noreply.github.com>
We are using two libraries to do the same job. This commit removes the usage of mini_mime in favour of Marcel instead.
Changes are as follows:
- Replace MiniMime lookup by extension with Marcel Mimetype for lookup with extension
- Replaces usage of MiniMime lookup by content type to fetch extension with usage of Marcel Magic lookup. Marcel has multiple extentions being returned, we pick the first one. MiniMime always returns just one
- Removes specs which we specifically checking failing identification issue of MiniMine on jpeg images
- Removes mini_mime from gemspec
This is a follow up to rails#47186, this time for all markdown content.
[markdownlint](https://github.com/markdownlint/markdownlint) is an excellent tool, and I've found it very useful for finding issues in the guides.
Many of the rules are common style issues I'm correcting on PRs, so it will be nice to have that automated.
We should also be able to use the same config with our editors, so that errors show up in real-time 🙏 and will update the contributing docs once this gets merged with how to debug and use mdl appropriately.
- Firstly, including irb as a dependency allows users with older versions
of Ruby to benefit from the latest version of irb, instead of being
limited to the version bundled with their Ruby installation.
- Additionally, there is an [ongoing discussion](https://bugs.ruby-lang.org/issues/19351) to move irb to bundled gems.
If this change is implemented, users may need to declare irb in their
Gemfile in order to use it for Rails console. By adding irb as a dependency,
users can avoid the extra effort of manually specifying irb in their Gemfile.
One particularly annoying thing with YAMLColumn type restriction
is that it is only checked on load.
Which means if your code insert data with unsupported types, the
insert will work, but now you'll be unable to read the record, which
makes it hard to fix etc.
That's the reason why I implemented `YAML.safe_dump` (https://github.com/ruby/psych/pull/495).
It applies exactly the same restrictions than `safe_load`, which means
if you attempt to store non-permitted fields, it will fail on insertion
and not on further reads, so you won't create an invalid record in your
database.
While we depend on rdoc through the sdoc gem, it only requires a minimum version.
This may be the cause for #47261 broke edgeapi.rubyonrails.org, those docs are generated with Ruby 2.6 or 2.7.
I'd also like to investigate increasing the Ruby version on the doc server, but I feel that has bigger impact.
## Summary
This PR bumps RuboCop Performance to 1.16.0 and suppresses the following new offenses:
```console
% bundle exec rubocop
(snip)
Offenses:
actionpack/lib/action_dispatch/routing/mapper.rb:309:16:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
if /#/.match?(to)
^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/routing/mapper.rb:1643:18:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
if /#/.match?(to)
^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/routing/route_set.rb:887:67:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
path = Journey::Router::Utils.normalize_path(path) unless %r{://}.match?(path)
^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/assertions/routing.rb:86:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
if %r{://}.match?(expected_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/assertions/routing.rb:205:14:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
if %r{://}.match?(path)
^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/integration.rb:235:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
if %r{://}.match?(path)
^^^^^^^^^^^^^^^^^^^^
actiontext/bin/webpack:18:6:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 150))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actiontext/bin/webpack-dev-server:18:6:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 150))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb:120:64:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
elsif column.type == :uuid && value.is_a?(String) && /\(\)/.match?(value)
^^^^^^^^^^^^^^^^^^^^
railties/lib/rails/commands/secrets/secrets_command.rb:28:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
if /secrets\.yml\.enc/.match?(error.message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3088 files inspected, 10 offenses detected, 10 offenses autocorrectable
```
## Additional Information
This behavior change is based on:
https://github.com/rubocop/rubocop-performance/pull/332
It was originally added in 175ba66664
as the database driver for Que in the Active Job integration tests.
However, the gem is now unused since the Que adapter and its integration
tests were removed in cb22eb2b36
Prior to this commit, the only out-of-the-box parsing that
`ActionDispatch::Testing::TestResponse#parsed_body` supported was for
`application/json` requests. This meant that `response.body ==
response.parsed_body` for HTML requests.
```ruby
get "/posts"
response.content_type # => "text/html; charset=utf-8"
response.parsed_body.class # => Nokogiri::HTML5::Document
response.parsed_body.to_html # => "<!DOCTYPE html>\n<html>\n..."
```
Using `parsed_body` for JSON requests supports `Hash#fetch`, `Hash#dig`,
and Ruby 3.2 destructuring assignment and pattern matching.
The introduction of [Nokogiri support for pattern
matching][nokogiri-pattern-matching] poses an opportunity to make assertions
about the structure of the HTML response.
On top of that, there is ongoing work to [introduce pattern matching
support in MiniTest][minitest-pattern-matching].
[nokogiri-pattern-matching]: https://github.com/sparklemotion/nokogiri/pull/2523
[minitest-pattern-matching]: https://github.com/minitest/minitest/pull/936
Rack 2 includes this code, but in Rack 3 it was extracted into gems. These
gems include a v1 release compatible with Rack 2, and a v2 release
compatible with Rack v3+.
Also bumped rubocop, rubocop-minitest, rubocop-performance and rubocop-rails
because RuboCop workflow uses Gemfile.lock unlike Rails CI that removes it.
Its usage was removed in 7d116c9 but I forgot to remove it
The other changes come from running bundle install, it looks like they
were supposed to be removed in d9e79ce
The Mail gem changed format of the delivery method arguments for
sendmail from a string to an array of strings in this commit
7e1196bd29
As the settings are now a sendmail delivery method produces the
following error:
```
.../mail-2.8.0/lib/mail/network/delivery_methods/sendmail.rb:53:in `initialize': :arguments expected to be an Array of individual string args (ArgumentError)
```
This also updates the mail dependency since the new default won't work
with the older versions.
The `method_source` gem was added in
https://github.com/rails/rails/pull/19216. It was used to determine the
last line number of a given test method to support running tests by line
number.
But this is not something that requires an external dependency:
Ripper can do this easily, and it has the added advantage of not using
`eval` calls in a loop to do it as method_source does.
It gets a bit trickier when dealing with declarative `test "some test"`
style methods, but ripper can still handle those in a similar way.
This is a second try at a PR (https://github.com/rails/rails/pull/45904)
that got rolled back because the previous effort didn't handle the
declarative test style.