title: FactoryGirl, rails, cucumber: Make association with multiple records
body: <p>OK, the factoryGirl pages at thoughtbot are very helpful, but I'm doing something wrong. In an earlier iteration of a basic feature I made two records and forced the association per the abbreviated example below:</p>
  
  <pre><code> Given /^a price for corn has already been entered$/ do
     corn = Commodity.create!(name: "Corn", wholesale_unit: "ton")
     Price.create!(commodity: corn, retail_high: "19")
   end
  </code></pre>
  
  <p>Now I want to make two prices so that I can test the average in cucumber to assure that both are being pulled. I have easily created factories for the above per Nash's suggestion.</p>
  
  <pre><code> FactoryGirl.define do
     factory :commodity do 
       name 'Corn'
       wholesale_unit 'ton'
     end
  
     factory :price do 
       sequence(:retail_high) { |n| '19#{n}' }
       commodity
     end
   end
  </code></pre>
  
  <p>In my updated step.rb file, I try to create the conditions that work in the first iteration but have two records:</p>
  
  <pre><code> Given /^there are prices entered$/ do 
     Factory(:commodity)
     Factory(:price) do
       sequence(:retail_high)
     end
   end
  </code></pre>
  
  <p>So my real problem is that I'm unable to get to first base because when I use pry to see if a record is being created, I get a Price = nil. Same with commodity. There are so many attributes that getting factory to work would really help. Updating the above to Nash' examples below show the correct first record, but the second record is a repeat of the first. Following are my model, relevant controller and schema. thanx for hanging in, sam  </p>
  
  <p>commodity.rb:</p>
  
  <pre><code> class Commodity &lt; ActiveRecord::Base
     has_many :prices
   end
  </code></pre>
  
  <p>price.rb:</p>
  
  <pre><code> class Price &lt; ActiveRecord::Base
     belongs_to :commodity
   end
  </code></pre>
  
  <p>commodities_controller.rb:</p>
  
  <pre><code>  class CommoditiesController &lt; ApplicationController
      def show
      @commodity = Commodity.find(params[:id])
     end
  </code></pre>
  
  <p>relevant schema.rb:</p>
  
  <pre><code>   create_table "commodities", :force =&gt; true do |t|
     t.string   "name"
     t.datetime "created_at"
     t.datetime "updated_at"
     t.string   "wholesale_unit"
     t.string   "retail_unit"
     t.string   "farm_gate_unit"
     t.string   "delivered_unit"
     t.string   "receipt_unit"
       end
  
    create_table "prices", :force =&gt; true do |t|
     t.date     "date"
     t.string   "price_type"
     t.string   "quality"
     t.string   "farm_gate_unit"
     t.decimal  "farm_gate_high"
     t.decimal  "farm_gate_low"
     t.string   "delivered_unit"
     t.decimal  "delivered_high"
     t.decimal  "delivered_low"
     t.string   "wholesale_unit"
     t.decimal  "wholesale_high"
     t.decimal  "wholesale_low"
     t.string   "retail_unit"
     t.decimal  "retail_high"
     t.decimal  "retail_low"
     t.datetime "created_at"
     t.datetime "updated_at"
     t.integer  "commodity_id"
   end
  </code></pre>