1

如何在 rspec 中测试外键关联,

这是代码

has_one :store, :foreign_key => "seller_id", :class_name => "Store"

如何为此代码编写 rspec

请告诉我一些建议

4

2 回答 2

2

Model.new.build_store.class.should eql Store

于 2012-04-06T11:19:02.420 回答
1

答案是 shoulda-matchers gems。看看这个:https ://github.com/thoughtbot/shoulda-matchers

describe Post do
  it { should belong_to(:user) }
  it { should have_many(:tags).through(:taggings) }
end

describe User do
  it { should have_many(:posts) }
end
于 2012-04-06T15:41:15.973 回答