Skip to content

Commit

Permalink
fix user update
Browse files Browse the repository at this point in the history
  • Loading branch information
ka8725 committed Jun 28, 2024
1 parent 067b767 commit d28e32e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 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 @@ -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
Expand Down
4 changes: 0 additions & 4 deletions app/views/devise/registrations/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion spec/controllers/users/registrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d28e32e

Please sign in to comment.