DEV: Improve API usage when creating * updating categories

The category model already has a default value for `color` and
`text_color` so they don't need to be required via the API. The ember UI
already requires that colors be selected.

The name of the category also doesn't need to be required when updating
the category either because we are already passing in the id for the
category we want to change.

These changes improve the api experience because you no longer have to
lookup the category name, color, or text color before updating a single
category attribute. When creating a category the name is still required.

https://meta.discourse.org/t/-/132424/2
This commit is contained in:
Blake Erickson
2020-08-12 12:28:29 -06:00
parent 70d4420c8e
commit c68563a281
2 changed files with 12 additions and 37 deletions

View File

@@ -120,16 +120,6 @@ describe CategoriesController do
expect(response.status).to eq(400)
end
it "raises an exception when the color is missing" do
post "/categories.json", params: { name: "hello", text_color: "fff" }
expect(response.status).to eq(400)
end
it "raises an exception when the text color is missing" do
post "/categories.json", params: { name: "hello", color: "ff0" }
expect(response.status).to eq(400)
end
describe "failure" do
it "returns errors on a duplicate category name" do
category = Fabricate(:category, user: admin)
@@ -314,27 +304,6 @@ describe CategoriesController do
expect(response).to be_forbidden
end
it "requires a name" do
put "/categories/#{category.slug}.json", params: {
color: 'fff',
text_color: '0ff',
}
expect(response.status).to eq(400)
end
it "requires a color" do
put "/categories/#{category.slug}.json", params: {
name: 'asdf',
text_color: '0ff',
}
expect(response.status).to eq(400)
end
it "requires a text color" do
put "/categories/#{category.slug}.json", params: { name: 'asdf', color: 'fff' }
expect(response.status).to eq(400)
end
it "returns errors on a duplicate category name" do
other_category = Fabricate(:category, name: "Other", user: admin)
put "/categories/#{category.id}.json", params: {