【发布时间】:2011-11-14 10:37:35
【问题描述】:
我遇到了 factory_girl 的问题。这是 rspec 的错误。
“失败/错误:客户=工厂(:客户,:名称=>无) 无方法错误: #Customer:0x4175418 的未定义方法 `category1_id='
这是 rspec 代码:
describe "data integrity" do
it "should return error with no name" do
customer = Factory(:customer, :name => nil)
customer.errors[:name].should_not be_empty
customer.should_not be_valid
end
it "should take a good name" do
customer = Factory(:customer, :name => "good customer name")
customer.errors[:name].should be_empty
end
end
category1_id 是客户表中的一列。这是customer.rb
class Customer < ActiveRecord::Base
validates :name, :presence => true
end
Factory(:customer)的定义
Factory.define :customer do |c|
c.name "test customer"
c.email "t@acom.com"
c.phone "12345678"
c.cell "1234567890"
c.active 1
c.category1_id 2
c.short_name "test"
end
有什么想法吗?谢谢。
【问题讨论】:
-
检查
category1_id列是否存在于您的customer表中
标签: ruby-on-rails-3 rspec2 factory-bot