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

integrations_controller_shared_examples.rb « clusters « requests « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 91fdcbd9b1d8b5db7e631551206110bdb9545a8e (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: 'prometheus', 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