summaryrefslogtreecommitdiff
path: root/test/controllers
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-31 15:55:43 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-31 15:55:43 +0200
commit464dd4266bdc433805010b5dca428f4cb75c2a81 (patch)
tree47fdf4f065960d49da015eafdf56cb817dcf9ea4 /test/controllers
parent5f17f421b176d48ef556fb379f59bbb7d284b48e (diff)
Group user accounts by role
Replaces the two-way admin/user split with four groups ordered by capability: administration, Redaktion, editors, alumni. alumni takes precedence over capability in role_group, so a retired admin appears at the bottom rather than the top. Forms now offer the three roles as checkboxes rather than a single admin checkbox, with a trailing hidden blank so an empty set can be posted, and user_params permits roles only for admins. Three create buttons prefill the common combinations.
Diffstat (limited to 'test/controllers')
-rw-r--r--test/controllers/users_controller_test.rb27
1 files changed, 18 insertions, 9 deletions
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb
index 67f7c053..1c5d16fc 100644
--- a/test/controllers/users_controller_test.rb
+++ b/test/controllers/users_controller_test.rb
@@ -9,12 +9,12 @@ class UsersControllerTest < ActionController::TestCase
9 assert_select "a", { :count => 0, :text => "Destroy" } 9 assert_select "a", { :count => 0, :text => "Destroy" }
10 end 10 end
11 11
12 test "get index as admin user renders admin partial" do 12 test "get index as admin shows every group with per-row actions" do
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("admin.common.destroy")
17 assert_select "a", "show" 17 assert_select "a", I18n.t("admin.common.show")
18 end 18 end
19 19
20 test "get new when logged in as admin" do 20 test "get new when logged in as admin" do
@@ -60,7 +60,7 @@ class UsersControllerTest < ActionController::TestCase
60 :email => "foo@bar.com", 60 :email => "foo@bar.com",
61 :password => "xxxzzz", 61 :password => "xxxzzz",
62 :password_confirmation => "xxxzzz", 62 :password_confirmation => "xxxzzz",
63 :admin => true 63 :roles => ["admin", "redaktion"]
64 } 64 }
65 } 65 }
66 end 66 end
@@ -174,19 +174,17 @@ class UsersControllerTest < ActionController::TestCase
174 test "admin user can promote regular users to admins" do 174 test "admin user can promote regular users to admins" do
175 login_as :aaron 175 login_as :aaron
176 user = users(:quentin) 176 user = users(:quentin)
177 put :update, params: { :id => user.id, :user => {:admin => true} } 177 put :update, params: { :id => user.id, :user => {:roles => ["admin", "redaktion"]} }
178 178
179 user.reload 179 assert_equal true, user.reload.is_admin?
180 assert_equal true, user.is_admin?
181 end 180 end
182 181
183 test "regular users cannot promote themselves to admins" do 182 test "regular users cannot promote themselves to admins" do
184 login_as :quentin 183 login_as :quentin
185 user = users(:quentin) 184 user = users(:quentin)
186 put :update, params: { :id => user.id, :user => {:admin => true} } 185 put :update, params: { :id => user.id, :user => {:roles => ["admin", "redaktion"]} }
187 186
188 user.reload 187 assert_equal false, user.reload.is_admin?
189 assert_equal false, user.is_admin?
190 end 188 end
191 189
192 test "reset_otp is admin-only and witnessed" do 190 test "reset_otp is admin-only and witnessed" do
@@ -202,4 +200,15 @@ class UsersControllerTest < ActionController::TestCase
202 assert_not user.reload.otp_enrolled? 200 assert_not user.reload.otp_enrolled?
203 assert_equal "otp_reset", NodeAction.last.action 201 assert_equal "otp_reset", NodeAction.last.action
204 end 202 end
203
204 test "index groups a retired admin under alumni, not administration" do
205 login_as :aaron
206 user = users(:quentin)
207 user.update_column(:roles, ["admin", "alumni"])
208
209 get :index
210
211 assert_response :success
212 assert_select "h2", :text => /#{I18n.t("users.index.group_alumni")}/
213 end
205end 214end