simple_form 2.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

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