Skip to content

Commit 12ccb1e

Browse files
committed
added test for checking that categories with high trust level to view are not accessible to users with lower level
1 parent da9fae5 commit 12ccb1e

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/controllers/categories_controller_test.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,25 @@ class CategoriesControllerTest < ActionController::TestCase
7575
end
7676

7777
test 'should prevent users under min_view_trust_level viewing category that requires higher' do
78-
get :show, params: { id: categories(:admin_only).id }
78+
staff_only = categories(:admin_only)
7979

80-
assert_response(:not_found)
81-
assert_not_nil assigns(:category)
80+
users.reject { |u| u.can_see_category?(staff_only) && !u.staff? }.each do |user|
81+
sign_in user
82+
try_show_category(staff_only)
83+
84+
if user.staff?
85+
assert_response(:success)
86+
else
87+
assert_response(:not_found)
88+
end
89+
90+
assert_not_nil assigns(:category)
91+
end
92+
end
93+
94+
private
95+
96+
def try_show_category(category)
97+
get :show, params: { id: category.id }
8298
end
8399
end

0 commit comments

Comments
 (0)