diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/lib/release_highlights | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/lib/release_highlights')
-rw-r--r-- | spec/lib/release_highlights/validator/entry_spec.rb | 87 | ||||
-rw-r--r-- | spec/lib/release_highlights/validator_spec.rb | 85 |
2 files changed, 172 insertions, 0 deletions
diff --git a/spec/lib/release_highlights/validator/entry_spec.rb b/spec/lib/release_highlights/validator/entry_spec.rb new file mode 100644 index 00000000000..648356e63ba --- /dev/null +++ b/spec/lib/release_highlights/validator/entry_spec.rb @@ -0,0 +1,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 diff --git a/spec/lib/release_highlights/validator_spec.rb b/spec/lib/release_highlights/validator_spec.rb new file mode 100644 index 00000000000..e68d9145dcd --- /dev/null +++ b/spec/lib/release_highlights/validator_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ReleaseHighlights::Validator do + let(:validator) { described_class.new(file: yaml_path) } + let(:yaml_path) { 'spec/fixtures/whats_new/valid.yml' } + let(:invalid_yaml_path) { 'spec/fixtures/whats_new/invalid.yml' } + + describe '#valid?' do + subject { validator.valid? } + + context 'with a valid file' do + it 'passes entries to entry validator and returns true' do + expect(ReleaseHighlights::Validator::Entry).to receive(:new).exactly(:twice).and_call_original + expect(subject).to be true + expect(validator.errors).to be_empty + end + end + + context 'with invalid file' do + let(:yaml_path) { invalid_yaml_path } + + it 'returns false and has errors' do + expect(subject).to be false + expect(validator.errors).not_to be_empty + end + end + end + + describe '.validate_all!' do + subject { described_class.validate_all! } + + before do + allow(ReleaseHighlight).to receive(:file_paths).and_return(yaml_paths) + end + + context 'with valid files' do + let(:yaml_paths) { [yaml_path, yaml_path] } + + it { is_expected.to be true } + end + + context 'with an invalid file' do + let(:yaml_paths) { [invalid_yaml_path, yaml_path] } + + it { is_expected.to be false } + end + end + + describe '.error_message' do + subject do + described_class.validate_all! + described_class.error_message + end + + before do + allow(ReleaseHighlight).to receive(:file_paths).and_return([yaml_path]) + end + + context 'with a valid file' do + it { is_expected.to be_empty } + end + + context 'with an invalid file' do + let(:yaml_path) { invalid_yaml_path } + + it 'returns a nice error message' do + expect(subject).to eq(<<-MESSAGE.strip_heredoc) + --------------------------------------------------------- + Validation failed for spec/fixtures/whats_new/invalid.yml + --------------------------------------------------------- + * Packages must be one of ["Core", "Starter", "Premium", "Ultimate"] (line 6) + + MESSAGE + end + end + end + + describe 'when validating all files' do + it 'they should have no errors' do + expect(described_class.validate_all!).to be_truthy, described_class.error_message + end + end +end |