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
end
unless suggestion.appliable?(cached: false)
return _('A suggestion is not applicable.')
return suggestion.inapplicable_reason(cached: false)
end
unless latest_source_head?(suggestion)
......
......@@ -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."
msgstr ""
msgid "A suggestion is not applicable."
msgstr ""
msgid "A user with write access to the source branch selected this option"
msgstr ""
......
......@@ -74,7 +74,7 @@ RSpec.describe API::Suggestions do
put api(url, user)
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
......@@ -133,7 +133,7 @@ RSpec.describe API::Suggestions do
params: { ids: [suggestion.id, unappliable_suggestion.id] }
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
......
......@@ -609,40 +609,16 @@ RSpec.describe Suggestions::ApplyService do
end
end
context 'suggestion is eligible to be outdated' do
it 'returns error message' do
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
context 'suggestion is not appliable' do
let(:inapplicable_reason) { "Can't apply this suggestion." }
it 'returns error message' do
result = apply_service.new(user, suggestion).execute
expect(result).to eq(message: 'A suggestion is not applicable.',
status: :error)
end
end
expect(suggestion).to receive(:appliable?).and_return(false)
expect(suggestion).to receive(:inapplicable_reason).and_return(inapplicable_reason)
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
expect(result).to eq(message: 'A suggestion is not applicable.',
status: :error)
expect(result).to eq(message: inapplicable_reason, status: :error)
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