simple_form 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +22 -32
  3. data/README.md +161 -119
  4. data/lib/generators/simple_form/install_generator.rb +3 -3
  5. data/lib/generators/simple_form/templates/README +1 -1
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +16 -13
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
  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 -319
  10. data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
  11. data/lib/simple_form/components/html5.rb +5 -2
  12. data/lib/simple_form/components/labels.rb +3 -3
  13. data/lib/simple_form/components/maxlength.rb +1 -8
  14. data/lib/simple_form/components/pattern.rb +2 -2
  15. data/lib/simple_form/components.rb +1 -1
  16. data/lib/simple_form/error_notification.rb +2 -2
  17. data/lib/simple_form/form_builder.rb +155 -51
  18. data/lib/simple_form/helpers.rb +1 -1
  19. data/lib/simple_form/inputs/base.rb +6 -6
  20. data/lib/simple_form/inputs/block_input.rb +1 -1
  21. data/lib/simple_form/inputs/boolean_input.rb +6 -4
  22. data/lib/simple_form/inputs/collection_input.rb +6 -6
  23. data/lib/simple_form/inputs/date_time_input.rb +1 -1
  24. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  25. data/lib/simple_form/inputs/password_input.rb +0 -1
  26. data/lib/simple_form/inputs/string_input.rb +0 -1
  27. data/lib/simple_form/railtie.rb +7 -0
  28. data/lib/simple_form/tags.rb +62 -0
  29. data/lib/simple_form/version.rb +1 -1
  30. data/lib/simple_form/wrappers/builder.rb +5 -29
  31. data/lib/simple_form/wrappers/many.rb +1 -1
  32. data/lib/simple_form/wrappers/root.rb +1 -1
  33. data/lib/simple_form/wrappers.rb +1 -1
  34. data/lib/simple_form.rb +43 -47
  35. data/test/action_view_extensions/builder_test.rb +78 -92
  36. data/test/action_view_extensions/form_helper_test.rb +25 -16
  37. data/test/components/label_test.rb +46 -46
  38. data/test/form_builder/association_test.rb +47 -29
  39. data/test/form_builder/button_test.rb +4 -4
  40. data/test/form_builder/error_notification_test.rb +8 -8
  41. data/test/form_builder/error_test.rb +12 -12
  42. data/test/form_builder/general_test.rb +71 -52
  43. data/test/form_builder/hint_test.rb +22 -22
  44. data/test/form_builder/input_field_test.rb +29 -12
  45. data/test/form_builder/label_test.rb +7 -7
  46. data/test/form_builder/wrapper_test.rb +21 -21
  47. data/test/inputs/boolean_input_test.rb +35 -23
  48. data/test/inputs/collection_check_boxes_input_test.rb +66 -55
  49. data/test/inputs/collection_radio_buttons_input_test.rb +81 -79
  50. data/test/inputs/collection_select_input_test.rb +76 -45
  51. data/test/inputs/datetime_input_test.rb +17 -11
  52. data/test/inputs/disabled_test.rb +10 -10
  53. data/test/inputs/discovery_test.rb +4 -4
  54. data/test/inputs/file_input_test.rb +1 -1
  55. data/test/inputs/general_test.rb +28 -12
  56. data/test/inputs/grouped_collection_select_input_test.rb +33 -20
  57. data/test/inputs/hidden_input_test.rb +3 -2
  58. data/test/inputs/numeric_input_test.rb +3 -3
  59. data/test/inputs/priority_input_test.rb +9 -3
  60. data/test/inputs/readonly_test.rb +12 -12
  61. data/test/inputs/required_test.rb +5 -5
  62. data/test/inputs/string_input_test.rb +15 -25
  63. data/test/inputs/text_input_test.rb +1 -1
  64. data/test/support/misc_helpers.rb +46 -24
  65. data/test/support/mock_controller.rb +6 -6
  66. data/test/support/models.rb +80 -62
  67. data/test/test_helper.rb +17 -34
  68. metadata +31 -29
  69. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -49,8 +49,7 @@ class BuilderTest < ActionView::TestCase
49
49
  end
50
50
 
51
51
  test "collection radio checks the correct value to local variables" do
52
- user = User.new
53
- user.active = false
52
+ user = User.build(active: false)
54
53
  with_collection_radio_buttons user, :active, [true, false], :to_s, :to_s
55
54
 
56
55
  assert_select 'form input[type=radio][value=true]'
