diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-31 17:05:05 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-31 17:05:05 +0200 |
| commit | 8c6a6516e1dc5c1b4f12740a6f7b32765b530bb7 (patch) | |
| tree | e40a1da656bedef0662f0e984b4e3b00b374bc1d /test/controllers/users_controller_test.rb | |
| parent | 464dd4266bdc433805010b5dca428f4cb75c2a81 (diff) | |
Replace user deletion with deactivation
Deactivation adds the alumni role and leaves the others in place, so
reactivation is lossless and nobody has to remember what an account held.
login_from_session checks alumni? on every request, so a signed-in user is
locked out on their next one without any session invalidation. Guards
prevent deactivating yourself or the last active admin, and both verbs are
witnessed in the action log.
Diffstat (limited to 'test/controllers/users_controller_test.rb')
| -rw-r--r-- | test/controllers/users_controller_test.rb | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 1c5d16fc..14133029 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb | |||
| @@ -13,7 +13,7 @@ class UsersControllerTest < ActionController::TestCase | |||
| 13 | login_as :aaron | 13 | login_as :aaron |
| 14 | get :index | 14 | get :index |
| 15 | assert_response :success | 15 | assert_response :success |
| 16 | assert_select "button[type=submit]", I18n.t("admin.common.destroy") | 16 | assert_select "button[type=submit]", I18n.t("users.user.deactivate") |
| 17 | assert_select "a", I18n.t("admin.common.show") | 17 | assert_select "a", I18n.t("admin.common.show") |
| 18 | end | 18 | end |
| 19 | 19 | ||
| @@ -146,22 +146,38 @@ class UsersControllerTest < ActionController::TestCase | |||
| 146 | 146 | ||
| 147 | test "destroying an user being logged in as regular user wont work" do | 147 | test "destroying an user being logged in as regular user wont work" do |
| 148 | login_as :quentin | 148 | login_as :quentin |
| 149 | assert_no_difference "User.count" do | 149 | put :deactivate, params: { :id => users(:quentin).id } |
| 150 | delete :destroy, params: { :id => User.find_by_login("aaron").id } | 150 | |
| 151 | end | ||
| 152 | assert_redirected_to users_path | 151 | assert_redirected_to users_path |
| 153 | assert_equal( | 152 | assert_not users(:quentin).reload.alumni? |
| 154 | I18n.t("flash.common.admin_required"), | ||
| 155 | flash[:notice] | ||
| 156 | ) | ||
| 157 | end | 153 | end |
| 158 | 154 | ||
| 159 | test "destroying an user being logged in as admin user" do | 155 | test "an admin deactivates another user, who can no longer sign in" do |
| 160 | login_as :aaron | 156 | login_as :aaron |
| 161 | assert_difference "User.count", -1 do | 157 | user = users(:quentin) |
| 162 | delete :destroy, params: { :id => User.find_by_login("quentin").id } | 158 | |
| 163 | end | 159 | put :deactivate, params: { :id => user.id } |
| 160 | |||
| 164 | assert_redirected_to users_path | 161 | assert_redirected_to users_path |
| 162 | assert user.reload.alumni? | ||
| 163 | assert_equal ["admin", "alumni"].sort, user.roles.sort if user.is_admin? | ||
| 164 | end | ||
| 165 | |||
| 166 | test "reactivation restores the other roles untouched" do | ||
| 167 | login_as :aaron | ||
| 168 | user = users(:quentin) | ||
| 169 | user.update_column(:roles, ["alumni", "redaktion"]) | ||
| 170 | |||
| 171 | put :reactivate, params: { :id => user.id } | ||
| 172 | |||
| 173 | assert_not user.reload.alumni? | ||
| 174 | assert_equal ["redaktion"], user.roles | ||
| 175 | end | ||
| 176 | |||
| 177 | test "an admin cannot deactivate their own account" do | ||
| 178 | login_as :aaron | ||
| 179 | put :deactivate, params: { :id => users(:aaron).id } | ||
| 180 | assert_not users(:aaron).reload.alumni? | ||
| 165 | end | 181 | end |
| 166 | 182 | ||
| 167 | test "enrolled user gets a working my account" do | 183 | test "enrolled user gets a working my account" do |
