FIX: Throw error when removing a user from group fails (#9162)

This commit ensures that an error is thrown when a user fails to be
removed from a group instead of silently failing.

This means when using the api you will receive a 400 instead of a 200 if
there is a failure. The remove group endpoint allows the removal of
multiple users, this change means that if you try to delete 10 users,
but 1 of them fails you will receive a 400 instead of 200 even though
the other 9 were removed successfully. Rather than adding a bunch more
complexity I think this is more than adequate for most use cases.
This commit is contained in:
Blake Erickson
2020-03-10 15:25:00 -06:00
committed by GitHub
parent 29b35aa64c
commit 6fb4c333b0
4 changed files with 19 additions and 11 deletions

View File

@@ -1192,6 +1192,11 @@ describe GroupsController do
expect(response.status).to eq(400)
end
it "raises an error when removing a valid user but is not a member of that group" do
delete "/groups/#{group.id}/members.json", params: { user_id: -1 }
expect(response.status).to eq(400)
end
context "is able to remove a member" do
it "removes by id" do
expect do
@@ -1314,12 +1319,10 @@ describe GroupsController do
end
it "only removes users in that group" do
expect do
delete "/groups/#{group1.id}/members.json",
params: { usernames: [user.username, user2.username].join(",") }
end.to change { group1.users.count }.by(-1)
delete "/groups/#{group1.id}/members.json",
params: { usernames: [user.username, user2.username].join(",") }
expect(response.status).to eq(200)
expect(response.status).to eq(400)
end
end
end