simple_form 3.4.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +118 -8
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +235 -67
  5. data/lib/generators/simple_form/install_generator.rb +1 -0
  6. data/lib/generators/simple_form/templates/README +2 -3
  7. data/lib/generators/simple_form/templates/_form.html.erb +2 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +2 -0
  9. data/lib/generators/simple_form/templates/_form.html.slim +1 -0
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +14 -7
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +360 -74
  12. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +20 -8
  13. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  14. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
  15. data/lib/simple_form/components/errors.rb +15 -2
  16. data/lib/simple_form/components/hints.rb +1 -0
  17. data/lib/simple_form/components/html5.rb +1 -0
  18. data/lib/simple_form/components/label_input.rb +2 -1
  19. data/lib/simple_form/components/labels.rb +12 -7
  20. data/lib/simple_form/components/maxlength.rb +4 -17
  21. data/lib/simple_form/components/min_max.rb +1 -0
  22. data/lib/simple_form/components/minlength.rb +5 -18
  23. data/lib/simple_form/components/pattern.rb +1 -0
  24. data/lib/simple_form/components/placeholders.rb +2 -1
  25. data/lib/simple_form/components/readonly.rb +1 -0
  26. data/lib/simple_form/components.rb +1 -0
  27. data/lib/simple_form/error_notification.rb +1 -0
  28. data/lib/simple_form/form_builder.rb +104 -29
  29. data/lib/simple_form/helpers/autofocus.rb +1 -0
  30. data/lib/simple_form/helpers/disabled.rb +1 -0
  31. data/lib/simple_form/helpers/readonly.rb +1 -0
  32. data/lib/simple_form/helpers/required.rb +1 -0
  33. data/lib/simple_form/helpers/validators.rb +2 -1
  34. data/lib/simple_form/helpers.rb +1 -0
  35. data/lib/simple_form/inputs/base.rb +24 -5
  36. data/lib/simple_form/inputs/block_input.rb +1 -0
  37. data/lib/simple_form/inputs/boolean_input.rb +4 -2
  38. data/lib/simple_form/inputs/collection_check_boxes_input.rb +3 -2
  39. data/lib/simple_form/inputs/collection_input.rb +6 -7
  40. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
  41. data/lib/simple_form/inputs/collection_select_input.rb +1 -0
  42. data/lib/simple_form/inputs/color_input.rb +14 -0
  43. data/lib/simple_form/inputs/date_time_input.rb +1 -0
  44. data/lib/simple_form/inputs/file_input.rb +1 -0
  45. data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
  46. data/lib/simple_form/inputs/hidden_input.rb +1 -0
  47. data/lib/simple_form/inputs/numeric_input.rb +1 -0
  48. data/lib/simple_form/inputs/password_input.rb +1 -0
  49. data/lib/simple_form/inputs/priority_input.rb +1 -4
  50. data/lib/simple_form/inputs/range_input.rb +1 -0
  51. data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
  52. data/lib/simple_form/inputs/string_input.rb +2 -1
  53. data/lib/simple_form/inputs/text_input.rb +1 -0
  54. data/lib/simple_form/inputs.rb +3 -0
  55. data/lib/simple_form/map_type.rb +1 -0
  56. data/lib/simple_form/railtie.rb +1 -0
  57. data/lib/simple_form/tags.rb +7 -2
  58. data/lib/simple_form/version.rb +2 -1
  59. data/lib/simple_form/wrappers/builder.rb +1 -0
  60. data/lib/simple_form/wrappers/leaf.rb +2 -1
  61. data/lib/simple_form/wrappers/many.rb +1 -0
  62. data/lib/simple_form/wrappers/root.rb +9 -2
  63. data/lib/simple_form/wrappers/single.rb +2 -1
  64. data/lib/simple_form/wrappers.rb +1 -0
  65. data/lib/simple_form.rb +79 -11
  66. data/test/action_view_extensions/builder_test.rb +28 -9
  67. data/test/action_view_extensions/form_helper_test.rb +3 -2
  68. data/test/components/custom_components_test.rb +62 -0
  69. data/test/components/label_test.rb +33 -8
  70. data/test/form_builder/association_test.rb +33 -2
  71. data/test/form_builder/button_test.rb +1 -0
  72. data/test/form_builder/error_notification_test.rb +1 -0
  73. data/test/form_builder/error_test.rb +12 -0
  74. data/test/form_builder/general_test.rb +75 -13
  75. data/test/form_builder/hint_test.rb +6 -0
  76. data/test/form_builder/input_field_test.rb +30 -10
  77. data/test/form_builder/label_test.rb +10 -4
  78. data/test/form_builder/wrapper_test.rb +32 -5
  79. data/test/generators/simple_form_generator_test.rb +4 -3
  80. data/test/inputs/boolean_input_test.rb +17 -0
  81. data/test/inputs/collection_check_boxes_input_test.rb +38 -18
  82. data/test/inputs/collection_radio_buttons_input_test.rb +48 -28
  83. data/test/inputs/collection_select_input_test.rb +46 -43
  84. data/test/inputs/color_input_test.rb +10 -0
  85. data/test/inputs/datetime_input_test.rb +7 -16
  86. data/test/inputs/disabled_test.rb +14 -0
  87. data/test/inputs/discovery_test.rb +22 -0
  88. data/test/inputs/file_input_test.rb +1 -0
  89. data/test/inputs/general_test.rb +3 -2
  90. data/test/inputs/grouped_collection_select_input_test.rb +11 -10
  91. data/test/inputs/hidden_input_test.rb +1 -0
  92. data/test/inputs/numeric_input_test.rb +2 -1
  93. data/test/inputs/priority_input_test.rb +7 -14
  94. data/test/inputs/readonly_test.rb +1 -0
  95. data/test/inputs/required_test.rb +1 -0
  96. data/test/inputs/rich_text_area_input_test.rb +15 -0
  97. data/test/inputs/string_input_test.rb +10 -16
  98. data/test/inputs/text_input_test.rb +1 -0
  99. data/test/simple_form_test.rb +1 -0
  100. data/test/support/discovery_inputs.rb +8 -0
  101. data/test/support/misc_helpers.rb +22 -1
  102. data/test/support/mock_controller.rb +7 -1
  103. data/test/support/models.rb +80 -18
  104. data/test/test_helper.rb +9 -4
  105. metadata +49 -55
  106. 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: ['Jose', 'Carlos']
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: [:male, :female]
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: [:male, :female]
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: ['Jose', 'Carlos']
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: ["Jose", "Carlos"], disabled: true
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: ["Jose", "Carlos"], disabled: 'Jose'
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: ['Jose', 'Carlos'],
245
- label_method: lambda { |i| i.upcase },
246
- value_method: lambda { |i| i.downcase }
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: ['Jose', 'Carlos'],
254
- label_method: lambda { |i| i.upcase }
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: ['Jose', 'Carlos'],
262
- value_method: lambda { |i| i.downcase }
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: [:jose, :carlos]
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: ['Jose', 'Carlos']
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: ['Jose', 'Carlos']
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: ['Jose', 'Carlos']
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: ['Jose', 'Carlos']
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: ['Jose', 'Carlos']
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: ['Jose', 'Carlos']
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: ['Jose', 'Carlos']
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: ['Jose', 'Carlos']
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: ['Jose', 'Carlos']
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: ["Carlos", "Antonio"],
331
- disabled: lambda { |x| x == "Carlos" }
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: ["Carlos", "Antonio"],
339
- disabled: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
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: ["Carlos", "Antonio"],
347
- disabled: "Carlos", label_method: lambda { |x| x.upcase }
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: ["Carlos", "Antonio"],
355
- selected: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
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: ["Carlos", "Antonio"],
363
- selected: "Carlos", label_method: lambda { |x| x.upcase }
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: ["Carlos", "Antonio"],
372
- label_method: lambda { |x| x.upcase }
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: ['month', 'day', 'year'] }) do
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: ['month', 'day', 'year'] }) do
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: ['month', 'year', 'day'], html5: false
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: ['month', 'year', 'day'], html5: false
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
@@ -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: ['Jose', 'Carlos']
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: [:wrapper, :label] do
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', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]],
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: Proc.new { [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]] },
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: { 'Authors' => ['Jose', 'Carlos'], 'General' => ['Bob', 'John'] },
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: { ['Jose', 'Carlos'] => 'Authors' },
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 = ['Jose', 'Carlos']
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: { 'Authors' => ['Jose', 'Carlos'] },
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: { 'Authors' => ['Jose', 'Carlos'] },
136
+ collection: { Authors: %w[Jose Carlos] },
136
137
  group_method: :last,
137
- label_method: lambda { |i| i.upcase },
138
- value_method: lambda { |i| i.downcase }
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
 
@@ -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
- [:integer, :float, :decimal].each do |type|
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
- if ActionPack::VERSION::STRING >= '5'
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
- if ActionPack::VERSION::STRING >= '5'
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 not generate invalid required html attribute' do
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
- assert_no_select 'select[required]'
42
+ assert_select 'select[required]'
50
43
  end
51
44
 
52
- test 'priority input does not generate invalid aria-required html attribute' do
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
- assert_no_select 'select[aria-required]'
48
+ assert_select 'select[aria-required]'
56
49
  end
57
50
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ReadonlyTest < ActionView::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class RequiredTest < ActionView::TestCase
@@ -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