From 8d5f932660f96367948fb89210f7a04d3fc90891 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 29 Jan 2012 21:09:44 +0000 Subject: [PATCH] Do not validate blank default custom field value. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8722 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/custom_field.rb | 2 +- test/unit/custom_field_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index f56eb3623..b8005fea1 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -57,7 +57,7 @@ class CustomField < ActiveRecord::Base end end - unless valid_field_value?(default_value) + if default_value.present? && !valid_field_value?(default_value) errors.add(:default_value, :invalid) end end diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb index 6cef44ea9..db7a637fd 100644 --- a/test/unit/custom_field_test.rb +++ b/test/unit/custom_field_test.rb @@ -52,6 +52,11 @@ class CustomFieldTest < ActiveSupport::TestCase assert field.valid? end + def test_default_value_should_not_be_validated_when_blank + field = CustomField.new(:name => 'Test', :field_format => 'list', :possible_values => ['a', 'b'], :is_required => true, :default_value => '') + assert field.valid? + end + def test_possible_values_should_accept_an_array field = CustomField.new field.possible_values = ["One value", ""]