FIX: return 422 for an invalid group name on category create

This commit is contained in:
Blake Erickson 2018-08-30 14:28:40 -06:00
parent 4b6381367e
commit ae532f8548
2 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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