summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/static_site_editor/config/file_config/entry/mount_spec.rb
blob: 04248fc60a50fd654c9828a3a48a4a03beaee2cb (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::StaticSiteEditor::Config::FileConfig::Entry::Mount do
  subject(:entry) { described_class.new(config) }

  describe 'validations' do
    context 'with a valid config' do
      context 'and target is a non-empty string' do
        let(:config) do
          {
            source: 'source',
            target: 'sub-site'
          }
        end

        it { is_expected.to be_valid }

        describe '#value' do
          it 'returns mount configuration' do
            expect(entry.value).to eq config
          end
        end
      end

      context 'and target is an empty string' do
        let(:config) do
          {
            source: 'source',
            target: ''
          }
        end

        it { is_expected.to be_valid }

        describe '#value' do
          it 'returns mount configuration' do
            expect(entry.value).to eq config
          end
        end
      end
    end

    context 'with an invalid config' do
      context 'when source is not a string' do
        let(:config) { { source: 123, target: 'target' } }

        it { is_expected.not_to be_valid }

        it 'reports error' do
          expect(entry.errors)
            .to include 'mount source should be a string'
        end
      end

      context 'when source is not present' do
        let(:config) { { target: 'target' } }

        it { is_expected.not_to be_valid }

        it 'reports error' do
          expect(entry.errors)
            .to include "mount source can't be blank"
        end
      end

      context 'when target is not a string' do
        let(:config) { { source: 'source', target: 123 } }

        it { is_expected.not_to be_valid }

        it 'reports error' do
          expect(entry.errors)
            .to include 'mount target should be a string'
        end
      end

      context 'when there is an unknown key present' do
        let(:config) { { test: 100 } }

        it { is_expected.not_to be_valid }

        it 'reports error' do
          expect(entry.errors)
            .to include 'mount config contains unknown keys: test'
        end
      end
    end
  end

  describe '.default' do
    it 'returns default mount' do
      expect(described_class.default)
        .to eq({
                 source: 'source',
                 target: ''
               })
    end
  end
end