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