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

gitlab_spec.rb « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ac3d115bc69edad507ba5b63fb524f312368900 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
require 'fast_spec_helper'

require_dependency 'gitlab'

describe Gitlab do
  describe '.root' do
    it 'returns the root path of the app' do
      expect(described_class.root).to eq(Pathname.new(File.expand_path('../..', __dir__)))
    end
  end

  describe '.revision' do
    let(:cmd) { %W[#{described_class.config.git.bin_path} log --pretty=format:%h -n 1] }

    around do |example|
      described_class.instance_variable_set(:@_revision, nil)
      example.run
      described_class.instance_variable_set(:@_revision, nil)
    end

    context 'when a REVISION file exists' do
      before do
        expect(File).to receive(:exist?)
          .with(described_class.root.join('REVISION'))
          .and_return(true)
      end

      it 'returns the actual Git revision' do
        expect(File).to receive(:read)
          .with(described_class.root.join('REVISION'))
          .and_return("abc123\n")

        expect(described_class.revision).to eq('abc123')
      end

      it 'memoizes the revision' do
        expect(File).to receive(:read)
          .once
          .with(described_class.root.join('REVISION'))
          .and_return("abc123\n")

        2.times { described_class.revision }
      end
    end

    context 'when no REVISION file exist' do
      context 'when the Git command succeeds' do
        before do
          expect(Gitlab::Popen).to receive(:popen_with_detail)
          .with(cmd)
          .and_return(Gitlab::Popen::Result.new(cmd, 'abc123', '', double(success?: true)))
        end

        it 'returns the actual Git revision' do
          expect(described_class.revision).to eq('abc123')
        end
      end

      context 'when the Git command fails' do
        before do
          expect(Gitlab::Popen).to receive(:popen_with_detail)
          .with(cmd)
          .and_return(Gitlab::Popen::Result.new(cmd, '', 'fatal: Not a git repository', double('Process::Status', success?: false)))
        end

        it 'returns "Unknown"' do
          expect(described_class.revision).to eq('Unknown')
        end
      end
    end
  end

  describe '.final_release?' do
    subject { described_class.final_release? }

    context 'returns the corrent boolean value' do
      it 'is false for a pre release' do
        stub_const('Gitlab::VERSION', '11.0.0-pre')

        expect(subject).to be false
      end

      it 'is false for a release candidate' do
        stub_const('Gitlab::VERSION', '11.0.0-rc2')

        expect(subject).to be false
      end

      it 'is true for a final release' do
        stub_const('Gitlab::VERSION', '11.0.2')

        expect(subject).to be true
      end
    end
  end

  describe '.minor_release' do
    subject { described_class.minor_release }

    it 'returns the minor release of the full GitLab version' do
      stub_const('Gitlab::VERSION', '11.0.1-rc3')

      expect(subject).to eql '11.0'
    end
  end

  describe '.previous_release' do
    subject { described_class.previous_release }

    context 'it should return the previous release' do
      it 'returns the previous major version when GitLab major version is not final' do
        stub_const('Gitlab::VERSION', '11.0.1-pre')

        expect(subject).to eql '10'
      end

      it 'returns the current minor version when the GitLab patch version is RC and > 0' do
        stub_const('Gitlab::VERSION', '11.2.1-rc3')

        expect(subject).to eql '11.2'
      end

      it 'returns the previous minor version when the GitLab patch version is RC and 0' do
        stub_const('Gitlab::VERSION', '11.2.0-rc3')

        expect(subject).to eql '11.1'
      end
    end
  end

  describe '.new_major_release?' do
    subject { described_class.new_major_release? }

    context 'returns the corrent boolean value' do
      it 'is true when the minor version is 0 and the patch is a pre release' do
        stub_const('Gitlab::VERSION', '11.0.1-pre')

        expect(subject).to be true
      end

      it 'is false when the minor version is above 0' do
        stub_const('Gitlab::VERSION', '11.2.1-rc3')

        expect(subject).to be false
      end
    end
  end

  describe '.com?' do
    it 'is true when on GitLab.com' do
      stub_config_setting(url: 'https://gitlab.com')

      expect(described_class.com?).to eq true
    end

    it 'is true when on staging' do
      stub_config_setting(url: 'https://staging.gitlab.com')

      expect(described_class.com?).to eq true
    end

    it 'is true when on other gitlab subdomain' do
      stub_config_setting(url: 'https://example.gitlab.com')

      expect(described_class.com?).to eq true
    end

    it 'is false when not on GitLab.com' do
      stub_config_setting(url: 'http://example.com')

      expect(described_class.com?).to eq false
    end
  end
end