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
@@ -58,21 +58,21 @@ class BuilderTest < ActionView::TestCase
58
58
  end
59
59
 
60
60
  test "collection radio accepts checked item" do
61
- with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => true
61
+ with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: true
62
62
 
63
63
  assert_select 'form input[type=radio][value=true][checked=checked]'
64
64
  assert_no_select 'form input[type=radio][value=false][checked=checked]'
65
65
  end
66
66
 
67
67
  test "collection radio accepts checked item which has a value of false" do
68
- with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => false
68
+ with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: false
69
69
  assert_no_select 'form input[type=radio][value=true][checked=checked]'
70
70
  assert_select 'form input[type=radio][value=false][checked=checked]'
71
71
  end
72
72
 
73
73
  test "collection radio accepts multiple disabled items" do
74
74
  collection = [[1, true], [0, false], [2, 'other']]
75
- with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => [true, false]
75
+ with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: [true, false]
76
76
 
77
77
  assert_select 'form input[type=radio][value=true][disabled=disabled]'
78
78
  assert_select 'form input[type=radio][value=false][disabled=disabled]'
@@ -81,7 +81,7 @@ class BuilderTest < ActionView::TestCase
81
81
 
82
82
  test "collection radio accepts single disable item" do
83
83
  collection = [[1, true], [0, false]]
84
- with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => true
84
+ with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: true
85
85
 
86
86
  assert_select 'form input[type=radio][value=true][disabled=disabled]'
87
87
  assert_no_select 'form input[type=radio][value=false][disabled=disabled]'
@@ -89,50 +89,50 @@ class BuilderTest < ActionView::TestCase
89
89
 
90
90
  test "collection radio accepts html options as input" do
91
91
  collection = [[1, true], [0, false]]
92
- with_collection_radio_buttons @user, :active, collection, :last, :first, {}, :class => 'special-radio'
92
+ with_collection_radio_buttons @user, :active, collection, :last, :first, {}, class: 'special-radio'
93
93
 
94
94
  assert_select 'form input[type=radio][value=true].special-radio#user_active_true'
95
95
  assert_select 'form input[type=radio][value=false].special-radio#user_active_false'
96
96
  end
97
97
 
98
98
  test "collection radio wraps the collection in the given collection wrapper tag" do
99
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
99
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
100
100
 
101
- assert_select 'form ul input[type=radio]', :count => 2
101
+ assert_select 'form ul input[type=radio]', count: 2
102
102
  end
103
103
 
104
104
  test "collection radio does not render any wrapper tag by default" do
105
105
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
106
106
 
107
- assert_select 'form input[type=radio]', :count => 2
107
+ assert_select 'form input[type=radio]', count: 2
108
108
  assert_no_select 'form ul'
109
109
  end
110
110
 
111
111
  test "collection radio does not wrap the collection when given falsy values" do
112
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
112
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
113
113
 
114
- assert_select 'form input[type=radio]', :count => 2
114
+ assert_select 'form input[type=radio]', count: 2
115
115
  assert_no_select 'form ul'
116
116
  end
117
117
 
118
118
  test "collection radio uses the given class for collection wrapper tag" do
119
119
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
120
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
120
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
121
121
 
122
- assert_select 'form ul.items-list input[type=radio]', :count => 2
122
+ assert_select 'form ul.items-list input[type=radio]', count: 2
123
123
  end
124
124
 
125
125
  test "collection radio uses no class for collection wrapper tag when no wrapper tag is given" do
126
126
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
127
- :collection_wrapper_class => "items-list"
127
+ collection_wrapper_class: "items-list"
128
128
 
129
- assert_select 'form input[type=radio]', :count => 2
129
+ assert_select 'form input[type=radio]', count: 2
130
130
  assert_no_select 'form ul'
131
131
  assert_no_select '.items-list'
132
132
  end
133
133
 
134
134
  test "collection radio uses no class for collection wrapper tag by default" do
135
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
135
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
136
136
 
137
137
  assert_select 'form ul'
138
138
  assert_no_select 'form ul[class]'
@@ -146,13 +146,13 @@ class BuilderTest < ActionView::TestCase
146
146
  end
