Ответ 1
Здесь у вас есть Shoulda
макрос для тестирования accepts_nested_attributes_for
: 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