如何在rspec中测试外键关联,
这是代码
has_one :store, :foreign_key => "seller_id", :class_name => "Store"
如何为此代码编写rspec
请告诉我一些建议
答案 0 :(得分:2)
Model.new.build_store.class.should eql Store
答案 1 :(得分:1)
答案是应该匹配的宝石。看看这个: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