From 9fd6f1b6009410cee0d0d7db8703ad64701db62b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 6 May 2016 08:47:19 +0200 Subject: [PATCH] Improve displaying validation messages for runner --- app/controllers/projects/runners_controller.rb | 1 - app/models/ci/runner.rb | 10 +++++++--- app/views/projects/runners/edit.html.haml | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/projects/runners_controller.rb b/app/controllers/projects/runners_controller.rb index 12172b47520..0b4fa572501 100644 --- a/app/controllers/projects/runners_controller.rb +++ b/app/controllers/projects/runners_controller.rb @@ -20,7 +20,6 @@ class Projects::RunnersController < Projects::ApplicationController if @runner.update_attributes(runner_params) redirect_to runner_path(@runner), notice: 'Runner was successfully updated.' else - 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 b1227d72405..f5813589492 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -27,9 +27,9 @@ module Ci 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!') + unless runner.has_tags? || runner.run_untagged? + errors.add(:tags_list, + 'can not be empty when runner is not allowed to pick untagged jobs') end end @@ -103,5 +103,9 @@ module Ci def short_sha token[0...8] if token end + + def has_tags? + tag_list.any? + end end end diff --git a/app/views/projects/runners/edit.html.haml b/app/views/projects/runners/edit.html.haml index 771947d7908..a5cfa9a8da9 100644 --- a/app/views/projects/runners/edit.html.haml +++ b/app/views/projects/runners/edit.html.haml @@ -1,5 +1,11 @@ - page_title "Edit", "#{@runner.description} ##{@runner.id}", "Runners" %h4 Runner ##{@runner.id} + +- if @runner.errors.any? + .error-message.js-errors + - @runner.errors.full_messages.each do |error| + %div= error + %hr = render 'form', runner: @runner, runner_form_url: runner_path(@runner)