simple_form 2.0.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +97 -198
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +572 -296
  5. data/lib/generators/simple_form/install_generator.rb +17 -7
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/_form.html.erb +1 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +1 -0
  9. data/lib/generators/simple_form/templates/config/initializers/{simple_form.rb.tt → simple_form.rb} +57 -63
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +155 -0
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +111 -0
  12. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +14 -7
  13. data/lib/simple_form/action_view_extensions/builder.rb +5 -305
  14. data/lib/simple_form/action_view_extensions/form_helper.rb +18 -20
  15. data/lib/simple_form/components/errors.rb +30 -3
  16. data/lib/simple_form/components/hints.rb +10 -3
  17. data/lib/simple_form/components/html5.rb +17 -3
  18. data/lib/simple_form/components/label_input.rb +21 -2
  19. data/lib/simple_form/components/labels.rb +16 -11
  20. data/lib/simple_form/components/maxlength.rb +19 -12
  21. data/lib/simple_form/components/min_max.rb +4 -2
  22. data/lib/simple_form/components/minlength.rb +48 -0
  23. data/lib/simple_form/components/pattern.rb +5 -4
  24. data/lib/simple_form/components/placeholders.rb +3 -2
  25. data/lib/simple_form/components/readonly.rb +3 -2
  26. data/lib/simple_form/components.rb +15 -11
  27. data/lib/simple_form/error_notification.rb +4 -3
  28. data/lib/simple_form/form_builder.rb +283 -105
  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 +4 -3
  34. data/lib/simple_form/helpers.rb +7 -6
  35. data/lib/simple_form/i18n_cache.rb +1 -0
  36. data/lib/simple_form/inputs/base.rb +76 -23
  37. data/lib/simple_form/inputs/block_input.rb +3 -2
  38. data/lib/simple_form/inputs/boolean_input.rb +55 -16
  39. data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
  40. data/lib/simple_form/inputs/collection_input.rb +41 -18
  41. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +11 -19
  42. data/lib/simple_form/inputs/collection_select_input.rb +5 -2
  43. data/lib/simple_form/inputs/date_time_input.rb +23 -12
  44. data/lib/simple_form/inputs/file_input.rb +5 -2
  45. data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
  46. data/lib/simple_form/inputs/hidden_input.rb +5 -2
  47. data/lib/simple_form/inputs/numeric_input.rb +4 -8
  48. data/lib/simple_form/inputs/password_input.rb +6 -4
  49. data/lib/simple_form/inputs/priority_input.rb +5 -2
  50. data/lib/simple_form/inputs/range_input.rb +2 -1
  51. data/lib/simple_form/inputs/string_input.rb +6 -4
  52. data/lib/simple_form/inputs/text_input.rb +6 -3
  53. data/lib/simple_form/inputs.rb +20 -17
  54. data/lib/simple_form/map_type.rb +1 -0
  55. data/lib/simple_form/railtie.rb +15 -0
  56. data/lib/simple_form/tags.rb +69 -0
  57. data/lib/simple_form/version.rb +2 -1
  58. data/lib/simple_form/wrappers/builder.rb +12 -35
  59. data/lib/simple_form/wrappers/leaf.rb +29 -0
  60. data/lib/simple_form/wrappers/many.rb +12 -7
  61. data/lib/simple_form/wrappers/root.rb +7 -4
  62. data/lib/simple_form/wrappers/single.rb +12 -3
  63. data/lib/simple_form/wrappers.rb +3 -1
  64. data/lib/simple_form.rb +118 -63
  65. data/test/action_view_extensions/builder_test.rb +230 -164
  66. data/test/action_view_extensions/form_helper_test.rb +107 -39
  67. data/test/components/label_test.rb +105 -87
  68. data/test/form_builder/association_test.rb +131 -62
  69. data/test/form_builder/button_test.rb +15 -14
  70. data/test/form_builder/error_notification_test.rb +11 -10
  71. data/test/form_builder/error_test.rb +188 -34
  72. data/test/form_builder/general_test.rb +247 -102
  73. data/test/form_builder/hint_test.rb +59 -32
  74. data/test/form_builder/input_field_test.rb +138 -25
  75. data/test/form_builder/label_test.rb +84 -13
  76. data/test/form_builder/wrapper_test.rb +236 -33
  77. data/test/generators/simple_form_generator_test.rb +15 -4
  78. data/test/inputs/boolean_input_test.rb +147 -13
  79. data/test/inputs/collection_check_boxes_input_test.rb +166 -71
  80. data/test/inputs/collection_radio_buttons_input_test.rb +229 -113
  81. data/test/inputs/collection_select_input_test.rb +222 -85
  82. data/test/inputs/datetime_input_test.rb +134 -47
  83. data/test/inputs/disabled_test.rb +62 -21
  84. data/test/inputs/discovery_test.rb +70 -10
  85. data/test/inputs/file_input_test.rb +4 -3
  86. data/test/inputs/general_test.rb +90 -26
  87. data/test/inputs/grouped_collection_select_input_test.rb +88 -23
  88. data/test/inputs/hidden_input_test.rb +7 -5
  89. data/test/inputs/numeric_input_test.rb +56 -46
  90. data/test/inputs/priority_input_test.rb +31 -16
  91. data/test/inputs/readonly_test.rb +68 -27
  92. data/test/inputs/required_test.rb +63 -18
  93. data/test/inputs/string_input_test.rb +76 -51
  94. data/test/inputs/text_input_test.rb +21 -8
  95. data/test/simple_form_test.rb +9 -0
  96. data/test/support/discovery_inputs.rb +39 -2
  97. data/test/support/misc_helpers.rb +176 -20
  98. data/test/support/mock_controller.rb +13 -7
  99. data/test/support/models.rb +187 -71
  100. data/test/test_helper.rb +38 -39
  101. metadata +53 -39
  102. data/lib/simple_form/core_ext/hash.rb +0 -16
  103. data/test/support/mock_response.rb +0 -14
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
@@ -6,77 +7,83 @@ 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
- store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
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
18
19
  with_input_for @user, :active, :select
