From 66b97bc27352520679f4a7b1f1836cc3680335bb Mon Sep 17 00:00:00 2001
From: Grzegorz Bizon <grzesiek.bizon@gmail.com>
Date: Tue, 22 May 2018 13:04:07 +0200
Subject: [PATCH] Abstract persisted/legacy stages in pipeline model

Conflicts:
	app/controllers/projects/pipelines_controller.rb
---
 app/models/ci/pipeline.rb                             | 10 ++++++++++
 app/serializers/pipeline_details_entity.rb            |  7 +------
 .../controllers/projects/pipelines_controller_spec.rb | 11 ++++++-----
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 9ffffec64d3..b57ac43a3fe 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -262,6 +262,16 @@ module Ci
       stage unless stage.statuses_count.zero?
     end
 
+    ##
+    # TODO consider switching to persisted stages only in pipelines table
+    # (not necessairly in the show pipeline page because of #23257.
+    # Hide this behind two feature flags - enabled / disabled and only
+    # gitlab-ce / everywhere.
+    #
+    def stages
+      super
+    end
+
     def legacy_stages
       # TODO, this needs refactoring, see gitlab-ce#26481.
 
diff --git a/app/serializers/pipeline_details_entity.rb b/app/serializers/pipeline_details_entity.rb
index 7f18c4e01a0..577b0555c92 100644
--- a/app/serializers/pipeline_details_entity.rb
+++ b/app/serializers/pipeline_details_entity.rb
@@ -1,11 +1,6 @@
 class PipelineDetailsEntity < PipelineEntity
   expose :details do
-    ##
-    # TODO consider switching to persisted stages only in pipelines table
-    # (not necessairly in the show pipeline page because of #23257.
-    # Hide this behind two feature flags - enabled / disabled and only
-    # gitlab-ce / everywhere.
-    expose :stages, as: :stages, using: StageEntity
+    expose :stages, using: StageEntity
     expose :artifacts, using: BuildArtifactEntity
     expose :manual_actions, using: BuildActionEntity
   end
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb
index d5a0d32054b..c8080056f69 100644
--- a/spec/controllers/projects/pipelines_controller_spec.rb
+++ b/spec/controllers/projects/pipelines_controller_spec.rb
@@ -17,8 +17,7 @@ describe Projects::PipelinesController do
 
   describe 'GET index.json' do
     before do
-      %w(pending running running success canceled)
-        .each_with_index do |status, index|
+      %w(pending running success failed).each_with_index do |status, index|
           create_pipeline(status, project.commit("HEAD~#{index}"))
         end
     end
@@ -32,11 +31,13 @@ describe Projects::PipelinesController do
       expect(response).to match_response_schema('pipeline')
 
       expect(json_response).to include('pipelines')
-      expect(json_response['pipelines'].count).to eq 5
-      expect(json_response['count']['all']).to eq '5'
-      expect(json_response['count']['running']).to eq '2'
+      expect(json_response['pipelines'].count).to eq 4
+      expect(json_response['count']['all']).to eq '4'
+      expect(json_response['count']['running']).to eq '1'
       expect(json_response['count']['pending']).to eq '1'
       expect(json_response['count']['finished']).to eq '2'
+      puts queries.log
+      puts "Queries count: #{queries.count}"
       expect(queries.count).to be < 32
     end
 
-- 
2.30.9