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