19
20
  assert_select 'select option[value=true]', 'Sim'
20
21
  assert_select 'select option[value=false]', 'Não'
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
- 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]
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]
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
- 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]
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]
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 mark the selected value also when using integers' do
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
60
67
  @user.age = 18
61
- with_input_for @user, :age, :select, :collection => 18..60
68
+ with_input_for @user, :age, :select, collection: 18..60
62
69
  assert_select 'select option[selected=selected]', '18'
63
70
  end
64
71
 
65
- 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
66
73
  @user.active = false
67
74
  with_input_for @user, :active, :select
68
75
  assert_no_select 'select option[selected][value=true]', 'Yes'
69
76
  assert_select 'select option[selected][value=false]', 'No'
70
77
  end
71
78
 
72
- test 'input should set the correct value when using a collection that includes floats' do
73
- with_input_for @user, :age, :select, :collection => [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
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]
74
81
  assert_select 'select option[value="2.0"]'
75
82
  assert_select 'select option[value="2.5"]'
76
83
  end
77
84
 
78
- test 'input should set the correct values when using a collection that uses mixed values' do
79
- with_input_for @user, :age, :select, :collection => ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
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]
80
87
  assert_select 'select option[value="Hello Kitty"]'
81
88
  assert_select 'select option[value="2"]'
82
89
  assert_select 'select option[value="4.5"]'
@@ -86,154 +93,284 @@ class CollectionSelectInputTest < ActionView::TestCase
86
93
  assert_select 'select option[value="false"]'
87
94
  end
88
95
 
89
- test 'input should include a blank option even if :include_blank is set to false if the collection includes a nil value' do
90
- with_input_for @user, :age, :select, :collection => [nil], :include_blank => false
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
91
98
  assert_select 'select option[value=""]'
92
99
  end
93
100
 
94
- test 'input should automatically set include blank' do
95
- with_input_for @user, :age, :select, :collection => 18..30
96
- assert_select 'select option[value=]', ''
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=""]', ''
97
173
  end
98
174
 
99
- test 'input should not set include blank if otherwise is told' do
100
- with_input_for @user, :age, :select, :collection => 18..30, :include_blank => false
101
- assert_no_select 'select option[value=]', ''
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
102
182
  end
103
183
 
104
- test 'input should not set include blank if prompt is given' do
105
- with_input_for @user, :age, :select, :collection => 18..30, :prompt => "Please select foo"
106
- assert_no_select 'select option[value=]', ''
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
107
191
  end
108
192
 
109
- test 'input should not set include blank if multiple is given' do
110
- with_input_for @user, :age, :select, :collection => 18..30, :input_html => { :multiple => true }
111
- assert_no_select 'select option[value=]', ''
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
112
200
  end
113
201
 
114
- test 'input should detect label and value on collections' do
115
- users = [ setup_new_user(:id => 1, :name => "Jose"), setup_new_user(:id => 2, :name => "Carlos") ]
116
- with_input_for @user, :description, :select, :collection => users
117
- assert_select 'select option[value=1]', 'Jose'
118
- assert_select 'select option[value=2]', 'Carlos'
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
119
209
  end
120
210
 
121
- test 'input should disable the anothers components when the option is a object' do
122
- with_input_for @user, :description, :select, :collection => ["Jose", "Carlos"], :disabled => true
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
123
229
  assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
124
230
  assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
125
231
  assert_select 'select[disabled=disabled]'
126
232
  assert_select 'div.disabled'
127
233
  end
128
234
 
129
- test 'input should not disable the anothers components when the option is a object' do
130
- 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'
131
237
  assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
132
238
  assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
133
239
  assert_no_select 'select[disabled=disabled]'
134
240
  assert_no_select 'div.disabled'
135
241
  end
136
242
 
137
- 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
138
244
  with_input_for @user, :name, :select,
139
- :collection => ['Jose' , 'Carlos'],
140
- :label_method => lambda { |i| i.upcase },
141
- :value_method => lambda { |i| i.downcase }
245
+ collection: %w[Jose Carlos],
246
+ label_method: ->(i) { i.upcase },
247
+ value_method: ->(i) { i.downcase }
142
248
  assert_select 'select option[value=jose]', "JOSE"
