This Week in Rails

April 28, 2023

End of April 2023 Edition

Hi, it’s zzak. ✈️ RailsConf has come to a close, and Golden Week is upon us here in Japan. Lots to catch up on in This Week in Rails.

Many documentation improvements to extend our SEO posture
The venerable @p8 has been very busy trying to improve Rails documentation fortune with search engines.

On the topic of documentation, the PostgreSQL guide received new sections on INCLUDE, UNIQUE, and EXCLUDE.

Only flatten first level to preserve nested for Enumerable#in_order_of
This is a great example where a developer was actively testing their application against Rails main branch and discovered this bug, and even sent a patch! Good work!

Fix pg 1.5.0 deprecation warning
This warning occurs when using the recently released pg gem version 1.5.0. The PR has been backported, so the next point release should quiet things!
@cache.read(nil) #=> ArgumentError
This PR ensures that we consistently raise on a blank key for all store implementations.

Make Rails cookies RFC6265-compliant with domain: :all
Rails has incorrectly been adding leading dots to cookie domain values in Set-Cookie headers when the "domain: :all" option is present.

This leading dot was required in cookies based on RFC 2965 (October 2000), but RFC 6265 (April 2011) changed that behaviour, making a leading dot strictly incorrect. Todays browsers aim to conform to RFC6265 with respect to cookies. The "domain: :all" functionality in Rails predates RFC6265.

Allow symbols as queue names in Active Job test assertions
This PR allows assert_enqueued_with and assert_performed_with to accept both symbol or strings.
The assert_enqueued_jobs and assert_performed_jobs variation already accepted both.
config.load_defaults = 7.0 #=> NoMethodError
Should be,
config.load_defaults(7.0)
Previously the first example would be silently accepted, although take no effect.

Add load hook for ActiveRecord::ConnectionAdapters::Mysql2Adapter
Now you are free to extend the MySQL adapter using the following hook:
ActiveSupport.on_load(:active_record_mysql2adapter) do
  # change some behavior
end
This PR brings the MySQL adapter up to speed with PostgreSQL and SQLite3.

Fix updated_at not updating in before_update callback
As described, this PR makes sure the updated_at timestamp is updated once all update callbacks have run, wherever mutations may occur, including before_update.

Using Rack::Test::UploadedFile.new with StringIO causes an exception
This PR fixes an issue in Active Storage with Rack::Test::UploadedFile and Attached::Changes::CreateOne#upload.

PostgreSQL can accept deferrable foreign key option for TableDefinition#references
Rails 7.0 added support for deferrable foreign key constraints via the add_foreign_key method, this PR adds support to t.references as well.

Deprecate “deferrable: true” option in favor of “deferrable: :immediate”
Because "deferrable: true" and "deferrable: :deferred" are hard to understand.
Using "deferrable: true" with add_foreign_key is deprecated in favor of "deferrable: :immediate", and will be removed in Rails 7.2.

Add support for Array#intersects? to ActiveRecord::Relation
Ruby 3.1 added intersects? which is equivalent to "(a & b).any?".
This PR adds the delegation of intersects? to Relation which fixes an issue with Rubocop false positive on CollectionProxy.

Add CTE support for joins
Last but certainly not least, you can now use joins and left_outer_joins when using the .with query method to create a Common Table Expression (CTE).

You can view the whole list of changes here.
We had 30 contributors to the Rails codebase this past week!

Until next time!

About This Week in Rails

Your weekly inside scoop of interesting commits, pull requests and more from Rails.