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