jeudi 9 avril 2020

Rspec - How to test respond_to in my controller

I'm writing the rspec unit test for the update method of controller. The method is:

def update
  @people = People.find(params[:id])
  if @people.update(people_params)
    respond_to do |format|
      format.html {redirect_to people_path(@person), flash: { info:'Update Success'}}
      format.js {render json: { success: 'Update Success' }}
    end
  else
    render :edit
  end

This method will update the people_params first and execute the repond_to, if the format is HTML, then the page will be redirected. If the format is JSON, it will render another JSON as response to my ajax request.

I just don't know how to write the rspec unit test for this, I have looked other questions and answers but still have no clue. Anyone could help me is appreciated!

Aucun commentaire:

Enregistrer un commentaire