我正在使用带有 rspec 的shoulda-has_many
matchers 来测试我的 Rails 模型上的关系。例如:
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