@@ -58,21 +57,21 @@ class BuilderTest < ActionView::TestCase
58
57
  end
59
58
 
60
59
  test "collection radio accepts checked item" do
61
- with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => true
60
+ with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: true
62
61
 
63
62
  assert_select 'form input[type=radio][value=true][checked=checked]'
64
63
  assert_no_select 'form input[type=radio][value=false][checked=checked]'
65
64
  end
66
65
 
67
66
  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
67
+ with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: false
69
68
  assert_no_select 'form input[type=radio][value=true][checked=checked]'
70
69
  assert_select 'form input[type=radio][value=false][checked=checked]'
71
70
  end
72
71
 
73
72
  test "collection radio accepts multiple disabled items" do
74
73
  collection = [[1, true], [0, false], [2, 'other']]
75
- with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => [true, false]
74
+ with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: [true, false]
76
75
 
77
76
  assert_select 'form input[type=radio][value=true][disabled=disabled]'
78
77
  assert_select 'form input[type=radio][value=false][disabled=disabled]'
@@ -81,7 +80,7 @@ class BuilderTest < ActionView::TestCase
81
80
 
82
81
  test "collection radio accepts single disable item" do
83
82
  collection = [[1, true], [0, false]]
84
- with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => true
83
+ with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: true
85
84
 
86
85
  assert_select 'form input[type=radio][value=true][disabled=disabled]'
87
86
  assert_no_select 'form input[type=radio][value=false][disabled=disabled]'
@@ -89,50 +88,50 @@ class BuilderTest < ActionView::TestCase
89
88
 
90
89
  test "collection radio accepts html options as input" do
91
90
  collection = [[1, true], [0, false]]
92
- with_collection_radio_buttons @user, :active, collection, :last, :first, {}, :class => 'special-radio'
91
+ with_collection_radio_buttons @user, :active, collection, :last, :first, {}, class: 'special-radio'
93
92
 
94
93
  assert_select 'form input[type=radio][value=true].special-radio#user_active_true'
95
94
  assert_select 'form input[type=radio][value=false].special-radio#user_active_false'
96
95
  end
97
96
 
98
97
  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
98
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
100
99
 
101
- assert_select 'form ul input[type=radio]', :count => 2
100
+ assert_select 'form ul input[type=radio]', count: 2
102
101
  end
103
102
 
104
103
  test "collection radio does not render any wrapper tag by default" do
105
104
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
106
105
 
107
- assert_select 'form input[type=radio]', :count => 2
106
+ assert_select 'form input[type=radio]', count: 2
108
107
  assert_no_select 'form ul'
109
108
  end
110
109
 
111
110
  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
111
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
113
112
 
114
- assert_select 'form input[type=radio]', :count => 2
113
+ assert_select 'form input[type=radio]', count: 2
115
114
  assert_no_select 'form ul'
116
115
  end
117
116
 
118
117
  test "collection radio uses the given class for collection wrapper tag" do
119
118
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
120
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
119
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
121
120
 
122
- assert_select 'form ul.items-list input[type=radio]', :count => 2
121
+ assert_select 'form ul.items-list input[type=radio]', count: 2
123
122
  end
124
123
 
125
124
  test "collection radio uses no class for collection wrapper tag when no wrapper tag is given" do
126
125
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
127
- :collection_wrapper_class => "items-list"
126
+ collection_wrapper_class: "items-list"
128
127
 
129
- assert_select 'form input[type=radio]', :count => 2
128
+ assert_select 'form input[type=radio]', count: 2
130
129
  assert_no_select 'form ul'
131
130
  assert_no_select '.items-list'
132
131
  end
133
132
 
134
133
  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
134
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
136
135
 
137
136
  assert_select 'form ul'
138
137
  assert_no_select 'form ul[class]'
@@ -146,13 +145,13 @@ class BuilderTest < ActionView::TestCase
146
145
  end
147
146
 
148
147
  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
148
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
150
149
 
151
- assert_select 'form li input[type=radio]', :count => 2
150
+ assert_select 'form li input[type=radio]', count: 2
152
151
  end
153
152
 
154
153
  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
154
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
156
155
 
157
156
  assert_select 'form input[type=radio]'
158
157
  assert_no_select 'form span input[type=radio]'
@@ -160,25 +159,25 @@ class BuilderTest < ActionView::TestCase
160
159
 
161
160
  test "collection radio uses the given class for item wrapper tag" do
162
161
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
163
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
162
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
164
163
 
