I'm getting a NoMethodError when trying to test the redirection of a post method using 'follow_redirect!'.
This is the error:
NoMethodError: NoMethodError: undefined method `follow_redirect!' for #<ChangePasswordsControllerTest:0x00005586ffd3c030>
Here is my controller.
def create
@user = current_user
if @user.authenticate(params[:user][:old_password])
if @user.update_attributes(params.require(:user).permit(:old_password, :password, :password_confirmation))
flash[:success] = "La contraseña se cambió correctamente"
redirect_to membership_dashboard_path
else
flash[:warning] = "No se pudo cambiar la contraseña"
render 'new'
end
else
flash[:warning] = "La contraseña actual no es correcta."
render 'new'
end
end
And here is my test
test "should redirect membership dashboard if create password" do
get :new
post :create, params: { user: {
old_password: '1234',
password: "123456",
password_confirmation: "123456" }
}
assert_equal 'La contraseña se cambió correctamente', flash[:success]
assert_redirected_to membership_dashboard_path
follow_redirect!
assert_response :success
end
It runs fine if I remove the last two lines
follow_redirect!
assert_response :success
The weirdest thing is that I'm already using 'follow_redirect!' in another test and it's fine!
Does anyone know how to fix this?
Aucun commentaire:
Enregistrer un commentaire