-
-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Labels
Description
FactoryBot has an enum traits feature that given a model:
class Task < ActiveRecord::Base
enum status: {queued: 0, started: 1, finished: 2}
endmakes the following definitions redundant:
FactoryBot.define do
factory :task do
trait :queued do
status { :queued }
endIt's near impossible to detect using static analysis, however, I've seen this defined as:
status { Model.status[:queued] }which is equivalent to the above (just translates a symbol to its DB-level numeric representation explicitly rather than relying on ORM to do that). Those cases are detectable.
NOTE: Enum traits appeared in FactoryBot 6.1, so probably we'll need to introduce version configuration a-la TargetFactoryBotVersion (see rubocop-rails for an example).