Skip to content

Commit

Permalink
delete password params
Browse files Browse the repository at this point in the history
  • Loading branch information
ka8725 committed Jun 28, 2024
1 parent 58990c2 commit 1545bff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions spec/controllers/users/registrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1545bff

Please sign in to comment.