Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
Merge branch 'coverage_fix' into 'master'
Browse files Browse the repository at this point in the history
Fix coverage colcalation on the commit page

See merge request !171
  • Loading branch information
vsizov committed Jun 26, 2015
2 parents 0738330 + 744d291 commit c4657e4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -4,6 +4,7 @@ v7.13.0
- Improved Lint stability
- Disable colors in rake tasks automatically (if IO is not a TTY)
- Implemented "rake env:info". Rake task to receive system information
- Fix coverage calculation on commit page

v7.12.1
- Runner without tag should pick builds without tag only
Expand Down
7 changes: 5 additions & 2 deletions app/models/commit.rb
Expand Up @@ -205,8 +205,11 @@ def finished_at
end

def coverage
if project.coverage_enabled? && builds.size > 0
builds.last.coverage
if project.coverage_enabled? && builds.count(:all) > 0
coverage_array = builds.map(&:coverage).compact
if coverage_array.size > 1
coverage_array.reduce(:+) / coverage_array.size
end
end
end

Expand Down
23 changes: 23 additions & 0 deletions spec/models/commit_spec.rb
Expand Up @@ -159,4 +159,27 @@
commit.finished_at.should be_nil
end
end

describe "coverage" do
let(:project) { FactoryGirl.create :project, coverage_regex: "/.*/" }
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
commit.coverage.should == 35.0
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, commit: commit
commit.coverage.should == 35.0
end

it "calculates average when there is one build without coverage" do
FactoryGirl.create :build, commit: commit
commit.coverage.should be_nil
end
end
end

0 comments on commit c4657e4

Please sign in to comment.