0
0

More than 1 year has passed since last update.

#Rails + FactoryBot でデータ作成 create での validation を無効化する例 : trait を利用

Last updated at Posted at 2019-11-20

trait 指定なし

FactoryGirl.define do
  factory :person do
    name { nil }
    sex { nil }

    to_create { |instance| instance.save(validate: false) }
  end
end

trait 指定あり

こいつで範囲を限定的にできる

FactoryGirl.define do
  factory :person do
    name { nil }
    sex { nil }

    trait :no_validation do
       to_create { |instance| instance.save(validate: false) }
    end
  end
end

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0