summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/release_blog_post_spec.rb
blob: d5fd6418afeac5069b4ad05be9eafced8a9bd6d0 (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
require 'spec_helper'

describe Gitlab::ReleaseBlogPost do
  describe '.blog_post_url' do
    let(:releases_xml) do
      <<~EOS
      <?xml version='1.0' encoding='utf-8' ?>
      <feed xmlns='http://www.w3.org/2005/Atom'>
      <entry>
      <release>11.2</release>
      <id>https://about.gitlab.com/2018/08/22/gitlab-11-2-released/</id>
      </entry>
      <entry>
      <release>11.1</release>
      <id>https://about.gitlab.com/2018/07/22/gitlab-11-1-released/</id>
      </entry>
      <entry>
      <release>11.0</release>
      <id>https://about.gitlab.com/2018/06/22/gitlab-11-0-released/</id>
      </entry>
      <entry>
      <release>10.8</release>
      <id>https://about.gitlab.com/2018/05/22/gitlab-10-8-released/</id>
      </entry>
      </feed>
      EOS
    end

    subject { described_class.instance.blog_post_url }

    before do
      stub_request(:get, 'https://about.gitlab.com/releases.xml')
        .to_return(status: 200, headers: { 'content-type' => ['text/xml'] }, body: releases_xml)
    end

    around do |example|
      release_post_url = described_class.instance.instance_variable_get(:@url)
      described_class.instance.instance_variable_set(:@url, nil)

      example.run

      described_class.instance.instance_variable_set(:@url, release_post_url)
    end

    context 'matches GitLab version to blog post url' do
      it 'returns the correct url for major pre release' do
        stub_const('Gitlab::VERSION', '11.0.0-pre')
        expect(subject).to eql('https://about.gitlab.com/2018/05/22/gitlab-10-8-released/')
      end

      it 'returns the correct url for major release candidate' do
        stub_const('Gitlab::VERSION', '11.0.0-rc3')
        expect(subject).to eql('https://about.gitlab.com/2018/05/22/gitlab-10-8-released/')
      end

      it 'returns the correct url for major release' do
        stub_const('Gitlab::VERSION', '11.0.0')
        expect(subject).to eql('https://about.gitlab.com/2018/06/22/gitlab-11-0-released/')
      end

      it 'returns the correct url for minor pre release' do
        stub_const('Gitlab::VERSION', '11.2.0-pre')
        expect(subject).to eql('https://about.gitlab.com/2018/07/22/gitlab-11-1-released/')
      end

      it 'returns the correct url for minor release candidate' do
        stub_const('Gitlab::VERSION', '11.2.0-rc3')
        expect(subject).to eql('https://about.gitlab.com/2018/07/22/gitlab-11-1-released/')
      end

      it 'returns the correct url for minor release' do
        stub_const('Gitlab::VERSION', '11.2.0')
        expect(subject).to eql('https://about.gitlab.com/2018/08/22/gitlab-11-2-released/')
      end

      it 'returns the correct url for patch pre release' do
        stub_const('Gitlab::VERSION', '11.2.1-pre')
        expect(subject).to eql('https://about.gitlab.com/2018/08/22/gitlab-11-2-released/')
      end

      it 'returns the correct url for patch release candidate' do
        stub_const('Gitlab::VERSION', '11.2.1-rc3')
        expect(subject).to eql('https://about.gitlab.com/2018/08/22/gitlab-11-2-released/')
      end

      it 'returns the correct url for patch release' do
        stub_const('Gitlab::VERSION', '11.2.1')
        expect(subject).to eql('https://about.gitlab.com/2018/08/22/gitlab-11-2-released/')
      end

      it 'returns nil when no blog post is matched' do
        stub_const('Gitlab::VERSION', '9.0.0')
        expect(subject).to be(nil)
      end
    end
  end
end