simple_form 2.1.3 → 3.0.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.

Potentially problematic release.


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

Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -51
  3. data/README.md +195 -161
  4. data/lib/generators/simple_form/install_generator.rb +4 -4
  5. data/lib/generators/simple_form/templates/README +2 -2
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +16 -13
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  9. data/lib/simple_form/action_view_extensions/builder.rb +1 -320
  10. data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
  12. data/lib/simple_form/components/errors.rb +1 -7
  13. data/lib/simple_form/components/hints.rb +2 -7
  14. data/lib/simple_form/components/html5.rb +5 -2
  15. data/lib/simple_form/components/labels.rb +4 -4
  16. data/lib/simple_form/components/maxlength.rb +1 -8
  17. data/lib/simple_form/components/pattern.rb +2 -2
  18. data/lib/simple_form/components.rb +1 -1
  19. data/lib/simple_form/error_notification.rb +2 -2
  20. data/lib/simple_form/form_builder.rb +154 -50
  21. data/lib/simple_form/form_builder.rb.orig +486 -0
  22. data/lib/simple_form/helpers.rb +1 -1
  23. data/lib/simple_form/inputs/base.rb +7 -10
  24. data/lib/simple_form/inputs/block_input.rb +1 -1
  25. data/lib/simple_form/inputs/boolean_input.rb +6 -5
  26. data/lib/simple_form/inputs/collection_input.rb +7 -7
  27. data/lib/simple_form/inputs/date_time_input.rb +1 -1
  28. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  29. data/lib/simple_form/inputs/password_input.rb +0 -1
  30. data/lib/simple_form/inputs/string_input.rb +0 -1
  31. data/lib/simple_form/railtie.rb +7 -0
  32. data/lib/simple_form/tags.rb +62 -0
  33. data/lib/simple_form/version.rb +1 -1
  34. data/lib/simple_form/version.rb.orig +7 -0
  35. data/lib/simple_form/wrappers/builder.rb +5 -29
  36. data/lib/simple_form/wrappers/many.rb +1 -1
  37. data/lib/simple_form/wrappers/root.rb +1 -1
  38. data/lib/simple_form/wrappers.rb +1 -1
  39. data/lib/simple_form.rb +43 -47
  40. data/test/action_view_extensions/builder_test.rb +78 -99
  41. data/test/action_view_extensions/form_helper_test.rb +25 -16
  42. data/test/components/label_test.rb +46 -46
  43. data/test/form_builder/association_test.rb +47 -29
  44. data/test/form_builder/button_test.rb +4 -4
  45. data/test/form_builder/error_notification_test.rb +8 -8
  46. data/test/form_builder/error_test.rb +18 -65
  47. data/test/form_builder/general_test.rb +62 -63
  48. data/test/form_builder/hint_test.rb +23 -29
  49. data/test/form_builder/input_field_test.rb +29 -12
  50. data/test/form_builder/label_test.rb +7 -17
  51. data/test/form_builder/wrapper_test.rb +21 -21
  52. data/test/inputs/boolean_input_test.rb +24 -24
  53. data/test/inputs/collection_check_boxes_input_test.rb +66 -55
  54. data/test/inputs/collection_radio_buttons_input_test.rb +81 -79
  55. data/test/inputs/collection_select_input_test.rb +76 -51
  56. data/test/inputs/datetime_input_test.rb +17 -11
  57. data/test/inputs/disabled_test.rb +10 -10
  58. data/test/inputs/discovery_test.rb +4 -4
  59. data/test/inputs/file_input_test.rb +1 -1
  60. data/test/inputs/general_test.rb +28 -12
  61. data/test/inputs/grouped_collection_select_input_test.rb +33 -20
  62. data/test/inputs/hidden_input_test.rb +3 -2
  63. data/test/inputs/numeric_input_test.rb +3 -3
  64. data/test/inputs/priority_input_test.rb +9 -3
  65. data/test/inputs/readonly_test.rb +12 -12
  66. data/test/inputs/required_test.rb +5 -5
  67. data/test/inputs/string_input_test.rb +15 -25
  68. data/test/inputs/text_input_test.rb +1 -1
  69. data/test/support/misc_helpers.rb +46 -24
  70. data/test/support/mock_controller.rb +6 -6
  71. data/test/support/models.rb +77 -62
  72. data/test/test_helper.rb +17 -34
  73. metadata +39 -22
  74. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -14,7 +14,7 @@ class CollectionSelectInputTest < ActionView::TestCase
14
14
  end
15
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
+ 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'
@@ -22,17 +22,17 @@ class CollectionSelectInputTest < ActionView::TestCase
22
22
  end
23
23
 
24
24
  test 'input should allow overriding collection for select types' do
25
- with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
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
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'}
32
+ store_translations(:en, simple_form: { options: { defaults: {
33
+ gender: { male: 'Male', female: 'Female'}
34
34
  } } } ) do
35
- with_input_for @user, :gender, :select, :collection => [:male, :female]
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'
@@ -40,10 +40,10 @@ class CollectionSelectInputTest < ActionView::TestCase
40
40
  end
41
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'}
43
+ store_translations(:en, simple_form: { options: { user: {
44
+ gender: { male: 'Male', female: 'Female'}
45
45
  } } } ) do
46
- with_input_for @user, :gender, :select, :collection => [:male, :female]
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'
@@ -52,13 +52,19 @@ class CollectionSelectInputTest < ActionView::TestCase
52
52
 
53
53
  test 'input should mark 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 accept 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
+
59
65
  test 'input should mark 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
 
@@ -70,13 +76,13 @@ class CollectionSelectInputTest < ActionView::TestCase
70
76
  end
71
77
 
72
78
  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
+ 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
84
  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
+ 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"]'
@@ -87,39 +93,39 @@ class CollectionSelectInputTest < ActionView::TestCase
87
93
  end
88
94
 
89
95
  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
+ with_input_for @user, :age, :select, collection: [nil], include_blank: false
91
97
  assert_select 'select option[value=""]'
92
98
  end
93
99
 
94
100
  test 'input should automatically set include blank' do
95
- with_input_for @user, :age, :select, :collection => 18..30
101
+ with_input_for @user, :age, :select, collection: 18..30
96
102
  assert_select 'select option[value=]', ''
97
103
  end
98
104
 
99
105
  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
106
+ with_input_for @user, :age, :select, collection: 18..30, include_blank: false
101
107
  assert_no_select 'select option[value=]', ''
102
108
  end
103
109
 
104
110
  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"
111
+ with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
106
112
  assert_no_select 'select option[value=]', ''
107
113
  end
108
114
 
109
115
  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 }
116
+ with_input_for @user, :age, :select, collection: 18..30, input_html: { multiple: true }
111
117
  assert_no_select 'select option[value=]', ''
112
118
  end
113
119
 
114
120
  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
121
+ users = [User.build(id: 1, name: "Jose"), User.build(id: 2, name: "Carlos")]
122
+ with_input_for @user, :description, :select, collection: users
117
123
  assert_select 'select option[value=1]', 'Jose'
118
124
  assert_select 'select option[value=2]', 'Carlos'
119
125
  end
120
126
 
121
127
  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
128
+ with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: true
123
129
  assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
124
130
  assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
125
131
  assert_select 'select[disabled=disabled]'
@@ -127,7 +133,7 @@ class CollectionSelectInputTest < ActionView::TestCase
127
133
  end
128
134
 
129
135
  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'
136
+ with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: 'Jose'
131
137
  assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
132
138
  assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
133
139
  assert_no_select 'select[disabled=disabled]'
@@ -136,101 +142,120 @@ class CollectionSelectInputTest < ActionView::TestCase
136
142
 
137
143
  test 'input should allow overriding label and value method using a lambda for collection selects' do
138
144
  with_input_for @user, :name, :select,
