From dd8e9e2d7acf05b837a3bacd1258e9f3df4254a6 Mon Sep 17 00:00:00 2001
From: Grzegorz Bizon <grzesiek.bizon@gmail.com>
Date: Thu, 5 May 2016 14:27:06 +0200
Subject: [PATCH] Add custom validator to runner model

---
 app/controllers/projects/runners_controller.rb | 3 ++-
 app/models/ci/runner.rb                        | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/app/controllers/projects/runners_controller.rb b/app/controllers/projects/runners_controller.rb
index 3a9d67aff6..12172b4752 100644
--- a/app/controllers/projects/runners_controller.rb
+++ b/app/controllers/projects/runners_controller.rb
@@ -20,7 +20,8 @@ class Projects::RunnersController < Projects::ApplicationController
     if @runner.update_attributes(runner_params)
       redirect_to runner_path(@runner), notice: 'Runner was successfully updated.'
     else
-      redirect_to runner_path(@runner), alert: 'Runner was not updated.'
+      flash[:alert] = @runner.errors.full_messages.to_sentence
+      render 'edit'
     end
   end
 
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index 23b1556712..b1227d7240 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -26,6 +26,13 @@ module Ci
         .where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id)
     end
 
+    validate do |runner|
+      if runner.tag_list.empty? && !runner.run_untagged?
+        errors.add(:tags_errors,
+          'Runner without tags must be able to pick untagged jobs!')
+      end
+    end
+
     acts_as_taggable
 
     # Searches for runners matching the given query.
-- 
2.30.9