This Week in Rails

May 26, 2023

This Week In Rails - May 26, 2023

Hey! zzak here with another edition of This Week in Rails.

Reminder: The Rails World CFP is open until June 16.
Whether you’re a seasoned veteran or a newcomer to the Rails ecosystem, we encourage you to submit proposals that showcase forward-thinking ideas and push the boundaries of what’s possible with Rails.

Rails 7.0.5 has been released
In case you missed it, a bugfix release for the 7.0 series of Rails was cut.

Improve performance of MemoryStore
This PR optimizes the MemoryStore::DupCoder internal API to avoid unnecessary work when writing and reading complex objects.

Refactor error highlight detection
Before this commit, some calls to render were hard-coding error highlight as “not available”. This was causing some error pages to show the “you should install error highlight” message even though the right version of error highlight was installed.

Use short-form fixed-width RDoc form for namespaces
Some work went into replacing occurrences of “Some::Namespace::Thing” with the shorter “+…+” syntax supported by RDoc.
This is just a reminder to folks writing documentation that this syntax can be used for nearly all fixed-width code that doesn’t contain brackets, spaces, or like raw “strings”. Which is much nicer on the eyes for readers looking directly at the code (and writing).

Automatically add “test/fixtures” in engines to “fixture_paths”
This PR takes advantage of the recently added TestFixtures#fixture_paths feature so that any engines your application uses fixtures will also be automatically loaded.

Fix “change_in_place?” for binary serialized columns
A bug occurred when giving unicode characters to serialized attributes stored in a blob column, that would always show changes had occurred on that attribute.

Run “after_bundle” blocks with “app:template” command
App templates may contain after_bundle blocks which should be run after the template is executed, after running bundle install. For example:
gem "devise"

after_bundle do
  generate "devise:install"

“ERB::Util.html_escape_once” now always returns an “html_safe” string
This method previously maintained the html_safe? property of a string on the return value. Because this string has been escaped, however, not marking it as html_safecauses entities to be double-escaped. Before this change, that would be double-escaped and render as:
<p>this &amp;amp; that &amp;amp; the other</p>
After this change, it renders correctly as:
<p>this &amp; that &amp; the other</p>

Deprecate “SafeBuffer#clone_empty”
This internal method hasn’t been used within the Rails codebase since the last caller was removed in 2014 (Rails 4.2.0).

Add “Arel::Nodes::Cte” for use in WITH expressions
While Arel is still private API, this PR is still worth noting. This addition gives the withmethod the ability to accept a Common Table Expression (CTE) which adds MATERIALIZED or NOT MATERIALIZED hints to the generated SQL statement.
Postgres and SQLite both support a non-standard extension to the CTE syntax to indicate that a CTE subquery should be materialized, i.e., not folded into the main query but evaluated separately. This can be useful in cases where the query planner would otherwise make poor decisions.

Deprecate params via “:args” for “assert_enqueued_email_with”
When testing Action Mailer using assert_enqueued_email_with, you should be using the :params kwarg to pass a hash of options to the mailer. For example:
assert_enqueued_email_with MyMailer, :my_method, params: { my_param: "value" }

Fix issue with empty values within delimited authorization header
The bug here occurs when delimited Authorization header values containing blanks (e.g. ,,,) will produce an ArgumentError resulting in a 500 error response.

Adds “ActiveRecord.disconnect_all!” to close all connections
This is basically a multi-db aware version of ActiveRecord::Base.connection.disconnect!. It also avoid connecting to the database if we weren’t already. This can be useful to reset state after establish_connection has been used.

Improve JS and CSS options of app generator
The UX for generating new Rails applications when using the --javascript and --cssflags has been improved here. Take a look at the table in the PR that explains the behavior changes in greater detail.

Model Generator Source Paths Should Allow for Customization
This PR resurrects and older PR that had been lost to time, with the addition of tests and silenced warnings. It’s always good to see folks who can scratch their own itch, and recycle code from an older PR. Not everything needs to be reinvented!

Update comments in all three en.yml files relating to booleans
I’m calling this one out because as this was @justinperkins first PR to Rails! They’ve gone and fixed up the comments for the generated locale files. Congrats!

Make the test environment show rescuable exceptions in responses
The last PR for the week is changing the behavior of the config.action_dispatch.show_exceptions option to use the new “rescuable” option which will only show exceptions that can be rescued (e.g. ActiveRecord::RecordNotFound) in the test environment.

You can view the whole list of changes here.
We had 26 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.