diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2015-07-10 13:32:32 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2015-07-10 13:32:32 +0000 |
commit | d841ed56d39db1b33947b9b9c0291beaa7dcdd43 (patch) | |
tree | 9afc7861f8bd55bb8a7804982b1c37468a1d00ec | |
parent | 9b6e7a17d9a1a7275689b5b237940582cf1ee792 (diff) | |
parent | 39cfebdcf4225a9384ddb59578adeaec4b11d06d (diff) | |
download | gitlab-ci-d841ed56d39db1b33947b9b9c0291beaa7dcdd43.tar.gz |
Merge branch 'coverage-calc' into 'master'
Use builds_without_retry to calculate average coverage
/cc @vsizov
See merge request !197
-rw-r--r-- | app/models/commit.rb | 4 | ||||
-rw-r--r-- | spec/models/commit_spec.rb | 15 |
2 files changed, 13 insertions, 6 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 3680220..e173ed4 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -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 diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 14d6d99..0038e36 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -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 |