summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/requests/clusters/integrations_controller_shared_examples.rb
blob: 490c7d12115deca533d2ddd6dc5afe20ff0ff8a7 (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 '#create_or_update action' do
  let(:params) do
    { integration: { application_type: Clusters::Applications::Prometheus.application_name, enabled: true } }
  end

  let(:path) { raise NotImplementedError }
  let(:redirect_path) { raise NotImplementedError }

  describe 'authorization' do
    subject do
      post path, params: params
    end

    it_behaves_like 'a secure endpoint'
  end

  describe 'functionality' do
    before do
      sign_in(user)
    end

    it 'redirects on success' do
      post path, params: params

      expect(response).to have_gitlab_http_status(:redirect)
      expect(response).to redirect_to(redirect_path)
      expect(flash[:notice]).to be_present
    end

    it 'redirects on error' do
      error = ServiceResponse.error(message: 'failed')

      expect_next_instance_of(Clusters::Integrations::CreateService) do |service|
        expect(service).to receive(:execute).and_return(error)
      end

      post path, params: params

      expect(response).to have_gitlab_http_status(:redirect)
      expect(response).to redirect_to(redirect_path)
      expect(flash[:alert]).to eq(error.message)
    end
  end
end