simple_form 3.5.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +38 -28
- data/lib/generators/simple_form/install_generator.rb +1 -0
- data/lib/generators/simple_form/templates/_form.html.erb +1 -0
- data/lib/generators/simple_form/templates/_form.html.haml +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +2 -1
- data/lib/simple_form.rb +8 -6
- 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.rb +1 -0
- data/lib/simple_form/components/errors.rb +2 -1
- 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 +2 -1
- data/lib/simple_form/components/maxlength.rb +1 -0
- data/lib/simple_form/components/min_max.rb +1 -0
- data/lib/simple_form/components/minlength.rb +2 -1
- data/lib/simple_form/components/pattern.rb +1 -0
- data/lib/simple_form/components/placeholders.rb +1 -0
- data/lib/simple_form/components/readonly.rb +1 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +9 -3
- data/lib/simple_form/helpers.rb +1 -0
- 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/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/inputs/base.rb +2 -1
- data/lib/simple_form/inputs/block_input.rb +1 -0
- data/lib/simple_form/inputs/boolean_input.rb +3 -2
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +3 -2
- 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/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 -0
- data/lib/simple_form/inputs/range_input.rb +1 -0
- data/lib/simple_form/inputs/string_input.rb +1 -0
- data/lib/simple_form/inputs/text_input.rb +1 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +1 -0
- data/lib/simple_form/tags.rb +1 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers.rb +1 -0
- 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 +1 -0
- data/lib/simple_form/wrappers/single.rb +2 -1
- data/test/action_view_extensions/builder_test.rb +6 -5
- data/test/action_view_extensions/form_helper_test.rb +3 -2
- data/test/components/label_test.rb +5 -4
- data/test/form_builder/association_test.rb +27 -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 +6 -0
- data/test/form_builder/general_test.rb +10 -3
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +2 -1
- data/test/form_builder/label_test.rb +9 -3
- data/test/form_builder/wrapper_test.rb +3 -2
- data/test/generators/simple_form_generator_test.rb +4 -3
- data/test/inputs/boolean_input_test.rb +9 -0
- data/test/inputs/collection_check_boxes_input_test.rb +30 -14
- data/test/inputs/collection_radio_buttons_input_test.rb +40 -24
- data/test/inputs/collection_select_input_test.rb +40 -39
- data/test/inputs/datetime_input_test.rb +5 -4
- data/test/inputs/disabled_test.rb +1 -0
- data/test/inputs/discovery_test.rb +1 -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 +1 -0
- data/test/inputs/readonly_test.rb +1 -0
- data/test/inputs/required_test.rb +1 -0
- data/test/inputs/string_input_test.rb +2 -1
- data/test/inputs/text_input_test.rb +1 -0
- data/test/simple_form_test.rb +1 -0
- data/test/support/discovery_inputs.rb +1 -0
- data/test/support/misc_helpers.rb +2 -1
- data/test/support/mock_controller.rb +4 -0
- data/test/support/models.rb +36 -12
- data/test/test_helper.rb +2 -0
- metadata +3 -3
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
# Tests for f.hint
|
@@ -18,6 +19,11 @@ class HintTest < ActionView::TestCase
|
|
18
19
|
assert_select 'span.hint', 'Use with care...'
|
19
20
|
end
|
20
21
|
|
22
|
+
test 'hint is generated with decorated object responsive to #to_model' do
|
23
|
+
with_hint_for @decorated_user, :name, hint: 'Use with care...'
|
24
|
+
assert_select 'span.hint', 'Use with care...'
|
25
|
+
end
|
26
|
+
|
21
27
|
test 'hint does not modify the options hash' do
|
22
28
|
options = { hint: 'Use with care...' }
|
23
29
|
with_hint_for @user, :name, options
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
# Tests for f.input_field
|
@@ -112,7 +113,7 @@ class InputFieldTest < ActionView::TestCase
|
|
112
113
|
end
|
113
114
|
|
114
115
|
test 'builder collection input_field generates input tag with a clean HTML' do
|
115
|
-
with_input_field_for @user, :status, collection: [
|
116
|
+
with_input_field_for @user, :status, collection: %w[Open Closed],
|
116
117
|
class: 'status', label_method: :to_s, value_method: :to_s
|
117
118
|
|
118
119
|
assert_no_select 'select.status[input_html]'
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -13,6 +14,11 @@ class LabelTest < ActionView::TestCase
|
|
13
14
|
assert_select 'label.string[for=user_name]', /Name/
|
14
15
|
end
|
15
16
|
|
17
|
+
test 'builder generates a label for the attribute with decorated object responsive to #to_model' do
|
18
|
+
with_label_for @decorated_user, :name
|
19
|
+
assert_select 'label.string[for=user_name]', /Name/
|
20
|
+
end
|
21
|
+
|
16
22
|
test 'builder generates a label for the boolean attrbiute' do
|
17
23
|
with_label_for @user, :name, as: :boolean
|
18
24
|
assert_select 'label.boolean[for=user_name]', /Name/
|
@@ -108,21 +114,21 @@ class LabelTest < ActionView::TestCase
|
|
108
114
|
end
|
109
115
|
|
110
116
|
test 'builder allows custom formatting when label is explicitly specified' do
|
111
|
-
swap SimpleForm, label_text:
|
117
|
+
swap SimpleForm, label_text: ->(l, r, explicit_label) { explicit_label ? l : "#{l.titleize}:" } do
|
112
118
|
with_label_for @user, :time_zone, 'What is your home time zone?'
|
113
119
|
assert_select 'label[for=user_time_zone]', 'What is your home time zone?'
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
117
123
|
test 'builder allows custom formatting when label is generated' do
|
118
|
-
swap SimpleForm, label_text:
|
124
|
+
swap SimpleForm, label_text: ->(l, r, explicit_label) { explicit_label ? l : "#{l.titleize}:" } do
|
119
125
|
with_label_for @user, :time_zone
|
120
126
|
assert_select 'label[for=user_time_zone]', 'Time Zone:'
|
121
127
|
end
|
122
128
|
end
|
123
129
|
|
124
130
|
test 'builder allows label specific `label_text` option' do
|
125
|
-
with_label_for @user, :time_zone, label_text:
|
131
|
+
with_label_for @user, :time_zone, label_text: ->(l, _, _) { "#{l.titleize}:" }
|
126
132
|
|
127
133
|
assert_no_select 'label[label_text]'
|
128
134
|
assert_select 'label[for=user_time_zone]', 'Time Zone:'
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class WrapperTest < ActionView::TestCase
|
@@ -88,7 +89,7 @@ class WrapperTest < ActionView::TestCase
|
|
88
89
|
end
|
89
90
|
|
90
91
|
test 'wrapper skips additional classes when configured' do
|
91
|
-
swap SimpleForm, generate_additional_classes_for: [
|
92
|
+
swap SimpleForm, generate_additional_classes_for: %i[input label] do
|
92
93
|
with_form_for @user, :name, wrapper_class: :wrapper
|
93
94
|
assert_select 'form div.wrapper'
|
94
95
|
assert_no_select 'div.required'
|
@@ -98,7 +99,7 @@ class WrapperTest < ActionView::TestCase
|
|
98
99
|
end
|
99
100
|
|
100
101
|
test 'wrapper does not generate empty css class' do
|
101
|
-
swap SimpleForm, generate_additional_classes_for: [
|
102
|
+
swap SimpleForm, generate_additional_classes_for: %i[input label] do
|
102
103
|
swap_wrapper :default, custom_wrapper_without_class do
|
103
104
|
with_form_for @user, :name
|
104
105
|
assert_no_select 'div#custom_wrapper_without_class[class]'
|
@@ -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
|
|
@@ -145,6 +146,14 @@ class BooleanInputTest < ActionView::TestCase
|
|
145
146
|
end
|
146
147
|
end
|
147
148
|
|
149
|
+
test 'input with nested style does not include hidden field when unchecked_value is false' do
|
150
|
+
swap SimpleForm, boolean_style: :nested do
|
151
|
+
with_input_for @user, :active, :boolean, unchecked_value: false
|
152
|
+
assert_select "label.boolean > input.boolean"
|
153
|
+
assert_no_select "input[type=hidden] + label.boolean"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
148
157
|
test 'input boolean works using :input only in wrapper config (no label_input)' do
|
149
158
|
swap_wrapper do
|
150
159
|
with_input_for @user, :active, :boolean
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -7,33 +8,33 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
7
8
|
end
|
8
9
|
|
9
10
|
test 'input check boxes does not include for attribute by default' do
|
10
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
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
16
|
test 'input check boxes includes for attribute when giving as html option' do
|
16
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
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
21
|
test 'collection input with check_boxes type does not generate required html attribute' do
|
21
|
-
with_input_for @user, :name, :check_boxes, collection: [
|
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
27
|
test 'collection input with check_boxes type does not generate aria-required html attribute' do
|
27
|
-
with_input_for @user, :name, :check_boxes, collection: [
|
28
|
+
with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
|
28
29
|
assert_select 'input.required'
|
29
30
|
assert_no_select 'input[aria-required]'
|
30
31
|
end
|
31
32
|
|
32
33
|
test 'input does automatic collection translation for check_box types using defaults key' do
|
33
34
|
store_translations(:en, simple_form: { options: { defaults: {
|
34
|
-
gender: { male: 'Male', female: 'Female'}
|
35
|
+
gender: { male: 'Male', female: 'Female' }
|
35
36
|
} } } ) do
|
36
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
37
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
37
38
|
assert_select 'input[type=checkbox][value=male]'
|
38
39
|
assert_select 'input[type=checkbox][value=female]'
|
39
40
|
assert_select 'label.collection_check_boxes', 'Male'
|
@@ -43,9 +44,9 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
43
44
|
|
44
45
|
test 'input does automatic collection translation for check_box types using specific object key' do
|
45
46
|
store_translations(:en, simple_form: { options: { user: {
|
46
|
-
gender: { male: 'Male', female: 'Female'}
|
47
|
+
gender: { male: 'Male', female: 'Female' }
|
47
48
|
} } } ) do
|
48
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
49
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
49
50
|
assert_select 'input[type=checkbox][value=male]'
|
50
51
|
assert_select 'input[type=checkbox][value=female]'
|
51
52
|
assert_select 'label.collection_check_boxes', 'Male'
|
@@ -55,11 +56,11 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
55
56
|
|
56
57
|
test 'input that uses automatic collection translation for check_boxes properly sets checked values' do
|
57
58
|
store_translations(:en, simple_form: { options: { defaults: {
|
58
|
-
gender: { male: 'Male', female: 'Female'}
|
59
|
+
gender: { male: 'Male', female: 'Female' }
|
59
60
|
} } } ) do
|
60
61
|
@user.gender = 'male'
|
61
62
|
|
62
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
63
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
63
64
|
assert_select 'input[type=checkbox][value=male][checked=checked]'
|
64
65
|
assert_select 'input[type=checkbox][value=female]'
|
65
66
|
assert_select 'label.collection_check_boxes', 'Male'
|
@@ -264,7 +265,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
264
265
|
|
265
266
|
test 'input check boxes wrapper class are not included when set to falsey' do
|
266
267
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
267
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
268
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
268
269
|
|
269
270
|
assert_no_select 'label.checkbox'
|
270
271
|
end
|
@@ -272,7 +273,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
272
273
|
|
273
274
|
test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
|
274
275
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
275
|
-
with_input_for @user, :gender, :check_boxes, collection: [
|
276
|
+
with_input_for @user, :gender, :check_boxes, collection: %i[male female], item_wrapper_class: 'custom'
|
276
277
|
|
277
278
|
assert_no_select 'label.checkbox'
|
278
279
|
assert_select 'span.custom'
|
@@ -282,7 +283,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
282
283
|
test 'input check boxes with nested style and namespace uses the right for attribute' do
|
283
284
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
284
285
|
with_concat_form_for @user, namespace: :foo do |f|
|
285
|
-
concat f.input :gender, as: :check_boxes, collection: [
|
286
|
+
concat f.input :gender, as: :check_boxes, collection: %i[male female]
|
286
287
|
end
|
287
288
|
|
288
289
|
assert_select 'label[for=foo_user_gender_male]'
|
@@ -293,11 +294,26 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
293
294
|
test 'input check boxes with nested style and index uses the right for attribute' do
|
294
295
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
295
296
|
with_concat_form_for @user, index: 1 do |f|
|
296
|
-
concat f.input :gender, as: :check_boxes, collection: [
|
297
|
+
concat f.input :gender, as: :check_boxes, collection: %i[male female]
|
297
298
|
end
|
298
299
|
|
299
300
|
assert_select 'label[for=user_1_gender_male]'
|
300
301
|
assert_select 'label[for=user_1_gender_female]'
|
301
302
|
end
|
302
303
|
end
|
304
|
+
|
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'
|
317
|
+
end
|
318
|
+
end
|
303
319
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -43,13 +44,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
43
44
|
end
|
44
45
|
|
45
46
|
test 'input radio does not include for attribute by default' do
|
46
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
47
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
47
48
|
assert_select 'label'
|
48
49
|
assert_no_select 'label[for=user_gender]'
|
49
50
|
end
|
50
51
|
|
51
52
|
test 'input radio includes for attribute when giving as html option' do
|
52
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
53
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female], label_html: { for: 'gender' }
|
53
54
|
assert_select 'label[for=gender]'
|
54
55
|
end
|
55
56
|
|
@@ -61,7 +62,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
61
62
|
end
|
62
63
|
|
63
64
|
test 'input allows overriding collection for radio types' do
|
64
|
-
with_input_for @user, :name, :radio_buttons, collection: [
|
65
|
+
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
65
66
|
assert_select 'input[type=radio][value=Jose]'
|
66
67
|
assert_select 'input[type=radio][value=Carlos]'
|
67
68
|
assert_select 'label.collection_radio_buttons[for=user_name_jose]', 'Jose'
|
@@ -70,9 +71,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
70
71
|
|
71
72
|
test 'input does automatic collection translation for radio types using defaults key' do
|
72
73
|
store_translations(:en, simple_form: { options: { defaults: {
|
73
|
-
gender: { male: 'Male', female: 'Female'}
|
74
|
+
gender: { male: 'Male', female: 'Female' }
|
74
75
|
} } } ) do
|
75
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
76
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
76
77
|
assert_select 'input[type=radio][value=male]'
|
77
78
|
assert_select 'input[type=radio][value=female]'
|
78
79
|
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
@@ -82,9 +83,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
82
83
|
|
83
84
|
test 'input does automatic collection translation for radio types using specific object key' do
|
84
85
|
store_translations(:en, simple_form: { options: { user: {
|
85
|
-
gender: { male: 'Male', female: 'Female'}
|
86
|
+
gender: { male: 'Male', female: 'Female' }
|
86
87
|
} } } ) do
|
87
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
88
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
88
89
|
assert_select 'input[type=radio][value=male]'
|
89
90
|
assert_select 'input[type=radio][value=female]'
|
90
91
|
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
@@ -97,7 +98,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
97
98
|
store_translations(:en, simple_form: { options: { user: {
|
98
99
|
gender: { male_html: '<strong>Male</strong>', female_html: '<strong>Female</strong>' }
|
99
100
|
} } } ) do
|
100
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
101
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
101
102
|
assert_select 'input[type=radio][value=male]'
|
102
103
|
assert_select 'input[type=radio][value=female]'
|
103
104
|
assert_select 'label[for=user_gender_male] strong', 'Male'
|
@@ -111,7 +112,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
111
112
|
store_translations(:en, simple_form: { options: { user: {
|
112
113
|
gender: { male_html: 'Male', female_html: 'Female' }
|
113
114
|
} } } ) do
|
114
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
115
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
115
116
|
assert_select 'input[type=radio][value=male]'
|
116
117
|
assert_select 'input[type=radio][value=female]'
|
117
118
|
assert_select 'label[for=user_gender_male]', 'Male'
|
@@ -122,7 +123,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
122
123
|
|
123
124
|
test 'input marks the current radio value by default' do
|
124
125
|
@user.name = "Carlos"
|
125
|
-
with_input_for @user, :name, :radio_buttons, collection: [
|
126
|
+
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
126
127
|
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
127
128
|
end
|
128
129
|
|
@@ -132,7 +133,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
132
133
|
end
|
133
134
|
|
134
135
|
test 'input allows using a collection with text/value arrays' do
|
135
|
-
with_input_for @user, :name, :radio_buttons, collection: [[
|
136
|
+
with_input_for @user, :name, :radio_buttons, collection: [%w[Jose jose], %w[Carlos carlos]]
|
136
137
|
assert_select 'input[type=radio][value=jose]'
|
137
138
|
assert_select 'input[type=radio][value=carlos]'
|
138
139
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
@@ -140,14 +141,14 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
140
141
|
end
|
141
142
|
|
142
143
|
test 'input allows using a collection with a Proc' do
|
143
|
-
with_input_for @user, :name, :radio_buttons, collection:
|
144
|
+
with_input_for @user, :name, :radio_buttons, collection: proc { %w[Jose Carlos] }
|
144
145
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
145
146
|
assert_select 'label.collection_radio_buttons', 'Carlos'
|
146
147
|
end
|
147
148
|
|
148
149
|
test 'input allows overriding only label method for collections' do
|
149
150
|
with_input_for @user, :name, :radio_buttons,
|
150
|
-
collection: [
|
151
|
+
collection: %w[Jose Carlos],
|
151
152
|
label_method: :upcase
|
152
153
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
153
154
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
@@ -155,7 +156,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
155
156
|
|
156
157
|
test 'input allows overriding only value method for collections' do
|
157
158
|
with_input_for @user, :name, :radio_buttons,
|
158
|
-
collection: [
|
159
|
+
collection: %w[Jose Carlos],
|
159
160
|
value_method: :upcase
|
160
161
|
assert_select 'input[type=radio][value=JOSE]'
|
161
162
|
assert_select 'input[type=radio][value=CARLOS]'
|
@@ -163,7 +164,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
163
164
|
|
164
165
|
test 'input allows overriding label and value method for collections' do
|
165
166
|
with_input_for @user, :name, :radio_buttons,
|
166
|
-
collection: [
|
167
|
+
collection: %w[Jose Carlos],
|
167
168
|
label_method: :upcase,
|
168
169
|
value_method: :downcase
|
169
170
|
assert_select 'input[type=radio][value=jose]'
|
@@ -174,9 +175,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
174
175
|
|
175
176
|
test 'input allows overriding label and value method using a lambda for collections' do
|
176
177
|
with_input_for @user, :name, :radio_buttons,
|
177
|
-
collection: [
|
178
|
-
label_method:
|
179
|
-
value_method:
|
178
|
+
collection: %w[Jose Carlos],
|
179
|
+
label_method: ->(i) { i.upcase },
|
180
|
+
value_method: ->(i) { i.downcase }
|
180
181
|
assert_select 'input[type=radio][value=jose]'
|
181
182
|
assert_select 'input[type=radio][value=carlos]'
|
182
183
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
@@ -184,13 +185,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
184
185
|
end
|
185
186
|
|
186
187
|
test 'collection input with radio type generates required html attribute' do
|
187
|
-
with_input_for @user, :name, :radio_buttons, collection: [
|
188
|
+
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
188
189
|
assert_select 'input[type=radio].required'
|
189
190
|
assert_select 'input[type=radio][required]'
|
190
191
|
end
|
191
192
|
|
192
193
|
test 'collection input with radio type generates aria-required html attribute' do
|
193
|
-
with_input_for @user, :name, :radio_buttons, collection: [
|
194
|
+
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
194
195
|
assert_select 'input[type=radio].required'
|
195
196
|
assert_select 'input[type=radio][aria-required=true]'
|
196
197
|
end
|
@@ -387,7 +388,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
387
388
|
|
388
389
|
test 'input radio wrapper class are not included when set to falsey' do
|
389
390
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
390
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
391
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
391
392
|
|
392
393
|
assert_no_select 'label.radio'
|
393
394
|
end
|
@@ -395,7 +396,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
395
396
|
|
396
397
|
test 'input radio custom wrapper class is included when include input wrapper class is falsey' do
|
397
398
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
398
|
-
with_input_for @user, :gender, :radio_buttons, collection: [
|
399
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female], item_wrapper_class: 'custom'
|
399
400
|
|
400
401
|
assert_no_select 'label.radio'
|
401
402
|
assert_select 'span.custom'
|
@@ -405,7 +406,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
405
406
|
test 'input radio with nested style and namespace uses the right for attribute' do
|
406
407
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
407
408
|
with_concat_form_for @user, namespace: :foo do |f|
|
408
|
-
concat f.input :gender, as: :radio_buttons, collection: [
|
409
|
+
concat f.input :gender, as: :radio_buttons, collection: %i[male female]
|
409
410
|
end
|
410
411
|
|
411
412
|
assert_select 'label[for=foo_user_gender_male]'
|
@@ -416,11 +417,26 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
416
417
|
test 'input radio with nested style and index uses the right for attribute' do
|
417
418
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
418
419
|
with_concat_form_for @user, index: 1 do |f|
|
419
|
-
concat f.input :gender, as: :radio_buttons, collection: [
|
420
|
+
concat f.input :gender, as: :radio_buttons, collection: %i[male female]
|
420
421
|
end
|
421
422
|
|
422
423
|
assert_select 'label[for=user_1_gender_male]'
|
423
424
|
assert_select 'label[for=user_1_gender_female]'
|
424
425
|
end
|
425
426
|
end
|
427
|
+
|
428
|
+
test 'input radio with nested style accetps non-string attribute as label' do
|
429
|
+
swap SimpleForm, boolean_style: :nested do
|
430
|
+
with_input_for @user, :amount,
|
431
|
+
:radio_buttons,
|
432
|
+
collection: { 100 => 'hundred', 200 => 'two_hundred' },
|
433
|
+
label_method: :first,
|
434
|
+
value_method: :second
|
435
|
+
|
436
|
+
assert_select 'input[type=radio][value=hundred]'
|
437
|
+
assert_select 'input[type=radio][value=two_hundred]'
|
438
|
+
assert_select 'span.radio > label', '100'
|
439
|
+
assert_select 'span.radio > label', '200'
|
440
|
+
end
|
441
|
+
end
|
426
442
|
end
|