mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Fix tests and add more comments
This commit is contained in:
parent
46b8d3ce9f
commit
95cb7ec799
2 changed files with 10 additions and 4 deletions
|
|
@ -131,16 +131,20 @@ class UsersController < ApplicationController
|
||||||
# DELETE /users/id DELETE /users/id.xml
|
# DELETE /users/id DELETE /users/id.xml
|
||||||
def destroy
|
def destroy
|
||||||
@deleted_user = User.find(params[:id])
|
@deleted_user = User.find(params[:id])
|
||||||
|
|
||||||
|
# Check that the user has access (logged in as admin or the target user.)
|
||||||
unless current_user && (current_user.is_admin || current_user == @deleted_user)
|
unless current_user && (current_user.is_admin || current_user == @deleted_user)
|
||||||
render :body => t('errors.user_unauthorized'), :status => 401
|
render :body => t('errors.user_unauthorized'), :status => 401
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Remove the user
|
||||||
@saved = @deleted_user.destroy
|
@saved = @deleted_user.destroy
|
||||||
if current_user == @deleted_user
|
|
||||||
|
# Log out the user if they've deleted their own user and it succeeded.
|
||||||
|
if @saved && current_user == @deleted_user
|
||||||
logout_user
|
logout_user
|
||||||
end
|
end
|
||||||
@total_users = User.count
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
|
|
@ -155,7 +159,9 @@ class UsersController < ApplicationController
|
||||||
redirect_to users_url
|
redirect_to users_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
format.js
|
format.js do
|
||||||
|
@total_users = User.count
|
||||||
|
end
|
||||||
format.xml do
|
format.xml do
|
||||||
head :ok
|
head :ok
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ class ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_401_unauthorized_admin
|
def assert_401_unauthorized_admin
|
||||||
assert_response_and_body 401, "401 Unauthorized: Only admin users are allowed access to this function."
|
assert_response_and_body 401, "401 Unauthorized: Only administrative users are allowed access to this function."
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_responses_with_error(error_msg)
|
def assert_responses_with_error(error_msg)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue