File: diffs_stream_shared_examples.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (58 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download
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
54
55
56
57
58
# frozen_string_literal: true

RSpec.shared_examples 'diffs stream tests' do
  it 'streams the response' do
    send_request

    expect(response).to have_gitlab_http_status(:success)
  end

  context 'when offset is given' do
    context 'when offset is 1' do
      let(:offset) { 1 }

      it 'streams diffs except the offset' do
        send_request

        diff_files_array = diff_files.to_a
        expect(response.body).not_to include(diff_files_array.first.new_path)
        expect(response.body).to include(diff_files_array.last.new_path)
      end
    end

    context 'when offset is the same as the number of diffs' do
      let(:offset) { diff_files.size }

      it 'no diffs are streamed' do
        send_request

        expect(response.body).to be_empty
      end
    end
  end

  context 'when an exception occurs' do
    before do
      allow(::RapidDiffs::DiffFileComponent)
        .to receive(:new).and_raise(StandardError.new('something went wrong'))
    end

    it 'prints out error message' do
      send_request

      expect(response.body).to include('something went wrong')
    end
  end

  context 'when the rapid_diffs feature flag is disabled' do
    before do
      stub_feature_flags(rapid_diffs: false)
    end

    it 'returns a 404 status' do
      send_request

      expect(response).to have_gitlab_http_status(:not_found)
    end
  end
end