Commit 86ef67ee authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Present ajax call errors when failing to update an Issue

parent 4ea85da9
...@@ -148,7 +148,14 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -148,7 +148,14 @@ class Projects::IssuesController < Projects::ApplicationController
end end
format.json do format.json do
render json: @issue.to_json(include: { milestone: {}, assignee: { only: [:name, :username], methods: [:avatar_url] }, labels: { methods: :text_color } }, methods: [:task_status, :task_status_short]) if @issue.valid?
render json: @issue.to_json(methods: [:task_status, :task_status_short],
include: { milestone: {},
assignee: { only: [:name, :username], methods: [:avatar_url] },
labels: { methods: :text_color } })
else
render json: { errors: @issue.errors.full_messages }, status: :unprocessable_entity
end
end end
end end
......
...@@ -41,7 +41,7 @@ module Spammable ...@@ -41,7 +41,7 @@ module Spammable
def check_for_spam def check_for_spam
error_msg = if Gitlab::Recaptcha.enabled? error_msg = if Gitlab::Recaptcha.enabled?
"Your #{spammable_entity_type} has been recognized as spam. "\ "Your #{spammable_entity_type} has been recognized as spam. "\
"You can still submit it by solving Captcha." "Please, change the content or solve the reCAPTCHA to proceed."
else else
"Your #{spammable_entity_type} has been recognized as spam and has been discarded." "Your #{spammable_entity_type} has been recognized as spam and has been discarded."
end end
......
...@@ -241,10 +241,27 @@ describe Projects::IssuesController do ...@@ -241,10 +241,27 @@ describe Projects::IssuesController do
expect(spam_logs.first.recaptcha_verified).to be_falsey expect(spam_logs.first.recaptcha_verified).to be_falsey
end end
it 'renders verify template' do context 'as HTML' do
update_spam_issue it 'renders verify template' do
update_spam_issue
expect(response).to render_template(:verify)
end
end
context 'as JSON' do
before do
update_issue({ title: 'Spam Title', description: 'Spam lives here' }, format: :json)
end
it 'renders json errors' do
expect(json_response)
.to eql("errors" => ["Your issue has been recognized as spam. Please, change the content or solve the reCAPTCHA to proceed."])
end
expect(response).to render_template(:verify) it 'returns 422 status' do
expect(response).to have_http_status(422)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment