This Week in Rails

January 20, 2023

Active Record regroup, CurrentAttributes name restrictions and more!

Hola, this is Greg, bringing you the latest changes from Rails.

Raise exception when if a restricted attribute name is used with CurrentAttributes
Attribute names like set and reset should not be used with ActiveSupport::CurrentAttributes, because they clash with its public API. With this change, an ArgumentError is raised when a restricted attribute name is used.

Add regroup method to Active Record
This pull request adds regroup and regroup! methods to Active Record. Here is an example on how to use it:

Change assert_emails to return the emails that were sent
Before this pull request, assert_emails just returned true or raised if the assertion failed. From now on, if a single email is sent, a single Mail::Message is returned. If multiple emails were sent, an array is returned.

Rename ::normalize to ::normalize_value_for
The ::normalize method accepts an attribute name and a value, and type casts the value, applying any declared normalizations for the attribute. Because of the way type casting works for most types, the type of the given value can be very different than the attribute type. This allows for potential confusion between the ::normalize method and the ::normalizes method, so to prevent such confusion, this change renames ::normalize to ::normalize_value_for.

We had 28 contributors this past week! 

Until next time!

About This Week in Rails

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