165
- assert_select "form li.inline input[type=radio]", :count => 2
164
+ assert_select "form li.inline input[type=radio]", count: 2
166
165
  end
167
166
 
168
167
  test "collection radio uses no class for item wrapper tag when no wrapper tag is given" do
169
168
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
170
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
169
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
171
170
 
172
- assert_select 'form input[type=radio]', :count => 2
171
+ assert_select 'form input[type=radio]', count: 2
173
172
  assert_no_select 'form li'
174
173
  assert_no_select '.inline'
175
174
  end
176
175
 
177
176
  test "collection radio uses no class for item wrapper tag by default" do
178
177
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
179
- :item_wrapper_tag => :li
178
+ item_wrapper_tag: :li
180
179
 
181
- assert_select "form li", :count => 2
180
+ assert_select "form li", count: 2
182
181
  assert_no_select "form li[class]"
183
182
  end
184
183
 
@@ -209,7 +208,7 @@ class BuilderTest < ActionView::TestCase
209
208
 
210
209
  test "collection radio with block helpers accept extra html options" do
211
210
  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")
211
+ b.label(class: "radio_button") + b.radio_button(class: "radio_button")
213
212
  end
214
213
 
215
214
  assert_select 'label.radio_button[for=user_active_true] + input#user_active_true.radio_button[type=radio]'
@@ -231,7 +230,7 @@ class BuilderTest < ActionView::TestCase
231
230
 
232
231
  test "collection radio with block helpers allows access to the current object item in the collection to access extra properties" do
233
232
  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 }
233
+ b.label(class: b.object) { b.radio_button + b.text }
235
234
  end
236
235
 
237
236
  assert_select 'label.true[for=user_active_true]', 'true' do
@@ -245,33 +244,20 @@ class BuilderTest < ActionView::TestCase
245
244
  test "collection radio with block helpers does not leak the template" do
246
245
  with_concat_form_for(@user) do |f|
247
246
  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 }
247
+ b.label(class: b.object) { b.radio_button + b.text }
249
248
  end
250
249
  concat collection_input
251
250
 
252
251
  concat f.hidden_field :name
253
252
  end
254
253
 
255
- assert_select 'label.true[for=user_active_true]', :text => 'true', :count => 1 do
254
+ assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
256
255
  assert_select 'input#user_active_true[type=radio]'
257
256
  end
258
- assert_select 'label.false[for=user_active_false]', :text => 'false', :count => 1 do
257
+ assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
259
258
  assert_select 'input#user_active_false[type=radio]'
260
259
  end
261
260
  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
261
  # COLLECTION CHECK BOX
276
262
  test "collection check box accepts a collection and generate a serie of checkboxes for value method" do
277
263
  collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
@@ -285,7 +271,7 @@ class BuilderTest < ActionView::TestCase
285
271
  collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
286
272
  with_collection_check_boxes @user, :tag_ids, collection, :id, :name
287
273
 
288
- assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", :count => 1
274
+ assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", count: 1
289
275
  end
290
276
 
291
277
  test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
@@ -310,9 +296,9 @@ class BuilderTest < ActionView::TestCase
310
296
  end
311
297
 
312
298
  test "collection check box checks the correct value to local variables" do
313
- user = User.new
314
- user.tag_ids = [1, 3]
315
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
299
+ user = User.build(tag_ids: [1, 3])
300
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
301
+
316
302
  with_collection_check_boxes user, :tag_ids, collection, :first, :last
317
303
 
318
304
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -321,8 +307,8 @@ class BuilderTest < ActionView::TestCase
321
307
  end
322
308
 
323
309
  test "collection check box accepts selected values as :checked option" do
324
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
325
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
310
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
311
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
326
312
 
327
313
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
328
314
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -330,8 +316,8 @@ class BuilderTest < ActionView::TestCase
330
316
  end
331
317
 
332
318
  test "collection check boxes accepts selected string values as :checked option" do
333
- collection = (1..3).map{|i| [i, "Category #{i}"] }
334
- with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => ['1', '3']
319
+ collection = (1..3).map { |i| [i, "Category #{i}"] }
320
+ with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
335
321
 
336
322
  assert_select 'input[type=checkbox][value=1][checked=checked]'
337
323
  assert_select 'input[type=checkbox][value=3][checked=checked]'
@@ -339,8 +325,8 @@ class BuilderTest < ActionView::TestCase
339
325
  end
340
326
 
341
327
  test "collection check box accepts a single checked value" do
342
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
343
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => 3
328
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
329
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
344
330
 
345
331
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
346
332
  assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -348,9 +334,9 @@ class BuilderTest < ActionView::TestCase
348
334
  end
349
335
 
350
336
  test "collection check box accepts selected values as :checked option and override the model values" do
351
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
337
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
352
338
  @user.tag_ids = [2]
353
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
339
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
354
340
 
355
341
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
356
342
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -358,8 +344,8 @@ class BuilderTest < ActionView::TestCase
358
344
  end
359
345
 
360
346
  test "collection check box accepts multiple disabled items" do
361
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
362
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => [1, 3]
347
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
348
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
363
349
 
364
350
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
365
351
  assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -367,8 +353,8 @@ class BuilderTest < ActionView::TestCase
367
353
  end
368
354
 
369
355
  test "collection check box accepts single disable item" do
370
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
371
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => 1
356
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
357
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
372
358
 
373
359
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
374
360
  assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -376,8 +362,8 @@ class BuilderTest < ActionView::TestCase
376
362
  end
377
363
 
378
364
  test "collection check box accepts a proc to disabled items" do
379
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
380
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
365
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
366
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
381
367
 
382
368
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
383
369
  assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -386,7 +372,7 @@ class BuilderTest < ActionView::TestCase
386
372
 
387
373
  test "collection check box accepts html options" do
388
374
  collection = [[1, 'Tag 1'], [2, 'Tag 2']]
389
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, :class => 'check'
375
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, class: 'check'
390
376
 
391
377
  assert_select 'form input.check[type=checkbox][value=1]'
392
378
  assert_select 'form input.check[type=checkbox][value=2]'
@@ -408,43 +394,43 @@ class BuilderTest < ActionView::TestCase
408
394
  end
409
395
 
410
396
  test "collection check boxes wraps the collection in the given collection wrapper tag" do
411
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
397
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
412
398
 
413
- assert_select 'form ul input[type=checkbox]', :count => 2
399
+ assert_select 'form ul input[type=checkbox]', count: 2
414
400
  end
415
401
 
416
402
  test "collection check boxes does not render any wrapper tag by default" do
417
403
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
418
404
 
419
- assert_select 'form input[type=checkbox]', :count => 2
405
+ assert_select 'form input[type=checkbox]', count: 2
420
406
  assert_no_select 'form ul'
421
407
  end
422
408
 
423
409
  test "collection check boxes does not wrap the collection when given falsy values" do
424
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
410
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
425
411
 
426
- assert_select 'form input[type=checkbox]', :count => 2
412
+ assert_select 'form input[type=checkbox]', count: 2
427
413
  assert_no_select 'form ul'
428
414
  end
429
415
 
430
416
  test "collection check boxes uses the given class for collection wrapper tag" do
431
417
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
432
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
418
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
433
419
 
434
- assert_select 'form ul.items-list input[type=checkbox]', :count => 2
420
+ assert_select 'form ul.items-list input[type=checkbox]', count: 2
435
421
  end
436
422
 
437
423
  test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
438
424
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
439
- :collection_wrapper_class => "items-list"
425
+ collection_wrapper_class: "items-list"
440
426
 
441
- assert_select 'form input[type=checkbox]', :count => 2
427
+ assert_select 'form input[type=checkbox]', count: 2
442
428
  assert_no_select 'form ul'
443
429
  assert_no_select '.items-list'
444
430
  end
445
431
 
446
432
  test "collection check boxes uses no class for collection wrapper tag by default" do
447
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
433
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
448
434
 
449
435
  assert_select 'form ul'
450
436
  assert_no_select 'form ul[class]'
@@ -453,17 +439,17 @@ class BuilderTest < ActionView::TestCase
453
439
  test "collection check boxes wrap items in a span tag by default" do
454
440
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
455
441
 
456
- assert_select 'form span input[type=checkbox]', :count => 2
442
+ assert_select 'form span input[type=checkbox]', count: 2
457
443
  end
458
444
 
459
445
  test "collection check boxes wraps each item in the given item wrapper tag" do
460
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
446
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
461
447
 
462
- assert_select 'form li input[type=checkbox]', :count => 2
448
+ assert_select 'form li input[type=checkbox]', count: 2
463
449
  end
464
450
 
465
451
  test "collection check boxes does not wrap each item when given explicitly falsy value" do
466
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
452
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
467
453
 
468
454
  assert_select 'form input[type=checkbox]'
