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

base_spec.rb « api « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8513b8002736c09b64daffb39de4ef758a77502d (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
87
88
89
90
91
92
# frozen_string_literal: true

require 'spec_helper'

# rubocop:disable Rails/HttpPositionalArguments
RSpec.describe ::API::Base do
  let(:app_hello) do
    route = double(:route, request_method: 'GET', path: '/:version/test/hello')
    double(:endpoint, route: route, options: { for: api_handler, path: ["hello"] }, namespace: '/test')
  end

  let(:app_hi) do
    route = double(:route, request_method: 'GET', path: '/:version//test/hi')
    double(:endpoint, route: route, options: { for: api_handler, path: ["hi"] }, namespace: '/test')
  end

  describe 'declare feature categories at handler level for all routes' do
    let(:api_handler) do
      Class.new(described_class) do
        feature_category :foo
        urgency :medium

        namespace '/test' do
          get 'hello' do
          end
          post 'hi' do
          end
        end
      end
    end

    it 'sets feature category for a particular route', :aggregate_failures do
      expect(api_handler.feature_category_for_app(app_hello)).to eq(:foo)
      expect(api_handler.feature_category_for_app(app_hi)).to eq(:foo)
    end

    it 'sets request urgency for a particular route', :aggregate_failures do
      expect(api_handler.urgency_for_app(app_hello)).to be_request_urgency(:medium)
      expect(api_handler.urgency_for_app(app_hi)).to be_request_urgency(:medium)
    end
  end

  describe 'declare feature categories at route level' do
    let(:api_handler) do
      Class.new(described_class) do
        namespace '/test' do
          get 'hello', feature_category: :foo, urgency: :low do
          end
          post 'hi', feature_category: :bar, urgency: :medium do
          end
        end
      end
    end

    it 'sets feature category for a particular route', :aggregate_failures do
      expect(api_handler.feature_category_for_app(app_hello)).to eq(:foo)
      expect(api_handler.feature_category_for_app(app_hi)).to eq(:bar)
    end

    it 'sets request urgency for a particular route', :aggregate_failures do
      expect(api_handler.urgency_for_app(app_hello)).to be_request_urgency(:low)
      expect(api_handler.urgency_for_app(app_hi)).to be_request_urgency(:medium)
    end
  end

  describe 'declare feature categories at both handler level and route level' do
    let(:api_handler) do
      Class.new(described_class) do
        feature_category :foo, ['/test/hello']
        urgency :low, ['/test/hello']

        namespace '/test' do
          get 'hello' do
          end
          post 'hi', feature_category: :bar, urgency: :medium do
          end
        end
      end
    end

    it 'sets feature category for a particular route', :aggregate_failures do
      expect(api_handler.feature_category_for_app(app_hello)).to eq(:foo)
      expect(api_handler.feature_category_for_app(app_hi)).to eq(:bar)
    end

    it 'sets target duration for a particular route', :aggregate_failures do
      expect(api_handler.urgency_for_app(app_hello)).to be_request_urgency(:low)
      expect(api_handler.urgency_for_app(app_hi)).to be_request_urgency(:medium)
    end
  end
end
# rubocop:enable Rails/HttpPositionalArguments