how can I test accepts_nested_attributes_for with Rspec Rails3

chell picture chell · Jul 1, 2011 · Viewed 9.6k times · Source

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?

Answer

joselo picture joselo · Feb 27, 2012

I just found this shoulda macro, seems like it works fine:

https://gist.github.com/1353500/bae9d4514737a5cd7fa7315338fdd9053dbff543

you should use it like this:

it{ should accept_nested_attributes_for :samples }