我遇到了factory_girl的問題。這是rspec的錯誤。Factory_girl中的錯誤:NoMethodError:undefined方法 - rspec和rails 3.1.0
「故障/錯誤:客戶=出廠(:顧客,:名稱=>無) NoMethodError: 未定義的方法`category1_id爲#Customer =」:0x4175418"
這裏是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.define :customer do |c|
c.name "test customer"
c.email "[email protected]"
c.phone "12345678"
c.cell "1234567890"
c.active 1
c.category1_id 2
c.short_name "test"
end
有什麼想法?謝謝。
檢查'customer1'表中是否存在'category1_id'列 – NARKOZ