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

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

require 'spec_helper'

RSpec.describe Gitlab::Changelog::Generator do
  describe '#add' do
    let(:project) { build_stubbed(:project) }
    let(:author) { build_stubbed(:user) }
    let(:commit) { build_stubbed(:commit) }
    let(:config) { Gitlab::Changelog::Config.new(project) }

    it 'generates the Markdown for the first release' do
      release = Gitlab::Changelog::Release.new(
        version: '1.0.0',
        date: Time.utc(2021, 1, 5),
        config: config
      )

      release.add_entry(
        title: 'This is a new change',
        commit: commit,
        category: 'added',
        author: author
      )

      gen = described_class.new('')

      expect(gen.add(release)).to eq(<<~MARKDOWN)
        ## 1.0.0 (2021-01-05)

        ### added (1 change)

        - [This is a new change](#{commit.to_reference(full: true)})
      MARKDOWN
    end

    it 'generates the Markdown for a newer release' do
      release = Gitlab::Changelog::Release.new(
        version: '2.0.0',
        date: Time.utc(2021, 1, 5),
        config: config
      )

      release.add_entry(
        title: 'This is a new change',
        commit: commit,
        category: 'added',
        author: author
      )

      gen = described_class.new(<<~MARKDOWN)
        This is a changelog file.

        ## 1.0.0

        This is the changelog for version 1.0.0.
      MARKDOWN

      expect(gen.add(release)).to eq(<<~MARKDOWN)
        This is a changelog file.

        ## 2.0.0 (2021-01-05)

        ### added (1 change)

        - [This is a new change](#{commit.to_reference(full: true)})

        ## 1.0.0

        This is the changelog for version 1.0.0.
      MARKDOWN
    end

    it 'generates the Markdown for a patch release' do
      release = Gitlab::Changelog::Release.new(
        version: '1.1.0',
        date: Time.utc(2021, 1, 5),
        config: config
      )

      release.add_entry(
        title: 'This is a new change',
        commit: commit,
        category: 'added',
        author: author
      )

      gen = described_class.new(<<~MARKDOWN)
        This is a changelog file.

        ## 2.0.0

        This is another release.

        ## 1.0.0

        This is the changelog for version 1.0.0.
      MARKDOWN

      expect(gen.add(release)).to eq(<<~MARKDOWN)
        This is a changelog file.

        ## 2.0.0

        This is another release.

        ## 1.1.0 (2021-01-05)

        ### added (1 change)

        - [This is a new change](#{commit.to_reference(full: true)})

        ## 1.0.0

        This is the changelog for version 1.0.0.
      MARKDOWN
    end

    it 'generates the Markdown for an old release' do
      release = Gitlab::Changelog::Release.new(
        version: '0.5.0',
        date: Time.utc(2021, 1, 5),
        config: config
      )

      release.add_entry(
        title: 'This is a new change',
        commit: commit,
        category: 'added',
        author: author
      )

      gen = described_class.new(<<~MARKDOWN)
        This is a changelog file.

        ## 2.0.0

        This is another release.

        ## 1.0.0

        This is the changelog for version 1.0.0.
      MARKDOWN

      expect(gen.add(release)).to eq(<<~MARKDOWN)
        This is a changelog file.

        ## 2.0.0

        This is another release.

        ## 1.0.0

        This is the changelog for version 1.0.0.

        ## 0.5.0 (2021-01-05)

        ### added (1 change)

        - [This is a new change](#{commit.to_reference(full: true)})
      MARKDOWN
    end
  end
end