Commit df070646 authored by Sean McGivern's avatar Sean McGivern

Merge branch '343664-legacydiffnotes-have-st_diff-incorrectly-on-gitlab-import' into 'master'

Skip st_diff callback setting on LegacyDiffNote when importing

See merge request gitlab-org/gitlab!72897
parents d2434df0 e2c6b139
......@@ -13,7 +13,7 @@ class LegacyDiffNote < Note
validates :line_code, presence: true, line_code: true
before_create :set_diff
before_create :set_diff, unless: :skip_setting_st_diff?
def discussion_class(*)
LegacyDiffDiscussion
......@@ -90,6 +90,10 @@ class LegacyDiffNote < Note
self.st_diff = diff.to_hash if diff
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
attributes = {
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
it { is_expected.to eq('note') }
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
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