summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb
blob: acce7642cfe9445f60728e2deb21f778bce65b34 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true

RSpec.shared_examples 'editing snippet checks blob is binary' do
  let(:snippets_binary_blob_value) { true }

  before do
    sign_in(user)

    allow_next_instance_of(Blob) do |blob|
      allow(blob).to receive(:binary?).and_return(binary)
    end

    stub_feature_flags(snippets_binary_blob: snippets_binary_blob_value)

    subject
  end

  context 'when blob is text' do
    let(:binary) { false }

    it 'responds with status 200' do
      expect(response).to have_gitlab_http_status(:ok)
      expect(response).to render_template(:edit)
    end
  end

  context 'when blob is binary' do
    let(:binary) { true }

    it 'responds with status 200' do
      expect(response).to have_gitlab_http_status(:ok)
      expect(response).to render_template(:edit)
    end

    context 'when feature flag :snippets_binary_blob is disabled' do
      let(:snippets_binary_blob_value) { false }

      it 'redirects away' do
        expect(response).to redirect_to(gitlab_snippet_path(snippet))
      end
    end
  end
end

RSpec.shared_examples 'updating snippet checks blob is binary' do
  let(:snippets_binary_blob_value) { true }

  before do
    sign_in(user)

    allow_next_instance_of(Blob) do |blob|
      allow(blob).to receive(:binary?).and_return(binary)
    end

    stub_feature_flags(snippets_binary_blob: snippets_binary_blob_value)

    subject
  end

  context 'when blob is text' do
    let(:binary) { false }

    it 'updates successfully' do
      expect(snippet.reload.title).to eq title
      expect(response).to redirect_to(gitlab_snippet_path(snippet))
    end
  end

  context 'when blob is binary' do
    let(:binary) { true }

    it 'updates successfully' do
      expect(snippet.reload.title).to eq title
      expect(response).to redirect_to(gitlab_snippet_path(snippet))
    end

    context 'when feature flag :snippets_binary_blob is disabled' do
      let(:snippets_binary_blob_value) { false }

      it 'redirects away without updating' do
        expect(response).to redirect_to(gitlab_snippet_path(snippet))
        expect(snippet.reload.title).not_to eq title
      end
    end
  end
end