How to fabricate Mongoid document with embedded document using Fabrication?

前端 未结 1 434
我寻月下人不归
我寻月下人不归 2021-02-03 10:36

I use Mongoid and Fabrication gems. I have switched to Mongoid.rc7 from beta20 and now I can\'t fabricate document with embedded document:

#Models
class User
  in         


        
相关标签:
1条回答
  • 2021-02-03 11:13

    This is a working solution for embeds_many with Mongoid.rc7:

    Fabricator(:admin_user, :from => :user) do
      after_create { |user | user.roles << Fabricate.build(:role, :name => "admin") }
    end
    

    For embeds_one this code works (address embeds one location):

    Fabricator(:address) do
      location { |address| Fabricate(:location, :address => address) }
    end
    
    0 讨论(0)
提交回复
热议问题