summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-04-16 22:43:40 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-04-16 22:43:40 +0200
commit1c5b172abb1279a25731d35ee913daa91738606d (patch)
treefb523f73d57cb6b3ad216fc6f74ceeb877edba03 /app/models
parentdc0d7f1a9b4018541596680c643cc5489fd8e625 (diff)
downloadgitlab-ce-1c5b172abb1279a25731d35ee913daa91738606d.tar.gz
Write specs for this feature
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/commit.rb9
-rw-r--r--app/models/commit_status.rb17
-rw-r--r--app/models/concerns/statuseable.rb2
3 files changed, 16 insertions, 12 deletions
diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb
index 412ab44aaf6..f2667e5476b 100644
--- a/app/models/ci/commit.rb
+++ b/app/models/ci/commit.rb
@@ -26,7 +26,10 @@ module Ci
has_many :builds, class_name: 'Ci::Build'
has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest'
+ delegate :stages, to: :statuses
+
validates_presence_of :sha
+ validates_presence_of :status
validate :valid_commit_sha
# Invalidate object and save if when touched
@@ -40,10 +43,6 @@ module Ci
CommitStatus.where(commit: all).stages
end
- def stages
- statuses.stages
- end
-
def project_id
project.id
end
@@ -82,7 +81,7 @@ module Ci
def retryable?
builds.latest.any? do |build|
- build.failed? || build.retryable?
+ build.failed? && build.retryable?
end
end
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 06d296eef08..24a26b4be8c 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -93,7 +93,10 @@ class CommitStatus < ActiveRecord::Base
end
def self.stages_status
- Hash[group(:stage).pluck(:stage, self.status_sql)]
+ all.stages.inject({}) do |h, stage|
+ h[stage] = all.where(stage: stage).status
+ h
+ end
end
def ignored?
@@ -101,11 +104,13 @@ class CommitStatus < ActiveRecord::Base
end
def duration
- if started_at && finished_at
- finished_at - started_at
- elsif started_at
- Time.now - started_at
- end
+ duration =
+ if started_at && finished_at
+ finished_at - started_at
+ elsif started_at
+ Time.now - started_at
+ end
+ duration.to_i
end
def stuck?
diff --git a/app/models/concerns/statuseable.rb b/app/models/concerns/statuseable.rb
index f34dca29120..7b0c9789fb9 100644
--- a/app/models/concerns/statuseable.rb
+++ b/app/models/concerns/statuseable.rb
@@ -33,7 +33,7 @@ module Statuseable
def duration
duration_array = all.map(&:duration).compact
- duration_array.reduce(:+).to_i
+ duration_array.reduce(:+)
end
def started_at