mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 06:51:27 +08:00
DEV: Use more specific error responses (#9472)
* DEV: Use `render_json_error` (Adds specs for Admin::GroupsController) * DEV: Use a specific error on blank category slug (Fixes a `render_json_error` warning) * DEV: Use a specific error on reviewable claim conflict (Fixes a `render_json_error` warning) * DEV: Use specific errors in Admin::UsersController (Fixes `render_json_error` warnings) * FIX: PublishedPages error responses * FIX: TopicsController error responses (There was an issue of two separate `Topic` instances for the same record. This makes sure there's only one up-to-date instance.)
This commit is contained in:
@ -95,6 +95,33 @@ RSpec.describe Admin::GroupsController do
|
||||
expect(group.group_users.where(owner: true).map(&:user))
|
||||
.to contain_exactly(user, admin)
|
||||
end
|
||||
|
||||
it 'returns not-found error when there is no group' do
|
||||
group.destroy!
|
||||
|
||||
put "/admin/groups/#{group.id}/owners.json", params: {
|
||||
group: {
|
||||
usernames: user.username
|
||||
}
|
||||
}
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it 'does not allow adding owners to an automatic group' do
|
||||
group.update!(automatic: true)
|
||||
|
||||
expect do
|
||||
put "/admin/groups/#{group.id}/owners.json", params: {
|
||||
group: {
|
||||
usernames: user.username
|
||||
}
|
||||
}
|
||||
end.to_not change { group.group_users.count }
|
||||
|
||||
expect(response.status).to eq(422)
|
||||
expect(response.parsed_body["errors"]).to eq(["You cannot modify an automatic group"])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remove_owner' do
|
||||
@ -108,6 +135,27 @@ RSpec.describe Admin::GroupsController do
|
||||
expect(response.status).to eq(200)
|
||||
expect(group.group_users.where(owner: true)).to eq([])
|
||||
end
|
||||
|
||||
it 'returns not-found error when there is no group' do
|
||||
group.destroy!
|
||||
|
||||
delete "/admin/groups/#{group.id}/owners.json", params: {
|
||||
user_id: user.id
|
||||
}
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it 'does not allow removing owners from an automatic group' do
|
||||
group.update!(automatic: true)
|
||||
|
||||
delete "/admin/groups/#{group.id}/owners.json", params: {
|
||||
user_id: user.id
|
||||
}
|
||||
|
||||
expect(response.status).to eq(422)
|
||||
expect(response.parsed_body["errors"]).to eq(["You cannot modify an automatic group"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#bulk_perform" do
|
||||
|
Reference in New Issue
Block a user