Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 你在工厂里有很多交往吗_Ruby On Rails_Associations_Factory Bot_Has Many - Fatal编程技术网

Ruby on rails 你在工厂里有很多交往吗

Ruby on rails 你在工厂里有很多交往吗,ruby-on-rails,associations,factory-bot,has-many,Ruby On Rails,Associations,Factory Bot,Has Many,我有两类用户和身份验证,然后身份验证有很多用户: 用户类别: FactoryGirl.define do factory :user do first_name "Juan" last_name "Iturralde" sequence(:email) { |n| "person-#{n}@example.org" } password "1234567890" password_confirmation "1234567890"

我有两类用户和身份验证,然后身份验证有很多用户:

用户类别:

FactoryGirl.define do
  factory :user do
    first_name   "Juan"
    last_name    "Iturralde"
    sequence(:email)  { |n| "person-#{n}@example.org" }
    password  "1234567890"
    password_confirmation "1234567890"
    is_admin false
    factory :admin do
        is_admin true
    end
    after(:create) do |user|
        create(:authentication, user: user)
    end
  end
end
身份验证类别:

FactoryGirl.define do
  factory :authentication do
    user        {User.first || create(:user)}
    provider    "Apple"
    uid         "uid"
  end
end

我现在不知道。如何在身份验证中创建用户?

要在规范中建立关联,我使用以下方法:

# spec/factories/posts.rb
FactoryGirl.define do
  factory :post do
    title 'The best post'

    trait :with_comments do
      create_list :comment, 3
    end
  end
end

# spec/factories/comments.rb
FactoryGirl.define do
  factory :comment do
    post
    content 'Really awesome post'
  end
end

# in specs
. . .
let(:post_with_commments) { create :post, :with_comments }
. . .
请查看《入门指南》中的部分