147
147
 
148
148
  test "collection radio wraps each item in the given item wrapper tag" do
149
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
149
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
150
150
 
151
- assert_select 'form li input[type=radio]', :count => 2
151
+ assert_select 'form li input[type=radio]', count: 2
152
152
  end
153
153
 
154
154
  test "collection radio does not wrap each item when given explicitly falsy value" do
155
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
155
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
156
156
 
157
157
  assert_select 'form input[type=radio]'
158
158
  assert_no_select 'form span input[type=radio]'
@@ -160,25 +160,25 @@ class BuilderTest < ActionView::TestCase
160
160
 
161
161
  test "collection radio uses the given class for item wrapper tag" do
162
162
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
163
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
163
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
164
164
 
165
- assert_select "form li.inline input[type=radio]", :count => 2
165
+ assert_select "form li.inline input[type=radio]", count: 2
166
166
  end
167
167
 
168
168
  test "collection radio uses no class for item wrapper tag when no wrapper tag is given" do
169
169
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
170
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
170
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
171
171
 
172
- assert_select 'form input[type=radio]', :count => 2
172
+ assert_select 'form input[type=radio]', count: 2
173
173
  assert_no_select 'form li'
174
174
  assert_no_select '.inline'
175
175
  end
176
176
 
177
177
  test "collection radio uses no class for item wrapper tag by default" do
178
178
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
179
- :item_wrapper_tag => :li
179
+ item_wrapper_tag: :li
180
180
 
181
- assert_select "form li", :count => 2
181
+ assert_select "form li", count: 2
182
182
  assert_no_select "form li[class]"
183
183
  end
184
184
 
@@ -209,7 +209,7 @@ class BuilderTest < ActionView::TestCase
209
209
 
210
210
  test "collection radio with block helpers accept extra html options" do
211
211
  with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
212
- b.label(:class => "radio_button") + b.radio_button(:class => "radio_button")
212
+ b.label(class: "radio_button") + b.radio_button(class: "radio_button")
213
213
  end
214
214
 
215
215
  assert_select 'label.radio_button[for=user_active_true] + input#user_active_true.radio_button[type=radio]'
@@ -231,7 +231,7 @@ class BuilderTest < ActionView::TestCase
231
231
 
232
232
  test "collection radio with block helpers allows access to the current object item in the collection to access extra properties" do
233
233
  with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
234
- b.label(:class => b.object) { b.radio_button + b.text }
234
+ b.label(class: b.object) { b.radio_button + b.text }
235
235
  end
236
236
 
237
237
  assert_select 'label.true[for=user_active_true]', 'true' do
@@ -245,33 +245,20 @@ class BuilderTest < ActionView::TestCase
245
245
  test "collection radio with block helpers does not leak the template" do
246
246
  with_concat_form_for(@user) do |f|
247
247
  collection_input = f.collection_radio_buttons :active, [true, false], :to_s, :to_s do |b|
248
- b.label(:class => b.object) { b.radio_button + b.text }
248
+ b.label(class: b.object) { b.radio_button + b.text }
249
249
  end
250
250
  concat collection_input
251
251
 
252
252
  concat f.hidden_field :name
253
253
  end
254
254
 
255
- assert_select 'label.true[for=user_active_true]', :text => 'true', :count => 1 do
255
+ assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
256
256
  assert_select 'input#user_active_true[type=radio]'
257
257
  end
258
- assert_select 'label.false[for=user_active_false]', :text => 'false', :count => 1 do
258
+ assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
259
259
  assert_select 'input#user_active_false[type=radio]'
260
260
  end
261
261
  end
262
-
263
- test "collection_radio helper is deprecated in favor of collection_radio_buttons" do
264
- assert_deprecated "[SIMPLE_FORM] The `collection_radio` helper is deprecated, " \
265
- "please use `collection_radio_buttons` instead" do
266
- with_concat_form_for(@user) do |f|
267
- f.collection_radio :active, [true, false], :to_s, :to_s
268
- end
269
- end
270
-
271
- assert_select 'input[type=radio][value=true]'
272
- assert_select 'input[type=radio][value=false]'
273
- end
274
-
275
262
  # COLLECTION CHECK BOX
276
263
  test "collection check box accepts a collection and generate a serie of checkboxes for value method" do
277
264
  collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
@@ -285,14 +272,7 @@ class BuilderTest < ActionView::TestCase
285
272
  collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
286
273
  with_collection_check_boxes @user, :tag_ids, collection, :id, :name
287
274
 
288
- assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", :count => 1
289
- end
290
-
291
- test "collection check box generates a hidden field using the given :name in :input_html" do
292
- collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
293
- with_collection_check_boxes @user, :tag_ids, collection, :id, :name, {}, {:name => "user[other_tag_ids][]"}
294
-
295
- assert_select "form input[type=hidden][name='user[other_tag_ids][]'][value=]", :count => 1
275
+ assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", count: 1
296
276
  end
297
277
 
298
278
  test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
@@ -319,7 +299,7 @@ class BuilderTest < ActionView::TestCase
319
299
  test "collection check box checks the correct value to local variables" do
320
300
  user = User.new
321
301
  user.tag_ids = [1, 3]
322
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
302
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
323
303
  with_collection_check_boxes user, :tag_ids, collection, :first, :last
324
304
 
325
305
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -328,8 +308,8 @@ class BuilderTest < ActionView::TestCase
328
308
  end
329
309
 
330
310
  test "collection check box accepts selected values as :checked option" do
331
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
332
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
311
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
312
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
333
313
 
334
314
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
335
315
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -337,8 +317,8 @@ class BuilderTest < ActionView::TestCase
337
317
  end
338
318
 
339
319
  test "collection check boxes accepts selected string values as :checked option" do
340
- collection = (1..3).map{|i| [i, "Category #{i}"] }
341
- with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => ['1', '3']
320
+ collection = (1..3).map { |i| [i, "Category #{i}"] }
321
+ with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
342
322
 
343
323
  assert_select 'input[type=checkbox][value=1][checked=checked]'
344
324
  assert_select 'input[type=checkbox][value=3][checked=checked]'
@@ -346,8 +326,8 @@ class BuilderTest < ActionView::TestCase
346
326
  end
347
327
 
348
328
  test "collection check box accepts a single checked value" do
349
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
350
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => 3
329
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
330
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
351
331
 
352
332
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
353
333
  assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -355,9 +335,9 @@ class BuilderTest < ActionView::TestCase
355
335
  end
356
336
 
357
337
  test "collection check box accepts selected values as :checked option and override the model values" do
358
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
338
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
359
339
  @user.tag_ids = [2]
360
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
340
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
361
341
 
362
342
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
363
343
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -365,8 +345,8 @@ class BuilderTest < ActionView::TestCase
365
345
  end
366
346
 
367
347
  test "collection check box accepts multiple disabled items" do
368
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
369
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => [1, 3]
348
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
349
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
370
350
 
371
351
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
372
352
  assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -374,8 +354,8 @@ class BuilderTest < ActionView::TestCase
374
354
  end
375
355
 
376
356
  test "collection check box accepts single disable item" do
377
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
378
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => 1
357
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
358
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
379
359
 
380
360
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
381
361
  assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -383,8 +363,8 @@ class BuilderTest < ActionView::TestCase
383
363
  end
384
364
 
385
365
  test "collection check box accepts a proc to disabled items" do
386
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
387
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
366
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
367
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
388
368
 
389
369
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
390
370
  assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -393,7 +373,7 @@ class BuilderTest < ActionView::TestCase
393
373
 
394
374
  test "collection check box accepts html options" do
395
375
  collection = [[1, 'Tag 1'], [2, 'Tag 2']]
396
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, :class => 'check'
376
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, class: 'check'
397
377
 
398
378
  assert_select 'form input.check[type=checkbox][value=1]'
399
379
  assert_select 'form input.check[type=checkbox][value=2]'
@@ -415,43 +395,43 @@ class BuilderTest < ActionView::TestCase
415
395
  end
416
396
 
417
397
  test "collection check boxes wraps the collection in the given collection wrapper tag" do
418
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
398
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
419
399
 
420
- assert_select 'form ul input[type=checkbox]', :count => 2
400
+ assert_select 'form ul input[type=checkbox]', count: 2
421
401
  end
422
402
 
423
403
  test "collection check boxes does not render any wrapper tag by default" do
424
404
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
425
405
 
426
- assert_select 'form input[type=checkbox]', :count => 2
406
+ assert_select 'form input[type=checkbox]', count: 2
427
407
  assert_no_select 'form ul'
428
408
  end
429
409
 
430
410
  test "collection check boxes does not wrap the collection when given falsy values" do
431
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
411
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
432
412
 
433
- assert_select 'form input[type=checkbox]', :count => 2
413
+ assert_select 'form input[type=checkbox]', count: 2
434
414
  assert_no_select 'form ul'
435
415
  end
436
416
 
437
417
  test "collection check boxes uses the given class for collection wrapper tag" do
438
418
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
439
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
419
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
440
420
 
441
- assert_select 'form ul.items-list input[type=checkbox]', :count => 2
421
+ assert_select 'form ul.items-list input[type=checkbox]', count: 2
442
422
  end
443
423
 
444
424
  test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
445
425
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
446
- :collection_wrapper_class => "items-list"
426
+ collection_wrapper_class: "items-list"
447
427
 
448
- assert_select 'form input[type=checkbox]', :count => 2
428
+ assert_select 'form input[type=checkbox]', count: 2
449
429
  assert_no_select 'form ul'
450
430
  assert_no_select '.items-list'
451
431
  end
452
432
 
453
433
  test "collection check boxes uses no class for collection wrapper tag by default" do
454
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
434
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
455
435
 
456
436
  assert_select 'form ul'
457
437
  assert_no_select 'form ul[class]'
@@ -460,17 +440,17 @@ class BuilderTest < ActionView::TestCase
460
440
  test "collection check boxes wrap items in a span tag by default" do
461
441
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
462
442
 
463
- assert_select 'form span input[type=checkbox]', :count => 2
443
+ assert_select 'form span input[type=checkbox]', count: 2
464
444
  end
465
445
 
466
446
  test "collection check boxes wraps each item in the given item wrapper tag" do
467
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
447
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
468
448
 
469
- assert_select 'form li input[type=checkbox]', :count => 2
449
+ assert_select 'form li input[type=checkbox]', count: 2
470
450
  end
471
451
 
472
452
  test "collection check boxes does not wrap each item when given explicitly falsy value" do
473
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
453
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
474
454
 
475
455
  assert_select 'form input[type=checkbox]'
476
456
  assert_no_select 'form span input[type=checkbox]'
@@ -478,25 +458,25 @@ class BuilderTest < ActionView::TestCase
478
458
 
479
459
  test "collection check boxes uses the given class for item wrapper tag" do
480
460
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
481
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
461
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
482
462
 
483
- assert_select "form li.inline input[type=checkbox]", :count => 2
463
+ assert_select "form li.inline input[type=checkbox]", count: 2
484
464
  end
485
465
 
486
466
  test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
487
467
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
488
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
468
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
489
469
 
490
- assert_select 'form input[type=checkbox]', :count => 2
470
+ assert_select 'form input[type=checkbox]', count: 2
491
471
  assert_no_select 'form li'
492
472
  assert_no_select '.inline'
493
473
  end
494
474
 
495
475
  test "collection check boxes uses no class for item wrapper tag by default" do
496
476
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
497
- :item_wrapper_tag => :li
477
+ item_wrapper_tag: :li
498
478
 
499
- assert_select "form li", :count => 2
479
+ assert_select "form li", count: 2
500
480
  assert_no_select "form li[class]"
501
481
  end
502
482
 
@@ -527,7 +507,7 @@ class BuilderTest < ActionView::TestCase
527
507
 
528
508
  test "collection check boxes with block helpers accept extra html options" do
529
509
  with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
530
- b.label(:class => "check_box") + b.check_box(:class => "check_box")
510
+ b.label(class: "check_box") + b.check_box(class: "check_box")
531
511
  end
532
512
 
533
513
  assert_select 'label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]'
@@ -549,7 +529,7 @@ class BuilderTest < ActionView::TestCase
549
529
 
550
530
  test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
551
531
  with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
552
- b.label(:class => b.object) { b.check_box + b.text }
532
+ b.label(class: b.object) { b.check_box + b.text }
553
533
  end
554
534
 
555
535
  assert_select 'label.true[for=user_active_true]', 'true' do
@@ -563,17 +543,17 @@ class BuilderTest < ActionView::TestCase
563
543
  test "collection check boxes with block helpers does not leak the template" do
564
544
  with_concat_form_for(@user) do |f|
565
545
  collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
566
- b.label(:class => b.object) { b.check_box + b.text }
546
+ b.label(class: b.object) { b.check_box + b.text }
567
547
  end
568
548
  concat collection_input
569
549
 
570
550
  concat f.hidden_field :name
571
551
  end
572
552
 
573
- assert_select 'label.true[for=user_active_true]', :text => 'true', :count => 1 do
553
+ assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
574
554
  assert_select 'input#user_active_true[type=checkbox]'
575
555
  end
576
- assert_select 'label.false[for=user_active_false]', :text => 'false', :count => 1 do
556
+ assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
577
557
  assert_select 'input#user_active_false[type=checkbox]'
578
558
  end
579
559
  end
@@ -608,7 +588,7 @@ class BuilderTest < ActionView::TestCase
608
588
 
609
589
  test "fields for yields an instance of FormBuilder if it was set in options" do
610
590
  with_custom_form_for(:user) do |f|
611
- f.simple_fields_for(:company, :builder => SimpleForm::FormBuilder) do |company|
591
+ f.simple_fields_for(:company, builder: SimpleForm::FormBuilder) do |company|
612
592
  assert company.instance_of?(SimpleForm::FormBuilder)
613
593
  end
614
594
  end
@@ -616,7 +596,7 @@ class BuilderTest < ActionView::TestCase
616
596
 
617
597
  test "fields inherites wrapper option from the parent form" do
618
598
  swap_wrapper :another do
619
- simple_form_for(:user, :wrapper => :another) do |f|
599
+ simple_form_for(:user, wrapper: :another) do |f|
620
600
  f.simple_fields_for(:company) do |company|
621
601
  assert_equal :another, company.options[:wrapper]
622
602
  end
@@ -626,8 +606,8 @@ class BuilderTest < ActionView::TestCase
626
606
 
627
607
  test "fields overrides wrapper option from the parent form" do
628
608
  swap_wrapper :another do
629
- simple_form_for(:user, :wrapper => :another) do |f|
630
- f.simple_fields_for(:company, :wrapper => false) do |company|
609
+ simple_form_for(:user, wrapper: :another) do |f|
610
+ f.simple_fields_for(:company, wrapper: false) do |company|
631
611
  assert_equal false, company.options[:wrapper]
632
612
  end
633
613
  end
@@ -19,31 +19,31 @@ class FormHelperTest < ActionView::TestCase
19
19
  end
20
20
 
21
21
  test 'SimpleForm should not use default browser validations if specified in the configuration options' do
22
- swap SimpleForm, :browser_validations => false do
22
+ swap SimpleForm, browser_validations: false do
23
23
  with_concat_form_for(:user)
24
24
  assert_select 'form[novalidate="novalidate"]'
25
25
  end
26
26
  end
27
27
 
28
- test 'a form specific disabled validation option should override the default enabled browser validation configuration option' do
29
- with_concat_form_for(:user, :html => { :novalidate => true })
28
+ test 'disabled browser validations overrides default configuration' do
29
+ with_concat_form_for(:user, html: { novalidate: true })
30
30
  assert_select 'form[novalidate="novalidate"]'
31
31
  end
32
32
 
33
- test 'a form specific enabled validation option should override the disabled browser validation configuration option' do
34
- swap SimpleForm, :browser_validations => false do
35
- with_concat_form_for(:user, :html => { :novalidate => false })
33
+ test 'enabled browser validations overrides disabled configuration' do
34
+ swap SimpleForm, browser_validations: false do
35
+ with_concat_form_for(:user, html: { novalidate: false })
36
36
  assert_no_select 'form[novalidate]'
37
37
  end
38
38
  end
39
39
 
40
40
  test 'SimpleForm should add object name as css class to form when object is not present' do
41
- with_concat_form_for(:user, :html => { :novalidate => true })
41
+ with_concat_form_for(:user, html: { novalidate: true })
42
42
  assert_select 'form.simple_form.user'
43
43
  end
44
44
 
45
45
  test 'SimpleForm should add :as option as css class to form when object is not present' do
46
- with_concat_form_for(:user, :as => 'superuser')
46
+ with_concat_form_for(:user, as: 'superuser')
47
47
  assert_select 'form.simple_form.superuser'
48
48
  end
49
49
 
@@ -55,7 +55,7 @@ class FormHelperTest < ActionView::TestCase
55
55
 
56
56
  test 'SimpleForm should add :as option with new prefix as css class to form if record is not persisted' do
57
57
  @user.new_record!
58
- with_concat_form_for(@user, :as => 'superuser')
58
+ with_concat_form_for(@user, as: 'superuser')
59
59
  assert_select 'form.simple_form.new_superuser'
60
60
  end
61
61
 
@@ -65,7 +65,7 @@ class FormHelperTest < ActionView::TestCase
65
65
  end
66
66
 
67
67
  test 'SimpleForm should add :as options with edit prefix as css class to form if record is persisted' do
68
- with_concat_form_for(@user, :as => 'superuser')
68
+ with_concat_form_for(@user, as: 'superuser')
69
69
  assert_select 'form.simple_form.edit_superuser'
70
70
  end
71
71
 
@@ -75,28 +75,28 @@ class FormHelperTest < ActionView::TestCase
75
75
  end
76
76
 
77
77
  test 'SimpleForm should not add object class to form if css_class is specified' do
78
- with_concat_form_for(:user, :html => {:class => nil})
78
+ with_concat_form_for(:user, html: { class: nil })
79
79
  assert_no_select 'form.user'
80
80
  end
81
81
 
82
82
  test 'SimpleForm should add custom class to form if css_class is specified' do
83
- with_concat_form_for(:user, :html => {:class => 'my_class'})
83
+ with_concat_form_for(:user, html: { class: 'my_class' })
84
84
  assert_select 'form.my_class'
85
85
  end
86
86
 
87
87
  test 'pass options to SimpleForm' do
88
- with_concat_form_for(:user, :url => '/account', :html => { :id => 'my_form' })
88
+ with_concat_form_for(:user, url: '/account', html: { id: 'my_form' })
89
89
  assert_select 'form#my_form'
90
90
  assert_select 'form[action=/account]'
91
91
  end
92
92
 
93
- test 'fields for yields an instance of FormBuilder' do
93
+ test 'form_for yields an instance of FormBuilder' do
94
94
  with_concat_form_for(:user) do |f|
95
95
  assert f.instance_of?(SimpleForm::FormBuilder)
96
96
  end
97
97
  end
98
98
 
99
- test 'fields for with a hash like model yeilds an instance of FormBuilder' do
99
+ test 'fields_for with a hash like model yields an instance of FormBuilder' do
100
100
  with_concat_fields_for(:author, HashBackedAuthor.new) do |f|
101
101
  assert f.instance_of?(SimpleForm::FormBuilder)
102
102
  f.input :name
@@ -131,10 +131,19 @@ class FormHelperTest < ActionView::TestCase
131
131
  end
132
132
  end
133
133
 
134
+ test 'SimpleForm for swaps default action view field_error_proc' do
135
+ expected_error_proc = lambda {}
136
+ swap SimpleForm, field_error_proc: expected_error_proc do
137
+ simple_form_for :user do |f|
138
+ assert_equal expected_error_proc, ::ActionView::Base.field_error_proc
139
+ end
140
+ end
141
+ end
142
+
134
143
  private
135
144
 
136
145
  def swap_field_error_proc(expected_error_proc = lambda {})
137
- swap ActionView::Base, :field_error_proc => expected_error_proc do
146
+ swap ActionView::Base, field_error_proc: expected_error_proc do
138
147
  yield
139
148
 
140
149
  assert_equal expected_error_proc, ActionView::Base.field_error_proc