FIX: return 422 for an invalid group name on category create
This commit is contained in:
parent
4b6381367e
commit
ae532f8548
|
@ -134,6 +134,8 @@ class CategoriesController < ApplicationController
|
|||
else
|
||||
return render_json_error(@category) unless @category.save
|
||||
end
|
||||
rescue ArgumentError => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
@ -99,6 +99,18 @@ describe CategoriesController do
|
|||
|
||||
expect(response.status).to eq(422)
|
||||
end
|
||||
|
||||
it "returns errors with invalid group" do
|
||||
category = Fabricate(:category, user: admin)
|
||||
readonly = CategoryGroup.permission_types[:readonly]
|
||||
|
||||
post "/categories.json", params: {
|
||||
name: category.name, color: "ff0", text_color: "fff", permissions: {"invalid_group" => readonly}
|
||||
}
|
||||
|
||||
expect(response.status).to eq(422)
|
||||
expect(JSON.parse(response.body)['errors']).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe "success" do
|
||||
|
|
Loading…
Reference in New Issue