Mercurial > hg > soundsoftware-site
comparison .svn/pristine/a1/a13b287b0ac6810b1dd4f043e22916c40ff94b84.svn-base @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 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.expand_path('../../../../../test_helper', __FILE__) | |
19 require 'redmine/field_format' | |
20 | |
21 class Redmine::ListFieldFormatTest < ActionView::TestCase | |
22 include ApplicationHelper | |
23 include Redmine::I18n | |
24 | |
25 def setup | |
26 set_language_if_valid 'en' | |
27 end | |
28 | |
29 def test_possible_existing_value_should_be_valid | |
30 field = GroupCustomField.create!(:name => 'List', :field_format => 'list', :possible_values => ['Foo', 'Bar']) | |
31 group = Group.new(:name => 'Group') | |
32 group.custom_field_values = {field.id => 'Baz'} | |
33 assert group.save(:validate => false) | |
34 | |
35 group = Group.order('id DESC').first | |
36 assert_equal ['Foo', 'Bar', 'Baz'], field.possible_custom_value_options(group.custom_value_for(field)) | |
37 assert group.valid? | |
38 end | |
39 | |
40 def test_edit_tag_should_have_id_and_name | |
41 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false) | |
42 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new) | |
43 | |
44 tag = field.format.edit_tag(self, 'abc', 'xyz', value) | |
45 assert_select_in tag, 'select[id=abc][name=xyz]' | |
46 end | |
47 | |
48 def test_edit_tag_should_contain_possible_values | |
49 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false) | |
50 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new) | |
51 | |
52 tag = field.format.edit_tag(self, 'id', 'name', value) | |
53 assert_select_in tag, 'select' do | |
54 assert_select 'option', 3 | |
55 assert_select 'option[value=]' | |
56 assert_select 'option[value=Foo]', :text => 'Foo' | |
57 assert_select 'option[value=Bar]', :text => 'Bar' | |
58 end | |
59 end | |
60 | |
61 def test_edit_tag_should_select_current_value | |
62 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false) | |
63 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => 'Bar') | |
64 | |
65 tag = field.format.edit_tag(self, 'id', 'name', value) | |
66 assert_select_in tag, 'select' do | |
67 assert_select 'option[selected=selected]', 1 | |
68 assert_select 'option[value=Bar][selected=selected]', :text => 'Bar' | |
69 end | |
70 end | |
71 | |
72 def test_edit_tag_with_multiple_should_select_current_values | |
73 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false, | |
74 :multiple => true) | |
75 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => ['Bar', 'Baz']) | |
76 | |
77 tag = field.format.edit_tag(self, 'id', 'name', value) | |
78 assert_select_in tag, 'select[multiple=multiple]' do | |
79 assert_select 'option[selected=selected]', 2 | |
80 assert_select 'option[value=Bar][selected=selected]', :text => 'Bar' | |
81 assert_select 'option[value=Baz][selected=selected]', :text => 'Baz' | |
82 end | |
83 end | |
84 | |
85 def test_edit_tag_with_check_box_style_should_contain_possible_values | |
86 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false, | |
87 :edit_tag_style => 'check_box') | |
88 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new) | |
89 | |
90 tag = field.format.edit_tag(self, 'id', 'name', value) | |
91 assert_select_in tag, 'span' do | |
92 assert_select 'input[type=radio]', 3 | |
93 assert_select 'label', :text => '(none)' do | |
94 assert_select 'input[value=]' | |
95 end | |
96 assert_select 'label', :text => 'Foo' do | |
97 assert_select 'input[value=Foo]' | |
98 end | |
99 assert_select 'label', :text => 'Bar' do | |
100 assert_select 'input[value=Bar]' | |
101 end | |
102 end | |
103 end | |
104 | |
105 def test_edit_tag_with_check_box_style_should_select_current_value | |
106 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false, | |
107 :edit_tag_style => 'check_box') | |
108 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => 'Bar') | |
109 | |
110 tag = field.format.edit_tag(self, 'id', 'name', value) | |
111 assert_select_in tag, 'span' do | |
112 assert_select 'input[type=radio][checked=checked]', 1 | |
113 assert_select 'label', :text => 'Bar' do | |
114 assert_select 'input[value=Bar][checked=checked]' | |
115 end | |
116 end | |
117 end | |
118 | |
119 def test_edit_tag_with_check_box_style_and_multiple_values_should_contain_hidden_field_to_clear_value | |
120 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false, | |
121 :edit_tag_style => 'check_box', :multiple => true) | |
122 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new) | |
123 | |
124 tag = field.format.edit_tag(self, 'id', 'name', value) | |
125 assert_select_in tag, 'span' do | |
126 assert_select 'input[type=checkbox]', 2 | |
127 assert_select 'input[type=hidden]', 1 | |
128 end | |
129 end | |
130 | |
131 def test_field_with_url_pattern_should_link_value | |
132 field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%') | |
133 formatted = field.format.formatted_value(self, field, 'foo', Issue.new, true) | |
134 assert_equal '<a href="http://localhost/foo">foo</a>', formatted | |
135 assert formatted.html_safe? | |
136 end | |
137 | |
138 def test_field_with_url_pattern_and_multiple_values_should_link_values | |
139 field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%') | |
140 formatted = field.format.formatted_value(self, field, ['foo', 'bar'], Issue.new, true) | |
141 assert_equal '<a href="http://localhost/bar">bar</a>, <a href="http://localhost/foo">foo</a>', formatted | |
142 assert formatted.html_safe? | |
143 end | |
144 | |
145 def test_field_with_url_pattern_should_not_link_blank_value | |
146 field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%') | |
147 formatted = field.format.formatted_value(self, field, '', Issue.new, true) | |
148 assert_equal '', formatted | |
149 assert formatted.html_safe? | |
150 end | |
151 | |
152 def test_edit_tag_with_check_box_style_and_multiple_should_select_current_values | |
153 field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false, | |
154 :multiple => true, :edit_tag_style => 'check_box') | |
155 value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => ['Bar', 'Baz']) | |
156 | |
157 tag = field.format.edit_tag(self, 'id', 'name', value) | |
158 assert_select_in tag, 'span' do | |
159 assert_select 'input[type=checkbox][checked=checked]', 2 | |
160 assert_select 'label', :text => 'Bar' do | |
161 assert_select 'input[value=Bar][checked=checked]' | |
162 end | |
163 assert_select 'label', :text => 'Baz' do | |
164 assert_select 'input[value=Baz][checked=checked]' | |
165 end | |
166 end | |
167 end | |
168 end |