Skip to content

Commit

Permalink
Allow users to edit their account without providing a current password (
Browse files Browse the repository at this point in the history
  • Loading branch information
slavakisel authored and timurvafin committed Apr 22, 2016
1 parent 655e65c commit 06899bc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
9 changes: 9 additions & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Users
class RegistrationsController < Devise::RegistrationsController
protected

def update_resource(resource, params)
resource.update_without_password(params)
end
end
end
2 changes: 1 addition & 1 deletion app/sanitizers/user/parameter_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def sign_up
end

def account_update
default_params.permit(USER_PARAMS, :current_password)
default_params.permit(USER_PARAMS)
end
end
end
2 changes: 0 additions & 2 deletions app/views/users/registrations/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
required: false
= f.input :password_confirmation,
required: false
= f.input :current_password,
required: true

.form-actions
= f.button :submit, "Update"
Expand Down
1 change: 1 addition & 0 deletions config/rails_best_practices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ RemoveTrailingWhitespaceCheck: { }
RemoveUnusedMethodsInControllersCheck:
except_methods:
- ApplicationController#devise_parameter_sanitizer
- Users::RegistrationsController#update_resource
RemoveUnusedMethodsInHelpersCheck: { except_methods: [] }
RemoveUnusedMethodsInModelsCheck: { except_methods: [] }
ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Rails.application.routes.draw do
devise_for :users
devise_for :users, controllers: { registrations: "users/registrations" }
root to: "pages#home"
end
9 changes: 1 addition & 8 deletions spec/features/user/account/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@
end

scenario "User updates account with valid data" do
fill_form(:user, full_name: "New Name", current_password: current_user.password)
fill_form(:user, full_name: "New Name")
click_on "Update"

expect(page).to have_content("New Name")
end

scenario "User updates account with invalid password" do
fill_form(:user, full_name: "New Name", current_password: "wrong")
click_on "Update"

expect(page).to have_content("is invalid")
end
end

0 comments on commit 06899bc

Please sign in to comment.