Commit bae27142 authored by Max Woolf's avatar Max Woolf

Merge branch...

Merge branch '330275-ensure-draft-quick-action-and-the-button-un-mark-as-draft-will-flip-draft-status' into 'master'

Set draft status field before saving MR record

See merge request gitlab-org/gitlab!62517
parents 103fa967 745ece3f
...@@ -125,6 +125,8 @@ class MergeRequest < ApplicationRecord ...@@ -125,6 +125,8 @@ class MergeRequest < ApplicationRecord
].freeze ].freeze
serialize :merge_params, Hash # rubocop:disable Cop/ActiveRecordSerialize serialize :merge_params, Hash # rubocop:disable Cop/ActiveRecordSerialize
before_validation :set_draft_status
after_create :ensure_merge_request_diff after_create :ensure_merge_request_diff
after_update :clear_memoized_shas after_update :clear_memoized_shas
after_update :reload_diff_if_branch_changed after_update :reload_diff_if_branch_changed
...@@ -1908,6 +1910,10 @@ class MergeRequest < ApplicationRecord ...@@ -1908,6 +1910,10 @@ class MergeRequest < ApplicationRecord
private private
def set_draft_status
self.draft = draft?
end
def missing_report_error(report_type) def missing_report_error(report_type)
{ status: :error, status_reason: "This merge request does not have #{report_type} reports" } { status: :error, status_reason: "This merge request does not have #{report_type} reports" }
end end
......
...@@ -317,6 +317,38 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -317,6 +317,38 @@ RSpec.describe MergeRequest, factory_default: :keep do
expect(merge_request.target_project_id).to eq(merge_request.metrics.target_project_id) expect(merge_request.target_project_id).to eq(merge_request.metrics.target_project_id)
end end
end end
describe '#set_draft_status' do
let(:merge_request) { create(:merge_request) }
context 'MR is a draft' do
before do
expect(merge_request.draft).to be_falsy
merge_request.title = "Draft: #{merge_request.title}"
end
it 'sets draft to true' do
merge_request.save!
expect(merge_request.draft).to be_truthy
end
end
context 'MR is not a draft' do
before do
expect(merge_request.draft).to be_falsey
merge_request.title = "This is not a draft"
end
it 'sets draft to true' do
merge_request.save!
expect(merge_request.draft).to be_falsey
end
end
end
end end
describe 'respond to' do describe 'respond to' do
......
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