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

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

require 'spec_helper'

RSpec.describe ReleaseHighlights::Validator::Entry do
  subject(:entry) { described_class.new(document.root.children.first) }

  let(:document) { YAML.parse(File.read(yaml_path)) }
  let(:yaml_path) { 'spec/fixtures/whats_new/blank.yml' }

  describe 'validations' do
    before do
      allow(entry).to receive(:value_for).and_call_original
    end

    context 'with a valid entry' do
      let(:yaml_path) { 'spec/fixtures/whats_new/valid.yml' }

      it { is_expected.to be_valid }
    end

    context 'with an invalid entry' do
      let(:yaml_path) { 'spec/fixtures/whats_new/invalid.yml' }

      it 'returns line numbers in errors' do
        subject.valid?

        expect(entry.errors[:packages].first).to match('(line 6)')
      end
    end

    context 'with a blank entry' do
      it 'validate presence of title, body and stage' do
        subject.valid?

        expect(subject.errors[:title]).not_to be_empty
        expect(subject.errors[:body]).not_to be_empty
        expect(subject.errors[:stage]).not_to be_empty
        expect(subject.errors[:packages]).not_to be_empty
      end

      it 'validates boolean value of "self-managed" and "gitlab-com"' do
        allow(entry).to receive(:value_for).with('self-managed').and_return('nope')
        allow(entry).to receive(:value_for).with('gitlab-com').and_return('yerp')

        subject.valid?

        expect(subject.errors[:'self-managed']).to include(/must be a boolean/)
        expect(subject.errors[:'gitlab-com']).to include(/must be a boolean/)
      end

      it 'validates URI of "url" and "image_url"' do
        allow(entry).to receive(:value_for).with('image_url').and_return('imgur/gitlab_feature.gif')
        allow(entry).to receive(:value_for).with('url').and_return('gitlab/newest_release.html')

        subject.valid?

        expect(subject.errors[:url]).to include(/must be a URL/)
        expect(subject.errors[:image_url]).to include(/must be a URL/)
      end

      it 'validates release is numerical' do
        allow(entry).to receive(:value_for).with('release').and_return('one')

        subject.valid?

        expect(subject.errors[:release]).to include(/is not a number/)
      end

      it 'validates published_at is a date' do
        allow(entry).to receive(:value_for).with('published_at').and_return('christmas day')

        subject.valid?

        expect(subject.errors[:published_at]).to include(/must be valid Date/)
      end

      it 'validates packages are included in list' do
        allow(entry).to receive(:value_for).with('packages').and_return(['ALL'])

        subject.valid?

        expect(subject.errors[:packages].first).to include("must be one of", "Core", "Starter", "Premium", "Ultimate")
      end
    end
  end
end