title: Factory Girl testing with Ruby on Rails, dependencies
body: <p>I am writing some tests with RSpec for a Ruby on Rails application and am running into an issue I can't seem to figure out. I have a bunch of objects that are associated with others and I'm using Factory Girl to create them all. Here's an example of where I am having a problem:</p>
  
  <pre><code>    user = Factory.create(:user)
      package = Factory.build(:package, :user =&gt; user)
      item = Factory.create(:item, :package =&gt; package)
  </code></pre>
  
  <p>All packages belong to a user, so the first dependency is rather trivial. Create a user then associate it with a package, no problem. Now here's the problem. My Package model has a validation that says it cannot be created without at least one item in the package. That means I can't use Factory.create on it. It's almost the same as doing @Package.new in my packages_controller.rb, which is fine. Later, I go on to create an item, the problem is, I cannot associate this item with the package because the package has no ID yet. </p>
  
  <p>Is there anyway I can create my package, create an item and save it, then associate the two together once the package has an id?  </p>