From 85ceb8b72f5a67d21bc9530fe835fdece98f3d4e Mon Sep 17 00:00:00 2001
From: Lin Jen-Shin <godfat@godfat.org>
Date: Tue, 19 Jul 2016 17:51:45 +0800
Subject: [PATCH] Rename latest_success* to latest_successful:

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5142#note_13164642
---
 app/controllers/projects/artifacts_controller.rb          | 2 +-
 app/models/ci/build.rb                                    | 2 +-
 app/models/project.rb                                     | 8 ++++----
 app/views/projects/branches/_branch.html.haml             | 4 ++--
 app/views/projects/buttons/_download.html.haml            | 4 ++--
 .../projects/repositories/_download_archive.html.haml     | 4 ++--
 app/views/projects/tags/_download.html.haml               | 4 ++--
 lib/api/builds.rb                                         | 2 +-
 spec/models/build_spec.rb                                 | 8 ++++----
 9 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb
index f33cf238d88..05112571225 100644
--- a/app/controllers/projects/artifacts_controller.rb
+++ b/app/controllers/projects/artifacts_controller.rb
@@ -60,7 +60,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
 
   def build_from_ref
     if params[:ref_name]
-      builds = project.latest_success_builds_for(params[:ref_name])
+      builds = project.latest_successful_builds_for(params[:ref_name])
 
       builds.find_by(name: params[:job])
     end
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index c048eff0f80..65dfe4f0190 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -15,7 +15,7 @@ module Ci
     scope :with_artifacts, ->() { where.not(artifacts_file: nil) }
     scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
     scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
-    scope :latest_success_with_artifacts, ->() do
+    scope :latest_successful_with_artifacts, ->() do
       with_artifacts.success.order(id: :desc)
     end
 
diff --git a/app/models/project.rb b/app/models/project.rb
index c1cb1558132..60928bf9922 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -430,7 +430,7 @@ class Project < ActiveRecord::Base
   end
 
   # ref can't be HEAD, can only be branch/tag name or SHA
-  def latest_success_pipeline_for(ref = 'master')
+  def latest_successful_pipeline_for(ref = 'master')
     table = Ci::Pipeline.quoted_table_name
     # TODO: Use `where(ref: ref).or(sha: ref)` in Rails 5
     pipelines.where("#{table}.ref = ? OR #{table}.sha = ?", ref, ref).
@@ -438,10 +438,10 @@ class Project < ActiveRecord::Base
   end
 
   # ref can't be HEAD, can only be branch/tag name or SHA
-  def latest_success_builds_for(ref = 'master')
+  def latest_successful_builds_for(ref = 'master')
     Ci::Build.joins(:pipeline).
-      merge(latest_success_pipeline_for(ref)).
-      latest_success_with_artifacts
+      merge(latest_successful_pipeline_for(ref)).
+      latest_successful_with_artifacts
   end
 
   def merge_base_commit(first_commit_id, second_commit_id)
diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml
index cbd6ab74128..8f6ddfd9044 100644
--- a/app/views/projects/branches/_branch.html.haml
+++ b/app/views/projects/branches/_branch.html.haml
@@ -27,9 +27,9 @@
         = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: branch.name), class: 'btn btn-default', method: :post, title: "Compare" do
           Compare
 
-      - pipeline = @project.latest_success_pipeline_for(branch.name).first
+      - pipeline = @project.latest_successful_pipeline_for(branch.name).first
       - if pipeline
-        - artifacts = pipeline.builds.latest_success_with_artifacts
+        - artifacts = pipeline.builds.latest_successful_with_artifacts
         - if artifacts.any?
           .dropdown.inline.artifacts-btn
             %a.btn.dropdown-toggle{ 'data-toggle' => 'dropdown' }
diff --git a/app/views/projects/buttons/_download.html.haml b/app/views/projects/buttons/_download.html.haml
index f96045e09f0..047931a7fa5 100644
--- a/app/views/projects/buttons/_download.html.haml
+++ b/app/views/projects/buttons/_download.html.haml
@@ -14,9 +14,9 @@
         %li
           = link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: @ref, format: 'tar.gz'), rel: 'nofollow' do
             %span Download tar.gz
-        - pipeline = @project.latest_success_pipeline_for(@ref).first
+        - pipeline = @project.latest_successful_pipeline_for(@ref).first
         - if pipeline
-          - artifacts = pipeline.builds.latest_success_with_artifacts
+          - artifacts = pipeline.builds.latest_successful_with_artifacts
           - if artifacts.any?
             %li.dropdown-header Artifacts
             - unless pipeline.latest?
diff --git a/app/views/projects/repositories/_download_archive.html.haml b/app/views/projects/repositories/_download_archive.html.haml
index 396fb8598ae..1c03aa0a332 100644
--- a/app/views/projects/repositories/_download_archive.html.haml
+++ b/app/views/projects/repositories/_download_archive.html.haml
@@ -25,9 +25,9 @@
         = link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: ref, format: 'tar'), rel: 'nofollow' do
           %i.fa.fa-download
           %span Download tar
-      - pipeline = @project.latest_success_pipeline_for(ref).first
+      - pipeline = @project.latest_successful_pipeline_for(ref).first
       - if pipeline
-        - artifacts = pipeline.builds.latest_success_with_artifacts
+        - artifacts = pipeline.builds.latest_successful_with_artifacts
         - if artifacts.any?
           %li.dropdown-header Artifacts
           - unless pipeline.latest?
diff --git a/app/views/projects/tags/_download.html.haml b/app/views/projects/tags/_download.html.haml
index 6a431bcf7b2..8e5e5cb559b 100644
--- a/app/views/projects/tags/_download.html.haml
+++ b/app/views/projects/tags/_download.html.haml
@@ -12,9 +12,9 @@
     %li
       = link_to archive_namespace_project_repository_path(project.namespace, project, ref: ref, format: 'tar.gz'), rel: 'nofollow' do
         %span Download tar.gz
-    - pipeline = project.latest_success_pipeline_for(ref).first
+    - pipeline = project.latest_successful_pipeline_for(ref).first
     - if pipeline
-      - artifacts = pipeline.builds.latest_success_with_artifacts
+      - artifacts = pipeline.builds.latest_successful_with_artifacts
       - if artifacts.any?
         %li.dropdown-header Artifacts
         - unless pipeline.latest?
diff --git a/lib/api/builds.rb b/lib/api/builds.rb
index a27397a82f7..bb9e8f1ae6e 100644
--- a/lib/api/builds.rb
+++ b/lib/api/builds.rb
@@ -83,7 +83,7 @@ module API
       #   GET /projects/:id/artifacts/:ref_name/download?job=name
       get ':id/builds/artifacts/:ref_name/download',
         requirements: { ref_name: /.+/ } do
-        builds = user_project.latest_success_builds_for(params[:ref_name])
+        builds = user_project.latest_successful_builds_for(params[:ref_name])
         latest_build = builds.find_by!(name: params[:job])
 
         present_artifact!(latest_build.artifacts_file)
diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb
index d435cd745b3..355cb8fdfff 100644
--- a/spec/models/build_spec.rb
+++ b/spec/models/build_spec.rb
@@ -678,7 +678,7 @@ describe Ci::Build, models: true do
     end
   end
 
-  describe 'Project#latest_success_builds_for' do
+  describe 'Project#latest_successful_builds_for' do
     let(:build) do
       create(:ci_build, :artifacts, :success, pipeline: pipeline)
     end
@@ -689,13 +689,13 @@ describe Ci::Build, models: true do
 
     context 'with succeed pipeline' do
       it 'returns builds from ref' do
-        builds = project.latest_success_builds_for('fix')
+        builds = project.latest_successful_builds_for('fix')
 
         expect(builds).to contain_exactly(build)
       end
 
       it 'returns empty relation if the build cannot be found' do
-        builds = project.latest_success_builds_for('TAIL').all
+        builds = project.latest_successful_builds_for('TAIL').all
 
         expect(builds).to be_empty
       end
@@ -707,7 +707,7 @@ describe Ci::Build, models: true do
       end
 
       it 'returns empty relation' do
-        builds = project.latest_success_builds_for('fix').all
+        builds = project.latest_successful_builds_for('fix').all
 
         expect(builds).to be_empty
       end
-- 
GitLab