Timestamp Truncation: A Ruby on Rails ActiveRecord Tale

, Software Pundits
This post was originally published on this site

Toptal

Tests are supposed to help keep apps from being flaky. But once in a while, tests themselves can become flaky—even the most straightforward ones. Here’s how we dove into a problematic test on a Ruby on Rails app backed by PostgreSQL, and what we uncovered.

We wanted to check that certain business logic (called by a method perform) doesn’t change a calendar model (an instance of Calendar, a Ruby on Rails ActiveRecord model class) so we wrote:

let(:calendar) { create(:calendar) } specify do expect do perform # call the business action calendar.reload end .not_to change(calendar, :attributes) end

This was passing in one development environment (MacOS), but it was almost always failing in CI (Linux).

Fortunately, we managed to reproduce it on another development environment (Linux), where it failed with a message:

expected `Calendar#attributes` not to have changed, but did change from {“calendar_auth_id”=>8, “created_at”=>2020-01-02 13:36:22.459149334 +0000, “enabled”=>false,

To read the full article click on the 'post' link at the top.