title: User password update rspec
body: <p>In my controller, I have a method called update_password, this method updates the user password after validating token. But, my tests are failing.What might be the problem?</p>
  
  <p>In my controller,</p>
  
  <pre><code>      def update_password
          user = User.find_by(email: params[:email])
          if user.nil?
            render json: { error: 'Could not update' }, status: 422
          else
            user.update(user_params)
            render json: { message: 'Successfully Updated' }, status: 200
          end
        end
  
       def user_params
          params.permit(:password, :password_confirmation, :current_password, :email)
        end
  </code></pre>
  
  <p>Test:</p>
  
  <pre><code>   describe 'update password for valid token' do
      it'should update the password' do
        user_params = {
          password: 'newpassword',
          password_confirmation: 'newpassword',
          email: user.email
        }
        put '/api/v1/update_password', params: user_params
        expect(user.password).to eq 'newpassword'
        expect(user.reload.password_confirmation).to eq 'newpassword'
        expect(user.reload.password).to eq(user.reload.password_confirmation)
        json_response = JSON.parse(response.body)
        expect(json_response['message']).to eq('Successfully Updated')
      end
     end
  </code></pre>
  
  <p>Factories:</p>
  
  <pre><code>FactoryBot.define do
    factory :user do
      sequence(:email) { |n| "user#{n}@example.com" }
      password 'testcase'
      username 'testcase'
      password_confirmation 'testcase'
      first_name 'testname'
      last_name 'test'
    end
  end
  </code></pre>
  
  <p>Error I have got:</p>
  
  <pre><code>1) UsersRequests update password for valid token should update the password
       Failure/Error: expect(user.password).to eq 'newpassword'
  
         expected: "newpassword"
              got: "testcase"
  
         (compared using ==)
       # ./spec/requests/users_requests_spec.rb:105:in `block (3 levels) in &lt;top (required)&gt;'
  
  Finished in 0.35031 seconds (files took 5.69 seconds to load)
  1 example, 1 failure
  
  Failed examples:
  
  rspec ./spec/requests/users_requests_spec.rb:98 # UsersRequests update password for valid token should update the password
  </code></pre>