我想写控制器测试相关的密码更新测试。我在控制器的第一行找到了经过身份验证的人,条件是。我如何编写与这一行相关的测试。我不能放弃任何想法。
更改密码控制器
def update
person = Person.where(_id: session[:user_id]).first
identity = Identity.where(_id: person.user_id).first
unless params[:new_password] != params[:new_password_confirmation]
identity.password = params[:new_password].to_s
identity.password_confirmation = params[:new_password].to_s
identity.save
redirect_to root_url, :notice => "Password has been changed." + person.user_id
else
redirect_to :back, :alert => "Password & password confirmation are not match"
end
end
ChangePasswordsController 测试
describe ChangePasswordsController do
setup do
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:identity]
@auth=request.env["omniauth.auth"]
end
it "should have edit action" do
get :edit
assert_response :success
end
it "should find person" do
...
end
it "should find identity" do
...
end
end