title: Ruby on Rails - rspec Validation failed: Class must exist
body: <p>I'm currently writing tests for my web application and I came across something out of my intelligence scope.</p>
  
  <p>The context:
  I am testing the "show" method of the UserController. However, User has a 1 to 1 relation with the class Face.</p>
  
  <p>Here is the code testing the show method.</p>
  
  <pre><code>it "assigns the requested user as @user" do
     face = Face.create(:id =&gt; 1)
     user = User.create! valid_attributes
     get :show, params: {id: user.to_param}, session: valid_session
     expect(assigns(:user)).to eq(user)
    end                                                                
  end 
  </code></pre>
  
  <p><code>let(:valid_attributes) {
      { "lastName" =&gt; "lname", "firstName" =&gt; "fname", "face_id" =&gt; 1 }
    }</code>    </p>
  
  <p>When I run rspec here is the error in the console :</p>
  
  <pre><code>Failure/Error: user = User.create! valid_attributes
  
  ActiveRecord::RecordInvalid:
     Validation failed: Face must exist
  </code></pre>
  
  <p>How come Face doesn't exist If I created it?</p>