469
455
  assert_no_select 'form span input[type=checkbox]'
@@ -471,25 +457,25 @@ class BuilderTest < ActionView::TestCase
471
457
 
472
458
  test "collection check boxes uses the given class for item wrapper tag" do
473
459
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
474
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
460
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
475
461
 
476
- assert_select "form li.inline input[type=checkbox]", :count => 2
462
+ assert_select "form li.inline input[type=checkbox]", count: 2
477
463
  end
478
464
 
479
465
  test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
480
466
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
481
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
467
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
482
468
 
483
- assert_select 'form input[type=checkbox]', :count => 2
469
+ assert_select 'form input[type=checkbox]', count: 2
484
470
  assert_no_select 'form li'
485
471
  assert_no_select '.inline'
486
472
  end
487
473
 
488
474
  test "collection check boxes uses no class for item wrapper tag by default" do
489
475
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
490
- :item_wrapper_tag => :li
476
+ item_wrapper_tag: :li
491
477
 
492
- assert_select "form li", :count => 2
478
+ assert_select "form li", count: 2
493
479
  assert_no_select "form li[class]"
494
480
  end
495
481
 
@@ -520,7 +506,7 @@ class BuilderTest < ActionView::TestCase
520
506
 
521
507
  test "collection check boxes with block helpers accept extra html options" do
522
508
  with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
523
- b.label(:class => "check_box") + b.check_box(:class => "check_box")
509
+ b.label(class: "check_box") + b.check_box(class: "check_box")
524
510
  end
525
511
 
526
512
  assert_select 'label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]'
@@ -542,7 +528,7 @@ class BuilderTest < ActionView::TestCase
542
528
 
543
529
  test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
544
530
  with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
545
- b.label(:class => b.object) { b.check_box + b.text }
531
+ b.label(class: b.object) { b.check_box + b.text }
546
532
  end
547
533
 
548
534
  assert_select 'label.true[for=user_active_true]', 'true' do
@@ -556,17 +542,17 @@ class BuilderTest < ActionView::TestCase
556
542
  test "collection check boxes with block helpers does not leak the template" do
557
543
  with_concat_form_for(@user) do |f|
558
544
  collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
559
- b.label(:class => b.object) { b.check_box + b.text }
545
+ b.label(class: b.object) { b.check_box + b.text }
560
546
  end
561
547
  concat collection_input
562
548
 
563
549
  concat f.hidden_field :name
564
550
  end
565
551
 
566
- assert_select 'label.true[for=user_active_true]', :text => 'true', :count => 1 do
552
+ assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
567
553
  assert_select 'input#user_active_true[type=checkbox]'
568
554
  end
569
- assert_select 'label.false[for=user_active_false]', :text => 'false', :count => 1 do
555
+ assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
570
556
  assert_select 'input#user_active_false[type=checkbox]'
571
557
  end
572
558
  end
@@ -601,7 +587,7 @@ class BuilderTest < ActionView::TestCase
601
587
 
602
588
  test "fields for yields an instance of FormBuilder if it was set in options" do
603
589
  with_custom_form_for(:user) do |f|
604
- f.simple_fields_for(:company, :builder => SimpleForm::FormBuilder) do |company|
590
+ f.simple_fields_for(:company, builder: SimpleForm::FormBuilder) do |company|
605
591
  assert company.instance_of?(SimpleForm::FormBuilder)
606
592
  end
607
593
  end
@@ -609,7 +595,7 @@ class BuilderTest < ActionView::TestCase
609
595
 
610
596
  test "fields inherites wrapper option from the parent form" do
611
597
  swap_wrapper :another do
612
- simple_form_for(:user, :wrapper => :another) do |f|
598
+ simple_form_for(:user, wrapper: :another) do |f|
613
599
  f.simple_fields_for(:company) do |company|
614
600
  assert_equal :another, company.options[:wrapper]
615
601
  end
@@ -619,8 +605,8 @@ class BuilderTest < ActionView::TestCase
619
605
 
620
606
  test "fields overrides wrapper option from the parent form" do
621
607
  swap_wrapper :another do
622
- simple_form_for(:user, :wrapper => :another) do |f|
623
- f.simple_fields_for(:company, :wrapper => false) do |company|
608
+ simple_form_for(:user, wrapper: :another) do |f|
609
+ f.simple_fields_for(:company, wrapper: false) do |company|
624
610
  assert_equal false, company.options[:wrapper]
625
611
  end
626
612
  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