summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/etag_caching/router_spec.rb
blob: fd95e090e764c75d66849b2e52c720cede735a86 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require 'spec_helper'

describe Gitlab::EtagCaching::Router do
  it 'matches issue notes endpoint' do
    env = build_env(
      '/my-group/and-subgroup/here-comes-the-project/noteable/issue/1/notes'
    )

    result = described_class.match(env)

    expect(result).to be_present
    expect(result.name).to eq 'issue_notes'
  end

  it 'matches issue title endpoint' do
    env = build_env(
      '/my-group/my-project/issues/123/realtime_changes'
    )

    result = described_class.match(env)

    expect(result).to be_present
    expect(result.name).to eq 'issue_title'
  end

  it 'matches project pipelines endpoint' do
    env = build_env(
      '/my-group/my-project/pipelines.json'
    )

    result = described_class.match(env)

    expect(result).to be_present
    expect(result.name).to eq 'project_pipelines'
  end

  it 'matches commit pipelines endpoint' do
    env = build_env(
      '/my-group/my-project/commit/aa8260d253a53f73f6c26c734c72fdd600f6e6d4/pipelines.json'
    )

    result = described_class.match(env)

    expect(result).to be_present
    expect(result.name).to eq 'commit_pipelines'
  end

  it 'matches new merge request pipelines endpoint' do
    env = build_env(
      '/my-group/my-project/merge_requests/new.json'
    )

    result = described_class.match(env)

    expect(result).to be_present
    expect(result.name).to eq 'new_merge_request_pipelines'
  end

  it 'matches merge request pipelines endpoint' do
    env = build_env(
      '/my-group/my-project/merge_requests/234/pipelines.json'
    )

    result = described_class.match(env)

    expect(result).to be_present
    expect(result.name).to eq 'merge_request_pipelines'
  end

  it 'matches build endpoint' do
    env = build_env(
      '/my-group/my-project/builds/234.json'
    )

    result = described_class.match(env)

    expect(result).to be_present
    expect(result.name).to eq 'project_build'
  end

  it 'does not match blob with confusing name' do
    env = build_env(
      '/my-group/my-project/blob/master/pipelines.json'
    )

    result = described_class.match(env)

    expect(result).to be_blank
  end

<<<<<<< HEAD
  it 'matches pipeline#show endpoint' do
    env = build_env(
      '/my-group/my-project/pipelines/2.json'
=======
  it 'matches the environments path' do
    env = build_env(
      '/my-group/my-project/environments.json'
>>>>>>> ebede2b... Use etag caching for environments JSON
    )

    result = described_class.match(env)

<<<<<<< HEAD
<<<<<<< HEAD
    expect(result).to be_present
    expect(result.name).to eq 'project_pipeline'
=======
    expect(result).to be_blank
>>>>>>> ebede2b... Use etag caching for environments JSON
=======
    expect(result).to be_present
    expect(result.name).to eq 'environments'
>>>>>>> 3be9820... Test etag caching router and incorporate review
  end

  def build_env(path)
    { 'PATH_INFO' => path }
  end
end