From a3c969cd92a2f658d322bec1cfe07c520b678bf7 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Mon, 11 Aug 2014 23:59:30 +0200 Subject: [PATCH] Add testcase for invalid color --- app/models/label.rb | 6 ++++-- features/project/issues/labels.feature | 5 +++++ features/steps/project/labels.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/models/label.rb b/app/models/label.rb index ce982579675..e2379bb6d77 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -3,10 +3,12 @@ class Label < ActiveRecord::Base has_many :label_links, dependent: :destroy has_many :issues, through: :label_links, source: :target, source_type: 'Issue' - validates :color, format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ }, allow_blank: true + validates :color, + format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ }, + allow_blank: false validates :project, presence: true - # Dont allow '?', '&', and ',' for label titles + # Don't allow '?', '&', and ',' for label titles validates :title, presence: true, format: { with: /\A[^&\?,&]*\z/ } scope :order_by_name, -> { reorder("labels.title ASC") } diff --git a/features/project/issues/labels.feature b/features/project/issues/labels.feature index 4a37b6dc9fa..b88108af719 100644 --- a/features/project/issues/labels.feature +++ b/features/project/issues/labels.feature @@ -23,3 +23,8 @@ Feature: Project Labels Scenario: I remove label When I remove label 'bug' Then I should not see label 'bug' + + Scenario: I create a label with invalid color + Given I visit new label page + When I submit new label with invalid color + Then I should see label color error message diff --git a/features/steps/project/labels.rb b/features/steps/project/labels.rb index 3d9aa29299c..12ce23da832 100644 --- a/features/steps/project/labels.rb +++ b/features/steps/project/labels.rb @@ -31,6 +31,18 @@ class ProjectLabels < Spinach::FeatureSteps click_button 'Save' end + step 'I submit new label with invalid color' do + fill_in 'Title', with: 'support' + fill_in 'Background Color', with: '#12' + click_button 'Save' + end + + step 'I should see label color error message' do + within '.label-form' do + page.should have_content 'Color is invalid' + end + end + step 'I should not see label \'bug\'' do within '.manage-labels-list' do page.should_not have_content 'bug'