嗨,我有下面的模型
class User < ActiveRecord::Base
acts_as_messageable
before_save { email.downcase! }
before_create :create_remember_token
has_many :items , dependent: :destroy
has_many :routes , dependent: :destroy
has_many :bids, dependent: :destroy
....
end
class Bid < ActiveRecord::Base
belongs_to :user
has_one :package
....
end
class Package < ActiveRecord::Base
belongs_to :user
has_many :bids, dependent: :destroy
....
end当我运行我的单元测试时,我得到以下错误
Failure/Error:@bid =user.bids.build(数量: 34.00) ActiveRecord::不明属性: user_id
我的单元测试从下面开始
describe Bid do
let(:user) { FactoryGirl.create(:user) }
before {
@package = user.packages.build(destination: "Dublin", origin: "Naas", length: 4.9, width: 5.0, height: 9, weight:32, delivery_date: Time.now)
@bid = user.bids.build(amount: 34.00)
}
....
end我不知道是什么导致了这个错误,我觉得它很小,因为我可以在rails控制台中创建一个出价
u = User.new
bid = u.bids.build(amount: 33)
bid.save我的数据库中的投标表有列user_id,所以我不知道它在抱怨什么?当我修复这个错误时,我有点担心这可能是循环依赖,这只是一种感觉,如果有人能证实这一点,那也是很好的。
在为视图和控制器编写代码之前,我想先解决这个问题,因为我正试图约束自己遵守TDD规则
发布于 2014-06-10 20:07:11
https://stackoverflow.com/questions/24149714
复制相似问题