simple_form 3.4.0 → 5.1.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 +5 -5
- data/CHANGELOG.md +118 -8
- data/MIT-LICENSE +2 -1
- data/README.md +235 -67
- data/lib/generators/simple_form/install_generator.rb +1 -0
- data/lib/generators/simple_form/templates/README +2 -3
- 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 +14 -7
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +360 -74
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +20 -8
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
- data/lib/simple_form/components/errors.rb +15 -2
- data/lib/simple_form/components/hints.rb +1 -0
- data/lib/simple_form/components/html5.rb +1 -0
- data/lib/simple_form/components/label_input.rb +2 -1
- data/lib/simple_form/components/labels.rb +12 -7
- data/lib/simple_form/components/maxlength.rb +4 -17
- data/lib/simple_form/components/min_max.rb +1 -0
- data/lib/simple_form/components/minlength.rb +5 -18
- data/lib/simple_form/components/pattern.rb +1 -0
- data/lib/simple_form/components/placeholders.rb +2 -1
- data/lib/simple_form/components/readonly.rb +1 -0
- data/lib/simple_form/components.rb +1 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +104 -29
- 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 +1 -0
- data/lib/simple_form/inputs/base.rb +24 -5
- data/lib/simple_form/inputs/block_input.rb +1 -0
- data/lib/simple_form/inputs/boolean_input.rb +4 -2
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +3 -2
- data/lib/simple_form/inputs/collection_input.rb +6 -7
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
- data/lib/simple_form/inputs/collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/color_input.rb +14 -0
- data/lib/simple_form/inputs/date_time_input.rb +1 -0
- data/lib/simple_form/inputs/file_input.rb +1 -0
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/hidden_input.rb +1 -0
- data/lib/simple_form/inputs/numeric_input.rb +1 -0
- data/lib/simple_form/inputs/password_input.rb +1 -0
- data/lib/simple_form/inputs/priority_input.rb +1 -4
- data/lib/simple_form/inputs/range_input.rb +1 -0
- data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
- data/lib/simple_form/inputs/string_input.rb +2 -1
- data/lib/simple_form/inputs/text_input.rb +1 -0
- data/lib/simple_form/inputs.rb +3 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +1 -0
- data/lib/simple_form/tags.rb +7 -2
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +1 -0
- data/lib/simple_form/wrappers/leaf.rb +2 -1
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/lib/simple_form/wrappers/root.rb +9 -2
- data/lib/simple_form/wrappers/single.rb +2 -1
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +79 -11
- data/test/action_view_extensions/builder_test.rb +28 -9
- data/test/action_view_extensions/form_helper_test.rb +3 -2
- data/test/components/custom_components_test.rb +62 -0
- data/test/components/label_test.rb +33 -8
- data/test/form_builder/association_test.rb +33 -2
- data/test/form_builder/button_test.rb +1 -0
- data/test/form_builder/error_notification_test.rb +1 -0
- data/test/form_builder/error_test.rb +12 -0
- data/test/form_builder/general_test.rb +75 -13
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +30 -10
- data/test/form_builder/label_test.rb +10 -4
- data/test/form_builder/wrapper_test.rb +32 -5
- data/test/generators/simple_form_generator_test.rb +4 -3
- data/test/inputs/boolean_input_test.rb +17 -0
- data/test/inputs/collection_check_boxes_input_test.rb +38 -18
- data/test/inputs/collection_radio_buttons_input_test.rb +48 -28
- data/test/inputs/collection_select_input_test.rb +46 -43
- data/test/inputs/color_input_test.rb +10 -0
- data/test/inputs/datetime_input_test.rb +7 -16
- data/test/inputs/disabled_test.rb +14 -0
- data/test/inputs/discovery_test.rb +22 -0
- data/test/inputs/file_input_test.rb +1 -0
- data/test/inputs/general_test.rb +3 -2
- data/test/inputs/grouped_collection_select_input_test.rb +11 -10
- data/test/inputs/hidden_input_test.rb +1 -0
- data/test/inputs/numeric_input_test.rb +2 -1
- data/test/inputs/priority_input_test.rb +7 -14
- data/test/inputs/readonly_test.rb +1 -0
- data/test/inputs/required_test.rb +1 -0
- data/test/inputs/rich_text_area_input_test.rb +15 -0
- data/test/inputs/string_input_test.rb +10 -16
- data/test/inputs/text_input_test.rb +1 -0
- data/test/simple_form_test.rb +1 -0
- data/test/support/discovery_inputs.rb +8 -0
- data/test/support/misc_helpers.rb +22 -1
- data/test/support/mock_controller.rb +7 -1
- data/test/support/models.rb +80 -18
- data/test/test_helper.rb +9 -4
- metadata +49 -55
- data/lib/simple_form/i18n_cache.rb +0 -22
@@ -1,11 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
4
5
|
class CollectionSelectInputTest < ActionView::TestCase
|
5
|
-
setup do
|
6
|
-
SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
|
7
|
-
end
|
8
|
-
|
9
6
|
test 'input generates a boolean select with options by default for select types' do
|
10
7
|
with_input_for @user, :active, :select
|
11
8
|
assert_select 'select.select#user_active'
|
@@ -22,7 +19,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
22
19
|
end
|
23
20
|
|
24
21
|
test 'input allows overriding collection for select types' do
|
25
|
-
with_input_for @user, :name, :select, collection: [
|
22
|
+
with_input_for @user, :name, :select, collection: %w[Jose Carlos]
|
26
23
|
assert_select 'select.select#user_name'
|
27
24
|
assert_select 'select option', 'Jose'
|
28
25
|
assert_select 'select option', 'Carlos'
|
@@ -30,9 +27,9 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
30
27
|
|
31
28
|
test 'input does automatic collection translation for select types using defaults key' do
|
32
29
|
store_translations(:en, simple_form: { options: { defaults: {
|
33
|
-
gender: { male: 'Male', female: 'Female'}
|
30
|
+
gender: { male: 'Male', female: 'Female' }
|
34
31
|
} } }) do
|
35
|
-
with_input_for @user, :gender, :select, collection: [
|
32
|
+
with_input_for @user, :gender, :select, collection: %i[male female]
|
36
33
|
assert_select 'select.select#user_gender'
|
37
34
|
assert_select 'select option', 'Male'
|
38
35
|
assert_select 'select option', 'Female'
|
@@ -41,9 +38,9 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
41
38
|
|
42
39
|
test 'input does automatic collection translation for select types using specific object key' do
|
43
40
|
store_translations(:en, simple_form: { options: { user: {
|
44
|
-
gender: { male: 'Male', female: 'Female'}
|
41
|
+
gender: { male: 'Male', female: 'Female' }
|
45
42
|
} } }) do
|
46
|
-
with_input_for @user, :gender, :select, collection: [
|
43
|
+
with_input_for @user, :gender, :select, collection: %i[male female]
|
47
44
|
assert_select 'select.select#user_gender'
|
48
45
|
assert_select 'select option', 'Male'
|
49
46
|
assert_select 'select option', 'Female'
|
@@ -52,7 +49,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
52
49
|
|
53
50
|
test 'input marks the selected value by default' do
|
54
51
|
@user.name = "Carlos"
|
55
|
-
with_input_for @user, :name, :select, collection: [
|
52
|
+
with_input_for @user, :name, :select, collection: %w[Jose Carlos]
|
56
53
|
assert_select 'select option[selected=selected]', 'Carlos'
|
57
54
|
end
|
58
55
|
|
@@ -113,7 +110,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
113
110
|
|
114
111
|
test 'input translates include blank with a default' do
|
115
112
|
store_translations(:en, simple_form: { include_blanks: { defaults: {
|
116
|
-
age: 'Rather not say'
|
113
|
+
age: 'Rather not say'
|
117
114
|
} } }) do
|
118
115
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
119
116
|
assert_select 'select option[value=""]', 'Rather not say'
|
@@ -182,7 +179,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
182
179
|
|
183
180
|
test 'input translates prompt with a default' do
|
184
181
|
store_translations(:en, simple_form: { prompts: { defaults: {
|
185
|
-
age: 'Select age:'
|
182
|
+
age: 'Select age:'
|
186
183
|
} } }) do
|
187
184
|
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
188
185
|
assert_select 'select option[value=""]', 'Select age:'
|
@@ -224,7 +221,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
224
221
|
end
|
225
222
|
|
226
223
|
test 'input disables the anothers components when the option is a object' do
|
227
|
-
with_input_for @user, :description, :select, collection: [
|
224
|
+
with_input_for @user, :description, :select, collection: %w[Jose Carlos], disabled: true
|
228
225
|
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
229
226
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
230
227
|
assert_select 'select[disabled=disabled]'
|
@@ -232,7 +229,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
232
229
|
end
|
233
230
|
|
234
231
|
test 'input does not disable the anothers components when the option is a object' do
|
235
|
-
with_input_for @user, :description, :select, collection: [
|
232
|
+
with_input_for @user, :description, :select, collection: %w[Jose Carlos], disabled: 'Jose'
|
236
233
|
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
237
234
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
238
235
|
assert_no_select 'select[disabled=disabled]'
|
@@ -241,126 +238,132 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
241
238
|
|
242
239
|
test 'input allows overriding label and value method using a lambda for collection selects' do
|
243
240
|
with_input_for @user, :name, :select,
|
244
|
-
collection: [
|
245
|
-
label_method:
|
246
|
-
value_method:
|
241
|
+
collection: %w[Jose Carlos],
|
242
|
+
label_method: ->(i) { i.upcase },
|
243
|
+
value_method: ->(i) { i.downcase }
|
247
244
|
assert_select 'select option[value=jose]', "JOSE"
|
248
245
|
assert_select 'select option[value=carlos]', "CARLOS"
|
249
246
|
end
|
250
247
|
|
251
248
|
test 'input allows overriding only label but not value method using a lambda for collection select' do
|
252
249
|
with_input_for @user, :name, :select,
|
253
|
-
collection: [
|
254
|
-
label_method:
|
250
|
+
collection: %w[Jose Carlos],
|
251
|
+
label_method: ->(i) { i.upcase }
|
255
252
|
assert_select 'select option[value=Jose]', "JOSE"
|
256
253
|
assert_select 'select option[value=Carlos]', "CARLOS"
|
257
254
|
end
|
258
255
|
|
259
256
|
test 'input allows overriding only value but not label method using a lambda for collection select' do
|
260
257
|
with_input_for @user, :name, :select,
|
261
|
-
collection: [
|
262
|
-
value_method:
|
258
|
+
collection: %w[Jose Carlos],
|
259
|
+
value_method: ->(i) { i.downcase }
|
263
260
|
assert_select 'select option[value=jose]', "Jose"
|
264
261
|
assert_select 'select option[value=carlos]', "Carlos"
|
265
262
|
end
|
266
263
|
|
267
264
|
test 'input allows symbols for collections' do
|
268
|
-
with_input_for @user, :name, :select, collection: [
|
265
|
+
with_input_for @user, :name, :select, collection: %i[jose carlos]
|
269
266
|
assert_select 'select.select#user_name'
|
270
267
|
assert_select 'select option[value=jose]', 'jose'
|
271
268
|
assert_select 'select option[value=carlos]', 'carlos'
|
272
269
|
end
|
273
270
|
|
274
271
|
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: [
|
272
|
+
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
|
276
273
|
assert_select 'select.required'
|
277
274
|
assert_select 'select[required]'
|
278
275
|
end
|
279
276
|
|
280
277
|
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: [
|
278
|
+
with_input_for @user, :name, :select, prompt: 'Name...', collection: %w[Jose Carlos]
|
282
279
|
assert_select 'select.required'
|
283
280
|
assert_select 'select[required]'
|
284
281
|
end
|
285
282
|
|
283
|
+
test "collection input generated aria-label should contain 'true'" do
|
284
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
285
|
+
assert_select 'select.required'
|
286
|
+
assert_select 'select[aria-required=true]'
|
287
|
+
end
|
288
|
+
|
286
289
|
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: [
|
290
|
+
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
288
291
|
assert_select 'select.required'
|
289
292
|
assert_no_select 'select[required]'
|
290
293
|
assert_no_select 'select[aria-required=true]'
|
291
294
|
end
|
292
295
|
|
293
296
|
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: [
|
297
|
+
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
295
298
|
assert_select 'select.required'
|
296
299
|
assert_select 'select[required]'
|
297
300
|
end
|
298
301
|
|
299
302
|
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: [
|
303
|
+
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
301
304
|
assert_select 'select.required'
|
302
305
|
assert_select 'select[required]'
|
303
306
|
end
|
304
307
|
|
305
308
|
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: [
|
309
|
+
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
|
307
310
|
assert_select 'select.required'
|
308
311
|
assert_select 'select[aria-required=true]'
|
309
312
|
end
|
310
313
|
|
311
314
|
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: [
|
315
|
+
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
313
316
|
assert_select 'select.required'
|
314
317
|
assert_no_select 'select[aria-required]'
|
315
318
|
end
|
316
319
|
|
317
320
|
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: [
|
321
|
+
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
319
322
|
assert_select 'select.required'
|
320
323
|
assert_select 'select[aria-required=true]'
|
321
324
|
end
|
322
325
|
|
323
326
|
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: [
|
327
|
+
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
325
328
|
assert_select 'select.required'
|
326
329
|
assert_select 'select[aria-required]'
|
327
330
|
end
|
328
331
|
|
329
332
|
test 'input allows disabled options with a lambda for collection select' do
|
330
|
-
with_input_for @user, :name, :select, collection: [
|
331
|
-
disabled:
|
333
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
334
|
+
disabled: ->(x) { x == "Carlos" }
|
332
335
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
333
336
|
assert_select 'select option[value=Antonio]', 'Antonio'
|
334
337
|
assert_no_select 'select option[value=Antonio][disabled]'
|
335
338
|
end
|
336
339
|
|
337
340
|
test 'input allows disabled and label method with lambdas for collection select' do
|
338
|
-
with_input_for @user, :name, :select, collection: [
|
339
|
-
disabled:
|
341
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
342
|
+
disabled: ->(x) { x == "Carlos" }, label_method: ->(x) { x.upcase }
|
340
343
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
341
344
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
342
345
|
assert_no_select 'select option[value=Antonio][disabled]'
|
343
346
|
end
|
344
347
|
|
345
348
|
test 'input allows a non lambda disabled option with lambda label method for collections' do
|
346
|
-
with_input_for @user, :name, :select, collection: [
|
347
|
-
disabled: "Carlos", label_method:
|
349
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
350
|
+
disabled: "Carlos", label_method: ->(x) { x.upcase }
|
348
351
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
349
352
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
350
353
|
assert_no_select 'select option[value=Antonio][disabled]'
|
351
354
|
end
|
352
355
|
|
353
356
|
test 'input allows selected and label method with lambdas for collection select' do
|
354
|
-
with_input_for @user, :name, :select, collection: [
|
355
|
-
selected:
|
357
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
358
|
+
selected: ->(x) { x == "Carlos" }, label_method: ->(x) { x.upcase }
|
356
359
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
357
360
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
358
361
|
assert_no_select 'select option[value=Antonio][selected]'
|
359
362
|
end
|
360
363
|
|
361
364
|
test 'input allows a non lambda selected option with lambda label method for collection select' do
|
362
|
-
with_input_for @user, :name, :select, collection: [
|
363
|
-
selected: "Carlos", label_method:
|
365
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
366
|
+
selected: "Carlos", label_method: ->(x) { x.upcase }
|
364
367
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
365
368
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
366
369
|
assert_no_select 'select option[value=Antonio][selected]'
|
@@ -368,8 +371,8 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
368
371
|
|
369
372
|
test 'input does not override default selection through attribute value with label method as lambda for collection select' do
|
370
373
|
@user.name = "Carlos"
|
371
|
-
with_input_for @user, :name, :select, collection: [
|
372
|
-
label_method:
|
374
|
+
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
375
|
+
label_method: ->(x) { x.upcase }
|
373
376
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
374
377
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
375
378
|
assert_no_select 'select option[value=Antonio][selected]'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class ColorInputTest < ActionView::TestCase
|
6
|
+
test 'input generates a color field' do
|
7
|
+
with_input_for @user, :favorite_color, :color
|
8
|
+
assert_select 'input[type=color].color#user_favorite_color'
|
9
|
+
end
|
10
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -5,12 +6,7 @@ require 'test_helper'
|
|
5
6
|
class DateTimeInputWithHtml5Test < ActionView::TestCase
|
6
7
|
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enbled' do
|
7
8
|
with_input_for @user, :created_at, :datetime, html5: true
|
8
|
-
|
9
|
-
if ActionPack::VERSION::STRING >= '5'
|
10
|
-
assert_select 'input[type="datetime-local"]'
|
11
|
-
elsif ActionPack::VERSION::STRING < '5'
|
12
|
-
assert_select 'input[type="datetime"]'
|
13
|
-
end
|
9
|
+
assert_select 'input[type="datetime-local"]'
|
14
10
|
end
|
15
11
|
|
16
12
|
test 'input generates a datetime select for datetime attributes' do
|
@@ -79,12 +75,7 @@ class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
|
79
75
|
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enabled' do
|
80
76
|
swap_wrapper do
|
81
77
|
with_input_for @user, :created_at, :datetime, html5: true
|
82
|
-
|
83
|
-
if ActionPack::VERSION::STRING >= '5'
|
84
|
-
assert_select 'input[type="datetime-local"]'
|
85
|
-
elsif ActionPack::VERSION::STRING < '5'
|
86
|
-
assert_select 'input[type="datetime"]'
|
87
|
-
end
|
78
|
+
assert_select 'input[type="datetime-local"]'
|
88
79
|
end
|
89
80
|
end
|
90
81
|
|
@@ -150,26 +141,26 @@ class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
|
150
141
|
end
|
151
142
|
|
152
143
|
test 'label uses i18n to get target for date input type' do
|
153
|
-
store_translations(:en, date: { order: [
|
144
|
+
store_translations(:en, date: { order: %w[month day year] }) do
|
154
145
|
with_input_for :project, :created_at, :date, html5: false
|
155
146
|
assert_select 'label[for=project_created_at_2i]'
|
156
147
|
end
|
157
148
|
end
|
158
149
|
|
159
150
|
test 'label uses i18n to get target for datetime input type' do
|
160
|
-
store_translations(:en, date: { order: [
|
151
|
+
store_translations(:en, date: { order: %w[month day year] }) do
|
161
152
|
with_input_for :project, :created_at, :datetime, html5: false
|
162
153
|
assert_select 'label[for=project_created_at_2i]'
|
163
154
|
end
|
164
155
|
end
|
165
156
|
|
166
157
|
test 'label uses order to get target when date input type' do
|
167
|
-
with_input_for :project, :created_at, :date, order: [
|
158
|
+
with_input_for :project, :created_at, :date, order: %w[month year day], html5: false
|
168
159
|
assert_select 'label[for=project_created_at_2i]'
|
169
160
|
end
|
170
161
|
|
171
162
|
test 'label uses order to get target when datetime input type' do
|
172
|
-
with_input_for :project, :created_at, :datetime, order: [
|
163
|
+
with_input_for :project, :created_at, :datetime, order: %w[month year day], html5: false
|
173
164
|
assert_select 'label[for=project_created_at_2i]'
|
174
165
|
end
|
175
166
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class DisabledTest < ActionView::TestCase
|
@@ -75,4 +76,17 @@ class DisabledTest < ActionView::TestCase
|
|
75
76
|
with_input_for @user, :created_at, :datetime
|
76
77
|
assert_no_select 'select.datetime.disabled[disabled]'
|
77
78
|
end
|
79
|
+
|
80
|
+
test 'input_field collection allows disabled select' do
|
81
|
+
with_input_field_for @user, :description, collection: ['foo', 'bar'], disabled: true
|
82
|
+
assert_select 'select[disabled]'
|
83
|
+
assert_no_select 'option[disabled]'
|
84
|
+
end
|
85
|
+
|
86
|
+
test 'input_field collection allows individual disabled options' do
|
87
|
+
with_input_field_for @user, :description, collection: ['foo', 'bar'], disabled: 'bar'
|
88
|
+
assert_no_select 'select[disabled]'
|
89
|
+
assert_no_select 'option[disabled][value=foo]'
|
90
|
+
assert_select 'option[disabled][value=bar]'
|
91
|
+
end
|
78
92
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class DiscoveryTest < ActionView::TestCase
|
@@ -14,6 +15,7 @@ class DiscoveryTest < ActionView::TestCase
|
|
14
15
|
Object.send :remove_const, :CustomizedInput
|
15
16
|
Object.send :remove_const, :DeprecatedInput
|
16
17
|
Object.send :remove_const, :CollectionSelectInput
|
18
|
+
Object.send :remove_const, :FileInput
|
17
19
|
CustomInputs.send :remove_const, :CustomizedInput
|
18
20
|
CustomInputs.send :remove_const, :PasswordInput
|
19
21
|
CustomInputs.send :remove_const, :NumericInput
|
@@ -108,6 +110,26 @@ class DiscoveryTest < ActionView::TestCase
|
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
113
|
+
test 'does not duplicate the html classes giving a extra class' do
|
114
|
+
discovery do
|
115
|
+
swap SimpleForm, input_class: 'custom-default-input-class' do
|
116
|
+
with_form_for @user, :active, as: :select
|
117
|
+
assert_select 'form select#user_active.select' do
|
118
|
+
# Make sure class list contains 'chosen' only once.
|
119
|
+
assert_select ":match('class', ?)", /^(?!.*\bchosen\b.*\bchosen\b).*\bchosen\b.*$/
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'new inputs can override the default input_html_classes' do
|
126
|
+
discovery do
|
127
|
+
with_form_for @user, :avatar, as: :file
|
128
|
+
assert_no_select 'form input[type=file]#user_avatar.file.file-upload'
|
129
|
+
assert_select 'form input[type=file]#user_avatar.file-upload'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
111
133
|
test 'inputs method without wrapper_options are deprecated' do
|
112
134
|
discovery do
|
113
135
|
assert_deprecated do
|
data/test/inputs/general_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -119,12 +120,12 @@ class InputTest < ActionView::TestCase
|
|
119
120
|
end
|
120
121
|
|
121
122
|
test 'input as select with collection is generated properly when object is not present' do
|
122
|
-
with_input_for :project, :name, :select, collection: [
|
123
|
+
with_input_for :project, :name, :select, collection: %w[Jose Carlos]
|
123
124
|
assert_select 'select.select#project_name'
|
124
125
|
end
|
125
126
|
|
126
127
|
test 'input does not generate empty css class' do
|
127
|
-
swap SimpleForm, generate_additional_classes_for: [
|
128
|
+
swap SimpleForm, generate_additional_classes_for: %i[wrapper label] do
|
128
129
|
with_input_for :project, :name, :string
|
129
130
|
assert_no_select 'input#project_name[class]'
|
130
131
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
4
5
|
class GroupedCollectionSelectInputTest < ActionView::TestCase
|
5
6
|
test 'grouped collection accepts array collection form' do
|
6
7
|
with_input_for @user, :tag_ids, :grouped_select,
|
7
|
-
collection: [['Authors', [
|
8
|
+
collection: [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]]],
|
8
9
|
group_method: :last
|
9
10
|
|
10
11
|
assert_select 'select.grouped_select#user_tag_ids' do
|
@@ -31,7 +32,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
31
32
|
|
32
33
|
test 'grouped collection accepts proc as collection' do
|
33
34
|
with_input_for @user, :tag_ids, :grouped_select,
|
34
|
-
collection:
|
35
|
+
collection: proc { [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]]] },
|
35
36
|
group_method: :last
|
36
37
|
|
37
38
|
assert_select 'select.grouped_select#user_tag_ids' do
|
@@ -49,7 +50,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
49
50
|
|
50
51
|
test 'grouped collection accepts hash collection form' do
|
51
52
|
with_input_for @user, :tag_ids, :grouped_select,
|
52
|
-
collection: {
|
53
|
+
collection: { Authors: %w[Jose Carlos], General: %w[Bob John] },
|
53
54
|
group_method: :last
|
54
55
|
|
55
56
|
assert_select 'select.grouped_select#user_tag_ids' do
|
@@ -67,7 +68,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
67
68
|
|
68
69
|
test 'grouped collection accepts group_label_method option' do
|
69
70
|
with_input_for @user, :tag_ids, :grouped_select,
|
70
|
-
collection: { [
|
71
|
+
collection: { %w[Jose Carlos] => 'Authors' },
|
71
72
|
group_method: :first,
|
72
73
|
group_label_method: :last
|
73
74
|
|
@@ -80,7 +81,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
80
81
|
end
|
81
82
|
|
82
83
|
test 'grouped collection finds default label methods on the group objects' do
|
83
|
-
option_list = [
|
84
|
+
option_list = %w[Jose Carlos]
|
84
85
|
|
85
86
|
GroupedClass = Struct.new(:to_label, :options)
|
86
87
|
group = GroupedClass.new("Authors", option_list)
|
@@ -117,7 +118,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
117
118
|
|
118
119
|
test 'grouped collection accepts label and value methods options' do
|
119
120
|
with_input_for @user, :tag_ids, :grouped_select,
|
120
|
-
collection: {
|
121
|
+
collection: { Authors: %w[Jose Carlos] },
|
121
122
|
group_method: :last,
|
122
123
|
label_method: :upcase,
|
123
124
|
value_method: :downcase
|
@@ -132,10 +133,10 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
132
133
|
|
133
134
|
test 'grouped collection allows overriding label and value methods using a lambda' do
|
134
135
|
with_input_for @user, :tag_ids, :grouped_select,
|
135
|
-
collection: {
|
136
|
+
collection: { Authors: %w[Jose Carlos] },
|
136
137
|
group_method: :last,
|
137
|
-
label_method:
|
138
|
-
value_method:
|
138
|
+
label_method: ->(i) { i.upcase },
|
139
|
+
value_method: ->(i) { i.downcase }
|
139
140
|
|
140
141
|
assert_select 'select.grouped_select#user_tag_ids' do
|
141
142
|
assert_select 'optgroup[label=Authors]' do
|
@@ -148,7 +149,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
148
149
|
test 'grouped collection with associations' do
|
149
150
|
tag_groups = [
|
150
151
|
TagGroup.new(1, "Group of Tags", [Tag.new(1, "Tag 1"), Tag.new(2, "Tag 2")]),
|
151
|
-
TagGroup.new(2, "Other group", [Tag.new(3, "Tag 3"), Tag.new(4,"Tag 4")])
|
152
|
+
TagGroup.new(2, "Other group", [Tag.new(3, "Tag 3"), Tag.new(4, "Tag 4")])
|
152
153
|
]
|
153
154
|
|
154
155
|
with_input_for @user, :tag_ids, :grouped_select,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -156,7 +157,7 @@ class NumericInputTest < ActionView::TestCase
|
|
156
157
|
end
|
157
158
|
end
|
158
159
|
|
159
|
-
[
|
160
|
+
%i[integer float decimal].each do |type|
|
160
161
|
test "#{type} input infers min value from attributes with greater than or equal validation" do
|
161
162
|
with_input_for @validating_user, :age, type
|
162
163
|
assert_select 'input[min="18"]'
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -5,22 +6,14 @@ class PriorityInputTest < ActionView::TestCase
|
|
5
6
|
test 'input generates a country select field' do
|
6
7
|
with_input_for @user, :country, :country
|
7
8
|
assert_select 'select#user_country'
|
8
|
-
|
9
|
-
assert_select 'select option[value=BR]', 'Brazil'
|
10
|
-
elsif ActionPack::VERSION::STRING < '5'
|
11
|
-
assert_select 'select option[value=Brazil]', 'Brazil'
|
12
|
-
end
|
9
|
+
assert_select 'select option[value=BR]', 'Brazil'
|
13
10
|
assert_no_select 'select option[value=""][disabled=disabled]'
|
14
11
|
end
|
15
12
|
|
16
13
|
test 'input generates a country select with SimpleForm default' do
|
17
14
|
swap SimpleForm, country_priority: [ 'Brazil' ] do
|
18
15
|
with_input_for @user, :country, :country
|
19
|
-
|
20
|
-
assert_select 'select option[value="---------------"][disabled=disabled]'
|
21
|
-
elsif ActionPack::VERSION::STRING < '5'
|
22
|
-
assert_select 'select option[value=""][disabled=disabled]'
|
23
|
-
end
|
16
|
+
assert_select 'select option[value="---------------"][disabled=disabled]'
|
24
17
|
end
|
25
18
|
end
|
26
19
|
|
@@ -43,15 +36,15 @@ class PriorityInputTest < ActionView::TestCase
|
|
43
36
|
assert_no_select 'select option[value=""]', /^$/
|
44
37
|
end
|
45
38
|
|
46
|
-
test 'priority input does
|
39
|
+
test 'priority input does generate select element with required html attribute' do
|
47
40
|
with_input_for @user, :country, :country
|
48
41
|
assert_select 'select.required'
|
49
|
-
|
42
|
+
assert_select 'select[required]'
|
50
43
|
end
|
51
44
|
|
52
|
-
test 'priority input does
|
45
|
+
test 'priority input does generate select element with aria-required html attribute' do
|
53
46
|
with_input_for @user, :country, :country
|
54
47
|
assert_select 'select.required'
|
55
|
-
|
48
|
+
assert_select 'select[aria-required]'
|
56
49
|
end
|
57
50
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: UTF-8
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class RichTextAreaInputTest < ActionView::TestCase
|
6
|
+
test 'input generates a text area for text attributes' do
|
7
|
+
with_input_for @user, :description, :text
|
8
|
+
assert_select 'textarea.text#user_description'
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'input generates a text area for text attributes that accept placeholder' do
|
12
|
+
with_input_for @user, :description, :text, placeholder: 'Put in some text'
|
13
|
+
assert_select 'textarea.text[placeholder="Put in some text"]'
|
14
|
+
end
|
15
|
+
end
|