当构建以下工厂时:
Factory.define :user do |f|
f.sequence(:name) { |n| "foo#{n}" }
f.resume_type_id { ResumeType.first.id }
end
ResumeType.first
返回nil并出现错误。
ResumeType
记录通过固定装置进行加载。我使用控制台检查了记录,条目已经存在,表不为空。
我在factory_girl邮件列表中找到了一个类似的例子,它应该可以工作。
我错过了什么?我需要告诉factory_girl在运行测试之前设置好装置吗?
这是我的test_helper:
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class ActiveSupport::TestCase
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
fixtures :all
end