simple_form 2.0.0 → 3.5.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.

Potentially problematic release.


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

Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +97 -198
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +572 -296
  5. data/lib/generators/simple_form/install_generator.rb +17 -7
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/_form.html.erb +1 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +1 -0
  9. data/lib/generators/simple_form/templates/config/initializers/{simple_form.rb.tt → simple_form.rb} +57 -63
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +155 -0
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +111 -0
  12. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +14 -7
  13. data/lib/simple_form/action_view_extensions/builder.rb +5 -305
  14. data/lib/simple_form/action_view_extensions/form_helper.rb +18 -20
  15. data/lib/simple_form/components/errors.rb +30 -3
  16. data/lib/simple_form/components/hints.rb +10 -3
  17. data/lib/simple_form/components/html5.rb +17 -3
  18. data/lib/simple_form/components/label_input.rb +21 -2
  19. data/lib/simple_form/components/labels.rb +16 -11
  20. data/lib/simple_form/components/maxlength.rb +19 -12
  21. data/lib/simple_form/components/min_max.rb +4 -2
  22. data/lib/simple_form/components/minlength.rb +48 -0
  23. data/lib/simple_form/components/pattern.rb +5 -4
  24. data/lib/simple_form/components/placeholders.rb +3 -2
  25. data/lib/simple_form/components/readonly.rb +3 -2
  26. data/lib/simple_form/components.rb +15 -11
  27. data/lib/simple_form/error_notification.rb +4 -3
  28. data/lib/simple_form/form_builder.rb +283 -105
  29. data/lib/simple_form/helpers/autofocus.rb +1 -0
  30. data/lib/simple_form/helpers/disabled.rb +1 -0
  31. data/lib/simple_form/helpers/readonly.rb +1 -0
  32. data/lib/simple_form/helpers/required.rb +1 -0
  33. data/lib/simple_form/helpers/validators.rb +4 -3
  34. data/lib/simple_form/helpers.rb +7 -6
  35. data/lib/simple_form/i18n_cache.rb +1 -0
  36. data/lib/simple_form/inputs/base.rb +76 -23
  37. data/lib/simple_form/inputs/block_input.rb +3 -2
  38. data/lib/simple_form/inputs/boolean_input.rb +55 -16
  39. data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
  40. data/lib/simple_form/inputs/collection_input.rb +41 -18
  41. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +11 -19
  42. data/lib/simple_form/inputs/collection_select_input.rb +5 -2
  43. data/lib/simple_form/inputs/date_time_input.rb +23 -12
  44. data/lib/simple_form/inputs/file_input.rb +5 -2
  45. data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
  46. data/lib/simple_form/inputs/hidden_input.rb +5 -2
  47. data/lib/simple_form/inputs/numeric_input.rb +4 -8
  48. data/lib/simple_form/inputs/password_input.rb +6 -4
  49. data/lib/simple_form/inputs/priority_input.rb +5 -2
  50. data/lib/simple_form/inputs/range_input.rb +2 -1
  51. data/lib/simple_form/inputs/string_input.rb +6 -4
  52. data/lib/simple_form/inputs/text_input.rb +6 -3
  53. data/lib/simple_form/inputs.rb +20 -17
  54. data/lib/simple_form/map_type.rb +1 -0
  55. data/lib/simple_form/railtie.rb +15 -0
  56. data/lib/simple_form/tags.rb +69 -0
  57. data/lib/simple_form/version.rb +2 -1
  58. data/lib/simple_form/wrappers/builder.rb +12 -35
  59. data/lib/simple_form/wrappers/leaf.rb +29 -0
  60. data/lib/simple_form/wrappers/many.rb +12 -7
  61. data/lib/simple_form/wrappers/root.rb +7 -4
  62. data/lib/simple_form/wrappers/single.rb +12 -3
  63. data/lib/simple_form/wrappers.rb +3 -1
  64. data/lib/simple_form.rb +118 -63
  65. data/test/action_view_extensions/builder_test.rb +230 -164
  66. data/test/action_view_extensions/form_helper_test.rb +107 -39
  67. data/test/components/label_test.rb +105 -87
  68. data/test/form_builder/association_test.rb +131 -62
  69. data/test/form_builder/button_test.rb +15 -14
  70. data/test/form_builder/error_notification_test.rb +11 -10
  71. data/test/form_builder/error_test.rb +188 -34
  72. data/test/form_builder/general_test.rb +247 -102
  73. data/test/form_builder/hint_test.rb +59 -32
  74. data/test/form_builder/input_field_test.rb +138 -25
  75. data/test/form_builder/label_test.rb +84 -13
  76. data/test/form_builder/wrapper_test.rb +236 -33
  77. data/test/generators/simple_form_generator_test.rb +15 -4
  78. data/test/inputs/boolean_input_test.rb +147 -13
  79. data/test/inputs/collection_check_boxes_input_test.rb +166 -71
  80. data/test/inputs/collection_radio_buttons_input_test.rb +229 -113
  81. data/test/inputs/collection_select_input_test.rb +222 -85
  82. data/test/inputs/datetime_input_test.rb +134 -47
  83. data/test/inputs/disabled_test.rb +62 -21
  84. data/test/inputs/discovery_test.rb +70 -10
  85. data/test/inputs/file_input_test.rb +4 -3
  86. data/test/inputs/general_test.rb +90 -26
  87. data/test/inputs/grouped_collection_select_input_test.rb +88 -23
  88. data/test/inputs/hidden_input_test.rb +7 -5
  89. data/test/inputs/numeric_input_test.rb +56 -46
  90. data/test/inputs/priority_input_test.rb +31 -16
  91. data/test/inputs/readonly_test.rb +68 -27
  92. data/test/inputs/required_test.rb +63 -18
  93. data/test/inputs/string_input_test.rb +76 -51
  94. data/test/inputs/text_input_test.rb +21 -8
  95. data/test/simple_form_test.rb +9 -0
  96. data/test/support/discovery_inputs.rb +39 -2
  97. data/test/support/misc_helpers.rb +176 -20
  98. data/test/support/mock_controller.rb +13 -7
  99. data/test/support/models.rb +187 -71
  100. data/test/test_helper.rb +38 -39
  101. metadata +53 -39
  102. data/lib/simple_form/core_ext/hash.rb +0 -16
  103. data/test/support/mock_response.rb +0 -14
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
@@ -6,28 +7,34 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
6
7
  SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
