diff options
Diffstat (limited to 'users')
-rw-r--r-- | users/app/controllers/users_controller.rb | 2 | ||||
-rw-r--r-- | users/app/views/users/edit.html.haml | 7 | ||||
-rw-r--r-- | users/test/functional/users_controller_test.rb | 13 |
3 files changed, 19 insertions, 3 deletions
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 3407191..cffc8c6 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -36,7 +36,7 @@ class UsersController < ApplicationController def destroy @user.destroy - redirect_to users_path + redirect_to admin? ? users_path : login_path end protected diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml index 8298443..cfcf220 100644 --- a/users/app/views/users/edit.html.haml +++ b/users/app/views/users/edit.html.haml @@ -1,3 +1,10 @@ .span8.offset2 %h2=t :settings = render 'form' + - if @user == current_user + %legend + =t :cancel_account + %small You will not be able to login anymore. + = link_to user_path(@user), :method => :delete, :class => "btn btn-danger" do + %i.icon-remove.icon-white + Remove my Account diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index f008cda..44b6768 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -63,10 +63,19 @@ class UsersControllerTest < ActionController::TestCase login :is_admin? => true user = stub_record User user.expects(:destroy) - User.expects(:find_by_param).with(user.id.to_s).returns(user) + User.expects(:find_by_param).with(user.id).returns(user) delete :destroy, :id => user.id assert_response :redirect - # assert_redirected_to users_path + assert_redirected_to users_path + end + + test "user can cancel account" do + login + @current_user.expects(:destroy) + User.expects(:find_by_param).with(@current_user.id).returns(@current_user) + delete :destroy, :id => @current_user.id + assert_response :redirect + assert_redirected_to login_path end test "non-admin can't destroy user" do |