title: How to test PUT/PATCH API with RSpec
body: <p>I am trying to test some PUT/PATCH endpoint from my API, but my 'record_to_update' is not chaging as expect.</p>
  
  <p>I organize the spec as follow using Rails 5.2 and RSpec 3.8:</p>
  
  <pre><code>require 'rails_helper'
  
  RSpec.describe UsersController, type: :controller do
    context 'when request with no valid headers' do
      ...
      ...
      ...
    end
  
    context 'when resquest with valid headers' do
      before do
        request.accept = 'application/vnd.api+json'
        request.content_type = 'application/vnd.api+json'
  
        2.times do
          create(:user)
        end
      end
  
      describe 'PATCH/PUT /users/:id' do
        let(:record_to_update) { create(:user) }
        let(:user_params) do
          { id: first_user.id, name: 'goku', email: 'goku@bol.com' }
        end
  
        before do
          put :update, params: { id: record_to_update, user: user_params }
          record_to_update.reload
        end
  
        it 'should update user' do
          expect(record_to_update.name).to eq('goku')
          expect(response.status).to eq 200
        end
      end
    end
  end
  </code></pre>
  
  <p>As I said the problem here that I am facing is that 'record_to_update' is not chaging. I already test the same PUT/PATCH endpoint in the same API with Postman and successfully updated from there. What am I doing wrong here?</p>
  
  <p>Thanks in advance.</p>