From d9ece71ef0677a1d3468697485db7cbcf1b83745 Mon Sep 17 00:00:00 2001
From: Kamil Trzcinski <ayufan@ayufan.eu>
Date: Wed, 14 Oct 2015 14:21:49 +0200
Subject: [PATCH] Fix specs

---
 app/controllers/projects/builds_controller.rb | 12 ++++----
 app/models/ci/runner.rb                       |  2 +-
 features/steps/project/commits/commits.rb     |  2 +-
 spec/features/builds_spec.rb                  | 28 +++++++++----------
 spec/models/ci/runner_spec.rb                 |  2 +-
 5 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb
index b7d77c21e72..54c01ddf238 100644
--- a/app/controllers/projects/builds_controller.rb
+++ b/app/controllers/projects/builds_controller.rb
@@ -12,12 +12,12 @@ class Projects::BuildsController < Projects::ApplicationController
 
     @builds =
       case @scope
-        when 'all'
-          @all_builds
-        when 'finished'
-          @all_builds.finished
-        else
-          @all_builds.running_or_pending
+      when 'all'
+        @all_builds
+      when 'finished'
+        @all_builds.finished
+      else
+        @all_builds.running_or_pending
       end
   end
 
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index bc5cd137e91..52fdc2578e3 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -78,7 +78,7 @@ module Ci
     end
 
     def short_sha
-      token[0...8]
+      token[0...8] if token
     end
   end
 end
diff --git a/features/steps/project/commits/commits.rb b/features/steps/project/commits/commits.rb
index a3cb83880e3..e5b3f27135d 100644
--- a/features/steps/project/commits/commits.rb
+++ b/features/steps/project/commits/commits.rb
@@ -113,7 +113,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
   end
 
   step 'I click status link' do
-    click_link "Builds"
+    find('.commit-ci-menu').click_link "Builds"
   end
 
   step 'I see builds list' do
diff --git a/spec/features/builds_spec.rb b/spec/features/builds_spec.rb
index 31f8aa83981..a339a151112 100644
--- a/spec/features/builds_spec.rb
+++ b/spec/features/builds_spec.rb
@@ -10,40 +10,40 @@ describe "Builds" do
   end
 
   describe "GET /:project/builds" do
-    context "All builds" do
+    context "Running scope" do
       before do
-        @build.success
+        @build.run!
         visit namespace_project_builds_path(@gl_project.namespace, @gl_project)
       end
 
-      it { expect(page).to have_content 'All builds' }
+      it { expect(page).to have_content 'Running' }
+      it { expect(page).to have_content 'Cancel all' }
       it { expect(page).to have_content @build.short_sha }
       it { expect(page).to have_content @build.ref }
       it { expect(page).to have_content @build.name }
-      it { expect(page).to_not have_content 'Cancel all' }
     end
 
-    context "Pending scope" do
+    context "Finished scope" do
       before do
-        @build.success
-        visit namespace_project_builds_path(@gl_project.namespace, @gl_project, scope: :pending)
+        @build.run!
+        visit namespace_project_builds_path(@gl_project.namespace, @gl_project, scope: :finished)
       end
 
       it { expect(page).to have_content 'No builds to show' }
-      it { expect(page).to_not have_content 'Cancel all' }
+      it { expect(page).to have_content 'Cancel all' }
     end
 
-    context "Running scope" do
+    context "All builds" do
       before do
-        @build.run!
-        visit namespace_project_builds_path(@gl_project.namespace, @gl_project, scope: :running)
+        @gl_project.ci_builds.running_or_pending.each(&:success)
+        visit namespace_project_builds_path(@gl_project.namespace, @gl_project, scope: :all)
       end
 
-      it { expect(page).to have_content 'Running' }
-      it { expect(page).to have_content 'Cancel all' }
+      it { expect(page).to have_content 'All' }
       it { expect(page).to have_content @build.short_sha }
       it { expect(page).to have_content @build.ref }
       it { expect(page).to have_content @build.name }
+      it { expect(page).to_not have_content 'Cancel all' }
     end
   end
 
@@ -53,7 +53,7 @@ describe "Builds" do
       visit cancel_namespace_project_build_path(@gl_project.namespace, @gl_project, @build)
     end
 
-    it { expect(page).to have_content 'All builds' }
+    it { expect(page).to have_content 'All' }
     it { expect(page).to have_content 'canceled' }
     it { expect(page).to_not have_content 'Cancel all' }
   end
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index 757593a7ab8..a401ae7fe51 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -32,7 +32,7 @@ describe Ci::Runner do
     end
 
     it 'should return the token if the description is an empty string' do
-      runner = FactoryGirl.build(:ci_runner, description: '')
+      runner = FactoryGirl.build(:ci_runner, description: '', token: 'token')
       expect(runner.display_name).to eq runner.token
     end
   end
-- 
GitLab