139
- :collection => ['Jose' , 'Carlos'],
140
- :label_method => lambda { |i| i.upcase },
141
- :value_method => lambda { |i| i.downcase }
145
+ collection: ['Jose', 'Carlos'],
146
+ label_method: lambda { |i| i.upcase },
147
+ value_method: lambda { |i| i.downcase }
142
148
  assert_select 'select option[value=jose]', "JOSE"
143
149
  assert_select 'select option[value=carlos]', "CARLOS"
144
150
  end
145
151
 
146
152
  test 'input should allow overriding only label but not value method using a lambda for collection select' do
147
153
  with_input_for @user, :name, :select,
148
- :collection => ['Jose' , 'Carlos'],
149
- :label_method => lambda { |i| i.upcase }
154
+ collection: ['Jose', 'Carlos'],
155
+ label_method: lambda { |i| i.upcase }
150
156
  assert_select 'select option[value=Jose]', "JOSE"
151
157
  assert_select 'select option[value=Carlos]', "CARLOS"
152
158
  end
153
159
 
154
160
  test 'input should allow overriding only value but not label method using a lambda for collection select' do
155
161
  with_input_for @user, :name, :select,
156
- :collection => ['Jose' , 'Carlos'],
157
- :value_method => lambda { |i| i.downcase }
162
+ collection: ['Jose', 'Carlos'],
163
+ value_method: lambda { |i| i.downcase }
158
164
  assert_select 'select option[value=jose]', "Jose"
159
165
  assert_select 'select option[value=carlos]', "Carlos"
160
166
  end
161
167
 
162
168
  test 'input should allow symbols for collections' do
163
- with_input_for @user, :name, :select, :collection => [:jose, :carlos]
169
+ with_input_for @user, :name, :select, collection: [:jose, :carlos]
164
170
  assert_select 'select.select#user_name'
165
171
  assert_select 'select option[value=jose]', 'jose'
166
172
  assert_select 'select option[value=carlos]', 'carlos'
167
173
  end
168
174
 
169
175
  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']
171
- assert_select 'select.required'
172
- assert_select 'select[required]'
173
- end
174
-
175
- test 'collection input with select type should generate required html attribute only with blank option or prompt' do
176
- with_input_for @user, :name, :select, :prompt => 'Name...', :collection => ['Jose', 'Carlos']
176
+ with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
177
177
  assert_select 'select.required'
178
178
  assert_select 'select[required]'
179
179
  end
180
180
 
181
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']
182
+ with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
183
183
  assert_select 'select.required'
184
184
  assert_no_select 'select[required]'
185
+ assert_no_select 'select[aria-required=true]'
185
186
  end
186
187
 
187
188
  test 'collection input with select type with multiple attribute should generate required html attribute without blank option' do
188
- with_input_for @user, :name, :select, :include_blank => false, :input_html => {:multiple => true}, :collection => ['Jose' , 'Carlos']
189
+ with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
189
190
  assert_select 'select.required'
190
191
  assert_select 'select[required]'
191
192
  end
192
193
 
193
194
  test 'collection input with select type with multiple attribute should generate required html attribute with blank option' do
194
- with_input_for @user, :name, :select, :include_blank => true, :input_html => {:multiple => true}, :collection => ['Jose' , 'Carlos']
195
+ with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
195
196
  assert_select 'select.required'
196
197
  assert_select 'select[required]'
197
198
  end
198
199
 
200
+ 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']
202
+ assert_select 'select.required'
203
+ assert_select 'select[aria-required=true]'
204
+ end
205
+
206
+ 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']
208
+ assert_select 'select.required'
209
+ assert_no_select 'select[aria-required]'
210
+ end
211
+
212
+ 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']
214
+ assert_select 'select.required'
215
+ assert_select 'select[aria-required=true]'
216
+ end
217
+
218
+ 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']
220
+ assert_select 'select.required'
221
+ assert_select 'select[aria-required]'
222
+ end
223
+
199
224
  test 'input should allow disabled options with a lambda for collection select' do
200
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
201
- :disabled => lambda { |x| x == "Carlos" }
225
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
226
+ disabled: lambda { |x| x == "Carlos" }
202
227
  assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
203
228
  assert_select 'select option[value=Antonio]', 'Antonio'
