Skip to content

Remove useless boolean inclusion validations

Description

Running the any of the changed specs outputs the following warnings:

************************************************************************
Warning from shoulda-matchers:

You are using `validate_inclusion_of` to assert that a boolean column
allows boolean values and disallows non-boolean ones. Be aware that it
is not possible to fully test this, as boolean columns will
automatically convert non-boolean values to boolean ones. Hence, you
should consider removing this test.
************************************************************************

The official documentation states

We discourage using validate_inclusion_of with boolean columns. In fact, there is never a case where a boolean column will be anything but true, false, or nil, as ActiveRecord will type-cast an incoming value to one of these three values. That means there isn't any way we can refute this logic in a test. Hence, this will produce a warning:

it do
  should validate_inclusion_of(:imported).
    in_array([true, false])
end

Thus, we should remove this validation from our specs to avoid this warning. I have validated that in all cases the corresponding column is a boolean type. There were a few that I found that weren't ActiveRecord types, so I left/re-added those.

NOTE: Description shamelessly borrowed from Vishal Tak from !140312 (merged)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Edited by Drew Blessing

Merge request reports

Loading