Commit 919d0b02 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'mo-add-json-schema-daily-build-group-report-result' into 'master'

Add JSON schema validation for DailyBuildGroupReportResult

See merge request gitlab-org/gitlab!33755
parents b525ae01 389ffbc5
......@@ -9,6 +9,8 @@ module Ci
belongs_to :last_pipeline, class_name: 'Ci::Pipeline', foreign_key: :last_pipeline_id
belongs_to :project
validates :data, json_schema: { filename: "daily_build_group_report_result_data" }
def self.upsert_reports(data)
upsert_all(data, unique_by: :index_daily_build_group_report_results_unique_columns) if data.any?
end
......
{
"description": "Daily build group report result data",
"type": "object",
"properties": {
"coverage": { "type": "float" }
},
"additionalProperties": false
}
......@@ -3,6 +3,30 @@
require 'spec_helper'
describe Ci::DailyBuildGroupReportResult do
let(:daily_build_group_report_result) { build(:ci_daily_build_group_report_result)}
describe 'associations' do
it { is_expected.to belong_to(:last_pipeline) }
it { is_expected.to belong_to(:project) }
end
describe 'validations' do
context 'when attributes are valid' do
it 'returns no errors' do
expect(daily_build_group_report_result).to be_valid
end
end
context 'when data is invalid' do
it 'returns errors' do
daily_build_group_report_result.data = { invalid: 'data' }
expect(daily_build_group_report_result).to be_invalid
expect(daily_build_group_report_result.errors.full_messages).to eq(["Data must be a valid json schema"])
end
end
end
describe '.upsert_reports' do
let!(:rspec_coverage) do
create(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment