This Week in Rails: yarn, webpack, BIGINT PKs and more!

Posted by chancancode, December 10, 2016 @ 12:00 am in News

Hello everyone, this is Godfrey reporting from Portland, OR. This week has been a mix bag for me – on one hand, Portland had a pretty miserable week due to the storm; on the other hand, a lot of exciting changes landed in Rails. Does that make things even? I guess we’ll go through the changes and you can decide for yourself!

“Yarn is good. Yarn works.”

Last week, we mentioned that Rails 5.1 is gaining a –yarn  option. This option is now promoted to be the default: every new Rails app will be set up to use yarn out-of-the-box. It’s also worth noting that yarn packages are now installed into the vendor/node_modules directory.

Basic webpack integration

While we are talking about JavaScript, the asset bundling side of things is also getting some love. Rails 5.1 will gain first-class support for webpack via the –webpack option. This is still a pretty early spike, so definitely try it out and help improve it.

Change default primary keys to BIGINTs

Friends don’t let friends use INT as a primary key – your app might hit Webscale™ before you know it, resulting in much sadness when your primary key column overflows. To help put you on the right path, Rails 5.1 will default to using BIGINTs for primary key columns in MySQL and PostgreSQL.

New

Introduce ActiveRecord::NotNullViolation error

As of this pull request, if your model failed to save due to a NOT NULL constraint, Rails will raise a NotNullViolation error (instead of a generic StatementInvalid error) so you could rescue the error and handle it appropriately.

Improved

Speeding up RSpec integration tests by 40%

This patch fixes an issue where templates are needlessly recompiled between integration test, resulting in a significant speedup.

Fixed

Idempotent after_commit callbacks

Previously, certain race conditions could cause your after_commit callbacks to fire more often than expected. This patch attempts to more accurately track the work that actually happened in the database to ensure your hooks are triggered only when appropriate.

Allow variales named block in templates

Have you tried using variables named block  in your templates? If you did, you might have seen a pretty strange error from Rails. Not anymore! With this patch, you would be able to do that without issues.

Exclude singleton classes from subclasses and descendants

A change in Ruby 2.3.0unexpectedly changed the behavior of Active Support’s Class#subclasses and Class#descendants  methods to include singleton classes. This patch restores the previous behavior and made things consistent across different versions of Ruby (again).

Wrapping up

That’s it from This Week in Rails! There were many other great contributions, so please feel free to check them out yourself!

Until next week!