204
229
  assert_no_select 'select option[value=Antonio][disabled]'
205
230
  end
206
231
 
207
232
  test 'input should allow disabled and label method with lambdas for collection select' do
208
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
209
- :disabled => lambda { |x| x == "Carlos" }, :label_method => lambda { |x| x.upcase }
233
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
234
+ disabled: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
210
235
  assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
211
236
  assert_select 'select option[value=Antonio]', 'ANTONIO'
212
237
  assert_no_select 'select option[value=Antonio][disabled]'
213
238
  end
214
239
 
215
240
  test 'input should allow a non lambda disabled option with lambda label method for collections' do
216
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
217
- :disabled => "Carlos", :label_method => lambda { |x| x.upcase }
241
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
242
+ disabled: "Carlos", label_method: lambda { |x| x.upcase }
218
243
  assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
219
244
  assert_select 'select option[value=Antonio]', 'ANTONIO'
220
245
  assert_no_select 'select option[value=Antonio][disabled]'
221
246
  end
222
247
 
223
248
  test 'input should allow selected and label method with lambdas for collection select' do
224
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
225
- :selected => lambda { |x| x == "Carlos" }, :label_method => lambda { |x| x.upcase }
249
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
250
+ selected: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
226
251
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
227
252
  assert_select 'select option[value=Antonio]', 'ANTONIO'
228
253
  assert_no_select 'select option[value=Antonio][selected]'
229
254
  end
230
255
 
231
256
  test 'input should allow a non lambda selected option with lambda label method for collection select' do
232
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
233
- :selected => "Carlos", :label_method => lambda { |x| x.upcase }
257
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
258
+ selected: "Carlos", label_method: lambda { |x| x.upcase }
234
259
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
235
260
  assert_select 'select option[value=Antonio]', 'ANTONIO'
236
261
  assert_no_select 'select option[value=Antonio][selected]'
@@ -238,8 +263,8 @@ class CollectionSelectInputTest < ActionView::TestCase
238
263
 
239
264
  test 'input should not override default selection through attribute value with label method as lambda for collection select' do
240
265
  @user.name = "Carlos"
241
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
242
- :label_method => lambda { |x| x.upcase }
266
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
267
+ label_method: lambda { |x| x.upcase }
243
268
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
244
269
  assert_select 'select option[value=Antonio]', 'ANTONIO'
245
270
  assert_no_select 'select option[value=Antonio][selected]'
@@ -13,7 +13,7 @@ class DateTimeInputTest < ActionView::TestCase
13
13
 
14
14
  test 'input should be able to pass options to datetime select' do
15
15
  with_input_for @user, :created_at, :datetime,
16
- :disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
16
+ disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
17
17
 
18
18
  assert_select 'select.datetime[disabled=disabled]'
19
19
  assert_select 'select.datetime option', 'ano'
@@ -30,8 +30,8 @@ class DateTimeInputTest < ActionView::TestCase
30
30
  end
31
31
 
32
32
  test 'input should be able to pass options to date select' do
33
- with_input_for @user, :born_at, :date, :as => :date,
34
- :disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
33
+ with_input_for @user, :born_at, :date, as: :date,
34
+ disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
35
35
 
36
36
  assert_select 'select.date[disabled=disabled]'
37
37
  assert_select 'select.date option', 'ano'
@@ -40,7 +40,7 @@ class DateTimeInputTest < ActionView::TestCase
40
40
  end
41
41
 
42
42
  test 'input should be able to pass :default to date select' do
43
- with_input_for @user, :born_at, :date, :default => Date.today
43
+ with_input_for @user, :born_at, :date, default: Date.today
44
44
  assert_select "select.date option[value=#{Date.today.year}][selected=selected]"
45
45
  end
46
46
 
@@ -54,8 +54,8 @@ class DateTimeInputTest < ActionView::TestCase
54
54
  end
55
55
 
56
56
  test 'input should be able to pass options to time select' do
