title: Testing if association exists in rspec
body: <p>I'm new to using rspec, so hopefully I'm explaining this correctly.  I want to make sure my object is created and afterwards make sure that a related object with a <code>has_one</code> relationship is created.</p>
  
  <p>So, my code would look like this in the model:</p>
  
  <pre><code>class Device &lt; ActiveRecord::Base
    has_one :scan_option
  
    validates_presence_of :name
  
    after_create :create_scan_option
  
    def create_scan_option
      self.scan_option.create!
    end
  end
  </code></pre>
  
  <p>I have a Factory for a device:</p>
  
  <pre><code>FactoryGirl.define do
    serial_number = SecureRandom.uuid.delete("-")
  
    factory :device do
      identifier serial_number
      name "Device 1"
      is_registered true
      timezone "America/Chicago"
    end
  end
  </code></pre>
  
  <p>In my rspec model test I imagine the code would look like this:</p>
  
  <pre><code>RSpec.describe Device, :type =&gt; :model do
    it "creates a scan_option after_create" do
      subject = build(:device)
      # test whether the scan_option object was created and associated with the device?
    end
  end
  </code></pre>
  
  <p>I'm not using <code>shoulda</code> or anything, just trying to understand Rspec better.</p>