Commit 745ece3f authored by Kerri Miller's avatar Kerri Miller

Set draft status field before saving MR

Set draft status (true/false) based on parsing the title.
parent 141a7cd2
......@@ -125,6 +125,8 @@ class MergeRequest < ApplicationRecord
].freeze
serialize :merge_params, Hash # rubocop:disable Cop/ActiveRecordSerialize
before_validation :set_draft_status
after_create :ensure_merge_request_diff
after_update :clear_memoized_shas
after_update :reload_diff_if_branch_changed
......@@ -1908,6 +1910,10 @@ class MergeRequest < ApplicationRecord
private
def set_draft_status
self.draft = draft?
end
def missing_report_error(report_type)
{ status: :error, status_reason: "This merge request does not have #{report_type} reports" }
end
......
......@@ -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)
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
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