simple_form 3.0.2 → 3.1.0.rc2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -32
- data/MIT-LICENSE +1 -1
- data/README.md +179 -73
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +25 -5
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +108 -24
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
- data/lib/simple_form/components/errors.rb +30 -2
- data/lib/simple_form/components/hints.rb +2 -2
- data/lib/simple_form/components/html5.rb +1 -1
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +10 -6
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/form_builder.rb +121 -72
- data/lib/simple_form/helpers.rb +5 -5
- data/lib/simple_form/inputs/base.rb +33 -11
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +27 -14
- data/lib/simple_form/inputs/collection_input.rb +32 -9
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +12 -2
- data/lib/simple_form/inputs/file_input.rb +4 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
- data/lib/simple_form/inputs/hidden_input.rb +4 -2
- data/lib/simple_form/inputs/numeric_input.rb +5 -4
- data/lib/simple_form/inputs/password_input.rb +4 -2
- data/lib/simple_form/inputs/priority_input.rb +4 -2
- data/lib/simple_form/inputs/range_input.rb +1 -1
- data/lib/simple_form/inputs/string_input.rb +4 -2
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +8 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +6 -6
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +6 -6
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +46 -6
- data/test/action_view_extensions/builder_test.rb +5 -5
- data/test/action_view_extensions/form_helper_test.rb +13 -13
- data/test/components/label_test.rb +36 -36
- data/test/form_builder/association_test.rb +21 -4
- data/test/form_builder/button_test.rb +5 -5
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/error_test.rb +78 -17
- data/test/form_builder/general_test.rb +65 -60
- data/test/form_builder/hint_test.rb +15 -15
- data/test/form_builder/input_field_test.rb +37 -13
- data/test/form_builder/label_test.rb +44 -12
- data/test/form_builder/wrapper_test.rb +120 -19
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +54 -6
- data/test/inputs/collection_check_boxes_input_test.rb +63 -17
- data/test/inputs/collection_radio_buttons_input_test.rb +112 -36
- data/test/inputs/collection_select_input_test.rb +141 -36
- data/test/inputs/datetime_input_test.rb +116 -49
- data/test/inputs/disabled_test.rb +15 -15
- data/test/inputs/discovery_test.rb +56 -6
- data/test/inputs/file_input_test.rb +2 -2
- data/test/inputs/general_test.rb +20 -20
- data/test/inputs/grouped_collection_select_input_test.rb +38 -2
- data/test/inputs/hidden_input_test.rb +4 -4
- data/test/inputs/numeric_input_test.rb +24 -24
- data/test/inputs/priority_input_test.rb +7 -7
- data/test/inputs/readonly_test.rb +19 -19
- data/test/inputs/required_test.rb +13 -13
- data/test/inputs/string_input_test.rb +41 -21
- data/test/inputs/text_input_test.rb +4 -4
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +32 -2
- data/test/support/misc_helpers.rb +71 -5
- data/test/support/models.rb +50 -24
- metadata +6 -5
|
@@ -6,30 +6,30 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
6
6
|
SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
test 'input check boxes
|
|
9
|
+
test 'input check boxes does not include for attribute by default' do
|
|
10
10
|
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
|
11
11
|
assert_select 'label'
|
|
12
12
|
assert_no_select 'label[for=user_gender]'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
test 'input check boxes
|
|
15
|
+
test 'input check boxes includes for attribute when giving as html option' do
|
|
16
16
|
with_input_for @user, :gender, :check_boxes, collection: [:male, :female], label_html: { for: 'gender' }
|
|
17
17
|
assert_select 'label[for=gender]'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
test 'collection input with check_boxes type
|
|
20
|
+
test 'collection input with check_boxes type does not generate required html attribute' do
|
|
21
21
|
with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
|
|
22
22
|
assert_select 'input.required'
|
|
23
23
|
assert_no_select 'input[required]'
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
test 'collection input with check_boxes type
|
|
26
|
+
test 'collection input with check_boxes type does not generate aria-required html attribute' do
|
|
27
27
|
with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
|
|
28
28
|
assert_select 'input.required'
|
|
29
29
|
assert_no_select 'input[aria-required]'
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
test 'input
|
|
32
|
+
test 'input does automatic collection translation for check_box types using defaults key' do
|
|
33
33
|
store_translations(:en, simple_form: { options: { defaults: {
|
|
34
34
|
gender: { male: 'Male', female: 'Female'}
|
|
35
35
|
} } } ) do
|
|
@@ -41,7 +41,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
test 'input
|
|
44
|
+
test 'input does automatic collection translation for check_box types using specific object key' do
|
|
45
45
|
store_translations(:en, simple_form: { options: { user: {
|
|
46
46
|
gender: { male: 'Male', female: 'Female'}
|
|
47
47
|
} } } ) do
|
|
@@ -53,6 +53,20 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
test 'input that uses automatic collection translation for check_boxes properly sets checked values' do
|
|
57
|
+
store_translations(:en, simple_form: { options: { defaults: {
|
|
58
|
+
gender: { male: 'Male', female: 'Female'}
|
|
59
|
+
} } } ) do
|
|
60
|
+
@user.gender = 'male'
|
|
61
|
+
|
|
62
|
+
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
|
63
|
+
assert_select 'input[type=checkbox][value=male][checked=checked]'
|
|
64
|
+
assert_select 'input[type=checkbox][value=female]'
|
|
65
|
+
assert_select 'label.collection_check_boxes', 'Male'
|
|
66
|
+
assert_select 'label.collection_check_boxes', 'Female'
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
56
70
|
test 'input check boxes does not wrap the collection by default' do
|
|
57
71
|
with_input_for @user, :active, :check_boxes
|
|
58
72
|
|
|
@@ -199,29 +213,27 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
199
213
|
swap SimpleForm, boolean_style: :nested do
|
|
200
214
|
with_input_for @user, :active, :check_boxes
|
|
201
215
|
|
|
202
|
-
assert_select '
|
|
203
|
-
assert_select '
|
|
204
|
-
assert_select '
|
|
205
|
-
assert_select '
|
|
216
|
+
assert_select 'span.checkbox > label > input#user_active_true[type=checkbox]'
|
|
217
|
+
assert_select 'span.checkbox > label', 'Yes'
|
|
218
|
+
assert_select 'span.checkbox > label > input#user_active_false[type=checkbox]'
|
|
219
|
+
assert_select 'span.checkbox > label', 'No'
|
|
206
220
|
assert_no_select 'label.collection_radio_buttons'
|
|
207
221
|
end
|
|
208
222
|
end
|
|
209
223
|
|
|
210
|
-
test 'input check boxes with nested style overrides configured item wrapper tag
|
|
224
|
+
test 'input check boxes with nested style does not overrides configured item wrapper tag' do
|
|
211
225
|
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
|
|
212
226
|
with_input_for @user, :active, :check_boxes
|
|
213
227
|
|
|
214
|
-
assert_select '
|
|
215
|
-
assert_no_select 'li'
|
|
228
|
+
assert_select 'li.checkbox > label > input'
|
|
216
229
|
end
|
|
217
230
|
end
|
|
218
231
|
|
|
219
|
-
test 'input check boxes with nested style overrides given item wrapper tag
|
|
232
|
+
test 'input check boxes with nested style does not overrides given item wrapper tag' do
|
|
220
233
|
swap SimpleForm, boolean_style: :nested do
|
|
221
234
|
with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
|
|
222
235
|
|
|
223
|
-
assert_select '
|
|
224
|
-
assert_no_select 'li'
|
|
236
|
+
assert_select 'li.checkbox > label > input'
|
|
225
237
|
end
|
|
226
238
|
end
|
|
227
239
|
|
|
@@ -229,7 +241,41 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
229
241
|
swap SimpleForm, boolean_style: :nested do
|
|
230
242
|
with_input_for @user, :active, :check_boxes, item_wrapper_class: "inline"
|
|
231
243
|
|
|
232
|
-
assert_select '
|
|
244
|
+
assert_select 'span.checkbox.inline > label > input'
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
test 'input check boxes with nested style renders item labels with specified class' do
|
|
249
|
+
swap SimpleForm, boolean_style: :nested do
|
|
250
|
+
with_input_for @user, :active, :check_boxes, item_label_class: "test"
|
|
251
|
+
|
|
252
|
+
assert_select 'span.checkbox > label.test > input'
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
test 'input check boxes with nested style and falsey input wrapper renders item labels with specified class' do
|
|
257
|
+
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: false do
|
|
258
|
+
with_input_for @user, :active, :check_boxes, item_label_class: "checkbox-inline"
|
|
259
|
+
|
|
260
|
+
assert_select 'label.checkbox-inline > input'
|
|
261
|
+
assert_no_select 'span.checkbox'
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
test 'input check boxes wrapper class are not included when set to falsey' do
|
|
266
|
+
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
267
|
+
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
|
268
|
+
|
|
269
|
+
assert_no_select 'label.checkbox'
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
|
|
274
|
+
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
275
|
+
with_input_for @user, :gender, :check_boxes, collection: [:male, :female], item_wrapper_class: 'custom'
|
|
276
|
+
|
|
277
|
+
assert_no_select 'label.checkbox'
|
|
278
|
+
assert_select 'span.custom'
|
|
233
279
|
end
|
|
234
280
|
end
|
|
235
281
|
end
|
|
@@ -6,19 +6,35 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
6
6
|
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
test 'input
|
|
9
|
+
test 'input generates boolean radio buttons by default for radio types' do
|
|
10
10
|
with_input_for @user, :active, :radio_buttons
|
|
11
11
|
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
|
12
12
|
assert_select 'input[type=radio][value=false].radio_buttons#user_active_false'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
test 'input as radio
|
|
15
|
+
test 'input as radio generates internal labels by default' do
|
|
16
16
|
with_input_for @user, :active, :radio_buttons
|
|
17
17
|
assert_select 'label[for=user_active_true]', 'Yes'
|
|
18
18
|
assert_select 'label[for=user_active_false]', 'No'
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
test 'input as radio
|
|
21
|
+
test 'input as radio generates internal labels with accurate `for` values with nested boolean style' do
|
|
22
|
+
swap SimpleForm, boolean_style: :nested do
|
|
23
|
+
with_input_for @user, :active, :radio_buttons
|
|
24
|
+
assert_select 'label[for=user_active_true]', 'Yes'
|
|
25
|
+
assert_select 'label[for=user_active_false]', 'No'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'nested label does not duplicate input id' do
|
|
30
|
+
swap SimpleForm, boolean_style: :nested do
|
|
31
|
+
with_input_for @user, :active, :radio_buttons, id: 'nested_id'
|
|
32
|
+
assert_select 'input#user_active_true'
|
|
33
|
+
assert_no_select 'label#user_active_true'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test 'input as radio uses i18n to translate internal labels' do
|
|
22
38
|
store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do
|
|
23
39
|
with_input_for @user, :active, :radio_buttons
|
|
24
40
|
assert_select 'label[for=user_active_true]', 'Sim'
|
|
@@ -26,68 +42,96 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
26
42
|
end
|
|
27
43
|
end
|
|
28
44
|
|
|
29
|
-
test 'input radio
|
|
45
|
+
test 'input radio does not include for attribute by default' do
|
|
30
46
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
31
47
|
assert_select 'label'
|
|
32
48
|
assert_no_select 'label[for=user_gender]'
|
|
33
49
|
end
|
|
34
50
|
|
|
35
|
-
test 'input radio
|
|
51
|
+
test 'input radio includes for attribute when giving as html option' do
|
|
36
52
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], label_html: { for: 'gender' }
|
|
37
53
|
assert_select 'label[for=gender]'
|
|
38
54
|
end
|
|
39
55
|
|
|
40
|
-
test 'input
|
|
56
|
+
test 'input marks the checked value when using boolean and radios' do
|
|
41
57
|
@user.active = false
|
|
42
58
|
with_input_for @user, :active, :radio_buttons
|
|
43
59
|
assert_no_select 'input[type=radio][value=true][checked]'
|
|
44
60
|
assert_select 'input[type=radio][value=false][checked]'
|
|
45
61
|
end
|
|
46
62
|
|
|
47
|
-
test 'input
|
|
63
|
+
test 'input allows overriding collection for radio types' do
|
|
48
64
|
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
|
49
65
|
assert_select 'input[type=radio][value=Jose]'
|
|
50
66
|
assert_select 'input[type=radio][value=Carlos]'
|
|
51
|
-
assert_select 'label.collection_radio_buttons', 'Jose'
|
|
52
|
-
assert_select 'label.collection_radio_buttons', 'Carlos'
|
|
67
|
+
assert_select 'label.collection_radio_buttons[for=user_name_jose]', 'Jose'
|
|
68
|
+
assert_select 'label.collection_radio_buttons[for=user_name_carlos]', 'Carlos'
|
|
53
69
|
end
|
|
54
70
|
|
|
55
|
-
test 'input
|
|
71
|
+
test 'input does automatic collection translation for radio types using defaults key' do
|
|
56
72
|
store_translations(:en, simple_form: { options: { defaults: {
|
|
57
73
|
gender: { male: 'Male', female: 'Female'}
|
|
58
74
|
} } } ) do
|
|
59
75
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
60
76
|
assert_select 'input[type=radio][value=male]'
|
|
61
77
|
assert_select 'input[type=radio][value=female]'
|
|
62
|
-
assert_select 'label.collection_radio_buttons', 'Male'
|
|
63
|
-
assert_select 'label.collection_radio_buttons', 'Female'
|
|
78
|
+
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
|
79
|
+
assert_select 'label.collection_radio_buttons[for=user_gender_female]', 'Female'
|
|
64
80
|
end
|
|
65
81
|
end
|
|
66
82
|
|
|
67
|
-
test 'input
|
|
83
|
+
test 'input does automatic collection translation for radio types using specific object key' do
|
|
68
84
|
store_translations(:en, simple_form: { options: { user: {
|
|
69
85
|
gender: { male: 'Male', female: 'Female'}
|
|
70
86
|
} } } ) do
|
|
71
87
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
72
88
|
assert_select 'input[type=radio][value=male]'
|
|
73
89
|
assert_select 'input[type=radio][value=female]'
|
|
74
|
-
assert_select 'label.collection_radio_buttons', 'Male'
|
|
75
|
-
assert_select 'label.collection_radio_buttons', 'Female'
|
|
90
|
+
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
|
91
|
+
assert_select 'label.collection_radio_buttons[for=user_gender_female]', 'Female'
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
test 'input does automatic collection translation and preserve html markup' do
|
|
96
|
+
swap SimpleForm, boolean_style: :nested do
|
|
97
|
+
store_translations(:en, simple_form: { options: { user: {
|
|
98
|
+
gender: { male_html: '<strong>Male</strong>', female_html: '<strong>Female</strong>' }
|
|
99
|
+
} } } ) do
|
|
100
|
+
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
101
|
+
assert_select 'input[type=radio][value=male]'
|
|
102
|
+
assert_select 'input[type=radio][value=female]'
|
|
103
|
+
assert_select 'label[for=user_gender_male]', 'Male'
|
|
104
|
+
assert_select 'label[for=user_gender_female]', 'Female'
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
test 'input does automatic collection translation with keys prefixed with _html and a string value' do
|
|
110
|
+
swap SimpleForm, boolean_style: :nested do
|
|
111
|
+
store_translations(:en, simple_form: { options: { user: {
|
|
112
|
+
gender: { male_html: 'Male', female_html: 'Female' }
|
|
113
|
+
} } } ) do
|
|
114
|
+
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
115
|
+
assert_select 'input[type=radio][value=male]'
|
|
116
|
+
assert_select 'input[type=radio][value=female]'
|
|
117
|
+
assert_select 'label[for=user_gender_male]', 'Male'
|
|
118
|
+
assert_select 'label[for=user_gender_female]', 'Female'
|
|
119
|
+
end
|
|
76
120
|
end
|
|
77
121
|
end
|
|
78
122
|
|
|
79
|
-
test 'input
|
|
123
|
+
test 'input marks the current radio value by default' do
|
|
80
124
|
@user.name = "Carlos"
|
|
81
125
|
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
|
82
126
|
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
|
83
127
|
end
|
|
84
128
|
|
|
85
|
-
test 'input
|
|
129
|
+
test 'input accepts html options as the last element of collection' do
|
|
86
130
|
with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose', class: 'foo']]
|
|
87
131
|
assert_select 'input.foo[type=radio][value=jose]'
|
|
88
132
|
end
|
|
89
133
|
|
|
90
|
-
test 'input
|
|
134
|
+
test 'input allows using a collection with text/value arrays' do
|
|
91
135
|
with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose'], ['Carlos', 'carlos']]
|
|
92
136
|
assert_select 'input[type=radio][value=jose]'
|
|
93
137
|
assert_select 'input[type=radio][value=carlos]'
|
|
@@ -95,13 +139,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
95
139
|
assert_select 'label.collection_radio_buttons', 'Carlos'
|
|
96
140
|
end
|
|
97
141
|
|
|
98
|
-
test 'input
|
|
142
|
+
test 'input allows using a collection with a Proc' do
|
|
99
143
|
with_input_for @user, :name, :radio_buttons, collection: Proc.new { ['Jose', 'Carlos' ] }
|
|
100
144
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
|
101
145
|
assert_select 'label.collection_radio_buttons', 'Carlos'
|
|
102
146
|
end
|
|
103
147
|
|
|
104
|
-
test 'input
|
|
148
|
+
test 'input allows overriding only label method for collections' do
|
|
105
149
|
with_input_for @user, :name, :radio_buttons,
|
|
106
150
|
collection: ['Jose', 'Carlos'],
|
|
107
151
|
label_method: :upcase
|
|
@@ -109,7 +153,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
109
153
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
|
110
154
|
end
|
|
111
155
|
|
|
112
|
-
test 'input
|
|
156
|
+
test 'input allows overriding only value method for collections' do
|
|
113
157
|
with_input_for @user, :name, :radio_buttons,
|
|
114
158
|
collection: ['Jose', 'Carlos'],
|
|
115
159
|
value_method: :upcase
|
|
@@ -117,7 +161,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
117
161
|
assert_select 'input[type=radio][value=CARLOS]'
|
|
118
162
|
end
|
|
119
163
|
|
|
120
|
-
test 'input
|
|
164
|
+
test 'input allows overriding label and value method for collections' do
|
|
121
165
|
with_input_for @user, :name, :radio_buttons,
|
|
122
166
|
collection: ['Jose', 'Carlos'],
|
|
123
167
|
label_method: :upcase,
|
|
@@ -128,7 +172,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
128
172
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
|
129
173
|
end
|
|
130
174
|
|
|
131
|
-
test 'input
|
|
175
|
+
test 'input allows overriding label and value method using a lambda for collections' do
|
|
132
176
|
with_input_for @user, :name, :radio_buttons,
|
|
133
177
|
collection: ['Jose', 'Carlos'],
|
|
134
178
|
label_method: lambda { |i| i.upcase },
|
|
@@ -139,13 +183,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
139
183
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
|
140
184
|
end
|
|
141
185
|
|
|
142
|
-
test 'collection input with radio type
|
|
186
|
+
test 'collection input with radio type generates required html attribute' do
|
|
143
187
|
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
|
144
188
|
assert_select 'input[type=radio].required'
|
|
145
189
|
assert_select 'input[type=radio][required]'
|
|
146
190
|
end
|
|
147
191
|
|
|
148
|
-
test 'collection input with radio type
|
|
192
|
+
test 'collection input with radio type generates aria-required html attribute' do
|
|
149
193
|
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
|
150
194
|
assert_select 'input[type=radio].required'
|
|
151
195
|
assert_select 'input[type=radio][aria-required=true]'
|
|
@@ -292,29 +336,27 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
292
336
|
swap SimpleForm, boolean_style: :nested do
|
|
293
337
|
with_input_for @user, :active, :radio_buttons
|
|
294
338
|
|
|
295
|
-
assert_select '
|
|
296
|
-
assert_select '
|
|
297
|
-
assert_select '
|
|
298
|
-
assert_select '
|
|
339
|
+
assert_select 'span.radio > label > input#user_active_true[type=radio]'
|
|
340
|
+
assert_select 'span.radio > label', 'Yes'
|
|
341
|
+
assert_select 'span.radio > label > input#user_active_false[type=radio]'
|
|
342
|
+
assert_select 'span.radio > label', 'No'
|
|
299
343
|
assert_no_select 'label.collection_radio_buttons'
|
|
300
344
|
end
|
|
301
345
|
end
|
|
302
346
|
|
|
303
|
-
test 'input radio with nested style overrides configured item wrapper tag
|
|
347
|
+
test 'input radio with nested style does not overrides configured item wrapper tag' do
|
|
304
348
|
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
|
|
305
349
|
with_input_for @user, :active, :radio_buttons
|
|
306
350
|
|
|
307
|
-
assert_select '
|
|
308
|
-
assert_no_select 'li'
|
|
351
|
+
assert_select 'li.radio > label > input'
|
|
309
352
|
end
|
|
310
353
|
end
|
|
311
354
|
|
|
312
|
-
test 'input radio with nested style overrides given item wrapper tag
|
|
355
|
+
test 'input radio with nested style does not overrides given item wrapper tag' do
|
|
313
356
|
swap SimpleForm, boolean_style: :nested do
|
|
314
357
|
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :li
|
|
315
358
|
|
|
316
|
-
assert_select '
|
|
317
|
-
assert_no_select 'li'
|
|
359
|
+
assert_select 'li.radio > label > input'
|
|
318
360
|
end
|
|
319
361
|
end
|
|
320
362
|
|
|
@@ -322,7 +364,41 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
|
322
364
|
swap SimpleForm, boolean_style: :nested do
|
|
323
365
|
with_input_for @user, :active, :radio_buttons, item_wrapper_class: "inline"
|
|
324
366
|
|
|
325
|
-
assert_select '
|
|
367
|
+
assert_select 'span.radio.inline > label > input'
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
test 'input radio with nested style renders item labels with specified class' do
|
|
372
|
+
swap SimpleForm, boolean_style: :nested do
|
|
373
|
+
with_input_for @user, :active, :radio_buttons, item_label_class: "test"
|
|
374
|
+
|
|
375
|
+
assert_select 'span.radio > label.test > input'
|
|
376
|
+
end
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
test 'input radio with nested style and falsey input wrapper renders item labels with specified class' do
|
|
380
|
+
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: false do
|
|
381
|
+
with_input_for @user, :active, :radio_buttons, item_label_class: "radio-inline"
|
|
382
|
+
|
|
383
|
+
assert_select 'label.radio-inline > input'
|
|
384
|
+
assert_no_select 'span.radio'
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
test 'input radio wrapper class are not included when set to falsey' do
|
|
389
|
+
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
390
|
+
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
391
|
+
|
|
392
|
+
assert_no_select 'label.radio'
|
|
393
|
+
end
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
|
|
397
|
+
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
398
|
+
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], item_wrapper_class: 'custom'
|
|
399
|
+
|
|
400
|
+
assert_no_select 'label.radio'
|
|
401
|
+
assert_select 'span.custom'
|
|
326
402
|
end
|
|
327
403
|
end
|
|
328
404
|
end
|