simple_form 2.1.3 → 3.0.0.rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -50
  3. data/README.md +140 -116
  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 +13 -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/form_helper.rb +2 -9
  11. data/lib/simple_form/components/errors.rb +1 -7
  12. data/lib/simple_form/components/hints.rb +2 -7
  13. data/lib/simple_form/components/html5.rb +5 -2
  14. data/lib/simple_form/components/labels.rb +4 -4
  15. data/lib/simple_form/components/maxlength.rb +1 -8
  16. data/lib/simple_form/components/pattern.rb +2 -2
  17. data/lib/simple_form/components.rb +1 -1
  18. data/lib/simple_form/error_notification.rb +2 -2
  19. data/lib/simple_form/form_builder.rb +148 -50
  20. data/lib/simple_form/helpers.rb +1 -1
  21. data/lib/simple_form/inputs/base.rb +3 -10
  22. data/lib/simple_form/inputs/block_input.rb +1 -1
  23. data/lib/simple_form/inputs/boolean_input.rb +6 -6
  24. data/lib/simple_form/inputs/collection_input.rb +7 -7
  25. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  26. data/lib/simple_form/inputs/password_input.rb +0 -1
  27. data/lib/simple_form/inputs/string_input.rb +0 -1
  28. data/lib/simple_form/railtie.rb +7 -0
  29. data/lib/simple_form/tags.rb +61 -0
  30. data/lib/simple_form/version.rb +1 -1
  31. data/lib/simple_form/wrappers/builder.rb +5 -29
  32. data/lib/simple_form/wrappers/many.rb +1 -1
  33. data/lib/simple_form/wrappers/root.rb +1 -1
  34. data/lib/simple_form/wrappers.rb +1 -1
  35. data/lib/simple_form.rb +39 -47
  36. data/test/action_view_extensions/builder_test.rb +75 -95
  37. data/test/action_view_extensions/form_helper_test.rb +25 -16
  38. data/test/components/label_test.rb +46 -46
  39. data/test/form_builder/association_test.rb +39 -29
  40. data/test/form_builder/button_test.rb +4 -4
  41. data/test/form_builder/error_notification_test.rb +8 -8
  42. data/test/form_builder/error_test.rb +18 -65
  43. data/test/form_builder/general_test.rb +60 -74
  44. data/test/form_builder/hint_test.rb +23 -29
  45. data/test/form_builder/input_field_test.rb +12 -12
  46. data/test/form_builder/label_test.rb +6 -16
  47. data/test/form_builder/wrapper_test.rb +21 -21
  48. data/test/inputs/boolean_input_test.rb +23 -35
  49. data/test/inputs/collection_check_boxes_input_test.rb +61 -55
  50. data/test/inputs/collection_radio_buttons_input_test.rb +76 -79
  51. data/test/inputs/collection_select_input_test.rb +70 -51
  52. data/test/inputs/datetime_input_test.rb +17 -11
  53. data/test/inputs/disabled_test.rb +10 -10
  54. data/test/inputs/discovery_test.rb +4 -4
  55. data/test/inputs/file_input_test.rb +1 -1
  56. data/test/inputs/general_test.rb +12 -12
  57. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  58. data/test/inputs/hidden_input_test.rb +3 -2
  59. data/test/inputs/numeric_input_test.rb +3 -3
  60. data/test/inputs/priority_input_test.rb +9 -3
  61. data/test/inputs/readonly_test.rb +12 -12
  62. data/test/inputs/required_test.rb +5 -5
  63. data/test/inputs/string_input_test.rb +15 -25
  64. data/test/inputs/text_input_test.rb +1 -1
  65. data/test/support/misc_helpers.rb +46 -24
  66. data/test/support/mock_controller.rb +6 -6
  67. data/test/support/models.rb +62 -64
  68. data/test/test_helper.rb +20 -24
  69. metadata +37 -23
  70. 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,13 @@ 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
59
  test 'input should mark the selected value also when using integers' do
60
60
  @user.age = 18
61
- with_input_for @user, :age, :select, :collection => 18..60
61
+ with_input_for @user, :age, :select, collection: 18..60
62
62
  assert_select 'select option[selected=selected]', '18'
63
63
  end
64
64
 
@@ -70,13 +70,13 @@ class CollectionSelectInputTest < ActionView::TestCase
70
70
  end
71
71
 
72
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]
73
+ with_input_for @user, :age, :select, collection: [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
74
74
  assert_select 'select option[value="2.0"]'
75
75
  assert_select 'select option[value="2.5"]'
76
76
  end
77
77
 
78
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]
79
+ with_input_for @user, :age, :select, collection: ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
80
80
  assert_select 'select option[value="Hello Kitty"]'
81
81
  assert_select 'select option[value="2"]'
82
82
  assert_select 'select option[value="4.5"]'
@@ -87,39 +87,39 @@ class CollectionSelectInputTest < ActionView::TestCase
87
87
  end
88
88
 
89
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
90
+ with_input_for @user, :age, :select, collection: [nil], include_blank: false
91
91
  assert_select 'select option[value=""]'
92
92
  end
93
93
 
94
94
  test 'input should automatically set include blank' do
