From d28e32eaec9a3667e10314489314313cb155eea6 Mon Sep 17 00:00:00 2001 From: Andrei Kaleshka Date: Fri, 28 Jun 2024 22:13:24 +0200 Subject: [PATCH] fix user update --- app/controllers/users/registrations_controller.rb | 4 ++++ app/views/devise/registrations/edit.html.slim | 4 ---- spec/controllers/users/registrations_spec.rb | 10 +++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index abebd22..94bff79 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -23,6 +23,10 @@ def edit_profile private + def update_resource(resource, params) + resource.update(params) + end + def devise_mapping @devise_mapping ||= Devise.mappings[:user] end diff --git a/app/views/devise/registrations/edit.html.slim b/app/views/devise/registrations/edit.html.slim index d35480f..d5ed8b1 100644 --- a/app/views/devise/registrations/edit.html.slim +++ b/app/views/devise/registrations/edit.html.slim @@ -19,10 +19,6 @@ | (#{@minimum_password_length} characters minimum) .field = f.password_field :password_confirmation, autocomplete: "new-password", placeholder: "password confirmation" - .field - = f.password_field :current_password, autocomplete: "current-password", placeholder: "current password" - p.help - | (we need your current password to confirm your changes) div.buttons.is-flex.is-justify-content-flex-end = link_to request.referer.present? && request.referer != edit_user_registration_path ? request.referer : root_path, class: 'button is-light' do span.icon diff --git a/spec/controllers/users/registrations_spec.rb b/spec/controllers/users/registrations_spec.rb index feee42a..e3597fc 100644 --- a/spec/controllers/users/registrations_spec.rb +++ b/spec/controllers/users/registrations_spec.rb @@ -22,12 +22,20 @@ before { sign_in user } let(:password) { FFaker::Internet.password } + let(:new_password) { FFaker::Internet.password } let(:user) { create(:user, password: password) } let(:new_email) { FFaker::Internet.email } - subject { put :update, params: { id: user.id, user: { email: new_email, current_password: password } } } + subject { put :update, params: { id: user.id, user: { email: new_email } } } it { expect(subject).to have_http_status(:redirect) } 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: { password: new_password, password_confirmation: new_password } } + }.to change { user.reload.valid_password?(new_password) }.from(false).to(true) + } end end