diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 2d09edf3ca..c7451ea0a8 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 82489235a3..dfd1e54ecf 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 90ac41666d..7f9a341783 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 0e654c3e40..1df516eafd 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 971e675037..eb3715f00d 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