Welcome to mirror list, hosted at ThFree Co, Russian Federation.

diff_note_after_commit_shared_examples.rb « models « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 64390ccdc25da52073aa45fa52bcb76a82ca7029 (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
# frozen_string_literal: true

RSpec.shared_examples 'a valid diff note with after commit callback' do
  context 'when diff file is fetched from repository' do
    before do
      allow_any_instance_of(::Gitlab::Diff::Position).to receive(:diff_file).with(project.repository).and_return(diff_file_from_repository)
    end

    context 'when diff_line is not found' do
      it 'raises an error' do
        allow(diff_file_from_repository).to receive(:line_for_position).with(position).and_return(nil)

        expect { subject.save! }.to raise_error(::DiffNote::NoteDiffFileCreationError,
                                               "Failed to find diff line for: #{diff_file_from_repository.file_path}, "\
                                               "old_line: #{position.old_line}"\
                                               ", new_line: #{position.new_line}")
      end
    end

    context 'when diff_line is found' do
      before do
        allow(diff_file_from_repository).to receive(:line_for_position).with(position).and_return(diff_line)
      end

      it 'fallback to fetch file from repository' do
        expect_any_instance_of(::Gitlab::Diff::Position).to receive(:diff_file).with(project.repository)

        subject.save!
      end

      it 'creates a diff note file' do
        subject.save!

        expect(subject.reload.note_diff_file).to be_present
      end
    end
  end

  context 'when diff file is not found in repository' do
    it 'raises an error' do
      allow_any_instance_of(::Gitlab::Diff::Position).to receive(:diff_file).with(project.repository).and_return(nil)

      expect { subject.save! }.to raise_error(::DiffNote::NoteDiffFileCreationError, 'Failed to find diff file')
    end
  end
end