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

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

RSpec.shared_examples 'successful response for #cancel_auto_stop' do
  include GitlabRoutingHelper

  context 'when request is html' do
    let(:params) { environment_params(format: :html) }

    it 'redirects to show page' do
      subject

      expect(response).to redirect_to(environment_path(environment))
      expect(flash[:notice]).to eq('Auto stop successfully canceled.')
    end

    it 'expires etag caching' do
      expect_next_instance_of(Gitlab::EtagCaching::Store) do |etag_caching|
        expect(etag_caching).to receive(:touch).with(project_environments_path(project, format: :json))
      end

      subject
    end
  end

  context 'when request is js' do
    let(:params) { environment_params(format: :json) }

    it 'responds as ok' do
      subject

      expect(response).to have_gitlab_http_status(:ok)
      expect(json_response['message']).to eq('Auto stop successfully canceled.')
    end

    it 'expires etag caching' do
      expect_next_instance_of(Gitlab::EtagCaching::Store) do |etag_caching|
        expect(etag_caching).to receive(:touch).with(project_environments_path(project, format: :json))
      end

      subject
    end
  end
end

RSpec.shared_examples 'failed response for #cancel_auto_stop' do
  context 'when request is html' do
    let(:params) { environment_params(format: :html) }

    it 'redirects to show page' do
      subject

      expect(response).to redirect_to(environment_path(environment))
      expect(flash[:alert]).to eq("Failed to cancel auto stop because #{message}.")
    end
  end

  context 'when request is js' do
    let(:params) { environment_params(format: :json) }

    it 'responds as unprocessable entity' do
      subject

      expect(response).to have_gitlab_http_status(:unprocessable_entity)
      expect(json_response['message']).to eq("Failed to cancel auto stop because #{message}.")
    end
  end
end