rspec association test only works in one direction
问题 I upgraded to Rails 3 and RSpec 2 and one of my RSpec tests stopped working: # 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