simple_form 3.0.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +149 -25
- data/MIT-LICENSE +1 -1
- data/README.md +441 -107
- data/lib/generators/simple_form/install_generator.rb +4 -3
- data/lib/generators/simple_form/templates/README +4 -5
- data/lib/generators/simple_form/templates/_form.html.erb +2 -0
- data/lib/generators/simple_form/templates/_form.html.haml +2 -0
- data/lib/generators/simple_form/templates/_form.html.slim +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +48 -11
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +417 -23
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +101 -5
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +2 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +10 -3
- data/lib/simple_form/components/errors.rb +38 -3
- data/lib/simple_form/components/hints.rb +3 -2
- data/lib/simple_form/components/html5.rb +16 -5
- data/lib/simple_form/components/label_input.rb +21 -2
- data/lib/simple_form/components/labels.rb +22 -11
- data/lib/simple_form/components/maxlength.rb +9 -5
- data/lib/simple_form/components/min_max.rb +2 -1
- data/lib/simple_form/components/minlength.rb +38 -0
- data/lib/simple_form/components/pattern.rb +2 -1
- data/lib/simple_form/components/placeholders.rb +4 -3
- data/lib/simple_form/components/readonly.rb +2 -1
- data/lib/simple_form/components.rb +2 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +193 -80
- data/lib/simple_form/helpers/autofocus.rb +1 -0
- data/lib/simple_form/helpers/disabled.rb +1 -0
- data/lib/simple_form/helpers/readonly.rb +1 -0
- data/lib/simple_form/helpers/required.rb +1 -0
- data/lib/simple_form/helpers/validators.rb +2 -1
- data/lib/simple_form/helpers.rb +6 -5
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +57 -14
- data/lib/simple_form/inputs/block_input.rb +2 -1
- data/lib/simple_form/inputs/boolean_input.rb +39 -16
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +37 -14
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +9 -13
- data/lib/simple_form/inputs/collection_select_input.rb +5 -2
- data/lib/simple_form/inputs/date_time_input.rb +24 -9
- data/lib/simple_form/inputs/file_input.rb +5 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
- data/lib/simple_form/inputs/hidden_input.rb +5 -2
- data/lib/simple_form/inputs/numeric_input.rb +6 -4
- data/lib/simple_form/inputs/password_input.rb +6 -3
- data/lib/simple_form/inputs/priority_input.rb +5 -2
- data/lib/simple_form/inputs/range_input.rb +2 -1
- data/lib/simple_form/inputs/string_input.rb +6 -3
- data/lib/simple_form/inputs/text_input.rb +6 -3
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +8 -0
- data/lib/simple_form/tags.rb +7 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +7 -6
- data/lib/simple_form/wrappers/leaf.rb +29 -0
- data/lib/simple_form/wrappers/many.rb +7 -6
- data/lib/simple_form/wrappers/root.rb +3 -1
- data/lib/simple_form/wrappers/single.rb +7 -4
- data/lib/simple_form/wrappers.rb +2 -0
- data/lib/simple_form.rb +117 -18
- data/test/action_view_extensions/builder_test.rb +42 -41
- data/test/action_view_extensions/form_helper_test.rb +36 -16
- data/test/components/custom_components_test.rb +62 -0
- data/test/components/label_test.rb +70 -41
- data/test/form_builder/association_test.rb +79 -37
- data/test/form_builder/button_test.rb +11 -10
- data/test/form_builder/error_notification_test.rb +2 -1
- data/test/form_builder/error_test.rb +173 -24
- data/test/form_builder/general_test.rb +171 -73
- data/test/form_builder/hint_test.rb +24 -18
- data/test/form_builder/input_field_test.rb +132 -56
- data/test/form_builder/label_test.rb +68 -13
- data/test/form_builder/wrapper_test.rb +190 -22
- data/test/generators/simple_form_generator_test.rb +8 -7
- data/test/inputs/boolean_input_test.rb +89 -6
- data/test/inputs/collection_check_boxes_input_test.rb +109 -25
- data/test/inputs/collection_radio_buttons_input_test.rb +168 -54
- data/test/inputs/collection_select_input_test.rb +183 -77
- data/test/inputs/datetime_input_test.rb +131 -50
- data/test/inputs/disabled_test.rb +16 -15
- data/test/inputs/discovery_test.rb +58 -6
- data/test/inputs/file_input_test.rb +3 -2
- data/test/inputs/general_test.rb +23 -22
- data/test/inputs/grouped_collection_select_input_test.rb +54 -17
- data/test/inputs/hidden_input_test.rb +5 -4
- data/test/inputs/numeric_input_test.rb +48 -44
- data/test/inputs/priority_input_test.rb +23 -14
- data/test/inputs/readonly_test.rb +20 -19
- data/test/inputs/required_test.rb +58 -13
- data/test/inputs/string_input_test.rb +62 -33
- data/test/inputs/text_input_test.rb +20 -7
- data/test/simple_form_test.rb +9 -0
- data/test/support/discovery_inputs.rb +33 -2
- data/test/support/misc_helpers.rb +113 -5
- data/test/support/mock_controller.rb +7 -1
- data/test/support/models.rb +137 -37
- data/test/test_helper.rb +15 -1
- metadata +25 -33
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
require 'test_helper'
|
|
3
4
|
|
|
@@ -6,14 +7,14 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
6
7
|
SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
|
|
7
8
|
end
|
|
8
9
|
|
|
9
|
-
test 'input
|
|
10
|
+
test 'input generates a boolean select with options by default for select types' do
|
|
10
11
|
with_input_for @user, :active, :select
|
|
11
12
|
assert_select 'select.select#user_active'
|
|
12
13
|
assert_select 'select option[value=true]', 'Yes'
|
|
13
14
|
assert_select 'select option[value=false]', 'No'
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
test 'input as select
|
|
17
|
+
test 'input as select uses i18n to translate select boolean options' do
|
|
17
18
|
store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do
|
|
18
19
|
with_input_for @user, :active, :select
|
|
19
20
|
assert_select 'select option[value=true]', 'Sim'
|
|
@@ -21,67 +22,67 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
24
|
|
|
24
|
-
test 'input
|
|
25
|
-
with_input_for @user, :name, :select, collection: [
|
|
25
|
+
test 'input allows overriding collection for select types' do
|
|
26
|
+
with_input_for @user, :name, :select, collection: %w[Jose Carlos]
|
|
26
27
|
assert_select 'select.select#user_name'
|
|
27
28
|
assert_select 'select option', 'Jose'
|
|
28
29
|
assert_select 'select option', 'Carlos'
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
test 'input
|
|
32
|
+
test 'input does automatic collection translation for select types using defaults key' do
|
|
32
33
|
store_translations(:en, simple_form: { options: { defaults: {
|
|
33
|
-
gender: { male: 'Male', female: 'Female'}
|
|
34
|
-
} } }
|
|
35
|
-
with_input_for @user, :gender, :select, collection: [
|
|
34
|
+
gender: { male: 'Male', female: 'Female' }
|
|
35
|
+
} } }) do
|
|
36
|
+
with_input_for @user, :gender, :select, collection: %i[male female]
|
|
36
37
|
assert_select 'select.select#user_gender'
|
|
37
38
|
assert_select 'select option', 'Male'
|
|
38
39
|
assert_select 'select option', 'Female'
|
|
39
40
|
end
|
|
40
41
|
end
|
|
41
42
|
|
|
42
|
-
test 'input
|
|
43
|
+
test 'input does automatic collection translation for select types using specific object key' do
|
|
43
44
|
store_translations(:en, simple_form: { options: { user: {
|
|
44
|
-
gender: { male: 'Male', female: 'Female'}
|
|
45
|
-
} } }
|
|
46
|
-
with_input_for @user, :gender, :select, collection: [
|
|
45
|
+
gender: { male: 'Male', female: 'Female' }
|
|
46
|
+
} } }) do
|
|
47
|
+
with_input_for @user, :gender, :select, collection: %i[male female]
|
|
47
48
|
assert_select 'select.select#user_gender'
|
|
48
49
|
assert_select 'select option', 'Male'
|
|
49
50
|
assert_select 'select option', 'Female'
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
|
53
|
-
test 'input
|
|
54
|
+
test 'input marks the selected value by default' do
|
|
54
55
|
@user.name = "Carlos"
|
|
55
|
-
with_input_for @user, :name, :select, collection: [
|
|
56
|
+
with_input_for @user, :name, :select, collection: %w[Jose Carlos]
|
|
56
57
|
assert_select 'select option[selected=selected]', 'Carlos'
|
|
57
58
|
end
|
|
58
59
|
|
|
59
|
-
test 'input
|
|
60
|
+
test 'input accepts html options as the last element of collection' do
|
|
60
61
|
with_input_for @user, :name, :select, collection: [['Jose', class: 'foo']]
|
|
61
62
|
assert_select 'select.select#user_name'
|
|
62
63
|
assert_select 'select option.foo', 'Jose'
|
|
63
64
|
end
|
|
64
65
|
|
|
65
|
-
test 'input
|
|
66
|
+
test 'input marks the selected value also when using integers' do
|
|
66
67
|
@user.age = 18
|
|
67
68
|
with_input_for @user, :age, :select, collection: 18..60
|
|
68
69
|
assert_select 'select option[selected=selected]', '18'
|
|
69
70
|
end
|
|
70
71
|
|
|
71
|
-
test 'input
|
|
72
|
+
test 'input marks the selected value when using booleans and select' do
|
|
72
73
|
@user.active = false
|
|
73
74
|
with_input_for @user, :active, :select
|
|
74
75
|
assert_no_select 'select option[selected][value=true]', 'Yes'
|
|
75
76
|
assert_select 'select option[selected][value=false]', 'No'
|
|
76
77
|
end
|
|
77
78
|
|
|
78
|
-
test 'input
|
|
79
|
+
test 'input sets the correct value when using a collection that includes floats' do
|
|
79
80
|
with_input_for @user, :age, :select, collection: [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
|
|
80
81
|
assert_select 'select option[value="2.0"]'
|
|
81
82
|
assert_select 'select option[value="2.5"]'
|
|
82
83
|
end
|
|
83
84
|
|
|
84
|
-
test 'input
|
|
85
|
+
test 'input sets the correct values when using a collection that uses mixed values' do
|
|
85
86
|
with_input_for @user, :age, :select, collection: ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
|
|
86
87
|
assert_select 'select option[value="Hello Kitty"]'
|
|
87
88
|
assert_select 'select option[value="2"]'
|
|
@@ -92,179 +93,284 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
92
93
|
assert_select 'select option[value="false"]'
|
|
93
94
|
end
|
|
94
95
|
|
|
95
|
-
test 'input
|
|
96
|
+
test 'input includes a blank option even if :include_blank is set to false if the collection includes a nil value' do
|
|
96
97
|
with_input_for @user, :age, :select, collection: [nil], include_blank: false
|
|
97
98
|
assert_select 'select option[value=""]'
|
|
98
99
|
end
|
|
99
100
|
|
|
100
|
-
test 'input
|
|
101
|
+
test 'input automatically sets include blank' do
|
|
101
102
|
with_input_for @user, :age, :select, collection: 18..30
|
|
102
|
-
assert_select 'select option[value=]', ''
|
|
103
|
+
assert_select 'select option[value=""]', ''
|
|
103
104
|
end
|
|
104
105
|
|
|
105
|
-
test 'input
|
|
106
|
+
test 'input translates include blank when set to :translate' do
|
|
107
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
108
|
+
age: 'Rather not say'
|
|
109
|
+
} } }) do
|
|
110
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
|
111
|
+
assert_select 'select option[value=""]', 'Rather not say'
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
test 'input translates include blank with a default' do
|
|
116
|
+
store_translations(:en, simple_form: { include_blanks: { defaults: {
|
|
117
|
+
age: 'Rather not say'
|
|
118
|
+
} } }) do
|
|
119
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
|
120
|
+
assert_select 'select option[value=""]', 'Rather not say'
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
test 'input does not translate include blank when set to a string' do
|
|
125
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
126
|
+
age: 'Rather not say'
|
|
127
|
+
} } }) do
|
|
128
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: 'Young at heart'
|
|
129
|
+
assert_select 'select option[value=""]', 'Young at heart'
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
test 'input does not translate include blank when automatically set' do
|
|
134
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
135
|
+
age: 'Rather not say'
|
|
136
|
+
} } }) do
|
|
137
|
+
with_input_for @user, :age, :select, collection: 18..30
|
|
138
|
+
assert_select 'select option[value=""]', ''
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
test 'input does not translate include blank when set to true' do
|
|
143
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
144
|
+
age: 'Rather not say'
|
|
145
|
+
} } }) do
|
|
146
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: true
|
|
147
|
+
assert_select 'select option[value=""]', ''
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
test 'input does not translate include blank when set to false' do
|
|
152
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
153
|
+
age: 'Rather not say'
|
|
154
|
+
} } }) do
|
|
155
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
|
156
|
+
assert_no_select 'select option[value=""]'
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
test 'input does not set include blank if otherwise is told' do
|
|
106
161
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
|
107
|
-
assert_no_select 'select option[value=]'
|
|
162
|
+
assert_no_select 'select option[value=""]'
|
|
108
163
|
end
|
|
109
164
|
|
|
110
|
-
test 'input
|
|
165
|
+
test 'input does not set include blank if prompt is given' do
|
|
111
166
|
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
|
112
|
-
assert_no_select 'select option[value=]', ''
|
|
167
|
+
assert_no_select 'select option[value=""]', ''
|
|
113
168
|
end
|
|
114
169
|
|
|
115
|
-
test 'input
|
|
170
|
+
test 'input does not set include blank if multiple is given' do
|
|
116
171
|
with_input_for @user, :age, :select, collection: 18..30, input_html: { multiple: true }
|
|
117
|
-
assert_no_select 'select option[value=]', ''
|
|
172
|
+
assert_no_select 'select option[value=""]', ''
|
|
118
173
|
end
|
|
119
174
|
|
|
120
|
-
test 'input
|
|
175
|
+
test 'input translates prompt when set to :translate' do
|
|
176
|
+
store_translations(:en, simple_form: { prompts: { user: {
|
|
177
|
+
age: 'Select age:'
|
|
178
|
+
} } }) do
|
|
179
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
180
|
+
assert_select 'select option[value=""]', 'Select age:'
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
test 'input translates prompt with a default' do
|
|
185
|
+
store_translations(:en, simple_form: { prompts: { defaults: {
|
|
186
|
+
age: 'Select age:'
|
|
187
|
+
} } }) do
|
|
188
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
189
|
+
assert_select 'select option[value=""]', 'Select age:'
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
test 'input does not translate prompt when set to a string' do
|
|
194
|
+
store_translations(:en, simple_form: { prompts: { user: {
|
|
195
|
+
age: 'Select age:'
|
|
196
|
+
} } }) do
|
|
197
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: 'Do it:'
|
|
198
|
+
assert_select 'select option[value=""]', 'Do it:'
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
test 'input does not translate prompt when set to false' do
|
|
203
|
+
store_translations(:en, simple_form: { prompts: { user: {
|
|
204
|
+
age: 'Select age:'
|
|
205
|
+
} } }) do
|
|
206
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: false
|
|
207
|
+
assert_no_select 'select option[value=""]'
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
test 'input uses Rails prompt translation as a fallback' do
|
|
212
|
+
store_translations(:en, helpers: { select: {
|
|
213
|
+
prompt: 'Select value:'
|
|
214
|
+
} }) do
|
|
215
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
216
|
+
assert_select 'select option[value=""]', "Select value:"
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
test 'input detects label and value on collections' do
|
|
121
221
|
users = [User.build(id: 1, name: "Jose"), User.build(id: 2, name: "Carlos")]
|
|
122
222
|
with_input_for @user, :description, :select, collection: users
|
|
123
|
-
assert_select 'select option[value=1]', 'Jose'
|
|
124
|
-
assert_select 'select option[value=2]', 'Carlos'
|
|
223
|
+
assert_select 'select option[value="1"]', 'Jose'
|
|
224
|
+
assert_select 'select option[value="2"]', 'Carlos'
|
|
125
225
|
end
|
|
126
226
|
|
|
127
|
-
test 'input
|
|
128
|
-
with_input_for @user, :description, :select, collection: [
|
|
227
|
+
test 'input disables the anothers components when the option is a object' do
|
|
228
|
+
with_input_for @user, :description, :select, collection: %w[Jose Carlos], disabled: true
|
|
129
229
|
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
|
130
230
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
131
231
|
assert_select 'select[disabled=disabled]'
|
|
132
232
|
assert_select 'div.disabled'
|
|
133
233
|
end
|
|
134
234
|
|
|
135
|
-
test 'input
|
|
136
|
-
with_input_for @user, :description, :select, collection: [
|
|
235
|
+
test 'input does not disable the anothers components when the option is a object' do
|
|
236
|
+
with_input_for @user, :description, :select, collection: %w[Jose Carlos], disabled: 'Jose'
|
|
137
237
|
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
|
138
238
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
139
239
|
assert_no_select 'select[disabled=disabled]'
|
|
140
240
|
assert_no_select 'div.disabled'
|
|
141
241
|
end
|
|
142
242
|
|
|
143
|
-
test 'input
|
|
243
|
+
test 'input allows overriding label and value method using a lambda for collection selects' do
|
|
144
244
|
with_input_for @user, :name, :select,
|
|
145
|
-
collection: [
|
|
146
|
-
label_method:
|
|
147
|
-
value_method:
|
|
245
|
+
collection: %w[Jose Carlos],
|
|
246
|
+
label_method: ->(i) { i.upcase },
|
|
247
|
+
value_method: ->(i) { i.downcase }
|
|
148
248
|
assert_select 'select option[value=jose]', "JOSE"
|
|
149
249
|
assert_select 'select option[value=carlos]', "CARLOS"
|
|
150
250
|
end
|
|
151
251
|
|
|
152
|
-
test 'input
|
|
252
|
+
test 'input allows overriding only label but not value method using a lambda for collection select' do
|
|
153
253
|
with_input_for @user, :name, :select,
|
|
154
|
-
collection: [
|
|
155
|
-
label_method:
|
|
254
|
+
collection: %w[Jose Carlos],
|
|
255
|
+
label_method: ->(i) { i.upcase }
|
|
156
256
|
assert_select 'select option[value=Jose]', "JOSE"
|
|
157
257
|
assert_select 'select option[value=Carlos]', "CARLOS"
|
|
158
258
|
end
|
|
159
259
|
|
|
160
|
-
test 'input
|
|
260
|
+
test 'input allows overriding only value but not label method using a lambda for collection select' do
|
|
161
261
|
with_input_for @user, :name, :select,
|
|
162
|
-
collection: [
|
|
163
|
-
value_method:
|
|
262
|
+
collection: %w[Jose Carlos],
|
|
263
|
+
value_method: ->(i) { i.downcase }
|
|
164
264
|
assert_select 'select option[value=jose]', "Jose"
|
|
165
265
|
assert_select 'select option[value=carlos]', "Carlos"
|
|
166
266
|
end
|
|
167
267
|
|
|
168
|
-
test 'input
|
|
169
|
-
with_input_for @user, :name, :select, collection: [
|
|
268
|
+
test 'input allows symbols for collections' do
|
|
269
|
+
with_input_for @user, :name, :select, collection: %i[jose carlos]
|
|
170
270
|
assert_select 'select.select#user_name'
|
|
171
271
|
assert_select 'select option[value=jose]', 'jose'
|
|
172
272
|
assert_select 'select option[value=carlos]', 'carlos'
|
|
173
273
|
end
|
|
174
274
|
|
|
175
|
-
test 'collection input with select type
|
|
176
|
-
with_input_for @user, :name, :select, include_blank: true, collection: [
|
|
275
|
+
test 'collection input with select type generates required html attribute only with blank option' do
|
|
276
|
+
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
|
|
277
|
+
assert_select 'select.required'
|
|
278
|
+
assert_select 'select[required]'
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
test 'collection input with select type generates required html attribute only with blank option or prompt' do
|
|
282
|
+
with_input_for @user, :name, :select, prompt: 'Name...', collection: %w[Jose Carlos]
|
|
177
283
|
assert_select 'select.required'
|
|
178
284
|
assert_select 'select[required]'
|
|
179
285
|
end
|
|
180
286
|
|
|
181
|
-
test 'collection input with select type
|
|
182
|
-
with_input_for @user, :name, :select, include_blank: false, collection: [
|
|
287
|
+
test 'collection input with select type does not generate required html attribute without blank option' do
|
|
288
|
+
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
|
183
289
|
assert_select 'select.required'
|
|
184
290
|
assert_no_select 'select[required]'
|
|
185
291
|
assert_no_select 'select[aria-required=true]'
|
|
186
292
|
end
|
|
187
293
|
|
|
188
|
-
test 'collection input with select type with multiple attribute
|
|
189
|
-
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: [
|
|
294
|
+
test 'collection input with select type with multiple attribute generates required html attribute without blank option' do
|
|
295
|
+
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
|
190
296
|
assert_select 'select.required'
|
|
191
297
|
assert_select 'select[required]'
|
|
192
298
|
end
|
|
193
299
|
|
|
194
|
-
test 'collection input with select type with multiple attribute
|
|
195
|
-
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: [
|
|
300
|
+
test 'collection input with select type with multiple attribute generates required html attribute with blank option' do
|
|
301
|
+
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
|
196
302
|
assert_select 'select.required'
|
|
197
303
|
assert_select 'select[required]'
|
|
198
304
|
end
|
|
199
305
|
|
|
200
306
|
test 'with a blank option, a collection input of type select has an aria-required html attribute' do
|
|
201
|
-
with_input_for @user, :name, :select, include_blank: true, collection: [
|
|
307
|
+
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
|
|
202
308
|
assert_select 'select.required'
|
|
203
309
|
assert_select 'select[aria-required=true]'
|
|
204
310
|
end
|
|
205
311
|
|
|
206
312
|
test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do
|
|
207
|
-
with_input_for @user, :name, :select, include_blank: false, collection: [
|
|
313
|
+
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
|
208
314
|
assert_select 'select.required'
|
|
209
315
|
assert_no_select 'select[aria-required]'
|
|
210
316
|
end
|
|
211
317
|
|
|
212
318
|
test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do
|
|
213
|
-
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: [
|
|
319
|
+
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
|
214
320
|
assert_select 'select.required'
|
|
215
321
|
assert_select 'select[aria-required=true]'
|
|
216
322
|
end
|
|
217
323
|
|
|
218
324
|
test 'with a blank option and a multiple option, a collection input of type select has an aria-required html attribute' do
|
|
219
|
-
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: [
|
|
325
|
+
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
|
220
326
|
assert_select 'select.required'
|
|
221
327
|
assert_select 'select[aria-required]'
|
|
222
328
|
end
|
|
223
329
|
|
|
224
|
-
test 'input
|
|
225
|
-
with_input_for @user, :name, :select, collection: [
|
|
226
|
-
disabled:
|
|
330
|
+
test 'input allows disabled options with a lambda for collection select' do
|
|
331
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
|
332
|
+
disabled: ->(x) { x == "Carlos" }
|
|
227
333
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
228
334
|
assert_select 'select option[value=Antonio]', 'Antonio'
|
|
229
335
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
230
336
|
end
|
|
231
337
|
|
|
232
|
-
test 'input
|
|
233
|
-
with_input_for @user, :name, :select, collection: [
|
|
234
|
-
disabled:
|
|
338
|
+
test 'input allows disabled and label method with lambdas for collection select' do
|
|
339
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
|
340
|
+
disabled: ->(x) { x == "Carlos" }, label_method: ->(x) { x.upcase }
|
|
235
341
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
|
236
342
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
237
343
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
238
344
|
end
|
|
239
345
|
|
|
240
|
-
test 'input
|
|
241
|
-
with_input_for @user, :name, :select, collection: [
|
|
242
|
-
disabled: "Carlos", label_method:
|
|
346
|
+
test 'input allows a non lambda disabled option with lambda label method for collections' do
|
|
347
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
|
348
|
+
disabled: "Carlos", label_method: ->(x) { x.upcase }
|
|
243
349
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
|
244
350
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
245
351
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
246
352
|
end
|
|
247
353
|
|
|
248
|
-
test 'input
|
|
249
|
-
with_input_for @user, :name, :select, collection: [
|
|
250
|
-
selected:
|
|
354
|
+
test 'input allows selected and label method with lambdas for collection select' do
|
|
355
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
|
356
|
+
selected: ->(x) { x == "Carlos" }, label_method: ->(x) { x.upcase }
|
|
251
357
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
|
252
358
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
253
359
|
assert_no_select 'select option[value=Antonio][selected]'
|
|
254
360
|
end
|
|
255
361
|
|
|
256
|
-
test 'input
|
|
257
|
-
with_input_for @user, :name, :select, collection: [
|
|
258
|
-
selected: "Carlos", label_method:
|
|
362
|
+
test 'input allows a non lambda selected option with lambda label method for collection select' do
|
|
363
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
|
364
|
+
selected: "Carlos", label_method: ->(x) { x.upcase }
|
|
259
365
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
|
260
366
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
261
367
|
assert_no_select 'select option[value=Antonio][selected]'
|
|
262
368
|
end
|
|
263
369
|
|
|
264
|
-
test 'input
|
|
370
|
+
test 'input does not override default selection through attribute value with label method as lambda for collection select' do
|
|
265
371
|
@user.name = "Carlos"
|
|
266
|
-
with_input_for @user, :name, :select, collection: [
|
|
267
|
-
label_method:
|
|
372
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
|
373
|
+
label_method: ->(x) { x.upcase }
|
|
268
374
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
|
269
375
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
270
376
|
assert_no_select 'select option[value=Antonio][selected]'
|