pundit: convert user name change requests to pundit.

Fix discrepancy between index action and show action. The index
action allowed members to see name changes for undeleted users, but the
show action didn't.
This commit is contained in:
evazion
2020-03-17 05:17:57 -05:00
parent db63b6d44f
commit 565a6572a7
5 changed files with 39 additions and 28 deletions

View File

@@ -26,6 +26,7 @@ class UserNameChangeRequestsControllerTest < ActionDispatch::IntegrationTest
context "show action" do
setup do
@change_request = as(@user) { create(:user_name_change_request, user_id: @user.id) }
@user.update!(name: "user_#{@user.id}")
end
should "render" do
@@ -33,7 +34,7 @@ class UserNameChangeRequestsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
context "when the current user is not an admin and does not own the request" do
context "when the current user is not an admin, doesn't own the request, and the other user is deleted" do
should "fail" do
@another_user = create(:user)
get_auth user_name_change_request_path(@change_request), @another_user
@@ -42,15 +43,20 @@ class UserNameChangeRequestsControllerTest < ActionDispatch::IntegrationTest
end
end
context "for actions restricted to admins" do
context "index action" do
should "render" do
post_auth user_name_change_requests_path, @user, params: { user_name_change_request: { desired_name: "zun", desired_name_confirmation: "zun" }}
get user_name_change_requests_path
context "index action" do
should "allows members to see name changes" do
create(:user_name_change_request)
get_auth user_name_change_requests_path, @user
assert_response :success
assert_select "table tbody tr", 1
end
assert_response :success
assert_select "table tbody tr", 1
end
should "not allow anonymous users to see name changes" do
create(:user_name_change_request)
get user_name_change_requests_path
assert_response 403
end
end
end