summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-13 17:11:57 -0500
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-13 17:11:57 -0500
commit6d19e13df62376916e024ff44939bf2a8f5b671b (patch)
tree4b5bae7c18ee25ebdc73be3730ed36efd270eef8
parentc1bc5c58a2861af25f4f03e0a757dceae4b67cda (diff)
downloadgitlab-ce-6d19e13df62376916e024ff44939bf2a8f5b671b.tar.gz
Fix specs
-rw-r--r--app/models/commit_status.rb11
-rw-r--r--app/models/project.rb2
-rw-r--r--app/views/projects/ci/commits/_commit.html.haml3
-rw-r--r--spec/features/pipelines_spec.rb21
-rw-r--r--spec/models/commit_status_spec.rb12
5 files changed, 17 insertions, 32 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 2d09edf3ca1..c7451ea0a86 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -92,16 +92,11 @@ class CommitStatus < ActiveRecord::Base
def self.stages
# We group by stage name, but order stages by theirs' index
- unscoped.from(all, :sg).group('stage').order('max(stage_idx)', 'stage').pluck('sg.stage')
+ unscoped.where(id: all).group('stage').order('max(stage_idx)', 'stage').pluck('stage')
end
- def self.stages_status
- # We execute subquery for each stage to calculate a stage status
- statuses = unscoped.from(all, :sg).group('stage').pluck('sg.stage', all.where('stage=sg.stage').status_sql)
- statuses.inject({}) do |h, k|
- h[k.first] = k.last
- h
- end
+ def self.status_for_stage(stage)
+ where(stage: stage).status
end
def ignored?
diff --git a/app/models/project.rb b/app/models/project.rb
index 82489235a3f..dfd1e54ecf7 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -354,7 +354,7 @@ class Project < ActiveRecord::Base
join_body = "INNER JOIN (
SELECT project_id, COUNT(*) AS amount
FROM notes
- WHERE created_at >= #{sanitize(since)}project.ci_commits
+ WHERE created_at >= #{sanitize(since)}
GROUP BY project_id
) join_note_counts ON projects.id = join_note_counts.project_id"
diff --git a/app/views/projects/ci/commits/_commit.html.haml b/app/views/projects/ci/commits/_commit.html.haml
index 90ac41666d0..7f9a3417836 100644
--- a/app/views/projects/ci/commits/_commit.html.haml
+++ b/app/views/projects/ci/commits/_commit.html.haml
@@ -31,10 +31,9 @@
Cant find HEAD commit for this branch
- - stages_status = commit.statuses.stages_status
- stages.each do |stage|
%td
- - if status = stages_status[stage]
+ - if status = commit.statuses.status_for_stage(stage)
- tooltip = "#{stage.titleize}: #{status}"
%span.has-tooltip(title="#{tooltip}"){class: "ci-status-icon-#{status}"}
= ci_icon_for_status(status)
diff --git a/spec/features/pipelines_spec.rb b/spec/features/pipelines_spec.rb
index 0e654c3e40f..1df516eafd5 100644
--- a/spec/features/pipelines_spec.rb
+++ b/spec/features/pipelines_spec.rb
@@ -52,15 +52,15 @@ describe "Pipelines" do
before { click_link('Retry') }
it { expect(page).to_not have_link('Retry') }
- it { expect(page).to have_selector('.ci-running') }
+ it { expect(page).to have_selector('.ci-pending') }
end
end
context 'downloadable pipelines' do
- before { visit namespace_project_pipelines_path(project.namespace, project) }
-
context 'with artifacts' do
- let!(:with_artifacts) { create(:ci_build, :success, :artifacts, commit: pipeline, name: 'rspec tests', stage: 'test') }
+ let!(:with_artifacts) { create(:ci_build, :artifacts, :success, commit: pipeline, name: 'rspec tests', stage: 'test') }
+
+ before { visit namespace_project_pipelines_path(project.namespace, project) }
it { expect(page).to have_selector('.build-artifacts') }
it { expect(page).to have_link(with_artifacts.name) }
@@ -78,10 +78,10 @@ describe "Pipelines" do
let(:pipeline) { create(:ci_commit, project: project, ref: 'master') }
before do
- @success = create(:ci_build, :success, commit: pipeline, stage: 'build')
- @failed = create(:ci_build, :failed, commit: pipeline, stage: 'test', commands: 'test')
- @running = create(:ci_build, :running, commit: pipeline, stage: 'deploy')
- @external = create(:generic_commit_status, :success, commit: pipeline, stage: 'external')
+ @success = create(:ci_build, :success, commit: pipeline, stage: 'build', name: 'build')
+ @failed = create(:ci_build, :failed, commit: pipeline, stage: 'test', name: 'test', commands: 'test')
+ @running = create(:ci_build, :running, commit: pipeline, stage: 'deploy', name: 'deploy')
+ @external = create(:generic_commit_status, status: 'success', commit: pipeline, name: 'jenkins', stage: 'external')
end
before { visit namespace_project_pipeline_path(project.namespace, project, pipeline) }
@@ -126,7 +126,10 @@ describe "Pipelines" do
before { visit new_namespace_project_pipeline_path(project.namespace, project) }
context 'for valid commit' do
- before { fill_in('Create for', with: 'master') }
+ before do
+ fill_in('Create for', with: 'master')
+ stub_ci_commit_to_return_yaml_file
+ end
it { expect{ click_on 'Create pipeline' }.to change{ Ci::Commit.count }.by(1) }
end
diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb
index 971e6750375..eb3715f00d4 100644
--- a/spec/models/commit_status_spec.rb
+++ b/spec/models/commit_status_spec.rb
@@ -219,17 +219,5 @@ describe CommitStatus, models: true do
is_expected.to eq(%w(build test deploy))
end
end
-
- context 'stages with statuses' do
- subject { CommitStatus.where(commit: commit).stages_status }
-
- it 'return list of stages with statuses' do
- is_expected.to eq({
- 'build' => 'failed',
- 'test' => 'success',
- 'deploy' => 'running'
- })
- end
- end
end
end