Skip to content
Snippets Groups Projects
Verified Commit 3ae84c12 authored by Kassio Borges's avatar Kassio Borges 3️⃣
Browse files

Do not fail import of merge request when unsupported diff note occurs

Some validations doesn't make sense during a project import, since the
objects are built in a custom way.

Related to: #285107
parent 5fc1123b
No related branches found
No related tags found
1 merge request!48189Do not fail import of merge request when unsupported diff note occurs
......@@ -19,7 +19,7 @@ def self.noteable_types
# EE might have added a type when the module was prepended
validates :noteable_type, inclusion: { in: -> (_note) { noteable_types } }
validate :positions_complete
validate :verify_supported
validate :verify_supported, unless: :importing?
before_validation :set_line_code, if: :on_text?, unless: :importing?
after_save :keep_around_commits, unless: :importing?
......
# frozen_string_literal: true
class SystemNoteMetadata < ApplicationRecord
include Importable
# These notes's action text might contain a reference that is external.
# We should always force a deep validation upon references that are found
# in this note type.
......@@ -23,7 +25,7 @@ class SystemNoteMetadata < ApplicationRecord
status alert_issue_added relate unrelate new_alert_added severity
].freeze
validates :note, presence: true
validates :note, presence: true, unless: :importing?
validates :action, inclusion: { in: :icon_types }, allow_nil: true
belongs_to :note
......
---
title: Avoid invalid notes on Project Import
merge_request: 48189
author:
type: fixed
......@@ -46,6 +46,18 @@
expect(note.errors[:noteable]).to include("doesn't support new-style diff notes")
end
context 'when importing' do
it "does not check if it's supported" do
note = build(:diff_note_on_merge_request, project: project, noteable: nil)
note.importing = true
note.valid?
expect(note.errors.full_messages).not_to include(
"Noteable doesn't support new-style diff notes"
)
end
end
end
describe "#position=" do
......
......@@ -13,7 +13,7 @@
context 'when action type is invalid' do
subject do
build(:system_note_metadata, note: build(:note), action: 'invalid_type' )
build(:system_note_metadata, note: build(:note), action: 'invalid_type')
end
it { is_expected.to be_invalid }
......@@ -21,7 +21,15 @@
context 'when action type is valid' do
subject do
build(:system_note_metadata, note: build(:note), action: 'merge' )
build(:system_note_metadata, note: build(:note), action: 'merge')
end
it { is_expected.to be_valid }
end
context 'when importing' do
subject do
build(:system_note_metadata, note: nil, action: 'merge', importing: true)
end
it { is_expected.to be_valid }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment