How to write a rspec test for edit user information function and change password function?

ⅰ亾dé卋堺 提交于 2019-12-24 21:37:26

问题


Does anyone knows how can I write a rspec test for these two functions? The update function is used to allow user to edit their information and update. The second function is used to change user's password with requiring user's old password.

def update
  @user = current_user
  if @user.update_attributes(user_params)
    head :no_content
  else 
    render_error(:unprocessable_entity, "Failed to update information")
  end
end

def change_password
  @user = current_user
  if @user.authenticate(params[:password])
    @user.update_attributes({:password => params[:password]})
    head :no_content
  else
    render_error(:unprocessable_entity, "Wrong Password!")
  end  
end  

来源:https://stackoverflow.com/questions/47357256/how-to-write-a-rspec-test-for-edit-user-information-function-and-change-password

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!