ブランド (has_many :products) と製品 (belongs_to :brand) の間の関連付けを正常にテストしました。ここで、Rspec でユーザー (has_many :brands、has_many products、:through => :brands) とそのブランドの製品との関連をテストできるかどうかを知りたいと思っています。以下のコードは、私が念頭に置いていたものですが、明らかに機能しません。
describe "user association" do
before(:each) do
@brand_attr = { :name => "Apple",
:established => "1976",
:description => "Born at the SV Homebrew"
}
@user = Factory(:user)
@brand = @user.brands.new(@brand_attr)
@product = @brand.products.new(@attr)
end
it "should have a user attribute through the brand" do
@product.brand.user.should == @user
end
ありがとうございました!