@@ -0,0 +1,32 | |||||
|
1 | # redMine - project management software | |||
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |||
|
19 | ||||
|
20 | class CustomFieldTest < Test::Unit::TestCase | |||
|
21 | fixtures :custom_fields | |||
|
22 | ||||
|
23 | def test_create | |||
|
24 | field = UserCustomField.new(:name => 'Money money money', :field_format => 'float') | |||
|
25 | assert field.save | |||
|
26 | end | |||
|
27 | ||||
|
28 | def test_destroy | |||
|
29 | field = CustomField.find(1) | |||
|
30 | assert field.destroy | |||
|
31 | end | |||
|
32 | end |
@@ -0,0 +1,34 | |||||
|
1 | # redMine - project management software | |||
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |||
|
19 | ||||
|
20 | class CustomValueTest < Test::Unit::TestCase | |||
|
21 | fixtures :custom_fields | |||
|
22 | ||||
|
23 | def test_float_field | |||
|
24 | v = CustomValue.new(:customized => User.find(:first), :custom_field => UserCustomField.find_by_name('Money')) | |||
|
25 | v.value = '11.2' | |||
|
26 | assert v.save | |||
|
27 | v.value = '' | |||
|
28 | assert v.save | |||
|
29 | v.value = '-6.250' | |||
|
30 | assert v.save | |||
|
31 | v.value = '6a' | |||
|
32 | assert !v.save | |||
|
33 | end | |||
|
34 | end |
@@ -24,8 +24,6 module CustomFieldsHelper | |||||
24 | field_id = "custom_fields_#{custom_field.id}" |
|
24 | field_id = "custom_fields_#{custom_field.id}" | |
25 |
|
25 | |||
26 | case custom_field.field_format |
|
26 | case custom_field.field_format | |
27 | when "string", "int" |
|
|||
28 | text_field 'custom_value', 'value', :name => field_name, :id => field_id |
|
|||
29 | when "date" |
|
27 | when "date" | |
30 | text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) + |
|
28 | text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) + | |
31 | calendar_for(field_id) |
|
29 | calendar_for(field_id) | |
@@ -35,6 +33,8 module CustomFieldsHelper | |||||
35 | check_box 'custom_value', 'value', :name => field_name, :id => field_id |
|
33 | check_box 'custom_value', 'value', :name => field_name, :id => field_id | |
36 | when "list" |
|
34 | when "list" | |
37 | select 'custom_value', 'value', custom_field.possible_values, { :include_blank => true }, :name => field_name, :id => field_id |
|
35 | select 'custom_value', 'value', custom_field.possible_values, { :include_blank => true }, :name => field_name, :id => field_id | |
|
36 | else | |||
|
37 | text_field 'custom_value', 'value', :name => field_name, :id => field_id | |||
38 | end |
|
38 | end | |
39 | end |
|
39 | end | |
40 |
|
40 |
@@ -22,9 +22,10 class CustomField < ActiveRecord::Base | |||||
22 | FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 }, |
|
22 | FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 }, | |
23 | "text" => { :name => :label_text, :order => 2 }, |
|
23 | "text" => { :name => :label_text, :order => 2 }, | |
24 | "int" => { :name => :label_integer, :order => 3 }, |
|
24 | "int" => { :name => :label_integer, :order => 3 }, | |
25 |
" |
|
25 | "float" => { :name => :label_float, :order => 4 }, | |
26 |
|
|
26 | "list" => { :name => :label_list, :order => 5 }, | |
27 |
" |
|
27 | "date" => { :name => :label_date, :order => 6 }, | |
|
28 | "bool" => { :name => :label_boolean, :order => 7 } | |||
28 | }.freeze |
|
29 | }.freeze | |
29 |
|
30 | |||
30 | validates_presence_of :name, :field_format |
|
31 | validates_presence_of :name, :field_format |
@@ -26,13 +26,14 protected | |||||
26 | errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0 |
|
26 | errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0 | |
27 | errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length |
|
27 | errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length | |
28 | case custom_field.field_format |
|
28 | case custom_field.field_format | |
29 |
when |
|
29 | when 'int' | |
30 |
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[ |
|
30 | errors.add(:value, :activerecord_error_not_a_number) unless value.blank? || value =~ /^[+-]?\d+$/ | |
31 |
when |
|
31 | when 'float' | |
|
32 | begin; !value.blank? && Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end | |||
|
33 | when 'date' | |||
32 | errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.empty? |
|
34 | errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.empty? | |
33 |
when |
|
35 | when 'list' | |
34 | errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include? value or value.empty? |
|
36 | errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include? value or value.empty? | |
35 | end |
|
37 | end | |
36 | end |
|
38 | end | |
37 | end |
|
39 | end | |
38 |
|
@@ -13,13 +13,6 function toggle_custom_field_format() { | |||||
13 | Element.hide(p_regexp.parentNode); |
|
13 | Element.hide(p_regexp.parentNode); | |
14 | Element.show(p_values); |
|
14 | Element.show(p_values); | |
15 | break; |
|
15 | break; | |
16 | case "int": |
|
|||
17 | case "string": |
|
|||
18 | case "text": |
|
|||
19 | Element.show(p_length.parentNode); |
|
|||
20 | Element.show(p_regexp.parentNode); |
|
|||
21 | Element.hide(p_values); |
|
|||
22 | break; |
|
|||
23 | case "date": |
|
16 | case "date": | |
24 | case "bool": |
|
17 | case "bool": | |
25 | Element.hide(p_length.parentNode); |
|
18 | Element.hide(p_length.parentNode); | |
@@ -29,7 +22,7 function toggle_custom_field_format() { | |||||
29 | default: |
|
22 | default: | |
30 | Element.show(p_length.parentNode); |
|
23 | Element.show(p_length.parentNode); | |
31 | Element.show(p_regexp.parentNode); |
|
24 | Element.show(p_regexp.parentNode); | |
32 |
Element. |
|
25 | Element.hide(p_values); | |
33 | break; |
|
26 | break; | |
34 | } |
|
27 | } | |
35 | } |
|
28 | } |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -259,6 +259,7 label_min_max_length: Min - Max length | |||||
259 | label_list: List |
|
259 | label_list: List | |
260 | label_date: Date |
|
260 | label_date: Date | |
261 | label_integer: Integer |
|
261 | label_integer: Integer | |
|
262 | label_float: Float | |||
262 | label_boolean: Boolean |
|
263 | label_boolean: Boolean | |
263 | label_string: Text |
|
264 | label_string: Text | |
264 | label_text: Long text |
|
265 | label_text: Long text |
@@ -535,3 +535,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
535 | label_user_mail_option_all: "For any event on all my projects" |
|
535 | label_user_mail_option_all: "For any event on all my projects" | |
536 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
536 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
537 | setting_emails_footer: Emails footer |
|
537 | setting_emails_footer: Emails footer | |
|
538 | label_float: Float |
@@ -259,6 +259,7 label_min_max_length: Longueurs mini - maxi | |||||
259 | label_list: Liste |
|
259 | label_list: Liste | |
260 | label_date: Date |
|
260 | label_date: Date | |
261 | label_integer: Entier |
|
261 | label_integer: Entier | |
|
262 | label_float: Nombre décimal | |||
262 | label_boolean: Booléen |
|
263 | label_boolean: Booléen | |
263 | label_string: Texte |
|
264 | label_string: Texte | |
264 | label_text: Texte long |
|
265 | label_text: Texte long |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -533,3 +533,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
533 | label_user_mail_option_all: "For any event on all my projects" |
|
533 | label_user_mail_option_all: "For any event on all my projects" | |
534 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
534 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
535 | setting_emails_footer: Emails footer |
|
535 | setting_emails_footer: Emails footer | |
|
536 | label_float: Float |
@@ -533,3 +533,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
533 | label_user_mail_option_all: "For any event on all my projects" |
|
533 | label_user_mail_option_all: "For any event on all my projects" | |
534 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
534 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
535 | setting_emails_footer: Emails footer |
|
535 | setting_emails_footer: Emails footer | |
|
536 | label_float: Float |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -532,3 +532,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
532 | label_user_mail_option_all: "For any event on all my projects" |
|
532 | label_user_mail_option_all: "For any event on all my projects" | |
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
533 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
534 | setting_emails_footer: Emails footer |
|
534 | setting_emails_footer: Emails footer | |
|
535 | label_float: Float |
@@ -533,3 +533,4 default_activity_development: Razvoj | |||||
533 | enumeration_issue_priorities: Prioriteti kartica |
|
533 | enumeration_issue_priorities: Prioriteti kartica | |
534 | enumeration_doc_categories: Kategorija dokumenata |
|
534 | enumeration_doc_categories: Kategorija dokumenata | |
535 | enumeration_activities: Aktivnosti (praćenje vremena)) |
|
535 | enumeration_activities: Aktivnosti (praćenje vremena)) | |
|
536 | label_float: Float |
@@ -533,3 +533,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
533 | label_user_mail_option_all: "For any event on all my projects" |
|
533 | label_user_mail_option_all: "For any event on all my projects" | |
534 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
534 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
535 | setting_emails_footer: Emails footer |
|
535 | setting_emails_footer: Emails footer | |
|
536 | label_float: Float |
@@ -535,3 +535,4 label_user_mail_option_selected: "For any event on the selected projects only... | |||||
535 | label_user_mail_option_all: "For any event on all my projects" |
|
535 | label_user_mail_option_all: "For any event on all my projects" | |
536 | label_user_mail_option_none: "Only for things I watch or I'm involved in" |
|
536 | label_user_mail_option_none: "Only for things I watch or I'm involved in" | |
537 | setting_emails_footer: Emails footer |
|
537 | setting_emails_footer: Emails footer | |
|
538 | label_float: Float |
@@ -43,3 +43,15 custom_fields_004: | |||||
43 | id: 4 |
|
43 | id: 4 | |
44 | is_required: false |
|
44 | is_required: false | |
45 | field_format: string |
|
45 | field_format: string | |
|
46 | custom_fields_005: | |||
|
47 | name: Money | |||
|
48 | min_length: 0 | |||
|
49 | regexp: "" | |||
|
50 | is_for_all: false | |||
|
51 | type: UserCustomField | |||
|
52 | max_length: 0 | |||
|
53 | possible_values: "" | |||
|
54 | id: 5 | |||
|
55 | is_required: false | |||
|
56 | field_format: float | |||
|
57 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now