diff options
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/projects/merge_requests/drafts_controller_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/controllers/projects/merge_requests/drafts_controller_spec.rb b/spec/controllers/projects/merge_requests/drafts_controller_spec.rb index fea176dfa5d..68fbeb00b67 100644 --- a/spec/controllers/projects/merge_requests/drafts_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/drafts_controller_spec.rb @@ -239,6 +239,30 @@ RSpec.describe Projects::MergeRequests::DraftsController, feature_category: :cod expect(draft.note).to eq('This is an updated unpublished comment') expect(json_response['note_html']).not_to be_empty end + + context 'when the draft note is invalid' do + before do + errors = ActiveModel::Errors.new(draft) + errors.add(:base, 'Error 1') + errors.add(:base, 'Error 2') + + allow_next_found_instance_of(DraftNote) do |instance| + allow(instance).to receive(:update).and_return(false) + allow(instance).to receive(:errors).and_return(errors) + end + end + + it 'does not update the draft' do + expect { update_draft_note }.not_to change { draft.reload.note } + end + + it 'returns status 422', :aggregate_failures do + update_draft_note + + expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(response.body).to eq('{"errors":"Error 1 and Error 2"}') + end + end end describe 'POST #publish' do |