Support the ability for admins to delete users
This commit is contained in:
parent
331e0a1610
commit
332bf8f1df
3 changed files with 28 additions and 5 deletions
|
|
@ -66,10 +66,14 @@ module Admin
|
|||
|
||||
def edit; end
|
||||
|
||||
def delete
|
||||
@user.destroy!
|
||||
flash[:notice] = "User #{@user.id} (#{@user.emai}) successfully deleted."
|
||||
redirect_to admin_users_path
|
||||
def destroy
|
||||
if @user.destroy
|
||||
redirect_to admin_users_path,
|
||||
notice: "User #{@user.id} (#{@user.email}) deleted."
|
||||
else
|
||||
redirect_to admin_users_path,
|
||||
error: "User #{@user.id} (#{@user.emai}) could not be deleted. #{@user.full_messages.join(',')}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@
|
|||
.tab-content
|
||||
#user-info-content.tab-pane{class: "#{'active' unless params[:tab] == 'submissions-content'}"}
|
||||
- if can? :edit, @user
|
||||
.pull-right
|
||||
.pull-right.btn-group
|
||||
= link_to 'Edit', edit_admin_user_path(@user), class: 'btn btn-primary'
|
||||
= link_to 'Delete', admin_user_path(@user),method: :delete, class: 'btn btn-danger',
|
||||
data: {confirm: "Are you sure?"}
|
||||
%table.table
|
||||
- @show_attributes.each do |attr|
|
||||
%tr
|
||||
|
|
|
|||
|
|
@ -103,4 +103,21 @@ describe Admin::UsersController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before do
|
||||
delete :destroy, params: { id: user.id }
|
||||
end
|
||||
it 'redirects to admin users index path' do
|
||||
expect(response).to redirect_to admin_users_path
|
||||
end
|
||||
|
||||
it 'shows success message in flash notice' do
|
||||
expect(flash[:notice]).to match("User #{user.id} (#{user.email}) deleted.")
|
||||
end
|
||||
|
||||
it 'deletes the user' do
|
||||
expect { user.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue