simple_form 3.0.1 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +75 -25
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +251 -93
  5. data/lib/generators/simple_form/install_generator.rb +3 -3
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +29 -9
  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 +86 -5
  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 +1 -0
  12. data/lib/simple_form/action_view_extensions/form_helper.rb +6 -2
  13. data/lib/simple_form/components/errors.rb +28 -2
  14. data/lib/simple_form/components/hints.rb +2 -2
  15. data/lib/simple_form/components/html5.rb +5 -5
  16. data/lib/simple_form/components/label_input.rb +20 -2
  17. data/lib/simple_form/components/labels.rb +11 -7
  18. data/lib/simple_form/components/maxlength.rb +1 -1
  19. data/lib/simple_form/components/min_max.rb +1 -1
  20. data/lib/simple_form/components/pattern.rb +1 -1
  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/form_builder.rb +127 -76
  24. data/lib/simple_form/helpers.rb +5 -5
  25. data/lib/simple_form/inputs/base.rb +33 -11
  26. data/lib/simple_form/inputs/block_input.rb +1 -1
  27. data/lib/simple_form/inputs/boolean_input.rb +28 -15
  28. data/lib/simple_form/inputs/collection_input.rb +30 -9
  29. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +7 -12
  30. data/lib/simple_form/inputs/collection_select_input.rb +4 -2
  31. data/lib/simple_form/inputs/date_time_input.rb +23 -9
  32. data/lib/simple_form/inputs/file_input.rb +4 -2
  33. data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
  34. data/lib/simple_form/inputs/hidden_input.rb +4 -2
  35. data/lib/simple_form/inputs/numeric_input.rb +5 -4
  36. data/lib/simple_form/inputs/password_input.rb +4 -2
  37. data/lib/simple_form/inputs/priority_input.rb +4 -2
  38. data/lib/simple_form/inputs/range_input.rb +1 -1
  39. data/lib/simple_form/inputs/string_input.rb +4 -2
  40. data/lib/simple_form/inputs/text_input.rb +4 -2
  41. data/lib/simple_form/railtie.rb +7 -0
  42. data/lib/simple_form/tags.rb +6 -0
  43. data/lib/simple_form/version.rb +1 -1
  44. data/lib/simple_form/wrappers/builder.rb +6 -6
  45. data/lib/simple_form/wrappers/leaf.rb +28 -0
  46. data/lib/simple_form/wrappers/many.rb +6 -6
  47. data/lib/simple_form/wrappers/root.rb +1 -1
  48. data/lib/simple_form/wrappers/single.rb +5 -3
  49. data/lib/simple_form/wrappers.rb +1 -0
  50. data/lib/simple_form.rb +59 -8
  51. data/test/action_view_extensions/builder_test.rb +36 -36
  52. data/test/action_view_extensions/form_helper_test.rb +33 -14
  53. data/test/components/label_test.rb +37 -37
  54. data/test/form_builder/association_test.rb +52 -35
  55. data/test/form_builder/button_test.rb +10 -10
  56. data/test/form_builder/error_notification_test.rb +1 -1
  57. data/test/form_builder/error_test.rb +144 -24
  58. data/test/form_builder/general_test.rb +107 -71
  59. data/test/form_builder/hint_test.rb +18 -18
  60. data/test/form_builder/input_field_test.rb +86 -56
  61. data/test/form_builder/label_test.rb +55 -13
  62. data/test/form_builder/wrapper_test.rb +136 -20
  63. data/test/generators/simple_form_generator_test.rb +4 -4
  64. data/test/inputs/boolean_input_test.rb +62 -6
  65. data/test/inputs/collection_check_boxes_input_test.rb +85 -17
  66. data/test/inputs/collection_radio_buttons_input_test.rb +134 -36
  67. data/test/inputs/collection_select_input_test.rb +146 -41
  68. data/test/inputs/datetime_input_test.rb +120 -48
  69. data/test/inputs/disabled_test.rb +15 -15
  70. data/test/inputs/discovery_test.rb +56 -6
  71. data/test/inputs/file_input_test.rb +2 -2
  72. data/test/inputs/general_test.rb +20 -20
  73. data/test/inputs/grouped_collection_select_input_test.rb +44 -8
  74. data/test/inputs/hidden_input_test.rb +4 -4
  75. data/test/inputs/numeric_input_test.rb +43 -43
  76. data/test/inputs/priority_input_test.rb +13 -13
  77. data/test/inputs/readonly_test.rb +19 -19
  78. data/test/inputs/required_test.rb +25 -13
  79. data/test/inputs/string_input_test.rb +50 -30
  80. data/test/inputs/text_input_test.rb +14 -7
  81. data/test/simple_form_test.rb +8 -0
  82. data/test/support/discovery_inputs.rb +32 -2
  83. data/test/support/misc_helpers.rb +84 -5
  84. data/test/support/models.rb +60 -24
  85. data/test/test_helper.rb +11 -1
  86. metadata +22 -33
@@ -8,7 +8,7 @@ class FormBuilderTest < ActionView::TestCase
8
8
  end
9
9
  end
10
10
 
11
- test 'nested simple fields should yield an instance of FormBuilder' do
11
+ test 'nested simple fields yields an instance of FormBuilder' do
12
12
  simple_form_for :user do |f|
13
13
  f.simple_fields_for :posts do |posts_form|
14
14
  assert posts_form.instance_of?(SimpleForm::FormBuilder)
@@ -22,7 +22,7 @@ class FormBuilderTest < ActionView::TestCase
22
22
  end
23
23
  end
24
24
 
25
- test 'builder should work without controller' do
25
+ test 'builder works without controller' do
26
26
  stub_any_instance ActionView::TestCase, :controller, nil do
27
27
  simple_form_for @user do |f|
28
28
  assert f.input(:name)
@@ -30,7 +30,7 @@ class FormBuilderTest < ActionView::TestCase
30
30
  end
31
31
  end
32
32
 
33
- test 'builder input should allow a block to configure input' do
33
+ test 'builder input allows a block to configure input' do
34
34
  with_form_for @user, :name do
35
35
  text_field_tag :foo, :bar, id: :cool
36
36
  end
@@ -38,7 +38,7 @@ class FormBuilderTest < ActionView::TestCase
38
38
  assert_select 'input#cool'
39
39
  end
40
40
 
41
- test 'builder should allow adding custom input mappings for default input types' do
41
+ test 'builder allows adding custom input mappings for default input types' do
42
42
  swap SimpleForm, input_mappings: { /count$/ => :integer } do
43
43
  with_form_for @user, :post_count
44
44
  assert_no_select 'form input#user_post_count.string'
@@ -46,7 +46,18 @@ class FormBuilderTest < ActionView::TestCase
46
46
  end
47
47
  end
48
48
 
49
- test 'builder should allow to skip input_type class' do
49
+ test 'builder does not override custom input mappings for custom collection' do
50
+ swap SimpleForm, input_mappings: { /gender$/ => :check_boxes } do
51
+ with_concat_form_for @user do |f|
52
+ f.input :gender, collection: [:male, :female]
53
+ end
54
+
55
+ assert_no_select 'select option', 'Male'
56
+ assert_select 'input[type=checkbox][value=male]'
57
+ end
58
+ end
59
+
60
+ test 'builder allows to skip input_type class' do
50
61
  swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
51
62
  with_form_for @user, :post_count
52
63
  assert_no_select "form input#user_post_count.integer"
@@ -54,7 +65,7 @@ class FormBuilderTest < ActionView::TestCase
54
65
  end
55
66
  end
56
67
 
57
- test 'builder should allow to add additional classes only for wrapper' do
68
+ test 'builder allows to add additional classes only for wrapper' do
58
69
  swap SimpleForm, generate_additional_classes_for: [:wrapper] do
59
70
  with_form_for @user, :post_count
60
71
  assert_no_select "form input#user_post_count.string"
@@ -63,7 +74,7 @@ class FormBuilderTest < ActionView::TestCase
63
74
  end
64
75
  end
65
76
 
66
- test 'builder should allow adding custom input mappings for integer input types' do
77
+ test 'builder allows adding custom input mappings for integer input types' do
67
78
  swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
68
79
  with_form_for @user, :lock_version
69
80
  assert_no_select 'form input#user_lock_version.integer'
@@ -101,82 +112,87 @@ class FormBuilderTest < ActionView::TestCase
101
112
  end
102
113
 
103
114
  # INPUT TYPES
104
- test 'builder should generate text fields for string columns' do
115
+ test 'builder generates text fields for string columns' do
105
116
  with_form_for @user, :name
106
117
  assert_select 'form input#user_name.string'
107
118
  end
108
119
 
109
- test 'builder should generate text areas for text columns' do
120
+ test 'builder generates text areas for text columns' do
110
121
  with_form_for @user, :description
111
122
  assert_select 'form textarea#user_description.text'
112
123
  end
113
124
 
114
- test 'builder should generate a checkbox for boolean columns' do
125
+ test 'builder generates a checkbox for boolean columns' do
115
126
  with_form_for @user, :active
116
127
  assert_select 'form input[type=checkbox]#user_active.boolean'
117
128
  end
118
129
 
119
- test 'builder should use integer text field for integer columns' do
130
+ test 'builder uses integer text field for integer columns' do
120
131
  with_form_for @user, :age
121
132
  assert_select 'form input#user_age.numeric.integer'
122
133
  end
123
134
 
124
- test 'builder should generate decimal text field for decimal columns' do
135
+ test 'builder generates decimal text field for decimal columns' do
125
136
  with_form_for @user, :credit_limit
126
137
  assert_select 'form input#user_credit_limit.numeric.decimal'
127
138
  end
128
139
 
129
- test 'builder should generate password fields for columns that matches password' do
140
+ test 'builder generates uuid fields for uuid columns' do
141
+ with_form_for @user, :uuid
142
+ assert_select 'form input#user_uuid.string.uuid'
143
+ end
144
+
145
+ test 'builder generates password fields for columns that matches password' do
130
146
  with_form_for @user, :password
131
147
  assert_select 'form input#user_password.password'
132
148
  end
133
149
 
134
- test 'builder should generate country fields for columns that matches country' do
150
+ test 'builder generates country fields for columns that matches country' do
135
151
  with_form_for @user, :residence_country
136
152
  assert_select 'form select#user_residence_country.country'
137
153
  end
138
154
 
139
- test 'builder should generate time_zone fields for columns that matches time_zone' do
155
+ test 'builder generates time_zone fields for columns that matches time_zone' do
140
156
  with_form_for @user, :time_zone
141
157
  assert_select 'form select#user_time_zone.time_zone'
142
158
  end
143
159
 
144
- test 'builder should generate email fields for columns that matches email' do
160
+ test 'builder generates email fields for columns that matches email' do
145
161
  with_form_for @user, :email
146
162
  assert_select 'form input#user_email.string.email'
147
163
  end
148
164
 
149
- test 'builder should generate tel fields for columns that matches phone' do
165
+ test 'builder generates tel fields for columns that matches phone' do
150
166
  with_form_for @user, :phone_number
151
167
  assert_select 'form input#user_phone_number.string.tel'
152
168
  end
153
169
 
154
- test 'builder should generate url fields for columns that matches url' do
170
+ test 'builder generates url fields for columns that matches url' do
155
171
  with_form_for @user, :url
156
172
  assert_select 'form input#user_url.string.url'
157
173
  end
158
174
 
159
- test 'builder should generate date select for date columns' do
175
+ test 'builder generates date select for date columns' do
160
176
  with_form_for @user, :born_at
161
177
  assert_select 'form select#user_born_at_1i.date'
162
178
  end
163
179
 
164
- test 'builder should generate time select for time columns' do
180
+ test 'builder generates time select for time columns' do
165
181
  with_form_for @user, :delivery_time
166
182
  assert_select 'form select#user_delivery_time_4i.time'
167
183
  end
168
184
 
169
- test 'builder should generate datetime select for datetime columns' do
185
+ test 'builder generates datetime select for datetime columns' do
170
186
  with_form_for @user, :created_at
171
187
  assert_select 'form select#user_created_at_1i.datetime'
172
188
  end
173
189
 
174
- test 'builder should generate datetime select for timestamp columns' do
190
+ test 'builder generates datetime select for timestamp columns' do
175
191
  with_form_for @user, :updated_at
176
192
  assert_select 'form select#user_updated_at_1i.datetime'
177
193
  end
178
194
 
179
- test 'builder should generate file for file columns' do
195
+ test 'builder generates file for file columns' do
180
196
  @user.avatar = MiniTest::Mock.new
181
197
  @user.avatar.expect(:public_filename, true)
182
198
 
@@ -184,7 +200,7 @@ class FormBuilderTest < ActionView::TestCase
184
200
  assert_select 'form input#user_avatar.file'
185
201
  end
186
202
 
187
- test 'builder should generate file for attributes that are real db columns but have file methods' do
203
+ test 'builder generates file for attributes that are real db columns but have file methods' do
188
204
  @user.home_picture = MiniTest::Mock.new
189
205
  @user.home_picture.expect(:mounted_as, true)
190
206
 
@@ -192,12 +208,12 @@ class FormBuilderTest < ActionView::TestCase
192
208
  assert_select 'form input#user_home_picture.file'
193
209
  end
194
210
 
195
- test 'build should generate select if a collection is given' do
211
+ test 'build generates select if a collection is given' do
196
212
  with_form_for @user, :age, collection: 1..60
197
213
  assert_select 'form select#user_age.select'
198
214
  end
199
215
 
200
- test 'builder should allow overriding default input type for text' do
216
+ test 'builder allows overriding default input type for text' do
201
217
  with_form_for @user, :name, as: :text
202
218
  assert_no_select 'form input#user_name'
203
219
  assert_select 'form textarea#user_name.text'
@@ -212,76 +228,96 @@ class FormBuilderTest < ActionView::TestCase
212
228
  end
213
229
 
214
230
  # COMMON OPTIONS
215
- test 'builder should add chosen form class' do
216
- swap SimpleForm, form_class: :my_custom_class do
231
+ # Remove this test when SimpleForm.form_class is removed in 4.x
232
+ test 'builder adds chosen form class' do
233
+ ActiveSupport::Deprecation.silence do
234
+ swap SimpleForm, form_class: :my_custom_class do
235
+ with_form_for @user, :name
236
+ assert_select 'form.my_custom_class'
237
+ end
238
+ end
239
+ end
240
+
241
+ # Remove this test when SimpleForm.form_class is removed in 4.x
242
+ test 'builder adds chosen form class and default form class' do
243
+ ActiveSupport::Deprecation.silence do
244
+ swap SimpleForm, form_class: "my_custom_class", default_form_class: "my_default_class" do
245
+ with_form_for @user, :name
246
+ assert_select 'form.my_custom_class.my_default_class'
247
+ end
248
+ end
249
+ end
250
+
251
+ test 'builder adds default form class' do
252
+ swap SimpleForm, default_form_class: "default_class" do
217
253
  with_form_for @user, :name
218
- assert_select 'form.my_custom_class'
254
+ assert_select 'form.default_class'
219
255
  end
220
256
  end
221
257
 
222
- test 'builder should allow passing options to input' do
258
+ test 'builder allows passing options to input' do
223
259
  with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
224
260
  assert_select 'form input#my_input.my_input.string'
225
261
  end
226
262
 
227
- test 'builder should not propagate input options to wrapper' do
263
+ test 'builder does not propagate input options to wrapper' do
228
264
  with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
229
265
  assert_no_select 'form div.input.my_input.string'
230
266
  assert_select 'form input#my_input.my_input.string'
231
267
  end
232
268
 
233
- test 'builder should not propagate input options to wrapper with custom wrapper' do
234
- swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
269
+ test 'builder does not propagate input options to wrapper with custom wrapper' do
270
+ swap_wrapper :default, custom_wrapper_with_wrapped_input do
235
271
  with_form_for @user, :name, input_html: { class: 'my_input' }
236
272
  assert_no_select 'form div.input.my_input'
237
273
  assert_select 'form input.my_input.string'
238
274
  end
239
275
  end
240
276
 
241
- test 'builder should not propagate label options to wrapper with custom wrapper' do
242
- swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
277
+ test 'builder does not propagate label options to wrapper with custom wrapper' do
278
+ swap_wrapper :default, custom_wrapper_with_wrapped_label do
243
279
  with_form_for @user, :name, label_html: { class: 'my_label' }
244
280
  assert_no_select 'form div.label.my_label'
245
281
  assert_select 'form label.my_label.string'
246
282
  end
247
283
  end
248
284
 
249
- test 'builder should generate a input with label' do
285
+ test 'builder generates an input with label' do
250
286
  with_form_for @user, :name
251
287
  assert_select 'form label.string[for=user_name]', /Name/
252
288
  end
253
289
 
254
- test 'builder should be able to disable the label for a input' do
290
+ test 'builder is able to disable the label for an input' do
255
291
  with_form_for @user, :name, label: false
256
292
  assert_no_select 'form label'
257
293
  end
258
294
 
259
- test 'builder should be able to disable the label for an input and return a html safe string' do
295
+ test 'builder is able to disable the label for an input and return a html safe string' do
260
296
  with_form_for @user, :name, label: false, wrapper: custom_wrapper_with_wrapped_label_input
261
297
  assert_select 'form input#user_name'
262
298
  end
263
299
 
264
- test 'builder should use custom label' do
300
+ test 'builder uses custom label' do
265
301
  with_form_for @user, :name, label: 'Yay!'
266
302
  assert_select 'form label', /Yay!/
267
303
  end
268
304
 
269
- test 'builder should pass options to label' do
305
+ test 'builder passes options to label' do
270
306
  with_form_for @user, :name, label_html: { id: "cool" }
271
307
  assert_select 'form label#cool', /Name/
272
308
  end
273
309
 
274
- test 'builder should not generate hints for a input' do
310
+ test 'builder does not generate hints for an input' do
275
311
  with_form_for @user, :name
276
312
  assert_no_select 'span.hint'
277
313
  end
278
314
 
279
- test 'builder should be able to add a hint for a input' do
315
+ test 'builder is able to add a hint for an input' do
280
316
  with_form_for @user, :name, hint: 'test'
281
317
  assert_select 'span.hint', 'test'
282
318
  end
283
319
 
284
- test 'builder should be able to disable a hint even if it exists in i18n' do
320
+ test 'builder is able to disable a hint even if it exists in i18n' do
285
321
  store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
286
322
  stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
287
323
  with_form_for @user, :name, hint: false
@@ -290,32 +326,32 @@ class FormBuilderTest < ActionView::TestCase
290
326
  end
291
327
  end
292
328
 
293
- test 'builder should pass options to hint' do
329
+ test 'builder passes options to hint' do
294
330
  with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }
295
331
  assert_select 'span.hint#cool', 'test'
296
332
  end
297
333
 
298
- test 'builder should generate errors for attribute without errors' do
334
+ test 'builder generates errors for attribute without errors' do
299
335
  with_form_for @user, :credit_limit
300
336
  assert_no_select 'span.errors'
301
337
  end
302
338
 
303
- test 'builder should generate errors for attribute with errors' do
339
+ test 'builder generates errors for attribute with errors' do
304
340
  with_form_for @user, :name
305
- assert_select 'span.error', "can't be blank"
341
+ assert_select 'span.error', "cannot be blank"
306
342
  end
307
343
 
308
- test 'builder should be able to disable showing errors for a input' do
344
+ test 'builder is able to disable showing errors for an input' do
309
345
  with_form_for @user, :name, error: false
310
346
  assert_no_select 'span.error'
311
347
  end
312
348
 
313
- test 'builder should pass options to errors' do
349
+ test 'builder passes options to errors' do
314
350
  with_form_for @user, :name, error_html: { id: "cool" }
315
- assert_select 'span.error#cool', "can't be blank"
351
+ assert_select 'span.error#cool', "cannot be blank"
316
352
  end
317
353
 
318
- test 'placeholder should not be generated when set to false' do
354
+ test 'placeholder does not be generated when set to false' do
319
355
  store_translations(:en, simple_form: { placeholders: { user: {
320
356
  name: 'Name goes here'
321
357
  } } }) do
@@ -326,30 +362,30 @@ class FormBuilderTest < ActionView::TestCase
326
362
 
327
363
  # DEFAULT OPTIONS
328
364
  [:input, :input_field].each do |method|
329
- test "builder should receive a default argument and pass it to the inputs when calling '#{method}'" do
365
+ test "builder receives a default argument and pass it to the inputs when calling '#{method}'" do
330
366
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
331
- f.send(method, :name)
367
+ f.public_send(method, :name)
332
368
  end
333
369
  assert_select 'input.default_class'
334
370
  end
335
371
 
336
- test "builder should receive a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
372
+ test "builder receives a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
337
373
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
338
- concat(f.send(method, :name))
339
- concat(f.send(method, :credit_limit))
374
+ concat(f.public_send(method, :name))
375
+ concat(f.public_send(method, :credit_limit))
340
376
  end
341
377
 
342
378
  assert_select "input.string.default_class[name='user[name]']"
343
379
  assert_no_select "input.string[name='user[credit_limit]']"
344
380
  end
345
381
 
346
- test "builder should receive a default argument and pass it to the inputs and nested form when calling '#{method}'" do
382
+ test "builder receives a default argument and pass it to the inputs and nested form when calling '#{method}'" do
347
383
  @user.company = Company.new(1, 'Empresa')
348
384
 
349
385
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
350
- concat(f.send(method, :name))
386
+ concat(f.public_send(method, :name))
351
387
  concat(f.simple_fields_for(:company) do |company_form|
352
- concat(company_form.send(method, :name))
388
+ concat(company_form.public_send(method, :name))
353
389
  end)
354
390
  end
355
391
 
@@ -358,28 +394,28 @@ class FormBuilderTest < ActionView::TestCase
358
394
  end
359
395
  end
360
396
 
361
- test "builder should receive a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
397
+ test "builder receives a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
362
398
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
363
399
  f.input :name, input_html: { id: 'specific_id' }
364
400
  end
365
401
  assert_select 'input.default_class#specific_id'
366
402
  end
367
403
 
368
- test "builder should receive a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
404
+ test "builder receives a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
369
405
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
370
406
  f.input_field :name, id: 'specific_id'
371
407
  end
372
408
  assert_select 'input.default_class#specific_id'
373
409
  end
374
410
 
375
- test "builder should receive a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
411
+ test "builder receives a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
376
412
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
377
413
  f.input :name, input_html: { id: 'specific_id' }
378
414
  end
379
415
  assert_select 'input.default_class#specific_id'
380
416
  end
381
417
 
382
- test "builder should receive a default argument and pass it to the inputs when calling 'input_field', overwriting the defaults with specific options" do
418
+ test "builder receives a default argument and pass it to the inputs when calling 'input_field', overwriting the defaults with specific options" do
383
419
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
384
420
  f.input_field :name, id: 'specific_id'
385
421
  end
@@ -387,24 +423,24 @@ class FormBuilderTest < ActionView::TestCase
387
423
  end
388
424
 
389
425
  # WITHOUT OBJECT
390
- test 'builder should generate properly when object is not present' do
426
+ test 'builder generates properly when object is not present' do
391
427
  with_form_for :project, :name
392
428
  assert_select 'form input.string#project_name'
393
429
  end
394
430
 
395
- test 'builder should generate password fields based on attribute name when object is not present' do
431
+ test 'builder generates password fields based on attribute name when object is not present' do
396
432
  with_form_for :project, :password_confirmation
397
433
  assert_select 'form input[type=password].password#project_password_confirmation'
398
434
  end
399
435
 
400
- test 'builder should generate text fields by default for all attributes when object is not present' do
436
+ test 'builder generates text fields by default for all attributes when object is not present' do
401
437
  with_form_for :project, :created_at
402
438
  assert_select 'form input.string#project_created_at'
403
439
  with_form_for :project, :budget
404
440
  assert_select 'form input.string#project_budget'
405
441
  end
406
442
 
407
- test 'builder should allow overriding input type when object is not present' do
443
+ test 'builder allows overriding input type when object is not present' do
408
444
  with_form_for :project, :created_at, as: :datetime
409
445
  assert_select 'form select.datetime#project_created_at_1i'
410
446
  with_form_for :project, :budget, as: :decimal
@@ -412,24 +448,24 @@ class FormBuilderTest < ActionView::TestCase
412
448
  end
413
449
 
414
450
  # CUSTOM FORM BUILDER
415
- test 'custom builder should inherit mappings' do
451
+ test 'custom builder inherits mappings' do
416
452
  with_custom_form_for @user, :email
417
453
  assert_select 'form input[type=email]#user_email.custom'
418
454
  end
419
455
 
420
- test 'form with CustomMapTypeFormBuilder should use custom map type builder' do
456
+ test 'form with CustomMapTypeFormBuilder uses custom map type builder' do
421
457
  with_concat_custom_mapping_form_for(:user) do |user|
422
458
  assert user.instance_of?(CustomMapTypeFormBuilder)
423
459
  end
424
460
  end
425
461
 
426
- test 'form with CustomMapTypeFormBuilder should use custom mapping' do
462
+ test 'form with CustomMapTypeFormBuilder uses custom mapping' do
427
463
  with_concat_custom_mapping_form_for(:user) do |user|
428
464
  assert_equal SimpleForm::Inputs::StringInput, user.class.mappings[:custom_type]
429
465
  end
430
466
  end
431
467
 
432
- test 'form without CustomMapTypeFormBuilder should not use custom mapping' do
468
+ test 'form without CustomMapTypeFormBuilder does not use custom mapping' do
433
469
  with_concat_form_for(:user) do |user|
434
470
  assert_nil user.class.mappings[:custom_type]
435
471
  end
@@ -8,24 +8,24 @@ class HintTest < ActionView::TestCase
8
8
  end
9
9
  end
10
10
 
11
- test 'hint should not be generated by default' do
11
+ test 'hint does not be generated by default' do
12
12
  with_hint_for @user, :name
13
13
  assert_no_select 'span.hint'
14
14
  end
15
15
 
16
- test 'hint should be generated with optional text' do
16
+ test 'hint is generated with optional text' do
17
17
  with_hint_for @user, :name, hint: 'Use with care...'
18
18
  assert_select 'span.hint', 'Use with care...'
19
19
  end
20
20
 
21
- test 'hint should not modify the options hash' do
21
+ test 'hint does not modify the options hash' do
22
22
  options = { hint: 'Use with care...' }
23
23
  with_hint_for @user, :name, options
24
24
  assert_select 'span.hint', 'Use with care...'
25
25
  assert_equal({ hint: 'Use with care...' }, options)
26
26
  end
27
27
 
28
- test 'hint should be generated cleanly with optional text' do
28
+ test 'hint is generated cleanly with optional text' do
29
29
  with_hint_for @user, :name, hint: 'Use with care...', hint_tag: :span
30
30
  assert_no_select 'span.hint[hint]'
31
31
  assert_no_select 'span.hint[hint_tag]'
@@ -37,20 +37,20 @@ class HintTest < ActionView::TestCase
37
37
  assert_select 'p.hint', 'Use with care...'
38
38
  end
39
39
 
40
- test 'hint should be able to pass html options' do
40
+ test 'hint is able to pass html options' do
41
41
  with_hint_for @user, :name, hint: 'Yay!', id: 'hint', class: 'yay'
42
42
  assert_select 'span#hint.hint.yay'
43
43
  end
44
44
 
45
- test 'hint should be output as html_safe' do
45
+ test 'hint is output as html_safe' do
46
46
  with_hint_for @user, :name, hint: '<b>Bold</b> and not...'.html_safe
47
47
  assert_select 'span.hint', 'Bold and not...'
48
48
  assert_select 'span.hint b', 'Bold'
49
49
  end
50
50
 
51
- test 'builder should escape hint text' do
51
+ test 'builder escapes hint text' do
52
52
  with_hint_for @user, :name, hint: '<script>alert(1337)</script>'
53
- assert_select 'span.hint', "&lt;script&gt;alert(1337)&lt;/script&gt;"
53
+ assert_no_select 'span.hint script'
54
54
  end
55
55
 
56
56
  # Without attribute name
@@ -60,7 +60,7 @@ class HintTest < ActionView::TestCase
60
60
  assert_select 'span.hint', 'Hello World!'
61
61
  end
62
62
 
63
- test 'hint without attribute name should generate component tag with a clean HTML' do
63
+ test 'hint without attribute name generates component tag with a clean HTML' do
64
64
  with_hint_for @validating_user, 'Hello World!'
65
65
  assert_no_select 'span.hint[hint]'
66
66
  assert_no_select 'span.hint[hint_html]'
@@ -73,14 +73,14 @@ class HintTest < ActionView::TestCase
73
73
  assert_no_select 'p.hint[hint_tag]'
74
74
  end
75
75
 
76
- test 'hint without attribute name should be able to pass html options' do
76
+ test 'hint without attribute name is able to pass html options' do
77
77
  with_hint_for @user, 'Yay', id: 'hint', class: 'yay'
78
78
  assert_select 'span#hint.hint.yay', 'Yay'
79
79
  end
80
80
 
81
81
  # I18n
82
82
 
83
- test 'hint should use i18n based on model, action, and attribute to lookup translation' do
83
+ test 'hint uses i18n based on model, action, and attribute to lookup translation' do
84
84
  store_translations(:en, simple_form: { hints: { user: {
85
85
  edit: { name: 'Content of this input will be truncated...' }
86
86
  } } }) do
@@ -89,7 +89,7 @@ class HintTest < ActionView::TestCase
89
89
  end
90
90
  end
91
91
 
92
- test 'hint should use i18n with model and attribute to lookup translation' do
92
+ test 'hint uses i18n with model and attribute to lookup translation' do
93
93
  store_translations(:en, simple_form: { hints: { user: {
94
94
  name: 'Content of this input will be capitalized...'
95
95
  } } }) do
@@ -98,7 +98,7 @@ class HintTest < ActionView::TestCase
98
98
  end
99
99
  end
100
100
 
101
- test 'hint should use i18n under defaults namespace to lookup translation' do
101
+ test 'hint uses i18n under defaults namespace to lookup translation' do
102
102
  store_translations(:en, simple_form: {
103
103
  hints: { defaults: { name: 'Content of this input will be downcased...' } }
104
104
  }) do
@@ -107,7 +107,7 @@ class HintTest < ActionView::TestCase
107
107
  end
108
108
  end
109
109
 
110
- test 'hint should use i18n with lookup for association name' do
110
+ test 'hint uses i18n with lookup for association name' do
111
111
  store_translations(:en, simple_form: { hints: {
112
112
  user: { company: 'My company!' }
113
113
  } } ) do
@@ -116,7 +116,7 @@ class HintTest < ActionView::TestCase
116
116
  end
117
117
  end
118
118
 
119
- test 'hint should output translations as html_safe' do
119
+ test 'hint outputs translations as html_safe' do
120
120
  store_translations(:en, simple_form: { hints: { user: {
121
121
  edit: { name: '<b>This is bold</b> and this is not...' }
122
122
  } } }) do
@@ -128,7 +128,7 @@ class HintTest < ActionView::TestCase
128
128
 
129
129
  # No object
130
130
 
131
- test 'hint should generate properly when object is not present' do
131
+ test 'hint generates properly when object is not present' do
132
132
  with_hint_for :project, :name, hint: 'Test without object'
133
133
  assert_select 'span.hint', 'Test without object'
134
134
  end
@@ -137,8 +137,8 @@ class HintTest < ActionView::TestCase
137
137
 
138
138
  test 'hint with custom wrappers works' do
139
139
  swap_wrapper do
140
- with_hint_for @user, :name, hint: "can't be blank"
141
- assert_select 'div.omg_hint', "can&#39;t be blank"
140
+ with_hint_for @user, :name, hint: "cannot be blank"
141
+ assert_select 'div.omg_hint', "cannot be blank"
142
142
  end
143
143
  end
144
144
  end