title: Failed to create nested attribute in Factory Girl?
body: <p>I have a <code>many-to-many</code> association between a <code>Post</code> and a <code>Category</code> model:</p>
  
  <p><strong>categorization.rb:</strong></p>
  
  <pre><code>class Categorization &lt; ActiveRecord::Base
    attr_accessible :category_id, :post_id, :position
  
    belongs_to :post
    belongs_to :category
  end
  </code></pre>
  
  <p><strong>category.rb:</strong></p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
    attr_accessible :name
  
    has_many :categorizations
    has_many :posts, :through =&gt; :categorizations  
  
    validates :name, presence: true, length: { maximum: 14 }
  end
  </code></pre>
  
  <p><strong>post.rb:</strong></p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    attr_accessible :title, :content, :category_ids
  
    has_many :categorizations
    has_many :categories, :through =&gt; :categorizations  
  
    accepts_nested_attributes_for :categorizations, allow_destroy: true
  
  end
  </code></pre>
  
  <p><em>This works:</em></p>
  
  <p><strong>post_spec.rb:</strong></p>
  
  <pre><code>describe Post do
  
    let(:user) { FactoryGirl.create(:user) }
    let(:category) { FactoryGirl.create(:category) }
    before { @post = user.posts.build(title: "Lorem ipsum",
                                      content: "Lorem ipsum dolor sit amet",
                                      category_ids: category) }
  </code></pre>
  
  <p><em>My problem it's here:</em></p>
  
  <p><strong>factories.rb:</strong></p>
  
  <pre><code>  factory :post do
      title "Lorem"
      content "Lorem ipsum"
      category_ids category
      user
    end
  
    factory :category do
      name "Lorem"
    end
  </code></pre>
  
  <p><strong>reply_spec.rb:</strong></p>
  
  <pre><code>describe Reply do
  
    let(:post) { FactoryGirl.create(:post) }
    let(:reply) { post.replies.build(content: "Lorem ipsum dolor sit amet") }
  </code></pre>
  
  <p>When I run the test for <code>reply_spec.rb</code> I get this error:</p>
  
  <pre><code>&gt; undefined method `category=' for #&lt;Post:0x9e07564&gt;
  </code></pre>
  
  <p><em>This is part that that is not working I think:</em></p>
  
  <p><strong>factories.rb:</strong></p>
  
  <pre><code>  category_ids category
  </code></pre>
  
  <p>Am I defining the nested attribute in a wrong way? What's the proper one?</p>