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

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

require 'spec_helper'

RSpec.describe VersionCheck do
  describe '.url' do
    it 'returns the correct URL' do
      expect(described_class.url).to match(%r{\A#{Regexp.escape(described_class.host)}/check\.json\?gitlab_info=\w+})
    end
  end

  context 'reactive cache properties' do
    describe '.reactive_cache_refresh_interval' do
      it 'returns 12.hours' do
        expect(described_class.reactive_cache_refresh_interval).to eq(12.hours)
      end
    end

    describe '.reactive_cache_lifetime' do
      it 'returns 7.days' do
        expect(described_class.reactive_cache_lifetime).to eq(7.days)
      end
    end
  end

  describe '#calculate_reactive_cache' do
    context 'response code is 200' do
      before do
        stub_request(:get, described_class.url).to_return(status: 200, body: '{ "status": "success" }', headers: {})
      end

      it 'returns the response object' do
        expect(described_class.new.calculate_reactive_cache).to eq("{ \"status\": \"success\" }")
      end
    end

    context 'response code is not 200' do
      before do
        stub_request(:get, described_class.url).to_return(status: 500, body: nil, headers: {})
      end

      it 'returns nil' do
        expect(described_class.new.calculate_reactive_cache).to be(nil)
      end
    end
  end

  describe '#response' do
    context 'cache returns value' do
      let(:response) { { "severity" => "success" }.to_json }

      before do
        allow_next_instance_of(described_class) do |instance|
          allow(instance).to receive(:with_reactive_cache).and_return(response)
        end
      end

      it 'returns the response object' do
        expect(described_class.new.response).to be(response)
      end
    end

    context 'cache returns nil' do
      let(:response) { nil }

      before do
        allow_next_instance_of(described_class) do |instance|
          allow(instance).to receive(:with_reactive_cache).and_return(response)
        end
      end

      it 'returns nil' do
        expect(described_class.new.response).to be(nil)
      end
    end
  end
end