diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-05-05 14:27:06 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-05-19 22:01:53 +0200 |
commit | dd8e9e2d7acf05b837a3bacd1258e9f3df4254a6 (patch) | |
tree | 3fad55f3a63506350711908260da20ca59c8d9cb | |
parent | 9129c37c5bd6e648e23ebe6847b909dd151c7e8a (diff) | |
download | gitlab-ce-dd8e9e2d7acf05b837a3bacd1258e9f3df4254a6.tar.gz |
Add custom validator to runner model
-rw-r--r-- | app/controllers/projects/runners_controller.rb | 3 | ||||
-rw-r--r-- | app/models/ci/runner.rb | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/app/controllers/projects/runners_controller.rb b/app/controllers/projects/runners_controller.rb index 3a9d67aff64..12172b47520 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 23b1556712c..b1227d72405 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. |