如何在 rspec 中测试外键关联,
这是代码
has_one :store, :foreign_key => "seller_id", :class_name => "Store"
如何为此代码编写 rspec
请告诉我一些建议
如何在 rspec 中测试外键关联,
这是代码
has_one :store, :foreign_key => "seller_id", :class_name => "Store"
如何为此代码编写 rspec
请告诉我一些建议
Model.new.build_store.class.should eql Store
答案是 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