Skip to content

Commit

Permalink
Fix Rails/Savebang rubocop related failures
Browse files Browse the repository at this point in the history
- Update method name 'update' to 'call'
- Fix test with weak password that wasn't previously being persisted correctly
- Rescue from ActiveRecord::RecordInvalid to keep user flow consistent after adding ! to `save` in 'suspend' and 'unsuspend' methods
  • Loading branch information
benbaumann95 committed Sep 2, 2020
1 parent f52eee6 commit 7d07eb0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/suspensions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class SuspensionsController < ApplicationController
before_action :authenticate_user!, :load_and_authorize_user
respond_to :html

rescue_from ActiveRecord::RecordInvalid, with: :render_edit

def update
if params[:user][:suspended] == "1"
succeeded = @user.suspend(params[:user][:reason_for_suspension])
Expand All @@ -20,8 +22,7 @@ def update

redirect_to @user.api_user? ? edit_api_user_path(@user) : edit_user_path(@user)
else
flash[:alert] = "Failed"
render :edit
render_edit
end
end

Expand All @@ -31,4 +32,9 @@ def load_and_authorize_user
@user = User.find(params[:id])
authorize @user, :suspension?
end

def render_edit
flash[:alert] = "Failed"
render :edit
end
end

0 comments on commit 7d07eb0

Please sign in to comment.