57
- with_input_for @user, :delivery_time, :time, :required => true,
58
- :disabled => true, :prompt => { :hour => 'hora', :minute => 'minuto' }
57
+ with_input_for @user, :delivery_time, :time, required: true,
58
+ disabled: true, prompt: { hour: 'hora', minute: 'minuto' }
59
59
 
60
60
  assert_select 'select.time[disabled=disabled]'
61
61
  assert_select 'select.time option', 'hora'
@@ -63,26 +63,26 @@ class DateTimeInputTest < ActionView::TestCase
63
63
  end
64
64
 
65
65
  test 'label should use i18n to get target for date input type' do
66
- store_translations(:en, :date => { :order => [:month, :day, :year] }) do
66
+ store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
67
67
  with_input_for :project, :created_at, :date
68
68
  assert_select 'label[for=project_created_at_2i]'
69
69
  end
70
70
  end
71
71
 
72
72
  test 'label should use i18n to get target for datetime input type' do
73
- store_translations(:en, :date => { :order => [:month, :day, :year] }) do
73
+ store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
74
74
  with_input_for :project, :created_at, :datetime
75
75
  assert_select 'label[for=project_created_at_2i]'
76
76
  end
77
77
  end
78
78
 
79
79
  test 'label should use order to get target when date input type' do
80
- with_input_for :project, :created_at, :date, :order => [:month, :year, :day]
80
+ with_input_for :project, :created_at, :date, order: ['month', 'year', 'day']
81
81
  assert_select 'label[for=project_created_at_2i]'
82
82
  end
83
83
 
84
84
  test 'label should use order to get target when datetime input type' do
85
- with_input_for :project, :created_at, :datetime, :order => [:month, :year, :day]
85
+ with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day']
86
86
  assert_select 'label[for=project_created_at_2i]'
87
87
  end
88
88
 
@@ -92,8 +92,14 @@ class DateTimeInputTest < ActionView::TestCase
92
92
  end
93
93
 
94
94
  test 'date time input should generate required html attribute' do
95
- with_input_for @user, :delivery_time, :time, :required => true
95
+ with_input_for @user, :delivery_time, :time, required: true
96
96
  assert_select 'select.required'
97
97
  assert_select 'select[required]'
98
98
  end
99
+
100
+ test 'date time input has an aria-required html attribute' do
101
+ with_input_for @user, :delivery_time, :time, required: true
102
+ assert_select 'select.required'
103
+ assert_select 'select[aria-required=true]'
104
+ end
99
105
  end
@@ -2,52 +2,52 @@ require 'test_helper'
2
2
 
3
3
  class DisabledTest < ActionView::TestCase
4
4
  test 'string input should be disabled when disabled option is true' do
5
- with_input_for @user, :name, :string, :disabled => true
5
+ with_input_for @user, :name, :string, disabled: true
6
6
  assert_select 'input.string.disabled[disabled]'
7
7
  end
8
8
 
9
9
  test 'text input should be disabled when disabled option is true' do
10
- with_input_for @user, :description, :text, :disabled => true
10
+ with_input_for @user, :description, :text, disabled: true
11
11
  assert_select 'textarea.text.disabled[disabled]'
12
12
  end
13
13
 
14
14
  test 'numeric input should be disabled when disabled option is true' do
15
- with_input_for @user, :age, :integer, :disabled => true
15
+ with_input_for @user, :age, :integer, disabled: true
16
16
  assert_select 'input.integer.disabled[disabled]'
17
17
  end
18
18
 
19
19
  test 'date input should be disabled when disabled option is true' do
20
- with_input_for @user, :born_at, :date, :disabled => true
20
+ with_input_for @user, :born_at, :date, disabled: true
21
21
  assert_select 'select.date.disabled[disabled]'
22
22
  end
23
23
 
24
24
  test 'datetime input should be disabled when disabled option is true' do
25
- with_input_for @user, :created_at, :datetime, :disabled => true
25
+ with_input_for @user, :created_at, :datetime, disabled: true
26
26
  assert_select 'select.datetime.disabled[disabled]'
27
27
  end
28
28
 
