I have a model as follows:
class Greeting < ActiveRecord::Base
attr_accessible :headline, :icon, :content
belongs_to :user
accepts_nested_attributes_for :user, :reject_if => proc { |a| a[:name].blank? || a[:email].blank? }
How can I do an Rspec test for this?
Here you have
Shouldamacro for testingaccepts_nested_attributes_for: http://mediumexposure.com/testing-acceptsnestedattributesfor-shoulda-macros/. It does not support any options (such as:reject_if), only bareaccepts_nested_attributes_for.But for
:reject_if, you can create a valid Greeting model with nested attributes forUserbut without:name. Then check if user has been saved, and then same with blank:emailSo you can do something like this: