diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 19f81e7..47d9545 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -48,11 +48,11 @@ class UsersController < AdminController def destroy_user if request.post? - person = environment.people.find(params[:id]) - if person.destroy + person = environment.people.find_by_id(params[:id]) + if person && person.destroy session[:notice] = _('The profile was deleted.') else - session[:notice] = _('Could not delete profile') + session[:notice] = _('Could not remove profile') end end redirect_to :action => :index, :q => params[:q], :filter => params[:filter] diff --git a/features/manage_users.feature b/features/manage_users.feature index 1a97011..96be778 100644 --- a/features/manage_users.feature +++ b/features/manage_users.feature @@ -26,7 +26,7 @@ Background: Then I should see "Deactivate user" within "tr[title='Paulo Santos']" @selenium - Scenario: ban user + Scenario: remove user When I follow "Remove" within "tr[title='Joao Silva']" And I confirm the "Do you want to remove this user?" dialog And I go to /admin/users @@ -44,4 +44,4 @@ Background: And I confirm the "Do you want to set this user as administrator?" dialog When I follow "Reset admin role" within "tr[title='Paulo Santos']" And I confirm the "Do you want to reset this user as administrator?" dialog - Then I should see "Set admin role" within "tr[title='Paulo Santos']" \ No newline at end of file + Then I should see "Set admin role" within "tr[title='Paulo Santos']" diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index af89c6b..3ab0f09 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -133,4 +133,20 @@ class UsersControllerTest < ActionController::TestCase assert_equal 'name;email', @response.body.split("\n")[0] end + should 'be able to remove a person' do + person = fast_create(Person, :environment_id => environment.id) + assert_difference Person, :count, -1 do + post :destroy_user, :id => person.id + end + end + + should 'not crash if user does not exist' do + person = fast_create(Person) + + assert_no_difference Person, :count do + post :destroy_user, :id => 99999 + end + assert_redirected_to :action => 'index' + end + end -- libgit2 0.21.2