29
29
  test 'string input should not be disabled when disabled option is false' do
30
- with_input_for @user, :name, :string, :disabled => false
30
+ with_input_for @user, :name, :string, disabled: false
31
31
  assert_no_select 'input.string.disabled[disabled]'
32
32
  end
33
33
 
34
34
  test 'text input should not be disabled when disabled option is false' do
35
- with_input_for @user, :description, :text, :disabled => false
35
+ with_input_for @user, :description, :text, disabled: false
36
36
  assert_no_select 'textarea.text.disabled[disabled]'
37
37
  end
38
38
 
39
39
  test 'numeric input should not be disabled when disabled option is false' do
40
- with_input_for @user, :age, :integer, :disabled => false
40
+ with_input_for @user, :age, :integer, disabled: false
41
41
  assert_no_select 'input.integer.disabled[disabled]'
42
42
  end
43
43
 
44
44
  test 'date input should not be disabled when disabled option is false' do
45
- with_input_for @user, :born_at, :date, :disabled => false
45
+ with_input_for @user, :born_at, :date, disabled: false
46
46
  assert_no_select 'select.date.disabled[disabled]'
47
47
  end
48
48
 
49
49
  test 'datetime input should not be disabled when disabled option is false' do
50
- with_input_for @user, :created_at, :datetime, :disabled => false
50
+ with_input_for @user, :created_at, :datetime, disabled: false
51
51
  assert_no_select 'select.datetime.disabled[disabled]'
52
52
  end
53
53
 
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class DiscoveryTest < ActionView::TestCase
4
4
  # Setup new inputs and remove them after the test.
5
5
  def discovery(value=false)
6
- swap SimpleForm, :cache_discovery => value do
6
+ swap SimpleForm, cache_discovery: value do
7
7
  begin
8
8
  load "support/discovery_inputs.rb"
9
9
  yield
@@ -29,7 +29,7 @@ class DiscoveryTest < ActionView::TestCase
29
29
 
30
30
  test 'builder should discover new inputs' do
31
31
  discovery do
32
- with_form_for @user, :name, :as => :customized
32
+ with_form_for @user, :name, as: :customized
33
33
  assert_select 'form section input#user_name.string'
34
34
  end
35
35
  end
@@ -38,7 +38,7 @@ class DiscoveryTest < ActionView::TestCase
38
38
  with_form_for @user, :name
39
39
  assert_select 'form input#user_name.string'
40
40
 
41
- swap SimpleForm, :inputs_discovery => false do
41
+ swap SimpleForm, inputs_discovery: false do
42
42
  discovery do
43
43
  with_form_for @user, :name
44
44
  assert_no_select 'form section input#user_name.string'
@@ -62,7 +62,7 @@ class DiscoveryTest < ActionView::TestCase
62
62
 
63
63
  test 'new inputs can override the input_html_options' do
64
64
  discovery do
65
- with_form_for @user, :active, :as => :select
65
+ with_form_for @user, :active, as: :select
66
66
  assert_select 'form select#user_active.select.chosen'
67
67
  end
68
68
  end
@@ -8,7 +8,7 @@ class FileInputTest < ActionView::TestCase
8
8
  end
9
9
 
10
10
  test "input should generate a file field that doesn't accept placeholder" do
11
- store_translations(:en, :simple_form => { :placeholders => { :user => { :name => "text" } } }) do
11
+ store_translations(:en, simple_form: { placeholders: { user: { name: "text" } } }) do
12
12
  with_input_for @user, :name, :file
13
13
  assert_no_select 'input[placeholder]'
14
14
  end
@@ -16,52 +16,68 @@ class InputTest < ActionView::TestCase
16
16
  end
17
17
 
18
18
  test 'string input should generate autofocus attribute when autofocus option is true' do
19
- with_input_for @user, :name, :string, :autofocus => true
19
+ with_input_for @user, :name, :string, autofocus: true
20
20
  assert_select 'input.string[autofocus]'
21
21
  end
22
22
 
