Skip to content
Snippets Groups Projects
Commit d841ed56 authored by Kamil Trzciński's avatar Kamil Trzciński
Browse files

Merge branch 'coverage-calc' into 'master'

Use builds_without_retry to calculate average coverage

/cc @vsizov

See merge request !197
parents 9b6e7a17 39cfebdc
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -211,8 +211,8 @@ class Commit < ActiveRecord::Base
end
 
def coverage
if project.coverage_enabled? && builds.count(:all) > 0
coverage_array = builds.map(&:coverage).compact
if project.coverage_enabled?
coverage_array = builds_without_retry.map(&:coverage).compact
if coverage_array.size >= 1
'%.2f' % (coverage_array.reduce(:+) / coverage_array.size)
end
Loading
Loading
Loading
Loading
@@ -167,18 +167,25 @@ describe Commit do
let(:commit) { FactoryGirl.create :commit, project: project }
 
it "calculates average when there are two builds with coverage" do
FactoryGirl.create :build, coverage: 30, commit: commit
FactoryGirl.create :build, coverage: 40, commit: commit
FactoryGirl.create :build, name: "rspec", coverage: 30, commit: commit
FactoryGirl.create :build, name: "rubocop", coverage: 40, commit: commit
commit.coverage.should == "35.00"
end
 
it "calculates average when there are two builds with coverage and one with nil" do
FactoryGirl.create :build, coverage: 30, commit: commit
FactoryGirl.create :build, coverage: 40, commit: commit
FactoryGirl.create :build, name: "rspec", coverage: 30, commit: commit
FactoryGirl.create :build, name: "rubocop", coverage: 40, commit: commit
FactoryGirl.create :build, commit: commit
commit.coverage.should == "35.00"
end
 
it "calculates average when there are two builds with coverage and one is retried" do
FactoryGirl.create :build, name: "rspec", coverage: 30, commit: commit
FactoryGirl.create :build, name: "rubocop", coverage: 30, commit: commit
FactoryGirl.create :build, name: "rubocop", coverage: 40, commit: commit
commit.coverage.should == "35.00"
end
it "calculates average when there is one build without coverage" do
FactoryGirl.create :build, commit: commit
commit.coverage.should be_nil
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment