【发布时间】:2013-11-08 11:03:48
【问题描述】:
我正在使用 shoulda-matchers 和 rspec 来测试我的 Rails 模型上的 has_many 关系。例如:
class Parent
has_many :children
has_many :other_children, :through => :intermediate
end
# spec/models/parent_spec.rb
describe Parent do
it "has children" do
should have_many(:children)
should have_many(:other_children).through(:intermediate)
end
end
一切正常。但是我如何最好地测试这些关系的额外约束,例如何时存在:
has_many :children, :dependent => :destroy
has_many :children, :uniq => true
has_many :children, :through => :intermediate, :source => :partner
【问题讨论】:
-
Shoulda-matchers现在是 havedependent和through匹配器。我没有看到uniq,但是您可以轻松查看源代码并以相同的方式执行您想要的操作。
标签: ruby-on-rails rspec shoulda