2011-07-01 33 views

答えて

12

Shouldaマクロ:http://mediumexposure.com/testing-acceptsnestedattributesfor-shoulda-macros/があります。どんなオプションもサポートしていません(:reject_ifなど)。accepts_nested_attributes_forのみです。

:reject_ifの場合、Userのネストされた属性を持つが、:nameを含まない有効なグリーティングモデルを作成できます。その後、ユーザーが保存されているかどうかを確認し、:email

空白と同じだから、あなたはこのような何か行うことができます。

describe Greeting 
    it { expect { Factory(:greeting, :user_attributes => Factory_attributes_for(:user)) }.to change(User, :count).by(1) } 
    it { expect { Factory(:greeting, :user_attributes => Factory_attributes_for(:user, :name => '')) }.to_not change(User, :count) } 
    it { expect { Factory(:greeting, :user_attributes => Factory.attributes_for(:user, :email => '')) }.to_not change(User, :count) } 
end 
関連する問題