"[Class_Name] must exist" rails 5 rspec testing associations
<p>In my rails application, I have Service, Request, and ServiceRequest models. </p>

<p>The associations are such that servicerequests belong_to both Service and Request. </p>

<p>When testing servicerequests with rspec, I have this:</p>

<pre><code>require "rails_helper"

describe Servicerequest, :type =&gt; :model do

  subject {
    described_class.new(userid: 'bbogus', status: 'new', request_id: 1, service_id: 3)
  }

  it "is valid with valid attributes"  do
    expect(subject).to be_valid
  end

  it "is not valid without a userid" do
    subject.userid = nil
    expect(subject).to_not be_valid
  end

  it "is not valid without a status" do
    subject.status = nil
    expect(subject).to_not be_valid
  end

  it "is not valid without a request_id" do
    subject.request_id = nil
    expect(subject).to_not be_valid
  end

  it "is not valid without a service_id" do
    subject.service_id = nil
    expect(subject).to_not be_valid
  end

  it { should belong_to(:request)}
  it { should belong_to(:service)}
end
</code></pre>

<p>and in the servicerequest model:</p>

<pre><code>class Servicerequest &lt; ApplicationRecord
  validates_presence_of :userid, :status, :request_id, :service_id

  belongs_to :request, class_name: "Request"
  belongs_to :service, class_name: "Service"
end
</code></pre>

<p>Fo some reason, my test fails with this statement:</p>

<pre><code>1) Servicerequest is valid with valid attributes
  Failure/Error: expect(subject).to be_valid
    expected #&lt;Servicerequest id: nil, created_at: nil, updated_at: nil, userid: "bbogus", status: true, request_id: 1, service_id: 3&gt; to be valid, but got errors: Request must exist, Service must exist
  # ./spec/models/servicerequest_spec.rb:10:in `block (2 levels) in &lt;top (required)&gt;'
</code></pre>

<p>How do I make my test pass the <code>Request must exist. Service must exist.</code> portion?</p>