jeudi 9 avril 2020

RSpec - How to test the if-else block in update method of controller

Let's say I have a database to store the data of people (name, email). And there's an update method in the controller. The method is like:

  def update
    @people = People.find(params[:id])
    if @people.update(people_params)
       redirect_to people_path
    else
       render 'edit'
    end
  end

I wonder how can I test the situation that the update failed? Or do I really need to test it? I have searched it on StackOverflow, there is a link about it, but it not says if I should or should not to test it. Could anyone give me some help about it? If it can be test, how? Thank you so much!

Aucun commentaire:

Enregistrer un commentaire