title: Generating nested attributes for FactoryGirl objects with accepts_nested_attributes_for
body: <p>I'm using RSpec and Factory Girl to test my application. What I'm trying to do is the following: I have a object which accepts nested attributes, and it is not valid that nested attribute. I want to test that the POST works:</p>
  
  <pre><code>let(:valid_attributes) { build(:user).attributes }
  it "creates a new User" do      
    expect {
      post :create, {user: valid_attributes}, valid_session
    }.to change(User, :count).by(1)
  end
  </code></pre>
  
  <p>That's the factory:</p>
  
  <pre><code>FactoryGirl.define do
    factory :user do |x|
      name "Homer"
      after(:build) do
        build :address
      end
    end
  end
  </code></pre>
  
  <p>The problem is that the hash returned by <code>build(:user).attributes</code> does not have the <code>address</code>, although if I inspect the object created by <code>build(:user)</code>, the <code>address</code> is correctly built.</p>
  
  <p>Is there some way to easily generate a hash with the nested attributes?</p>