7
8
  end
8
9
 
9
- test 'input check boxes should not include for attribute by default' do
10
- with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
10
+ test 'input check boxes does not include for attribute by default' do
11
+ with_input_for @user, :gender, :check_boxes, collection: %i[male female]
11
12
  assert_select 'label'
12
13
  assert_no_select 'label[for=user_gender]'
13
14
  end
14
15
 
15
- test 'input check boxes should include for attribute when giving as html option' do
16
- with_input_for @user, :gender, :check_boxes, :collection => [:male, :female], :label_html => { :for => 'gender' }
16
+ test 'input check boxes includes for attribute when giving as html option' do
17
+ with_input_for @user, :gender, :check_boxes, collection: %i[male female], label_html: { for: 'gender' }
17
18
  assert_select 'label[for=gender]'
18
19
  end
19
20
 
20
- test 'collection input with check_boxes type should not generate required html attribute' do
21
- with_input_for @user, :name, :check_boxes, :collection => ['Jose' , 'Carlos']
21
+ test 'collection input with check_boxes type does not generate required html attribute' do
22
+ with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
22
23
  assert_select 'input.required'
23
24
  assert_no_select 'input[required]'
24
25
  end
25
26
 
26
- test 'input should do automatic collection translation for check_box types using defaults key' do
27
- store_translations(:en, :simple_form => { :options => { :defaults => {
28
- :gender => { :male => 'Male', :female => 'Female'}
27
+ test 'collection input with check_boxes type does not generate aria-required html attribute' do
28
+ with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
29
+ assert_select 'input.required'
30
+ assert_no_select 'input[aria-required]'
31
+ end
32
+
33
+ test 'input does automatic collection translation for check_box types using defaults key' do
34
+ store_translations(:en, simple_form: { options: { defaults: {
35
+ gender: { male: 'Male', female: 'Female' }
29
36
  } } } ) do
30
- with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
37
+ with_input_for @user, :gender, :check_boxes, collection: %i[male female]
31
38
  assert_select 'input[type=checkbox][value=male]'
32
39
  assert_select 'input[type=checkbox][value=female]'
33
40
  assert_select 'label.collection_check_boxes', 'Male'
@@ -35,11 +42,11 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
35
42
  end
36
43
  end
37
44
 
38
- test 'input should do automatic collection translation for check_box types using specific object key' do
39
- store_translations(:en, :simple_form => { :options => { :user => {
40
- :gender => { :male => 'Male', :female => 'Female'}
45
+ test 'input does automatic collection translation for check_box types using specific object key' do
46
+ store_translations(:en, simple_form: { options: { user: {
47
+ gender: { male: 'Male', female: 'Female' }
41
48
  } } } ) do
42
- with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
49
+ with_input_for @user, :gender, :check_boxes, collection: %i[male female]
43
50
  assert_select 'input[type=checkbox][value=male]'
44
51
  assert_select 'input[type=checkbox][value=female]'
45
52
  assert_select 'label.collection_check_boxes', 'Male'
@@ -47,103 +54,122 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
47
54
  end
48
55
  end
49
56
 
57
+ test 'input that uses automatic collection translation for check_boxes properly sets checked values' do
58
+ store_translations(:en, simple_form: { options: { defaults: {
59
+ gender: { male: 'Male', female: 'Female' }
60
+ } } } ) do
61
+ @user.gender = 'male'
62
+
63
+ with_input_for @user, :gender, :check_boxes, collection: %i[male female]
64
+ assert_select 'input[type=checkbox][value=male][checked=checked]'
65
+ assert_select 'input[type=checkbox][value=female]'
66
+ assert_select 'label.collection_check_boxes', 'Male'
67
+ assert_select 'label.collection_check_boxes', 'Female'
68
+ end
69
+ end
70
+
50
71
  test 'input check boxes does not wrap the collection by default' do
51
72
  with_input_for @user, :active, :check_boxes
52
73
 
53
- assert_select 'form input[type=checkbox]', :count => 2
74
+ assert_select 'form input[type=checkbox]', count: 2
54
75
  assert_no_select 'form ul'
55
76
  end
56
77
 
78
+ test 'input check boxes accepts html options as the last element of collection' do
79
+ with_input_for @user, :name, :check_boxes, collection: [['Jose', 'jose', class: 'foo']]
80
+ assert_select 'input.foo[type=checkbox][value=jose]'
81
+ end
82
+
57
83
  test 'input check boxes wraps the collection in the configured collection wrapper tag' do
58
- swap SimpleForm, :collection_wrapper_tag => :ul do
84
+ swap SimpleForm, collection_wrapper_tag: :ul do
59
85
  with_input_for @user, :active, :check_boxes
60
86
 
61
- assert_select 'form ul input[type=checkbox]', :count => 2
87
+ assert_select 'form ul input[type=checkbox]', count: 2
62
88
  end
63
89
  end
64
90
 
65
91
  test 'input check boxes does not wrap the collection when configured with falsy values' do
66
- swap SimpleForm, :collection_wrapper_tag => false do
92
+ swap SimpleForm, collection_wrapper_tag: false do
67
93
  with_input_for @user, :active, :check_boxes
68
94
 
69
- assert_select 'form input[type=checkbox]', :count => 2
95
+ assert_select 'form input[type=checkbox]', count: 2
70
96
  assert_no_select 'form ul'
71
97
  end
72
98
  end
73
99
 
74
100
  test 'input check boxes allows overriding the collection wrapper tag at input level' do
75
- swap SimpleForm, :collection_wrapper_tag => :ul do
76
- with_input_for @user, :active, :check_boxes, :collection_wrapper_tag => :section
101
+ swap SimpleForm, collection_wrapper_tag: :ul do
102
+ with_input_for @user, :active, :check_boxes, collection_wrapper_tag: :section
77
103
 
78
- assert_select 'form section input[type=checkbox]', :count => 2
104
+ assert_select 'form section input[type=checkbox]', count: 2
79
105
  assert_no_select 'form ul'
80
106
  end
81
107
  end
82
108
 
83
109
  test 'input check boxes allows disabling the collection wrapper tag at input level' do
84
- swap SimpleForm, :collection_wrapper_tag => :ul do
85
- with_input_for @user, :active, :check_boxes, :collection_wrapper_tag => false
110
+ swap SimpleForm, collection_wrapper_tag: :ul do
111
+ with_input_for @user, :active, :check_boxes, collection_wrapper_tag: false
86
112
 
87
- assert_select 'form input[type=checkbox]', :count => 2
113
+ assert_select 'form input[type=checkbox]', count: 2
88
114
  assert_no_select 'form ul'
89
115
  end
90
116
  end
91
117
 
92
118
  test 'input check boxes renders the wrapper tag with the configured wrapper class' do
93
- swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
119
+ swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
94
120
  with_input_for @user, :active, :check_boxes
95
121
 
96
- assert_select 'form ul.inputs-list input[type=checkbox]', :count => 2
122
+ assert_select 'form ul.inputs-list input[type=checkbox]', count: 2
97
123
  end
98
124
  end
99
125
 
100
126
  test 'input check boxes allows giving wrapper class at input level only' do
101
- swap SimpleForm, :collection_wrapper_tag => :ul do
102
- with_input_for @user, :active, :check_boxes, :collection_wrapper_class => 'items-list'
127
+ swap SimpleForm, collection_wrapper_tag: :ul do
128
+ with_input_for @user, :active, :check_boxes, collection_wrapper_class: 'items-list'
103
129
 
104
- assert_select 'form ul.items-list input[type=checkbox]', :count => 2
130
+ assert_select 'form ul.items-list input[type=checkbox]', count: 2
105
131
  end
106
132
  end
107
133
 
108
134
  test 'input check boxes uses both configured and given wrapper classes for wrapper tag' do
109
- swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
110
- with_input_for @user, :active, :check_boxes, :collection_wrapper_class => 'items-list'
135
+ swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
136
+ with_input_for @user, :active, :check_boxes, collection_wrapper_class: 'items-list'
111
137
 
112
- assert_select 'form ul.inputs-list.items-list input[type=checkbox]', :count => 2
138
+ assert_select 'form ul.inputs-list.items-list input[type=checkbox]', count: 2
113
139
  end
114
140
  end
115
141
 
116
142
  test 'input check boxes wraps each item in the configured item wrapper tag' do
117
- swap SimpleForm, :item_wrapper_tag => :li do
143
+ swap SimpleForm, item_wrapper_tag: :li do
118
144
  with_input_for @user, :active, :check_boxes
119
145
 
120
- assert_select 'form li input[type=checkbox]', :count => 2
146
+ assert_select 'form li input[type=checkbox]', count: 2
121
147
  end
122
148
  end
123
149
 
124
150
  test 'input check boxes does not wrap items when configured with falsy values' do
125
- swap SimpleForm, :item_wrapper_tag => false do
151
+ swap SimpleForm, item_wrapper_tag: false do
126
152
  with_input_for @user, :active, :check_boxes
127
153
 
128
- assert_select 'form input[type=checkbox]', :count => 2
154
+ assert_select 'form input[type=checkbox]', count: 2
129
155
  assert_no_select 'form li'
130
156
  end
131
157
  end
132
158
 
133
159
  test 'input check boxes allows overriding the item wrapper tag at input level' do
134
- swap SimpleForm, :item_wrapper_tag => :li do
135
- with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :dl
160
+ swap SimpleForm, item_wrapper_tag: :li do
161
+ with_input_for @user, :active, :check_boxes, item_wrapper_tag: :dl
136
162
 
137
- assert_select 'form dl input[type=checkbox]', :count => 2
163
+ assert_select 'form dl input[type=checkbox]', count: 2
138
164
  assert_no_select 'form li'
139
165
  end
140
166
  end
141
167
 
142
168
  test 'input check boxes allows disabling the item wrapper tag at input level' do
143
- swap SimpleForm, :item_wrapper_tag => :ul do
144
- with_input_for @user, :active, :check_boxes, :item_wrapper_tag => false
169
+ swap SimpleForm, item_wrapper_tag: :ul do
170
+ with_input_for @user, :active, :check_boxes, item_wrapper_tag: false
145
171
 
146
- assert_select 'form input[type=checkbox]', :count => 2
172
+ assert_select 'form input[type=checkbox]', count: 2
147
173
  assert_no_select 'form li'
148
174
  end
149
175
  end
@@ -151,74 +177,143 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
151
177
  test 'input check boxes wraps items in a span tag by default' do
152
178
  with_input_for @user, :active, :check_boxes
153
179
 
154
- assert_select 'form span input[type=checkbox]', :count => 2
180
+ assert_select 'form span input[type=checkbox]', count: 2
155
181
  end
156
182
 
157
183
  test 'input check boxes renders the item wrapper tag with a default class "checkbox"' do
158
- with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :li
184
+ with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
159
185
 
160
- assert_select 'form li.checkbox input[type=checkbox]', :count => 2
186
+ assert_select 'form li.checkbox input[type=checkbox]', count: 2
161
187
  end
162
188
 
163
189
  test 'input check boxes renders the item wrapper tag with the configured item wrapper class' do
164
- swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
190
+ swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
165
191
  with_input_for @user, :active, :check_boxes
166
192
 
167
- assert_select 'form li.checkbox.item input[type=checkbox]', :count => 2
193
+ assert_select 'form li.checkbox.item input[type=checkbox]', count: 2
168
194
  end
169
195
  end
170
196
 
171
197
  test 'input check boxes allows giving item wrapper class at input level only' do
172
- swap SimpleForm, :item_wrapper_tag => :li do
173
- with_input_for @user, :active, :check_boxes, :item_wrapper_class => 'item'
198
+ swap SimpleForm, item_wrapper_tag: :li do
199
+ with_input_for @user, :active, :check_boxes, item_wrapper_class: 'item'
174
200
 
175
- assert_select 'form li.checkbox.item input[type=checkbox]', :count => 2
201
+ assert_select 'form li.checkbox.item input[type=checkbox]', count: 2
176
202
  end
177
203
  end
178
204
 
179
205
  test 'input check boxes uses both configured and given item wrapper classes for item wrapper tag' do
180
- swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
181
- with_input_for @user, :active, :check_boxes, :item_wrapper_class => 'inline'
206
+ swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
207
+ with_input_for @user, :active, :check_boxes, item_wrapper_class: 'inline'
182
208
 
183
- assert_select 'form li.checkbox.item.inline input[type=checkbox]', :count => 2
209
+ assert_select 'form li.checkbox.item.inline input[type=checkbox]', count: 2
184
210
  end
185
211
  end
186
212
 
187
213
  test 'input check boxes respects the nested boolean style config, generating nested label > input' do
188
- swap SimpleForm, :boolean_style => :nested do
214
+ swap SimpleForm, boolean_style: :nested do
189
215
  with_input_for @user, :active, :check_boxes
190
216
 
191
- assert_select 'label.checkbox > input#user_active_true[type=checkbox]'
192
- assert_select 'label.checkbox', 'Yes'
193
- assert_select 'label.checkbox > input#user_active_false[type=checkbox]'
194
- assert_select 'label.checkbox', 'No'
217
+ assert_select 'span.checkbox > label > input#user_active_true[type=checkbox]'
218
+ assert_select 'span.checkbox > label', 'Yes'
219
+ assert_select 'span.checkbox > label > input#user_active_false[type=checkbox]'
220
+ assert_select 'span.checkbox > label', 'No'
195
221
  assert_no_select 'label.collection_radio_buttons'
196
222
  end
197
223
  end
198
224
 
199
- test 'input check boxes with nested style overrides configured item wrapper tag, forcing the :label' do
200
- swap SimpleForm, :boolean_style => :nested, :item_wrapper_tag => :li do
225
+ test 'input check boxes with nested style does not overrides configured item wrapper tag' do
226
+ swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
201
227
  with_input_for @user, :active, :check_boxes
202
228
 
203
- assert_select 'label.checkbox > input'
204
- assert_no_select 'li'
229
+ assert_select 'li.checkbox > label > input'
205
230
  end
206
231
  end
207
232
 
208
- test 'input check boxes with nested style overrides given item wrapper tag, forcing the :label' do
209
- swap SimpleForm, :boolean_style => :nested do
210
- with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :li
233
+ test 'input check boxes with nested style does not overrides given item wrapper tag' do
234
+ swap SimpleForm, boolean_style: :nested do
235
+ with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
211
236
 
212
- assert_select 'label.checkbox > input'
213
- assert_no_select 'li'
237
+ assert_select 'li.checkbox > label > input'
214
238
  end
215
239
  end
216
240
 
217
241
  test 'input check boxes with nested style accepts giving extra wrapper classes' do
218
- swap SimpleForm, :boolean_style => :nested do
219
- with_input_for @user, :active, :check_boxes, :item_wrapper_class => "inline"
242
+ swap SimpleForm, boolean_style: :nested do
243
+ with_input_for @user, :active, :check_boxes, item_wrapper_class: "inline"
244
+
245
+ assert_select 'span.checkbox.inline > label > input'
246
+ end
247
+ end
248
+
249
+ test 'input check boxes with nested style renders item labels with specified class' do
250
+ swap SimpleForm, boolean_style: :nested do
251
+ with_input_for @user, :active, :check_boxes, item_label_class: "test"
252
+
253
+ assert_select 'span.checkbox > label.test > input'
254
+ end
255
+ end
256
+
257
+ test 'input check boxes with nested style and falsey input wrapper renders item labels with specified class' do
258
+ swap SimpleForm, boolean_style: :nested, item_wrapper_tag: false do
259
+ with_input_for @user, :active, :check_boxes, item_label_class: "checkbox-inline"
260
+
261
+ assert_select 'label.checkbox-inline > input'
262
+ assert_no_select 'span.checkbox'
263
+ end
264
+ end
265
+
266
+ test 'input check boxes wrapper class are not included when set to falsey' do
267
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
268
+ with_input_for @user, :gender, :check_boxes, collection: %i[male female]
269
+
270
+ assert_no_select 'label.checkbox'
271
+ end
272
+ end
273
+
274
+ test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
275
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
276
+ with_input_for @user, :gender, :check_boxes, collection: %i[male female], item_wrapper_class: 'custom'
277
+
278
+ assert_no_select 'label.checkbox'
279
+ assert_select 'span.custom'
280
+ end
281
+ end
282
+
283
+ test 'input check boxes with nested style and namespace uses the right for attribute' do
284
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
285
+ with_concat_form_for @user, namespace: :foo do |f|
286
+ concat f.input :gender, as: :check_boxes, collection: %i[male female]
287
+ end
288
+
289
+ assert_select 'label[for=foo_user_gender_male]'
290
+ assert_select 'label[for=foo_user_gender_female]'
291
+ end
292
+ end
293
+
294
+ test 'input check boxes with nested style and index uses the right for attribute' do
295
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
296
+ with_concat_form_for @user, index: 1 do |f|
297
+ concat f.input :gender, as: :check_boxes, collection: %i[male female]
298
+ end
299
+
300
+ assert_select 'label[for=user_1_gender_male]'
301
+ assert_select 'label[for=user_1_gender_female]'
302
+ end
303
+ end
220
304
 
221
- assert_select 'label.checkbox.inline > input'
305
+ test 'input check boxes with nested style accepts non-string attribute as label' do
306
+ swap SimpleForm, boolean_style: :nested do
307
+ with_input_for @user, :amount,
308
+ :check_boxes,
309
+ collection: { 100 => 'hundred', 200 => 'two_hundred' },
310
+ label_method: :first,
311
+ value_method: :second
312
+
313
+ assert_select 'input[type=checkbox][value=hundred]'
314
+ assert_select 'input[type=checkbox][value=two_hundred]'
315
+ assert_select 'span.checkbox > label', '100'
316
+ assert_select 'span.checkbox > label', '200'
222
317
  end
223
318
  end
224
319
  end