DEV: Return the right response code and error message.
Follow up tod1dbafebbc
. Also remove test that is a duplicate of867c1a5ac9
.
This commit is contained in:
parent
4a1755b780
commit
ce15f085c6
|
@ -121,7 +121,9 @@ class TopicCreator
|
||||||
category = find_category
|
category = find_category
|
||||||
@guardian.ensure_can_create!(Topic, category) unless (@opts[:skip_validations] || @opts[:archetype] == Archetype.private_message)
|
@guardian.ensure_can_create!(Topic, category) unless (@opts[:skip_validations] || @opts[:archetype] == Archetype.private_message)
|
||||||
|
|
||||||
raise Discourse::NotFound if @opts[:category].present? && category.nil?
|
if @opts[:category].present? && category.nil?
|
||||||
|
raise Discourse::InvalidParameters.new(:category)
|
||||||
|
end
|
||||||
|
|
||||||
topic_params[:category_id] = category.id if category.present?
|
topic_params[:category_id] = category.id if category.present?
|
||||||
|
|
||||||
|
|
|
@ -787,21 +787,12 @@ describe PostsController do
|
||||||
raw: 'this is test body',
|
raw: 'this is test body',
|
||||||
category: 'invalid'
|
category: 'invalid'
|
||||||
}
|
}
|
||||||
expect(response.status).to eq(404)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'can create topics with an empty category param' do
|
expect(response.status).to eq(400)
|
||||||
user = Fabricate(:admin)
|
|
||||||
master_key = ApiKey.create_master_key.key
|
|
||||||
|
|
||||||
post "/posts.json", params: {
|
expect(JSON.parse(response.body)["errors"]).to include(
|
||||||
api_username: user.username,
|
I18n.t("invalid_params", message: "category")
|
||||||
api_key: master_key,
|
)
|
||||||
title: 'title for a topic without a category',
|
|
||||||
raw: 'body for my topic without a category',
|
|
||||||
category: ''
|
|
||||||
}
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue