RSPEC用于活动模型中的关联

时间:2012-04-06 10:57:31

标签: ruby-on-rails rspec

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

这是代码

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

如何为此代码编写rspec

请告诉我一些建议

2 个答案:

答案 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