Commit bc7b37e2 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '225617-meaningful-inapplicable-error-message' into 'master'

Show meaningful message when applying inapplicable suggestion

See merge request gitlab-org/gitlab!37267
parents 684114bb 4f4d350e
---
title: Show meaningful message when applying inapplicable suggestion
merge_request: 37267
author:
type: changed
...@@ -83,7 +83,7 @@ module Gitlab ...@@ -83,7 +83,7 @@ module Gitlab
end end
unless suggestion.appliable?(cached: false) unless suggestion.appliable?(cached: false)
return _('A suggestion is not applicable.') return suggestion.inapplicable_reason(cached: false)
end end
unless latest_source_head?(suggestion) unless latest_source_head?(suggestion)
......
...@@ -1139,9 +1139,6 @@ msgstr "" ...@@ -1139,9 +1139,6 @@ msgstr ""
msgid "A subscription will trigger a new pipeline on the default branch of this project when a pipeline successfully completes for a new tag on the %{default_branch_docs} of the subscribed project." msgid "A subscription will trigger a new pipeline on the default branch of this project when a pipeline successfully completes for a new tag on the %{default_branch_docs} of the subscribed project."
msgstr "" msgstr ""
msgid "A suggestion is not applicable."
msgstr ""
msgid "A user with write access to the source branch selected this option" msgid "A user with write access to the source branch selected this option"
msgstr "" msgstr ""
......
...@@ -74,7 +74,7 @@ RSpec.describe API::Suggestions do ...@@ -74,7 +74,7 @@ RSpec.describe API::Suggestions do
put api(url, user) put api(url, user)
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to eq({ 'message' => 'A suggestion is not applicable.' }) expect(json_response).to eq({ 'message' => "Can't apply as this line was changed in a more recent version." })
end end
end end
...@@ -133,7 +133,7 @@ RSpec.describe API::Suggestions do ...@@ -133,7 +133,7 @@ RSpec.describe API::Suggestions do
params: { ids: [suggestion.id, unappliable_suggestion.id] } params: { ids: [suggestion.id, unappliable_suggestion.id] }
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to eq({ 'message' => 'A suggestion is not applicable.' }) expect(json_response).to eq({ 'message' => "Can't apply as this line was changed in a more recent version." })
end end
end end
......
...@@ -609,40 +609,16 @@ RSpec.describe Suggestions::ApplyService do ...@@ -609,40 +609,16 @@ RSpec.describe Suggestions::ApplyService do
end end
end end
context 'suggestion is eligible to be outdated' do context 'suggestion is not appliable' do
it 'returns error message' do let(:inapplicable_reason) { "Can't apply this suggestion." }
expect(suggestion).to receive(:outdated?) { true }
result = apply_service.new(user, suggestion).execute
expect(result).to eq(message: 'A suggestion is not applicable.',
status: :error)
end
end
context 'note is outdated' do
before do
allow(diff_note).to receive(:active?) { false }
end
it 'returns error message' do it 'returns error message' do
result = apply_service.new(user, suggestion).execute expect(suggestion).to receive(:appliable?).and_return(false)
expect(suggestion).to receive(:inapplicable_reason).and_return(inapplicable_reason)
expect(result).to eq(message: 'A suggestion is not applicable.',
status: :error)
end
end
context 'suggestion was already applied' do
before do
suggestion.update!(applied: true, commit_id: 'sha')
end
it 'returns error message' do
result = apply_service.new(user, suggestion).execute result = apply_service.new(user, suggestion).execute
expect(result).to eq(message: 'A suggestion is not applicable.', expect(result).to eq(message: inapplicable_reason, status: :error)
status: :error)
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