Factorybot_Sequence
ある値からインクリメントしたい時
sequence(:factory, <初期値>) { |n| n }のように書く
実装例
FactoryBot.define do
factory :example_model do
sequence(:year, 2000) { |n| n }
# 他の属性もここに定義できます
name { "Example Name" }
description { "Example Description" }
end
end
テクニック
sequence(:year) { |n| Time.current.year + n }
sequence(:month) { |n| ((Time.current.month + n - 1) % 12) + 1 }````