Commit 228a4f7e authored by Maxime Orefice's avatar Maxime Orefice Committed by Sean McGivern

Round average coverage to 2 decimal places

parent 0e8c176d
......@@ -23,7 +23,7 @@ module EE
def self.summaries_per_project
group(:project_id, 'latest_by_project.date').pluck(
:project_id,
Arel.sql("AVG(cast(data ->> 'coverage' AS FLOAT))"),
Arel.sql("ROUND(AVG(CAST(data ->> 'coverage' AS DECIMAL)), 2)::FLOAT"),
Arel.sql("COUNT(*)"),
Arel.sql("latest_by_project.date")
).each_with_object({}) do |(project_id, average_coverage, coverage_count, date), result|
......@@ -37,7 +37,7 @@ module EE
def self.activity_per_group
group(:date).pluck(
Arel.sql("AVG(cast(data ->> 'coverage' AS FLOAT))"),
Arel.sql("ROUND(AVG(CAST(data ->> 'coverage' AS DECIMAL)), 2)::FLOAT"),
Arel.sql("COUNT(*)"),
Arel.sql("COUNT(DISTINCT ci_daily_build_group_report_results.project_id)"),
Arel.sql("date")
......
......@@ -48,6 +48,16 @@ RSpec.describe Ci::DailyBuildGroupReportResult do
expect(summary).to eq(expected_summary)
end
context 'when coverage has more than 3 decimals' do
let!(:build_group_report_result_3) do
create(:ci_daily_build_group_report_result, project: project_2, group_name: 'karma', coverage: 55.55555)
end
it 'returns average_coverage with 2 decimals' do
expect(summary[project_2.id][:average_coverage]).to eq(66.78)
end
end
it 'executes only 1 SQL query' do
query_count = ActiveRecord::QueryRecorder.new { subject }.count
......@@ -101,7 +111,17 @@ RSpec.describe Ci::DailyBuildGroupReportResult do
project_count: 2
)
expect(subject).to contain_exactly(expected_results)
expect(activity).to contain_exactly(expected_results)
end
context 'when coverage has more than 3 decimals' do
let!(:coverage_3) do
create(:ci_daily_build_group_report_result, project: project_2, group_name: 'cobertura', coverage: 55.55555)
end
it 'returns average_coverage with 2 decimals' do
expect(activity.first[:average_coverage]).to eq(69.85)
end
end
end
......
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