Я пишу спецификации для API.Но ответ возвращается со статусом :created
, когда он должен быть :unprocessable_entity
.
announcements_controller
def update
head :unprocessable_entity unless announcement
if annnouncement.update(announcement_params)
render json: annoucement, status: :ok
else
render_unprocessable_entity
end
end
def announcement
Announcement.find(params[id])
end
announcements_controller_spec
it 'fails when announcement does not exists' do
data = {
id: 999_999,
announcement: {
body: ''
}
}.to_json
post "/api/announcements/#{property.slug}", params: data, headers: headers
expect(response).to have_http_status(:unprocessable_entity)
end
ошибка ответа
1) Api::AnnouncementsController#update fails when announcement does not exists
Failure/Error: expect(response).to have_http_status(:unprocessable_entity)
expected the response to have status code :unprocessable_entity (422) but it was :created (201)