我对测试和Rails很陌生,但我正试图正确地掌握我的TDD过程。
我想知道你是否使用任何范例来测试has_many:通过关系(或者一般的has_many关系)?
例如,我发现在我的模型规范中,我肯定会编写简单的测试来检查关联方法的两端。
即:
require 'spec_helper'
describe Post do
before(:each) do
@attr = { :subject => "f00 Post Subject", :content => "8ar Post Body Content" }
end
describe "validations" do
...
end
describe "categorized posts" do
before(:each) do
@post = Post.create!(@attr)
end
it "should have a categories method" do
@post.should respond_to(:categories)
end
end
end
然后在我的类别规范中,我进行反向测试,并检查 @category.posts。
还有什么我忽略的吗?谢谢!