From d8b32df644a632b143d6b9967311301a2fc83a6b Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 29 May 2020 21:08:35 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/validators/json_schema_validator_spec.rb | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 spec/validators/json_schema_validator_spec.rb (limited to 'spec/validators') diff --git a/spec/validators/json_schema_validator_spec.rb b/spec/validators/json_schema_validator_spec.rb new file mode 100644 index 00000000000..0e942e755f5 --- /dev/null +++ b/spec/validators/json_schema_validator_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe JsonSchemaValidator do + describe '#validates_each' do + let(:build_report_result) { build(:ci_build_report_result, :with_junit_success) } + + subject { validator.validate(build_report_result) } + + context 'when file_path is set' do + let(:validator) { described_class.new(attributes: [:data], filename: "build_report_result_data") } + + context 'when data is valid' do + it 'returns no errors' do + subject + + expect(build_report_result.errors).to be_empty + end + end + + context 'when data is invalid' do + it 'returns json schema is invalid' do + build_report_result.data = { invalid: 'data' } + + validator.validate(build_report_result) + + expect(build_report_result.errors.size).to eq(1) + expect(build_report_result.errors.full_messages).to eq(["Data must be a valid json schema"]) + end + end + end + + context 'when file_path is not set' do + let(:validator) { described_class.new(attributes: [:data]) } + + it 'raises an ArgumentError' do + expect { subject }.to raise_error(ArgumentError) + end + end + end +end -- cgit v1.2.1