143
249
  assert_select 'select option[value=carlos]', "CARLOS"
144
250
  end
145
251
 
146
- 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
147
253
  with_input_for @user, :name, :select,
148
- :collection => ['Jose' , 'Carlos'],
149
- :label_method => lambda { |i| i.upcase }
254
+ collection: %w[Jose Carlos],
255
+ label_method: ->(i) { i.upcase }
150
256
  assert_select 'select option[value=Jose]', "JOSE"
151
257
  assert_select 'select option[value=Carlos]', "CARLOS"
152
258
  end
153
259
 
154
- 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
155
261
  with_input_for @user, :name, :select,
156
- :collection => ['Jose' , 'Carlos'],
157
- :value_method => lambda { |i| i.downcase }
262
+ collection: %w[Jose Carlos],
263
+ value_method: ->(i) { i.downcase }
158
264
  assert_select 'select option[value=jose]', "Jose"
159
265
  assert_select 'select option[value=carlos]', "Carlos"
160
266
  end
161
267
 
162
- test 'input should allow symbols for collections' do
163
- 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]
164
270
  assert_select 'select.select#user_name'
165
271
  assert_select 'select option[value=jose]', 'jose'
166
272
  assert_select 'select option[value=carlos]', 'carlos'
167
273
  end
168
274
 
169
- test 'collection input with select type should generate required html attribute only with blank option' do
170
- 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]
171
283
  assert_select 'select.required'
172
284
  assert_select 'select[required]'
173
285
  end
174
286
 
175
- test 'collection input with select type should not generate required html attribute without blank option' do
176
- with_input_for @user, :name, :select, :include_blank => false, :collection => ['Jose' , 'Carlos']
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]
177
289
  assert_select 'select.required'
178
290
  assert_no_select 'select[required]'
291
+ assert_no_select 'select[aria-required=true]'
179
292
  end
180
293
 
181
- test 'collection input with select type with multiple attribute should generate required html attribute without blank option' do
182
- with_input_for @user, :name, :select, :include_blank => false, :input_html => {:multiple => true}, :collection => ['Jose' , 'Carlos']
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]
183
296
  assert_select 'select.required'
184
297
  assert_select 'select[required]'
185
298
  end
186
299
 
187
- test 'collection input with select type with multiple attribute should generate required html attribute with blank option' do
188
- with_input_for @user, :name, :select, :include_blank => true, :input_html => {:multiple => true}, :collection => ['Jose' , 'Carlos']
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]
189
302
  assert_select 'select.required'
190
303
  assert_select 'select[required]'
191
304
  end
192
305
 
193
- test 'input should allow disabled options with a lambda for collection select' do
194
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
195
- :disabled => lambda { |x| x == "Carlos" }
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" }
196
333
  assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
197
334
  assert_select 'select option[value=Antonio]', 'Antonio'
198
335
  assert_no_select 'select option[value=Antonio][disabled]'
199
336
  end
200
337
 
201
- test 'input should allow disabled and label method with lambdas for collection select' do
202
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
203
- :disabled => lambda { |x| x == "Carlos" }, :label_method => lambda { |x| x.upcase }
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 }
204
341
  assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
205
342
  assert_select 'select option[value=Antonio]', 'ANTONIO'
206
343
  assert_no_select 'select option[value=Antonio][disabled]'
207
344
  end
208
345
 
209
- test 'input should allow a non lambda disabled option with lambda label method for collections' do
210
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
211
- :disabled => "Carlos", :label_method => lambda { |x| x.upcase }
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 }
212
349
  assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
213
350
  assert_select 'select option[value=Antonio]', 'ANTONIO'
214
351
  assert_no_select 'select option[value=Antonio][disabled]'
215
352
  end
216
353
 
217
- test 'input should allow selected and label method with lambdas for collection select' do
218
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
219
- :selected => lambda { |x| x == "Carlos" }, :label_method => lambda { |x| x.upcase }
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 }
220
357
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
221
358
  assert_select 'select option[value=Antonio]', 'ANTONIO'
222
359
  assert_no_select 'select option[value=Antonio][selected]'
223
360
  end
224
361
 
225
- test 'input should allow a non lambda selected option with lambda label method for collection select' do
226
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
227
- :selected => "Carlos", :label_method => lambda { |x| x.upcase }
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 }
228
365
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
229
366
  assert_select 'select option[value=Antonio]', 'ANTONIO'
230
367
  assert_no_select 'select option[value=Antonio][selected]'
231
368
  end
232
369
 
233
- test 'input should not override default selection through attribute value with label method as lambda for collection select' do
370
+ test 'input does not override default selection through attribute value with label method as lambda for collection select' do
234
371
  @user.name = "Carlos"
235
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
236
- :label_method => lambda { |x| x.upcase }
372
+ with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
373
+ label_method: ->(x) { x.upcase }
237
374
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
238
375
  assert_select 'select option[value=Antonio]', 'ANTONIO'
239
376
  assert_no_select 'select option[value=Antonio][selected]'