FactoryGirl未注册(只有一家工厂参与其中) [英] FactoryGirl Not Registered (Only one factory runs into this)

查看:59
本文介绍了FactoryGirl未注册(只有一家工厂参与其中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三种模式:用户,网站和护照.

I have three models: users, sites, and passports.

用户和站点已经并且彼此之间属于彼此,而护照是具有两个额外列的联接模型.

users and sites has and belongs to many each other, while passports is the join model with a couple of extra columns.

我尝试了以下两种方法:

I've tried both of the following:

1.

FactoryGirl.define do
  factory :passports do
    association :site, factory: :site
    association :user, factory: :user
    access_token 'mock_token'
  end
end

2.

FactoryGirl.define do
  factory :passports do
    access_token 'mock_token'
  end
end

无论哪种方式,我都将其用于:

And either way, I'm using it with:

let(:site) { FactoryGirl.create :site }
let(:user) { FactoryGirl.create :user }
let(:site_user) { FactoryGirl.create :site_user, site: site, user: user }
let(:passport) { FactoryGirl.create :passport, user: user, site: site }

请不要问为什么同时有site_user和护照.这将需要一些时间来解释.

Please don't ask why there are both site_user and passport..that'll take a while to explain.

谢谢!

最大

推荐答案

OMFG这很愚蠢...

OMFG this is dumb...

切换到Factory.define:passport do | f |语法使其有效...

Switching to the Factory.define :passport do |f| syntax made it work...

一种耗时一个半小时的生产力的好方法

Great way to blow away an hour and half of productivity

这篇关于FactoryGirl未注册(只有一家工厂参与其中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