pundit: convert bulk update requests to pundit.
This commit is contained in:
@@ -19,6 +19,7 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
should "succeed" do
|
||||
assert_difference("BulkUpdateRequest.count", 1) do
|
||||
post_auth bulk_update_requests_path, @user, params: {bulk_update_request: {skip_secondary_validations: "1", script: "create alias aaa -> bbb", title: "xxx"}}
|
||||
assert_response :redirect
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -26,14 +27,26 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "#update" do
|
||||
should "still handle enabled secondary validations correctly" do
|
||||
put_auth bulk_update_request_path(@bulk_update_request.id), @user, params: {bulk_update_request: {script: "create alias zzz -> 222", skip_secondary_validations: "0"}}
|
||||
@bulk_update_request.reload
|
||||
assert_equal("create alias zzz -> 222", @bulk_update_request.script)
|
||||
assert_response :redirect
|
||||
assert_equal("create alias zzz -> 222", @bulk_update_request.reload.script)
|
||||
end
|
||||
|
||||
should "still handle disabled secondary validations correctly" do
|
||||
put_auth bulk_update_request_path(@bulk_update_request.id), @user, params: {bulk_update_request: {script: "create alias zzz -> 222", skip_secondary_validations: "1"}}
|
||||
@bulk_update_request.reload
|
||||
assert_equal("create alias zzz -> 222", @bulk_update_request.script)
|
||||
assert_response :redirect
|
||||
assert_equal("create alias zzz -> 222", @bulk_update_request.reload.script)
|
||||
end
|
||||
|
||||
should "allow builders to update other people's requests" do
|
||||
put_auth bulk_update_request_path(@bulk_update_request.id), create(:builder_user), params: {bulk_update_request: {script: "create alias zzz -> 222", skip_secondary_validations: "0"}}
|
||||
assert_response :redirect
|
||||
assert_equal("create alias zzz -> 222", @bulk_update_request.reload.script)
|
||||
end
|
||||
|
||||
should "not allow members to update other people's requests" do
|
||||
put_auth bulk_update_request_path(@bulk_update_request.id), create(:user), params: {bulk_update_request: {script: "create alias zzz -> 222", skip_secondary_validations: "0"}}
|
||||
assert_response 403
|
||||
assert_equal("create alias aaa -> bbb", @bulk_update_request.reload.script)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,19 +68,16 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "for the creator" do
|
||||
should "succeed" do
|
||||
delete_auth bulk_update_request_path(@bulk_update_request), @user
|
||||
@bulk_update_request.reload
|
||||
assert_equal("rejected", @bulk_update_request.status)
|
||||
assert_response :redirect
|
||||
assert_equal("rejected", @bulk_update_request.reload.status)
|
||||
end
|
||||
end
|
||||
|
||||
context "for another member" do
|
||||
setup do
|
||||
@another_user = create(:user)
|
||||
end
|
||||
|
||||
should "fail" do
|
||||
assert_difference("BulkUpdateRequest.count", 0) do
|
||||
delete_auth bulk_update_request_path(@bulk_update_request), @another_user
|
||||
delete_auth bulk_update_request_path(@bulk_update_request), create(:user)
|
||||
assert_response 403
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -75,8 +85,8 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "for an admin" do
|
||||
should "succeed" do
|
||||
delete_auth bulk_update_request_path(@bulk_update_request), @admin
|
||||
@bulk_update_request.reload
|
||||
assert_equal("rejected", @bulk_update_request.status)
|
||||
assert_response :redirect
|
||||
assert_equal("rejected", @bulk_update_request.reload.status)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -85,16 +95,16 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "for a member" do
|
||||
should "fail" do
|
||||
post_auth approve_bulk_update_request_path(@bulk_update_request), @user
|
||||
@bulk_update_request.reload
|
||||
assert_equal("pending", @bulk_update_request.status)
|
||||
assert_response 403
|
||||
assert_equal("pending", @bulk_update_request.reload.status)
|
||||
end
|
||||
end
|
||||
|
||||
context "for an admin" do
|
||||
should "succeed" do
|
||||
post_auth approve_bulk_update_request_path(@bulk_update_request), @admin
|
||||
@bulk_update_request.reload
|
||||
assert_equal("approved", @bulk_update_request.status)
|
||||
assert_response :redirect
|
||||
assert_equal("approved", @bulk_update_request.reload.status)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user