simple_form 3.0.4 → 5.0.3

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