我升级到Rails 3和RSpec 2,我的一个RSpec测试停止了工作:
# Job.rb
class Job < ActiveRecord::Base
has_one :location
belongs_to :company
validates_associated :location
end
# Location.rb
class Location < ActiveRecord::Base
belongs_to :job
end
# job_spec.rb
describe Job, "location" do
it "should have a location" do
job = Factory(:job)
location = Factory(:location, :job_id => job.id)
location.job.should == job #true
job.location.should == location #false
end
end
job.location
评估为零,但location.job
是正确的。如果我摆脱validates_associated :location
,它也可以正常工作。任何人都可以解释为什么这不起作用?
答案 0 :(得分:2)