Improve error message in Api::V0:ArticlesController#create (#4417)
This commit is contained in:
parent
0ff237cf20
commit
a6b51888c5
2 changed files with 12 additions and 1 deletions
|
|
@ -39,7 +39,12 @@ module Api
|
|||
|
||||
def create
|
||||
@article = Articles::Creator.call(@user, article_params)
|
||||
render "show", status: :created, location: @article.url
|
||||
if @article.persisted?
|
||||
render "show", status: :created, location: @article.url
|
||||
else
|
||||
message = @article.errors.full_messages
|
||||
render json: { errors: message, status: 422 }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
|||
|
|
@ -257,6 +257,12 @@ RSpec.describe "Api::V0::Articles", type: :request do
|
|||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it "fails if missing required params" do
|
||||
tags = %w[meta discussion]
|
||||
post_article(body_markdown: "Yo ho ho", tags: tags)
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it "creates an article belonging to the user" do
|
||||
post_article(title: Faker::Book.title)
|
||||
expect(response).to have_http_status(:created)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue