🖥

#ruby #rails の #FactoryBot で association を使わずに無理やり BuildStrategy ( cre

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

https://github.com/YumaInaura/YumaInaura/issues/2269

チャットメンバー募集

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

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-07-28

Discussion