LoginSignup
0
0

More than 1 year has passed since last update.

#ruby #rails の #FactoryBot で association を使わずに無理やり BuildStrategy ( create / build / attributes_for ) などを反転して条件分けする例

Last updated at Posted at 2019-07-28

Example of forcing condition inversion of BuildStrategy (create / build / attributes_for) forcibly without using association in #FactoryBot of #ruby #rails

FactoryBot.define do
  factory :company do
    user do
      build_stragy = self.instance_variable_get(:@build_strategy).class

      if build_stragy == FactoryBot::Strategy::Create
        create :user
      else
        build :user
      end
    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