summaryrefslogtreecommitdiff
path: root/spec/models/legacy_diff_note_spec.rb
blob: 8934fe6b1079b67d0ed0ce56c71f1362a0ba6ca4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe LegacyDiffNote do
  describe '#to_ability_name' do
    subject { described_class.new.to_ability_name }

    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 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