how to define factories with a inheritance user model

大憨熊 提交于 2019-11-29 05:27:32
Thanh

You can try this:

factory :user do
  name  "name"
  bla "bla"
end

factory :custom_user, class: CustomUser, parent: :user do
  customfield "customfield"
end

For more info: Inheritance.

Just add the class: CustomUser to :custom_user factory. That works for me. When you nested in :user it means parent is User, but it is simpler.

FactoryGirl.define do 
  factory :user do
    name  "name"
    bla "bla"

    factory :custom_user, class: CustomUser do
      customfield "customfield"
    end
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!