95
- with_input_for @user, :age, :select, :collection => 18..30
95
+ with_input_for @user, :age, :select, collection: 18..30
96
96
  assert_select 'select option[value=]', ''
97
97
  end
98
98
 
99
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
100
+ with_input_for @user, :age, :select, collection: 18..30, include_blank: false
101
101
  assert_no_select 'select option[value=]', ''
102
102
  end
103
103
 
104
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"
105
+ with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
106
106
  assert_no_select 'select option[value=]', ''
107
107
  end
108
108
 
109
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 }
110
+ with_input_for @user, :age, :select, collection: 18..30, input_html: { multiple: true }
111
111
  assert_no_select 'select option[value=]', ''
112
112
  end
113
113
 
114
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
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
117
  assert_select 'select option[value=1]', 'Jose'
118
118
  assert_select 'select option[value=2]', 'Carlos'
119
119
  end
120
120
 
121
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
122
+ with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: true
123
123
  assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
124
124
  assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
125
125
  assert_select 'select[disabled=disabled]'
@@ -127,7 +127,7 @@ class CollectionSelectInputTest < ActionView::TestCase
127
127
  end
128
128
 
129
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'
130
+ with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: 'Jose'
131
131
  assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
132
132
  assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
133
133
  assert_no_select 'select[disabled=disabled]'
@@ -136,101 +136,120 @@ class CollectionSelectInputTest < ActionView::TestCase
136
136
 
137
137
  test 'input should allow overriding label and value method using a lambda for collection selects' do
138
138
  with_input_for @user, :name, :select,
139
- :collection => ['Jose' , 'Carlos'],
140
- :label_method => lambda { |i| i.upcase },
141
- :value_method => lambda { |i| i.downcase }
139
+ collection: ['Jose', 'Carlos'],
140
+ label_method: lambda { |i| i.upcase },
141
+ value_method: lambda { |i| i.downcase }
142
142
  assert_select 'select option[value=jose]', "JOSE"
143
143
  assert_select 'select option[value=carlos]', "CARLOS"
144
144
  end
145
145
 
146
146
  test 'input should allow overriding only label but not value method using a lambda for collection select' do
147
147
  with_input_for @user, :name, :select,
148
- :collection => ['Jose' , 'Carlos'],
149
- :label_method => lambda { |i| i.upcase }
148
+ collection: ['Jose', 'Carlos'],
149
+ label_method: lambda { |i| i.upcase }
150
150
  assert_select 'select option[value=Jose]', "JOSE"
151
151
  assert_select 'select option[value=Carlos]', "CARLOS"
152
152
  end
153
153
 
154
154
  test 'input should allow overriding only value but not label method using a lambda for collection select' do
155
155
  with_input_for @user, :name, :select,
156
- :collection => ['Jose' , 'Carlos'],
157
- :value_method => lambda { |i| i.downcase }
156
+ collection: ['Jose', 'Carlos'],
157
+ value_method: lambda { |i| i.downcase }
158
158
  assert_select 'select option[value=jose]', "Jose"
159
159
  assert_select 'select option[value=carlos]', "Carlos"
160
160
  end
161
161
 
162
162
  test 'input should allow symbols for collections' do
163
- with_input_for @user, :name, :select, :collection => [:jose, :carlos]
163
+ with_input_for @user, :name, :select, collection: [:jose, :carlos]
164
164
  assert_select 'select.select#user_name'
165
165
  assert_select 'select option[value=jose]', 'jose'
166
166
  assert_select 'select option[value=carlos]', 'carlos'
167
167
  end
168
168
 
169
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']
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']
170
+ with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
177
171
  assert_select 'select.required'
178
172
  assert_select 'select[required]'
179
173
  end
180
174
 
181
175
  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']
176
+ with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
183
177
  assert_select 'select.required'
184
178
  assert_no_select 'select[required]'
179
+ assert_no_select 'select[aria-required=true]'
185
180
  end
186
181
 
187
182
  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']
183
+ with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
189
184
  assert_select 'select.required'
190
185
  assert_select 'select[required]'
191
186
  end
192
187
 
193
188
  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']
189
+ with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
195
190
  assert_select 'select.required'
196
191
  assert_select 'select[required]'
197
192
  end
198
193
 
194
+ test 'with a blank option, a collection input of type select has an aria-required html attribute' do
195
+ with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
196
+ assert_select 'select.required'
197
+ assert_select 'select[aria-required=true]'
198
+ end
199
+
200
+ test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do
201
+ with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
202
+ assert_select 'select.required'
203
+ assert_no_select 'select[aria-required]'
204
+ end
205
+
206
+ test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do
207
+ with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
208
+ assert_select 'select.required'
209
+ assert_select 'select[aria-required=true]'
210
+ end
211
+
212
+ test 'with a blank option and 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: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
214
+ assert_select 'select.required'
215
+ assert_select 'select[aria-required]'
216
+ end
217
+
199
218
  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" }
219
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
220
+ disabled: lambda { |x| x == "Carlos" }
202
221
  assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
203
222
  assert_select 'select option[value=Antonio]', 'Antonio'
