Commit e2c6b139 authored by Doug Stull's avatar Doug Stull Committed by Sean McGivern

Skip st_diff setting on LegacyDiffNote during import

- not needed as the import files will have this information

Changelog: fixed
parent 9064ff02
...@@ -13,7 +13,7 @@ class LegacyDiffNote < Note ...@@ -13,7 +13,7 @@ class LegacyDiffNote < Note
validates :line_code, presence: true, line_code: true validates :line_code, presence: true, line_code: true
before_create :set_diff before_create :set_diff, unless: :skip_setting_st_diff?
def discussion_class(*) def discussion_class(*)
LegacyDiffDiscussion LegacyDiffDiscussion
...@@ -90,6 +90,10 @@ class LegacyDiffNote < Note ...@@ -90,6 +90,10 @@ class LegacyDiffNote < Note
self.st_diff = diff.to_hash if diff self.st_diff = diff.to_hash if diff
end end
def skip_setting_st_diff?
st_diff.present? && importing? && Feature.enabled?(:skip_legacy_diff_note_callback_on_import, default_enabled: :yaml)
end
def diff_for_line_code def diff_for_line_code
attributes = { attributes = {
noteable_type: noteable_type, noteable_type: noteable_type,
......
---
name: skip_legacy_diff_note_callback_on_import
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72897
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343666
milestone: '14.5'
type: development
group: group::import
default_enabled: false
...@@ -8,4 +8,58 @@ RSpec.describe LegacyDiffNote do ...@@ -8,4 +8,58 @@ RSpec.describe LegacyDiffNote do
it { is_expected.to eq('note') } it { is_expected.to eq('note') }
end end
describe 'callbacks' do
describe '#set_diff' do
let(:note) do
build(:legacy_diff_note_on_merge_request, st_diff: '_st_diff_').tap do |record|
record.instance_variable_set(:@diff, {})
end
end
context 'when not importing' do
it 'updates st_diff' do
note.save!(validate: false)
expect(note.st_diff).to eq({})
end
end
context 'when importing' do
before do
note.importing = true
end
it 'does not update st_diff' do
note.save!(validate: false)
expect(note.st_diff).to eq('_st_diff_')
end
context 'when feature flag is false' do
before do
stub_feature_flags(skip_legacy_diff_note_callback_on_import: false)
end
it 'updates st_diff' do
note.save!(validate: false)
expect(note.st_diff).to eq({})
end
end
context 'when st_diff is blank' do
before do
note.st_diff = nil
end
it 'updates st_diff' do
note.save!(validate: false)
expect(note.st_diff).to eq({})
end
end
end
end
end
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