simple_form 3.4.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +118 -8
- data/MIT-LICENSE +2 -1
- data/README.md +235 -67
- data/lib/generators/simple_form/install_generator.rb +1 -0
- data/lib/generators/simple_form/templates/README +2 -3
- data/lib/generators/simple_form/templates/_form.html.erb +2 -0
- data/lib/generators/simple_form/templates/_form.html.haml +2 -0
- data/lib/generators/simple_form/templates/_form.html.slim +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +14 -7
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +360 -74
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +20 -8
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
- data/lib/simple_form/components/errors.rb +15 -2
- data/lib/simple_form/components/hints.rb +1 -0
- data/lib/simple_form/components/html5.rb +1 -0
- data/lib/simple_form/components/label_input.rb +2 -1
- data/lib/simple_form/components/labels.rb +12 -7
- data/lib/simple_form/components/maxlength.rb +4 -17
- data/lib/simple_form/components/min_max.rb +1 -0
- data/lib/simple_form/components/minlength.rb +5 -18
- data/lib/simple_form/components/pattern.rb +1 -0
- data/lib/simple_form/components/placeholders.rb +2 -1
- data/lib/simple_form/components/readonly.rb +1 -0
- data/lib/simple_form/components.rb +1 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +104 -29
- data/lib/simple_form/helpers/autofocus.rb +1 -0
- data/lib/simple_form/helpers/disabled.rb +1 -0
- data/lib/simple_form/helpers/readonly.rb +1 -0
- data/lib/simple_form/helpers/required.rb +1 -0
- data/lib/simple_form/helpers/validators.rb +2 -1
- data/lib/simple_form/helpers.rb +1 -0
- data/lib/simple_form/inputs/base.rb +24 -5
- data/lib/simple_form/inputs/block_input.rb +1 -0
- data/lib/simple_form/inputs/boolean_input.rb +4 -2
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +3 -2
- data/lib/simple_form/inputs/collection_input.rb +6 -7
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
- data/lib/simple_form/inputs/collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/color_input.rb +14 -0
- data/lib/simple_form/inputs/date_time_input.rb +1 -0
- data/lib/simple_form/inputs/file_input.rb +1 -0
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/hidden_input.rb +1 -0
- data/lib/simple_form/inputs/numeric_input.rb +1 -0
- data/lib/simple_form/inputs/password_input.rb +1 -0
- data/lib/simple_form/inputs/priority_input.rb +1 -4
- data/lib/simple_form/inputs/range_input.rb +1 -0
- data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
- data/lib/simple_form/inputs/string_input.rb +2 -1
- data/lib/simple_form/inputs/text_input.rb +1 -0
- data/lib/simple_form/inputs.rb +3 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +1 -0
- data/lib/simple_form/tags.rb +7 -2
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +1 -0
- data/lib/simple_form/wrappers/leaf.rb +2 -1
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/lib/simple_form/wrappers/root.rb +9 -2
- data/lib/simple_form/wrappers/single.rb +2 -1
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +79 -11
- data/test/action_view_extensions/builder_test.rb +28 -9
- data/test/action_view_extensions/form_helper_test.rb +3 -2
- data/test/components/custom_components_test.rb +62 -0
- data/test/components/label_test.rb +33 -8
- data/test/form_builder/association_test.rb +33 -2
- data/test/form_builder/button_test.rb +1 -0
- data/test/form_builder/error_notification_test.rb +1 -0
- data/test/form_builder/error_test.rb +12 -0
- data/test/form_builder/general_test.rb +75 -13
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +30 -10
- data/test/form_builder/label_test.rb +10 -4
- data/test/form_builder/wrapper_test.rb +32 -5
- data/test/generators/simple_form_generator_test.rb +4 -3
- data/test/inputs/boolean_input_test.rb +17 -0
- data/test/inputs/collection_check_boxes_input_test.rb +38 -18
- data/test/inputs/collection_radio_buttons_input_test.rb +48 -28
- data/test/inputs/collection_select_input_test.rb +46 -43
- data/test/inputs/color_input_test.rb +10 -0
- data/test/inputs/datetime_input_test.rb +7 -16
- data/test/inputs/disabled_test.rb +14 -0
- data/test/inputs/discovery_test.rb +22 -0
- data/test/inputs/file_input_test.rb +1 -0
- data/test/inputs/general_test.rb +3 -2
- data/test/inputs/grouped_collection_select_input_test.rb +11 -10
- data/test/inputs/hidden_input_test.rb +1 -0
- data/test/inputs/numeric_input_test.rb +2 -1
- data/test/inputs/priority_input_test.rb +7 -14
- data/test/inputs/readonly_test.rb +1 -0
- data/test/inputs/required_test.rb +1 -0
- data/test/inputs/rich_text_area_input_test.rb +15 -0
- data/test/inputs/string_input_test.rb +10 -16
- data/test/inputs/text_input_test.rb +1 -0
- data/test/simple_form_test.rb +1 -0
- data/test/support/discovery_inputs.rb +8 -0
- data/test/support/misc_helpers.rb +22 -1
- data/test/support/mock_controller.rb +7 -1
- data/test/support/models.rb +80 -18
- data/test/test_helper.rb +9 -4
- metadata +49 -55
- data/lib/simple_form/i18n_cache.rb +0 -22
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
@@ -18,7 +19,7 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
|
18
19
|
end
|
19
20
|
|
20
21
|
test 'generates the simple_form initializer with the bootstrap wrappers' do
|
21
|
-
run_generator %w
|
22
|
+
run_generator %w[--bootstrap]
|
22
23
|
assert_file 'config/initializers/simple_form.rb',
|
23
24
|
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
24
25
|
assert_file 'config/initializers/simple_form_bootstrap.rb', /config\.wrappers :vertical_form/,
|
@@ -26,14 +27,14 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
|
26
27
|
end
|
27
28
|
|
28
29
|
test 'generates the simple_form initializer with the foundation wrappers' do
|
29
|
-
run_generator %w
|
30
|
+
run_generator %w[--foundation]
|
30
31
|
assert_file 'config/initializers/simple_form.rb',
|
31
32
|
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
32
33
|
assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :vertical_form/,
|
33
34
|
/config\.default_wrapper = :vertical_form/, /config\.item_wrapper_tag = :div/
|
34
35
|
end
|
35
36
|
|
36
|
-
%
|
37
|
+
%w[erb haml slim].each do |engine|
|
37
38
|
test "generates the scaffold template when using #{engine}" do
|
38
39
|
run_generator ['-e', engine]
|
39
40
|
assert_file "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -106,6 +107,14 @@ class BooleanInputTest < ActionView::TestCase
|
|
106
107
|
end
|
107
108
|
end
|
108
109
|
|
110
|
+
test 'input boolean with nested generates a disabled hidden field with the form attribute when it is given' do
|
111
|
+
swap SimpleForm, boolean_style: :nested do
|
112
|
+
with_input_for @user, :active, :boolean, input_html: { form: 'form_id' }
|
113
|
+
|
114
|
+
assert_select "input[type=hidden][form=form_id]+ label.boolean > input.boolean"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
109
118
|
test 'input accepts changing boolean style to nested through given options' do
|
110
119
|
with_input_for @user, :active, :boolean, boolean_style: :nested
|
111
120
|
assert_select 'label[for=user_active]', 'Active'
|
@@ -145,6 +154,14 @@ class BooleanInputTest < ActionView::TestCase
|
|
145
154
|
end
|
146
155
|
end
|
147
156
|
|
157
|
+
test 'input with nested style does not include hidden field when unchecked_value is false' do
|
158
|
+
swap SimpleForm, boolean_style: :nested do
|
159
|
+
with_input_for @user, :active, :boolean, unchecked_value: false
|
160
|
+
assert_select "label.boolean > input.boolean"
|
161
|
+
assert_no_select "input[type=hidden] + label.boolean"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
148
165
|
test 'input boolean works using :input only in wrapper config (no label_input)' do
|
149
166
|
swap_wrapper do
|
150
167
|
with_input_for @user, :active, :boolean
|
@@ -1,39 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
4
5
|
class CollectionCheckBoxesInputTest < ActionView::TestCase
|
5
|
-
setup do
|
6
|
-
SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
|
7
|
-
end
|
8
|
-
|
9
6
|
test 'input check boxes does not include for attribute by default' do
|
10
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
7
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
11
8
|
assert_select 'label'
|
12
9
|
assert_no_select 'label[for=user_gender]'
|
13
10
|
end
|
14
11
|
|
15
12
|
test 'input check boxes includes for attribute when giving as html option' do
|
16
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
13
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female], label_html: { for: 'gender' }
|
17
14
|
assert_select 'label[for=gender]'
|
18
15
|
end
|
19
16
|
|
20
17
|
test 'collection input with check_boxes type does not generate required html attribute' do
|
21
|
-
with_input_for @user, :name, :check_boxes, collection: [
|
18
|
+
with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
|
22
19
|
assert_select 'input.required'
|
23
20
|
assert_no_select 'input[required]'
|
24
21
|
end
|
25
22
|
|
26
23
|
test 'collection input with check_boxes type does not generate aria-required html attribute' do
|
27
|
-
with_input_for @user, :name, :check_boxes, collection: [
|
24
|
+
with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
|
28
25
|
assert_select 'input.required'
|
29
26
|
assert_no_select 'input[aria-required]'
|
30
27
|
end
|
31
28
|
|
32
29
|
test 'input does automatic collection translation for check_box types using defaults key' do
|
33
30
|
store_translations(:en, simple_form: { options: { defaults: {
|
34
|
-
gender: { male: 'Male', female: 'Female'}
|
31
|
+
gender: { male: 'Male', female: 'Female' }
|
35
32
|
} } } ) do
|
36
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
33
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
37
34
|
assert_select 'input[type=checkbox][value=male]'
|
38
35
|
assert_select 'input[type=checkbox][value=female]'
|
39
36
|
assert_select 'label.collection_check_boxes', 'Male'
|
@@ -43,9 +40,9 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
43
40
|
|
44
41
|
test 'input does automatic collection translation for check_box types using specific object key' do
|
45
42
|
store_translations(:en, simple_form: { options: { user: {
|
46
|
-
gender: { male: 'Male', female: 'Female'}
|
43
|
+
gender: { male: 'Male', female: 'Female' }
|
47
44
|
} } } ) do
|
48
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
45
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
49
46
|
assert_select 'input[type=checkbox][value=male]'
|
50
47
|
assert_select 'input[type=checkbox][value=female]'
|
51
48
|
assert_select 'label.collection_check_boxes', 'Male'
|
@@ -55,11 +52,11 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
55
52
|
|
56
53
|
test 'input that uses automatic collection translation for check_boxes properly sets checked values' do
|
57
54
|
store_translations(:en, simple_form: { options: { defaults: {
|
58
|
-
gender: { male: 'Male', female: 'Female'}
|
55
|
+
gender: { male: 'Male', female: 'Female' }
|
59
56
|
} } } ) do
|
60
57
|
@user.gender = 'male'
|
61
58
|
|
62
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
59
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
63
60
|
assert_select 'input[type=checkbox][value=male][checked=checked]'
|
64
61
|
assert_select 'input[type=checkbox][value=female]'
|
65
62
|
assert_select 'label.collection_check_boxes', 'Male'
|
@@ -264,7 +261,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
264
261
|
|
265
262
|
test 'input check boxes wrapper class are not included when set to falsey' do
|
266
263
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
267
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
264
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
268
265
|
|
269
266
|
assert_no_select 'label.checkbox'
|
270
267
|
end
|
@@ -272,7 +269,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
272
269
|
|
273
270
|
test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
|
274
271
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
275
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
272
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female], item_wrapper_class: 'custom'
|
276
273
|
|
277
274
|
assert_no_select 'label.checkbox'
|
278
275
|
assert_select 'span.custom'
|
@@ -282,7 +279,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
282
279
|
test 'input check boxes with nested style and namespace uses the right for attribute' do
|
283
280
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
284
281
|
with_concat_form_for @user, namespace: :foo do |f|
|
285
|
-
concat f.input :gender, as: :check_boxes, collection: [
|
282
|
+
concat f.input :gender, as: :check_boxes, collection: %i[male female]
|
286
283
|
end
|
287
284
|
|
288
285
|
assert_select 'label[for=foo_user_gender_male]'
|
@@ -293,11 +290,34 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
293
290
|
test 'input check boxes with nested style and index uses the right for attribute' do
|
294
291
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
295
292
|
with_concat_form_for @user, index: 1 do |f|
|
296
|
-
concat f.input :gender, as: :check_boxes, collection: [
|
293
|
+
concat f.input :gender, as: :check_boxes, collection: %i[male female]
|
297
294
|
end
|
298
295
|
|
299
296
|
assert_select 'label[for=user_1_gender_male]'
|
300
297
|
assert_select 'label[for=user_1_gender_female]'
|
301
298
|
end
|
302
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
|
303
323
|
end
|
@@ -1,11 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
4
5
|
class CollectionRadioButtonsInputTest < ActionView::TestCase
|
5
|
-
setup do
|
6
|
-
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
7
|
-
end
|
8
|
-
|
9
6
|
test 'input generates boolean radio buttons by default for radio types' do
|
10
7
|
with_input_for @user, :active, :radio_buttons
|
11
8
|
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
@@ -43,13 +40,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
43
40
|
end
|
44
41
|
|
45
42
|
test 'input radio does not include for attribute by default' do
|
46
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
43
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
47
44
|
assert_select 'label'
|
48
45
|
assert_no_select 'label[for=user_gender]'
|
49
46
|
end
|
50
47
|
|
51
48
|
test 'input radio includes for attribute when giving as html option' do
|
52
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
49
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female], label_html: { for: 'gender' }
|
53
50
|
assert_select 'label[for=gender]'
|
54
51
|
end
|
55
52
|
|
@@ -61,7 +58,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
61
58
|
end
|
62
59
|
|
63
60
|
test 'input allows overriding collection for radio types' do
|
64
|
-
with_input_for @user, :name, :radio_buttons, collection: [
|
61
|
+
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
65
62
|
assert_select 'input[type=radio][value=Jose]'
|
66
63
|
assert_select 'input[type=radio][value=Carlos]'
|
67
64
|
assert_select 'label.collection_radio_buttons[for=user_name_jose]', 'Jose'
|
@@ -70,9 +67,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
70
67
|
|
71
68
|
test 'input does automatic collection translation for radio types using defaults key' do
|
72
69
|
store_translations(:en, simple_form: { options: { defaults: {
|
73
|
-
gender: { male: 'Male', female: 'Female'}
|
70
|
+
gender: { male: 'Male', female: 'Female' }
|
74
71
|
} } } ) do
|
75
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
72
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
76
73
|
assert_select 'input[type=radio][value=male]'
|
77
74
|
assert_select 'input[type=radio][value=female]'
|
78
75
|
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
@@ -82,9 +79,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
82
79
|
|
83
80
|
test 'input does automatic collection translation for radio types using specific object key' do
|
84
81
|
store_translations(:en, simple_form: { options: { user: {
|
85
|
-
gender: { male: 'Male', female: 'Female'}
|
82
|
+
gender: { male: 'Male', female: 'Female' }
|
86
83
|
} } } ) do
|
87
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
84
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
88
85
|
assert_select 'input[type=radio][value=male]'
|
89
86
|
assert_select 'input[type=radio][value=female]'
|
90
87
|
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
@@ -97,7 +94,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
97
94
|
store_translations(:en, simple_form: { options: { user: {
|
98
95
|
gender: { male_html: '<strong>Male</strong>', female_html: '<strong>Female</strong>' }
|
99
96
|
} } } ) do
|
100
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
97
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
101
98
|
assert_select 'input[type=radio][value=male]'
|
102
99
|
assert_select 'input[type=radio][value=female]'
|
103
100
|
assert_select 'label[for=user_gender_male] strong', 'Male'
|
@@ -111,7 +108,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
111
108
|
store_translations(:en, simple_form: { options: { user: {
|
112
109
|
gender: { male_html: 'Male', female_html: 'Female' }
|
113
110
|
} } } ) do
|
114
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
111
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
115
112
|
assert_select 'input[type=radio][value=male]'
|
116
113
|
assert_select 'input[type=radio][value=female]'
|
117
114
|
assert_select 'label[for=user_gender_male]', 'Male'
|
@@ -122,7 +119,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
122
119
|
|
123
120
|
test 'input marks the current radio value by default' do
|
124
121
|
@user.name = "Carlos"
|
125
|
-
with_input_for @user, :name, :radio_buttons, collection: [
|
122
|
+
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
126
123
|
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
127
124
|
end
|
128
125
|
|
@@ -132,7 +129,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
132
129
|
end
|
133
130
|
|
134
131
|
test 'input allows using a collection with text/value arrays' do
|
135
|
-
with_input_for @user, :name, :radio_buttons, collection: [[
|
132
|
+
with_input_for @user, :name, :radio_buttons, collection: [%w[Jose jose], %w[Carlos carlos]]
|
136
133
|
assert_select 'input[type=radio][value=jose]'
|
137
134
|
assert_select 'input[type=radio][value=carlos]'
|
138
135
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
@@ -140,14 +137,14 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
140
137
|
end
|
141
138
|
|
142
139
|
test 'input allows using a collection with a Proc' do
|
143
|
-
with_input_for @user, :name, :radio_buttons, collection:
|
140
|
+
with_input_for @user, :name, :radio_buttons, collection: proc { %w[Jose Carlos] }
|
144
141
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
145
142
|
assert_select 'label.collection_radio_buttons', 'Carlos'
|
146
143
|
end
|
147
144
|
|
148
145
|
test 'input allows overriding only label method for collections' do
|
149
146
|
with_input_for @user, :name, :radio_buttons,
|
150
|
-
collection: [
|
147
|
+
collection: %w[Jose Carlos],
|
151
148
|
label_method: :upcase
|
152
149
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
153
150
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
@@ -155,7 +152,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
155
152
|
|
156
153
|
test 'input allows overriding only value method for collections' do
|
157
154
|
with_input_for @user, :name, :radio_buttons,
|
158
|
-
collection: [
|
155
|
+
collection: %w[Jose Carlos],
|
159
156
|
value_method: :upcase
|
160
157
|
assert_select 'input[type=radio][value=JOSE]'
|
161
158
|
assert_select 'input[type=radio][value=CARLOS]'
|
@@ -163,7 +160,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
163
160
|
|
164
161
|
test 'input allows overriding label and value method for collections' do
|
165
162
|
with_input_for @user, :name, :radio_buttons,
|
166
|
-
collection: [
|
163
|
+
collection: %w[Jose Carlos],
|
167
164
|
label_method: :upcase,
|
168
165
|
value_method: :downcase
|
169
166
|
assert_select 'input[type=radio][value=jose]'
|
@@ -174,9 +171,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
174
171
|
|
175
172
|
test 'input allows overriding label and value method using a lambda for collections' do
|
176
173
|
with_input_for @user, :name, :radio_buttons,
|
177
|
-
collection: [
|
178
|
-
label_method:
|
179
|
-
value_method:
|
174
|
+
collection: %w[Jose Carlos],
|
175
|
+
label_method: ->(i) { i.upcase },
|
176
|
+
value_method: ->(i) { i.downcase }
|
180
177
|
assert_select 'input[type=radio][value=jose]'
|
181
178
|
assert_select 'input[type=radio][value=carlos]'
|
182
179
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
@@ -184,13 +181,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
184
181
|
end
|
185
182
|
|
186
183
|
test 'collection input with radio type generates required html attribute' do
|
187
|
-
with_input_for @user, :name, :radio_buttons, collection: [
|
184
|
+
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
188
185
|
assert_select 'input[type=radio].required'
|
189
186
|
assert_select 'input[type=radio][required]'
|
190
187
|
end
|
191
188
|
|
192
189
|
test 'collection input with radio type generates aria-required html attribute' do
|
193
|
-
with_input_for @user, :name, :radio_buttons, collection: [
|
190
|
+
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
194
191
|
assert_select 'input[type=radio].required'
|
195
192
|
assert_select 'input[type=radio][aria-required=true]'
|
196
193
|
end
|
@@ -387,7 +384,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
387
384
|
|
388
385
|
test 'input radio wrapper class are not included when set to falsey' do
|
389
386
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
390
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
387
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
391
388
|
|
392
389
|
assert_no_select 'label.radio'
|
393
390
|
end
|
@@ -395,7 +392,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
395
392
|
|
396
393
|
test 'input radio custom wrapper class is included when include input wrapper class is falsey' do
|
397
394
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
398
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
395
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female], item_wrapper_class: 'custom'
|
399
396
|
|
400
397
|
assert_no_select 'label.radio'
|
401
398
|
assert_select 'span.custom'
|
@@ -405,7 +402,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
405
402
|
test 'input radio with nested style and namespace uses the right for attribute' do
|
406
403
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
407
404
|
with_concat_form_for @user, namespace: :foo do |f|
|
408
|
-
concat f.input :gender, as: :radio_buttons, collection: [
|
405
|
+
concat f.input :gender, as: :radio_buttons, collection: %i[male female]
|
409
406
|
end
|
410
407
|
|
411
408
|
assert_select 'label[for=foo_user_gender_male]'
|
@@ -416,11 +413,34 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
416
413
|
test 'input radio with nested style and index uses the right for attribute' do
|
417
414
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
418
415
|
with_concat_form_for @user, index: 1 do |f|
|
419
|
-
concat f.input :gender, as: :radio_buttons, collection: [
|
416
|
+
concat f.input :gender, as: :radio_buttons, collection: %i[male female]
|
420
417
|
end
|
421
418
|
|
422
419
|
assert_select 'label[for=user_1_gender_male]'
|
423
420
|
assert_select 'label[for=user_1_gender_female]'
|
424
421
|
end
|
425
422
|
end
|
423
|
+
|
424
|
+
test 'input radio with nested style accetps non-string attribute as label' do
|
425
|
+
swap SimpleForm, boolean_style: :nested do
|
426
|
+
with_input_for @user, :amount,
|
427
|
+
:radio_buttons,
|
428
|
+
collection: { 100 => 'hundred', 200 => 'two_hundred' },
|
429
|
+
label_method: :first,
|
430
|
+
value_method: :second
|
431
|
+
|
432
|
+
assert_select 'input[type=radio][value=hundred]'
|
433
|
+
assert_select 'input[type=radio][value=two_hundred]'
|
434
|
+
assert_select 'span.radio > label', '100'
|
435
|
+
assert_select 'span.radio > label', '200'
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
test 'input check boxes with inline style support label custom classes' do
|
440
|
+
swap SimpleForm, boolean_style: :inline do
|
441
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female], item_label_class: 'beautiful-label'
|
442
|
+
|
443
|
+
assert_select 'label.beautiful-label', count: 2
|
444
|
+
end
|
445
|
+
end
|
426
446
|
end
|