204
223
  assert_no_select 'select option[value=Antonio][disabled]'
205
224
  end
206
225
 
207
226
  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 }
227
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
228
+ disabled: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
210
229
  assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
211
230
  assert_select 'select option[value=Antonio]', 'ANTONIO'
212
231
  assert_no_select 'select option[value=Antonio][disabled]'
213
232
  end
214
233
 
215
234
  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 }
235
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
236
+ disabled: "Carlos", label_method: lambda { |x| x.upcase }
218
237
  assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
219
238
  assert_select 'select option[value=Antonio]', 'ANTONIO'
220
239
  assert_no_select 'select option[value=Antonio][disabled]'
221
240
  end
222
241
 
223
242
  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 }
243
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
244
+ selected: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
226
245
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
227
246
  assert_select 'select option[value=Antonio]', 'ANTONIO'
228
247
  assert_no_select 'select option[value=Antonio][selected]'
229
248
  end
230
249
 
231
250
  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 }
251
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
252
+ selected: "Carlos", label_method: lambda { |x| x.upcase }
234
253
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
235
254
  assert_select 'select option[value=Antonio]', 'ANTONIO'
236
255
  assert_no_select 'select option[value=Antonio][selected]'
@@ -238,8 +257,8 @@ class CollectionSelectInputTest < ActionView::TestCase
238
257
 
239
258
  test 'input should not override default selection through attribute value with label method as lambda for collection select' do
240
259
  @user.name = "Carlos"
241
- with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
242
- :label_method => lambda { |x| x.upcase }
260
+ with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
261
+ label_method: lambda { |x| x.upcase }
243
262
  assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
244
263
  assert_select 'select option[value=Antonio]', 'ANTONIO'
245
264
  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,52 @@ 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
23
  test 'text input should generate autofocus attribute when autofocus option is true' do
24
- with_input_for @user, :description, :text, :autofocus => true
24
+ with_input_for @user, :description, :text, autofocus: true
25
25
  assert_select 'textarea.text[autofocus]'
26
26
  end
27
27
 
28
28
  test 'numeric input should generate autofocus attribute when autofocus option is true' do
29
- with_input_for @user, :age, :integer, :autofocus => true
29
+ with_input_for @user, :age, :integer, autofocus: true
30
30
  assert_select 'input.integer[autofocus]'
31
31
  end
32
32
 
33
33
  test 'date input should generate autofocus attribute when autofocus option is true' do
34
- with_input_for @user, :born_at, :date, :autofocus => true
34
+ with_input_for @user, :born_at, :date, autofocus: true
35
35
  assert_select 'select.date[autofocus]'
36
36
  end
37
37
 
38
38
  test 'datetime input should generate autofocus attribute when autofocus option is true' do
39
- with_input_for @user, :created_at, :datetime, :autofocus => true
39
+ with_input_for @user, :created_at, :datetime, autofocus: true
40
40
  assert_select 'select.datetime[autofocus]'
41
41
  end
42
42
 
43
43
  test 'string input should generate autofocus attribute when autofocus option is false' do
44
- with_input_for @user, :name, :string, :autofocus => false
44
+ with_input_for @user, :name, :string, autofocus: false
45
45
  assert_no_select 'input.string[autofocus]'
46
46
  end
47
47
 
48
48
  test 'text input should generate autofocus attribute when autofocus option is false' do
49
- with_input_for @user, :description, :text, :autofocus => false
49
+ with_input_for @user, :description, :text, autofocus: false
50
50
  assert_no_select 'textarea.text[autofocus]'
51
51
  end
52
52
 
53
53
  test 'numeric input should generate autofocus attribute when autofocus option is false' do
54
- with_input_for @user, :age, :integer, :autofocus => false
54
+ with_input_for @user, :age, :integer, autofocus: false
55
55
  assert_no_select 'input.integer[autofocus]'
56
56
  end
57
57
 
58
58
  test 'date input should generate autofocus attribute when autofocus option is false' do
59
- with_input_for @user, :born_at, :date, :autofocus => false
59
+ with_input_for @user, :born_at, :date, autofocus: false
60
60
  assert_no_select 'select.date[autofocus]'
61
61
  end
62
62
 
63
63
  test 'datetime input should generate autofocus attribute when autofocus option is false' do
64
- with_input_for @user, :created_at, :datetime, :autofocus => false
64
+ with_input_for @user, :created_at, :datetime, autofocus: false
65
65
  assert_no_select 'select.datetime[autofocus]'
66
66
  end
67
67
 
@@ -103,12 +103,12 @@ class InputTest < ActionView::TestCase
103
103
  end
104
104
 
105
105
  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']
106
+ with_input_for :project, :name, :select, collection: ['Jose', 'Carlos']
107
107
  assert_select 'select.select#project_name'
108
108
  end
109
109
 
110
110
  test 'input should not generate empty css class' do
111
- swap SimpleForm, :generate_additional_classes_for => [:wrapper, :label] do
111
+ swap SimpleForm, generate_additional_classes_for: [:wrapper, :label] do
112
112
  with_input_for :project, :name, :string
113
113
  assert_no_select 'input#project_name[class]'
114
114
  end