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: a79b94209f37793980376190169b96498546628c (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
# 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

RSpec.shared_examples 'avoids N+1 queries on environment detail page' do
  render_views

  before do
    create_deployment_with_associations(sequence: 0)
  end

  it 'avoids N+1 queries' do
    control = ActiveRecord::QueryRecorder.new { get :show, params: environment_params }

    create_deployment_with_associations(sequence: 1)
    create_deployment_with_associations(sequence: 2)

    expect { get :show, params: environment_params }.not_to exceed_query_limit(control.count).with_threshold(34)
  end
end