title: How to pass in extra params in RSpec Rails request spec
body: <p>I'm still a beginner so what I am trying to do is probably not optimal, feel free to suggest a better method:</p>
  
  <p>I am trying to test creating a contract for an associated user. The user and authenticate_user method are to be stubbed, however RSpec is saying it's not seeing the user_id foreign key in the params I'm passing in inside of :contract_params. Can someone please tell me of a way to pass in user_id so that RSpec would recognize it? 
  Thank you!</p>
  
  <p><a href="https://i.stack.imgur.com/wp9Yu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wp9Yu.png" alt="enter image description here"></a></p>
  
  <p>spec/requests/contracts_api_spec.rb</p>
  
  <pre><code>RSpec.describe "ContractsApi", type: :request do
  
    describe "POST #create" do
      let (:contract_params) do
        {
          user: {
            vendor: "Lebara",
            starts_on: "2018-12-12",
            ends_on: "2018-12-16",
            price: "15",
            user_id: "8"
          }
        }
      end
      before(:each) do
        controller.stub(:authenticate_user)
      end
  
      it 'creates a new contract' do
        expect { post api_v1_user_contracts_path, params: contract_params }.to change(Contract, :count).by(1)
      end
    end
  end
  </code></pre>
  
  <p>app/controllers/api/v1/contracts_controller.rb</p>
  
  <pre><code>class Api::V1::ContractsController &lt; ApplicationController
    before_action :authenticate_user
  
    def create
      contract = @current_user.contracts.build(contract_params)
      if contract.save
        render json: contract
      else
        render json: contract.errors
      end
    end
  
    private
  
    def contract_params
      params.require(:contract).permit(:vendor, :starts_on, :ends_on, :price)
    end
  </code></pre>