Commit 389ffbc5 authored by Maxime Orefice's avatar Maxime Orefice

Add JSON schema validation for DailyBuildGroupReportResult

parent 747b0afb
......@@ -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