23
+ test 'input accepts input_class configuration' do
24
+ swap SimpleForm, input_class: :xlarge do
25
+ with_input_for @user, :name, :string
26
+ assert_select 'input.xlarge'
27
+ assert_no_select 'div.xlarge'
28
+ end
29
+ end
30
+
31
+ test 'input does not add input_class when configured to not generate additional classes for input' do
32
+ swap SimpleForm, input_class: 'xlarge', generate_additional_classes_for: [:wrapper] do
33
+ with_input_for @user, :name, :string
34
+ assert_select 'input'
35
+ assert_no_select '.xlarge'
36
+ end
37
+ end
38
+
23
39
  test 'text input should generate autofocus attribute when autofocus option is true' do
24
- with_input_for @user, :description, :text, :autofocus => true
40
+ with_input_for @user, :description, :text, autofocus: true
25
41
  assert_select 'textarea.text[autofocus]'
26
42
  end
27
43
 
28
44
  test 'numeric input should generate autofocus attribute when autofocus option is true' do
29
- with_input_for @user, :age, :integer, :autofocus => true
45
+ with_input_for @user, :age, :integer, autofocus: true
30
46
  assert_select 'input.integer[autofocus]'
31
47
  end
32
48
 
33
49
  test 'date input should generate autofocus attribute when autofocus option is true' do
34
- with_input_for @user, :born_at, :date, :autofocus => true
50
+ with_input_for @user, :born_at, :date, autofocus: true
35
51
  assert_select 'select.date[autofocus]'
36
52
  end
37
53
 
38
54
  test 'datetime input should generate autofocus attribute when autofocus option is true' do
39
- with_input_for @user, :created_at, :datetime, :autofocus => true
55
+ with_input_for @user, :created_at, :datetime, autofocus: true
40
56
  assert_select 'select.datetime[autofocus]'
41
57
  end
42
58
 
43
59
  test 'string input should generate autofocus attribute when autofocus option is false' do
44
- with_input_for @user, :name, :string, :autofocus => false
60
+ with_input_for @user, :name, :string, autofocus: false
45
61
  assert_no_select 'input.string[autofocus]'
46
62
  end
47
63
 
48
64
  test 'text input should generate autofocus attribute when autofocus option is false' do
49
- with_input_for @user, :description, :text, :autofocus => false
65
+ with_input_for @user, :description, :text, autofocus: false
50
66
  assert_no_select 'textarea.text[autofocus]'
51
67
  end
52
68
 
53
69
  test 'numeric input should generate autofocus attribute when autofocus option is false' do
54
- with_input_for @user, :age, :integer, :autofocus => false
70
+ with_input_for @user, :age, :integer, autofocus: false
55
71
  assert_no_select 'input.integer[autofocus]'
56
72
  end
57
73
 
58
74
  test 'date input should generate autofocus attribute when autofocus option is false' do
59
- with_input_for @user, :born_at, :date, :autofocus => false
75
+ with_input_for @user, :born_at, :date, autofocus: false
60
76
  assert_no_select 'select.date[autofocus]'
61
77
  end
62
78
 
63
79
  test 'datetime input should generate autofocus attribute when autofocus option is false' do
64
- with_input_for @user, :created_at, :datetime, :autofocus => false
80
+ with_input_for @user, :created_at, :datetime, autofocus: false
65
81
  assert_no_select 'select.datetime[autofocus]'
66
82
  end
67
83
 
@@ -103,12 +119,12 @@ class InputTest < ActionView::TestCase
103
119
  end
104
120
 
105
121
  test 'input as select with collection should be generated properly when object is not present' do
106
- with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
122
+ with_input_for :project, :name, :select, collection: ['Jose', 'Carlos']
107
123
  assert_select 'select.select#project_name'
108
124
  end
109
125
 
110
126
  test 'input should not generate empty css class' do
111
- swap SimpleForm, :generate_additional_classes_for => [:wrapper, :label] do
127
+ swap SimpleForm, generate_additional_classes_for: [:wrapper, :label] do
112
128
  with_input_for :project, :name, :string
113
129
  assert_no_select 'input#project_name[class]'
114
130
  end