From 1545bff647e284d8c3230017c5ca0bec117e7656 Mon Sep 17 00:00:00 2001 From: Andrei Kaleshka Date: Fri, 28 Jun 2024 22:25:50 +0200 Subject: [PATCH] delete password params --- app/controllers/users/registrations_controller.rb | 4 ++++ spec/controllers/users/registrations_spec.rb | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 94bff79..a6faa03 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -24,6 +24,10 @@ def edit_profile private def update_resource(resource, params) + if params[:password].blank? + params.delete(:password) + params.delete(:password_confirmation) + end resource.update(params) end diff --git a/spec/controllers/users/registrations_spec.rb b/spec/controllers/users/registrations_spec.rb index 0d69ced..67cc052 100644 --- a/spec/controllers/users/registrations_spec.rb +++ b/spec/controllers/users/registrations_spec.rb @@ -32,10 +32,17 @@ it { expect { subject }.to change { user.reload.email }.to(new_email) } it { expect { put :update, params: { id: user.id, user: { name: new_email } } }.to change { user.reload.name }.to(new_email) } + it { expect { put :update, params: { id: user.id, user: { name: new_email, password: '' } } }.to change { user.reload.name }.to(new_email) } it { expect do put :update, params: { id: user.id, user: { password: new_password, password_confirmation: new_password } } end.to change { user.reload.valid_password?(new_password) }.from(false).to(true) } + + it { + expect do + put :update, params: { id: user.id, user: { password: '', password_confirmation: new_password } } + end.to_not change { user.reload.valid_password?(new_password) }.from(false) + } end end