simple_form 2.1.0 → 3.0.0.rc
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 +7 -0
- data/CHANGELOG.md +15 -32
- data/README.md +103 -71
- data/lib/generators/simple_form/install_generator.rb +3 -3
- data/lib/generators/simple_form/templates/README +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +13 -13
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
- data/lib/simple_form/components/html5.rb +5 -2
- data/lib/simple_form/components/labels.rb +3 -3
- data/lib/simple_form/components/maxlength.rb +1 -8
- data/lib/simple_form/components/pattern.rb +2 -2
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +147 -49
- data/lib/simple_form/helpers.rb +1 -1
- data/lib/simple_form/inputs/base.rb +2 -6
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +5 -4
- data/lib/simple_form/inputs/collection_input.rb +6 -6
- data/lib/simple_form/inputs/numeric_input.rb +0 -6
- data/lib/simple_form/inputs/password_input.rb +0 -1
- data/lib/simple_form/inputs/string_input.rb +0 -1
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +61 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +5 -29
- data/lib/simple_form/wrappers/many.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -1
- data/lib/simple_form.rb +39 -47
- data/test/action_view_extensions/builder_test.rb +75 -88
- data/test/action_view_extensions/form_helper_test.rb +25 -16
- data/test/components/label_test.rb +46 -46
- data/test/form_builder/association_test.rb +39 -29
- data/test/form_builder/button_test.rb +4 -4
- data/test/form_builder/error_notification_test.rb +8 -8
- data/test/form_builder/error_test.rb +12 -12
- data/test/form_builder/general_test.rb +58 -52
- data/test/form_builder/hint_test.rb +22 -22
- data/test/form_builder/input_field_test.rb +12 -12
- data/test/form_builder/label_test.rb +6 -6
- data/test/form_builder/wrapper_test.rb +21 -21
- data/test/inputs/boolean_input_test.rb +23 -23
- data/test/inputs/collection_check_boxes_input_test.rb +61 -55
- data/test/inputs/collection_radio_buttons_input_test.rb +76 -79
- data/test/inputs/collection_select_input_test.rb +70 -45
- data/test/inputs/datetime_input_test.rb +17 -11
- data/test/inputs/disabled_test.rb +10 -10
- data/test/inputs/discovery_test.rb +4 -4
- data/test/inputs/file_input_test.rb +1 -1
- data/test/inputs/general_test.rb +12 -12
- data/test/inputs/grouped_collection_select_input_test.rb +20 -20
- data/test/inputs/hidden_input_test.rb +3 -2
- data/test/inputs/numeric_input_test.rb +3 -3
- data/test/inputs/priority_input_test.rb +9 -3
- data/test/inputs/readonly_test.rb +12 -12
- data/test/inputs/required_test.rb +5 -5
- data/test/inputs/string_input_test.rb +15 -25
- data/test/inputs/text_input_test.rb +1 -1
- data/test/support/misc_helpers.rb +46 -24
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +62 -61
- data/test/test_helper.rb +20 -24
- metadata +32 -33
- data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
- data/lib/simple_form/core_ext/hash.rb +0 -16
- data/lib/simple_form/form_builder.rb.orig +0 -486
- data/lib/simple_form/version.rb.orig +0 -7
|
@@ -14,7 +14,7 @@ class LabelTest < ActionView::TestCase
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
test 'builder should generate a label for the boolean attrbiute' do
|
|
17
|
-
with_label_for @user, :name, :
|
|
17
|
+
with_label_for @user, :name, as: :boolean
|
|
18
18
|
assert_select 'label.boolean[for=user_name]', /Name/
|
|
19
19
|
assert_no_select 'label[as=boolean]'
|
|
20
20
|
end
|
|
@@ -30,22 +30,22 @@ class LabelTest < ActionView::TestCase
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
test 'builder should allow passing options to label tag' do
|
|
33
|
-
with_label_for @user, :name, :
|
|
33
|
+
with_label_for @user, :name, label: 'My label', id: 'name_label'
|
|
34
34
|
assert_select 'label.string#name_label', /My label/
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
test 'builder label should generate label tag with clean HTML' do
|
|
38
|
-
with_label_for @user, :name, :
|
|
38
|
+
with_label_for @user, :name, label: 'My label', required: true, id: 'name_label'
|
|
39
39
|
assert_select 'label.string#name_label', /My label/
|
|
40
40
|
assert_no_select 'label[label]'
|
|
41
41
|
assert_no_select 'label[required]'
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
test 'builder should not modify the options hash' do
|
|
45
|
-
options = { :
|
|
45
|
+
options = { label: 'My label', id: 'name_label' }
|
|
46
46
|
with_label_for @user, :name, options
|
|
47
47
|
assert_select 'label.string#name_label', /My label/
|
|
48
|
-
assert_equal({ :
|
|
48
|
+
assert_equal({ label: 'My label', id: 'name_label' }, options)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
test 'builder should fallback to default label when string is given' do
|
|
@@ -63,7 +63,7 @@ class LabelTest < ActionView::TestCase
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
test 'builder allows label order to be changed' do
|
|
66
|
-
swap SimpleForm, :
|
|
66
|
+
swap SimpleForm, label_text: lambda { |l, r| "#{l}:" } do
|
|
67
67
|
with_label_for @user, :age
|
|
68
68
|
assert_select 'label.integer[for=user_age]', "Age:"
|
|
69
69
|
end
|
|
@@ -38,7 +38,7 @@ class WrapperTest < ActionView::TestCase
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
test 'wrapper should add hint class for attribute with a hint' do
|
|
41
|
-
with_form_for @user, :name, :
|
|
41
|
+
with_form_for @user, :name, hint: 'hint'
|
|
42
42
|
assert_select 'div.field_with_hint'
|
|
43
43
|
end
|
|
44
44
|
|
|
@@ -48,18 +48,18 @@ class WrapperTest < ActionView::TestCase
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
test 'wrapper should have disabled class when input is disabled' do
|
|
51
|
-
with_form_for @user, :active, :
|
|
51
|
+
with_form_for @user, :active, disabled: true
|
|
52
52
|
assert_select 'div.disabled'
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
test 'wrapper should support no wrapping when wrapper is false' do
|
|
56
|
-
with_form_for @user, :name, :
|
|
56
|
+
with_form_for @user, :name, wrapper: false
|
|
57
57
|
assert_select 'form > label[for=user_name]'
|
|
58
58
|
assert_select 'form > input#user_name.string'
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
test 'wrapper should support no wrapping when wrapper tag is false' do
|
|
62
|
-
with_form_for @user, :name, :
|
|
62
|
+
with_form_for @user, :name, wrapper: custom_wrapper_without_top_level
|
|
63
63
|
assert_select 'form > label[for=user_name]'
|
|
64
64
|
assert_select 'form > input#user_name.string'
|
|
65
65
|
end
|
|
@@ -68,28 +68,28 @@ class WrapperTest < ActionView::TestCase
|
|
|
68
68
|
with_form_for @user, :name
|
|
69
69
|
assert_select 'form div.input.required.string'
|
|
70
70
|
|
|
71
|
-
with_form_for @user, :age, :
|
|
71
|
+
with_form_for @user, :age, required: false
|
|
72
72
|
assert_select 'form div.input.optional.integer'
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
test 'wrapper should allow custom options to be given' do
|
|
76
|
-
with_form_for @user, :name, :
|
|
76
|
+
with_form_for @user, :name, wrapper_html: { id: "super_cool", class: 'yay' }
|
|
77
77
|
assert_select 'form #super_cool.required.string.yay'
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
test 'wrapper should allow tag to be given on demand' do
|
|
81
|
-
with_form_for @user, :name, :
|
|
81
|
+
with_form_for @user, :name, wrapper_tag: :b
|
|
82
82
|
assert_select 'form b.required.string'
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
test 'wrapper should allow wrapper class to be given on demand' do
|
|
86
|
-
with_form_for @user, :name, :
|
|
86
|
+
with_form_for @user, :name, wrapper_class: :wrapper
|
|
87
87
|
assert_select 'form div.wrapper.required.string'
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
test 'wrapper should skip additional classes when configured' do
|
|
91
|
-
swap SimpleForm, :
|
|
92
|
-
with_form_for @user, :name, :
|
|
91
|
+
swap SimpleForm, generate_additional_classes_for: [:input, :label] do
|
|
92
|
+
with_form_for @user, :name, wrapper_class: :wrapper
|
|
93
93
|
assert_select 'form div.wrapper'
|
|
94
94
|
assert_no_select 'div.required'
|
|
95
95
|
assert_no_select 'div.string'
|
|
@@ -98,7 +98,7 @@ class WrapperTest < ActionView::TestCase
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
test 'wrapper should not generate empty css class' do
|
|
101
|
-
swap SimpleForm, :
|
|
101
|
+
swap SimpleForm, generate_additional_classes_for: [:input, :label] do
|
|
102
102
|
swap_wrapper :default, custom_wrapper_without_class do
|
|
103
103
|
with_form_for @user, :name
|
|
104
104
|
assert_no_select 'div#custom_wrapper_without_class[class]'
|
|
@@ -110,7 +110,7 @@ class WrapperTest < ActionView::TestCase
|
|
|
110
110
|
|
|
111
111
|
test 'custom wrappers works' do
|
|
112
112
|
swap_wrapper do
|
|
113
|
-
with_form_for @user, :name, :
|
|
113
|
+
with_form_for @user, :name, hint: "cool"
|
|
114
114
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
|
115
115
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
|
116
116
|
assert_no_select "section.custom_wrapper div.another_wrapper span.omg_error"
|
|
@@ -121,7 +121,7 @@ class WrapperTest < ActionView::TestCase
|
|
|
121
121
|
|
|
122
122
|
test 'custom wrappers can be turned off' do
|
|
123
123
|
swap_wrapper do
|
|
124
|
-
with_form_for @user, :name, :
|
|
124
|
+
with_form_for @user, :name, another: false
|
|
125
125
|
assert_no_select "section.custom_wrapper div.another_wrapper label"
|
|
126
126
|
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
|
127
127
|
assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
|
|
@@ -137,7 +137,7 @@ class WrapperTest < ActionView::TestCase
|
|
|
137
137
|
assert_no_select "section.custom_wrapper div.another_wrapper label"
|
|
138
138
|
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
|
139
139
|
|
|
140
|
-
with_concat_form_for(@user, :
|
|
140
|
+
with_concat_form_for(@user, wrapper: :another) do |f|
|
|
141
141
|
f.input :name
|
|
142
142
|
end
|
|
143
143
|
|
|
@@ -153,20 +153,20 @@ class WrapperTest < ActionView::TestCase
|
|
|
153
153
|
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
|
154
154
|
output_buffer.replace ""
|
|
155
155
|
|
|
156
|
-
with_form_for @user, :name, :
|
|
156
|
+
with_form_for @user, :name, wrapper: :another
|
|
157
157
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
|
158
158
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
|
159
159
|
output_buffer.replace ""
|
|
160
160
|
end
|
|
161
161
|
|
|
162
|
-
with_form_for @user, :name, :
|
|
162
|
+
with_form_for @user, :name, wrapper: custom_wrapper
|
|
163
163
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
|
164
164
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
test 'access wrappers with indifferent access' do
|
|
168
168
|
swap_wrapper :another do
|
|
169
|
-
with_form_for @user, :name, :
|
|
169
|
+
with_form_for @user, :name, wrapper: "another"
|
|
170
170
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
|
171
171
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
|
172
172
|
end
|
|
@@ -175,8 +175,8 @@ class WrapperTest < ActionView::TestCase
|
|
|
175
175
|
test 'do not duplicate label classes for different inputs' do
|
|
176
176
|
swap_wrapper :default, self.custom_wrapper_with_label_html_option do
|
|
177
177
|
with_concat_form_for(@user) do |f|
|
|
178
|
-
concat f.input :name, :
|
|
179
|
-
concat f.input :email, :
|
|
178
|
+
concat f.input :name, required: false
|
|
179
|
+
concat f.input :email, as: :email, required: true
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
assert_select "label.string.optional.extra-label-class[for='user_name']"
|
|
@@ -187,13 +187,13 @@ class WrapperTest < ActionView::TestCase
|
|
|
187
187
|
|
|
188
188
|
test 'raise error when wrapper not found' do
|
|
189
189
|
assert_raise SimpleForm::WrapperNotFound do
|
|
190
|
-
with_form_for @user, :name, :
|
|
190
|
+
with_form_for @user, :name, wrapper: :not_found
|
|
191
191
|
end
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
test 'use wrapper for specified in config mapping' do
|
|
195
195
|
swap_wrapper :another do
|
|
196
|
-
swap SimpleForm, :
|
|
196
|
+
swap SimpleForm, wrapper_mappings: { string: :another } do
|
|
197
197
|
with_form_for @user, :name
|
|
198
198
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
|
199
199
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
|
@@ -9,26 +9,26 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
test 'input does not generate the label with the checkbox when label option is false' do
|
|
12
|
-
with_input_for @user, :active, :boolean, :
|
|
12
|
+
with_input_for @user, :active, :boolean, label: false
|
|
13
13
|
assert_select 'input[type=checkbox].boolean#user_active'
|
|
14
14
|
assert_no_select 'label'
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
test 'input uses custom checked value' do
|
|
18
18
|
@user.action = 'on'
|
|
19
|
-
with_input_for @user, :action, :boolean, :
|
|
19
|
+
with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
|
|
20
20
|
assert_select 'input[type=checkbox][value=on][checked=checked]'
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
test 'input uses custom unchecked value' do
|
|
24
24
|
@user.action = 'off'
|
|
25
|
-
with_input_for @user, :action, :boolean, :
|
|
25
|
+
with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
|
|
26
26
|
assert_select 'input[type=checkbox][value=on]'
|
|
27
27
|
assert_no_select 'input[checked=checked][value=on]'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
test 'input generates hidden input with custom unchecked value' do
|
|
31
|
-
with_input_for @user, :action, :boolean, :
|
|
31
|
+
with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
|
|
32
32
|
assert_select 'input[type=hidden][value=off]'
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -39,7 +39,7 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
test 'input allows changing default boolean style config to nested, generating a default label and a manual hidden field for checkbox' do
|
|
42
|
-
swap SimpleForm, :
|
|
42
|
+
swap SimpleForm, boolean_style: :nested do
|
|
43
43
|
with_input_for @user, :active, :boolean
|
|
44
44
|
assert_select 'label[for=user_active]', 'Active'
|
|
45
45
|
assert_select 'label.boolean > input.boolean'
|
|
@@ -48,21 +48,21 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
test 'input boolean with nested allows :inline_label' do
|
|
51
|
-
swap SimpleForm, :
|
|
52
|
-
with_input_for @user, :active, :boolean, :
|
|
53
|
-
assert_select 'label.checkbox', :
|
|
51
|
+
swap SimpleForm, boolean_style: :nested do
|
|
52
|
+
with_input_for @user, :active, :boolean, label: false, inline_label: 'I am so inline.'
|
|
53
|
+
assert_select 'label.checkbox', text: 'I am so inline.'
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
test 'input boolean with nested style creates an inline label using the default label text when inline_label option set to true' do
|
|
58
|
-
swap SimpleForm, :
|
|
59
|
-
with_input_for @user, :active, :boolean, :
|
|
60
|
-
assert_select 'label.checkbox', :
|
|
58
|
+
swap SimpleForm, boolean_style: :nested do
|
|
59
|
+
with_input_for @user, :active, :boolean, label: false, inline_label: true
|
|
60
|
+
assert_select 'label.checkbox', text: 'Active'
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
test 'input boolean with nested generates a manual hidden field for checkbox outside the label, to recreate Rails functionality with valid html5' do
|
|
65
|
-
swap SimpleForm, :
|
|
65
|
+
swap SimpleForm, boolean_style: :nested do
|
|
66
66
|
with_input_for @user, :active, :boolean
|
|
67
67
|
|
|
68
68
|
assert_select "input[type=hidden][name='user[active]'] + label.boolean > input.boolean"
|
|
@@ -71,23 +71,23 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
test 'input boolean with nested generates a disabled hidden field for checkbox outside the label, if the field is disabled' do
|
|
74
|
-
swap SimpleForm, :
|
|
75
|
-
with_input_for @user, :active, :boolean, :
|
|
74
|
+
swap SimpleForm, boolean_style: :nested do
|
|
75
|
+
with_input_for @user, :active, :boolean, disabled: true
|
|
76
76
|
|
|
77
77
|
assert_select "input[type=hidden][name='user[active]'][disabled] + label.boolean > input.boolean[disabled]"
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
test 'input accepts changing boolean style to nested through given options' do
|
|
82
|
-
with_input_for @user, :active, :boolean, :
|
|
82
|
+
with_input_for @user, :active, :boolean, boolean_style: :nested
|
|
83
83
|
assert_select 'label[for=user_active]', 'Active'
|
|
84
84
|
assert_select 'label.boolean > input.boolean'
|
|
85
85
|
assert_no_select 'input[type=checkbox] + label'
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
test 'input accepts changing boolean style to inline through given options, when default is nested' do
|
|
89
|
-
swap SimpleForm, :
|
|
90
|
-
with_input_for @user, :active, :boolean, :
|
|
89
|
+
swap SimpleForm, boolean_style: :nested do
|
|
90
|
+
with_input_for @user, :active, :boolean, boolean_style: :inline
|
|
91
91
|
assert_select 'label[for=user_active]', 'Active'
|
|
92
92
|
assert_select 'input.boolean + label.boolean'
|
|
93
93
|
assert_no_select 'label > input'
|
|
@@ -95,16 +95,16 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
test 'input with nested style allows disabling label' do
|
|
98
|
-
swap SimpleForm, :
|
|
99
|
-
with_input_for @user, :active, :boolean, :
|
|
98
|
+
swap SimpleForm, boolean_style: :nested do
|
|
99
|
+
with_input_for @user, :active, :boolean, label: false
|
|
100
100
|
assert_select 'input.boolean'
|
|
101
101
|
assert_no_select 'label.boolean'
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
test 'input with nested style allows customizing input_html' do
|
|
106
|
-
swap SimpleForm, :
|
|
107
|
-
with_input_for @user, :active, :boolean, :
|
|
106
|
+
swap SimpleForm, boolean_style: :nested do
|
|
107
|
+
with_input_for @user, :active, :boolean, input_html: { name: 'active_user' }
|
|
108
108
|
assert_select "input[type=hidden][name=active_user] + label.boolean > input.boolean[name=active_user]"
|
|
109
109
|
end
|
|
110
110
|
end
|
|
@@ -120,7 +120,7 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
120
120
|
|
|
121
121
|
test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra "checkbox" label wrapper' do
|
|
122
122
|
swap_wrapper do
|
|
123
|
-
swap SimpleForm, :
|
|
123
|
+
swap SimpleForm, boolean_style: :nested do
|
|
124
124
|
with_input_for @user, :active, :boolean
|
|
125
125
|
|
|
126
126
|
assert_select 'label.boolean + input[type=hidden] + label.checkbox > input.boolean'
|
|
@@ -130,7 +130,7 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
130
130
|
|
|
131
131
|
test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
|
|
132
132
|
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
|
133
|
-
swap SimpleForm, :
|
|
133
|
+
swap SimpleForm, boolean_style: :nested do
|
|
134
134
|
with_input_for @user, :active, :boolean
|
|
135
135
|
|
|
136
136
|
assert_select 'input[type=hidden] + label.boolean.checkbox > input.boolean'
|
|
@@ -7,27 +7,33 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
test 'input check boxes should not include for attribute by default' do
|
|
10
|
-
with_input_for @user, :gender, :check_boxes, :
|
|
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
15
|
test 'input check boxes should include for attribute when giving as html option' do
|
|
16
|
-
with_input_for @user, :gender, :check_boxes, :
|
|
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
20
|
test 'collection input with check_boxes type should not generate required html attribute' do
|
|
21
|
-
with_input_for @user, :name, :check_boxes, :
|
|
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 should not generate aria-required html attribute' do
|
|
27
|
+
with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
|
|
28
|
+
assert_select 'input.required'
|
|
29
|
+
assert_no_select 'input[aria-required]'
|
|
30
|
+
end
|
|
31
|
+
|
|
26
32
|
test 'input should do automatic collection translation for check_box types using defaults key' do
|
|
27
|
-
store_translations(:en, :
|
|
28
|
-
:
|
|
33
|
+
store_translations(:en, simple_form: { options: { defaults: {
|
|
34
|
+
gender: { male: 'Male', female: 'Female'}
|
|
29
35
|
} } } ) do
|
|
30
|
-
with_input_for @user, :gender, :check_boxes, :
|
|
36
|
+
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
|
31
37
|
assert_select 'input[type=checkbox][value=male]'
|
|
32
38
|
assert_select 'input[type=checkbox][value=female]'
|
|
33
39
|
assert_select 'label.collection_check_boxes', 'Male'
|
|
@@ -36,10 +42,10 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
36
42
|
end
|
|
37
43
|
|
|
38
44
|
test 'input should do automatic collection translation for check_box types using specific object key' do
|
|
39
|
-
store_translations(:en, :
|
|
40
|
-
:
|
|
45
|
+
store_translations(:en, simple_form: { options: { user: {
|
|
46
|
+
gender: { male: 'Male', female: 'Female'}
|
|
41
47
|
} } } ) do
|
|
42
|
-
with_input_for @user, :gender, :check_boxes, :
|
|
48
|
+
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
|
43
49
|
assert_select 'input[type=checkbox][value=male]'
|
|
44
50
|
assert_select 'input[type=checkbox][value=female]'
|
|
45
51
|
assert_select 'label.collection_check_boxes', 'Male'
|
|
@@ -50,100 +56,100 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
50
56
|
test 'input check boxes does not wrap the collection by default' do
|
|
51
57
|
with_input_for @user, :active, :check_boxes
|
|
52
58
|
|
|
53
|
-
assert_select 'form input[type=checkbox]', :
|
|
59
|
+
assert_select 'form input[type=checkbox]', count: 2
|
|
54
60
|
assert_no_select 'form ul'
|
|
55
61
|
end
|
|
56
62
|
|
|
57
63
|
test 'input check boxes wraps the collection in the configured collection wrapper tag' do
|
|
58
|
-
swap SimpleForm, :
|
|
64
|
+
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
59
65
|
with_input_for @user, :active, :check_boxes
|
|
60
66
|
|
|
61
|
-
assert_select 'form ul input[type=checkbox]', :
|
|
67
|
+
assert_select 'form ul input[type=checkbox]', count: 2
|
|
62
68
|
end
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
test 'input check boxes does not wrap the collection when configured with falsy values' do
|
|
66
|
-
swap SimpleForm, :
|
|
72
|
+
swap SimpleForm, collection_wrapper_tag: false do
|
|
67
73
|
with_input_for @user, :active, :check_boxes
|
|
68
74
|
|
|
69
|
-
assert_select 'form input[type=checkbox]', :
|
|
75
|
+
assert_select 'form input[type=checkbox]', count: 2
|
|
70
76
|
assert_no_select 'form ul'
|
|
71
77
|
end
|
|
72
78
|
end
|
|
73
79
|
|
|
74
80
|
test 'input check boxes allows overriding the collection wrapper tag at input level' do
|
|
75
|
-
swap SimpleForm, :
|
|
76
|
-
with_input_for @user, :active, :check_boxes, :
|
|
81
|
+
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
82
|
+
with_input_for @user, :active, :check_boxes, collection_wrapper_tag: :section
|
|
77
83
|
|
|
78
|
-
assert_select 'form section input[type=checkbox]', :
|
|
84
|
+
assert_select 'form section input[type=checkbox]', count: 2
|
|
79
85
|
assert_no_select 'form ul'
|
|
80
86
|
end
|
|
81
87
|
end
|
|
82
88
|
|
|
83
89
|
test 'input check boxes allows disabling the collection wrapper tag at input level' do
|
|
84
|
-
swap SimpleForm, :
|
|
85
|
-
with_input_for @user, :active, :check_boxes, :
|
|
90
|
+
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
91
|
+
with_input_for @user, :active, :check_boxes, collection_wrapper_tag: false
|
|
86
92
|
|
|
87
|
-
assert_select 'form input[type=checkbox]', :
|
|
93
|
+
assert_select 'form input[type=checkbox]', count: 2
|
|
88
94
|
assert_no_select 'form ul'
|
|
89
95
|
end
|
|
90
96
|
end
|
|
91
97
|
|
|
92
98
|
test 'input check boxes renders the wrapper tag with the configured wrapper class' do
|
|
93
|
-
swap SimpleForm, :
|
|
99
|
+
swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
|
|
94
100
|
with_input_for @user, :active, :check_boxes
|
|
95
101
|
|
|
96
|
-
assert_select 'form ul.inputs-list input[type=checkbox]', :
|
|
102
|
+
assert_select 'form ul.inputs-list input[type=checkbox]', count: 2
|
|
97
103
|
end
|
|
98
104
|
end
|
|
99
105
|
|
|
100
106
|
test 'input check boxes allows giving wrapper class at input level only' do
|
|
101
|
-
swap SimpleForm, :
|
|
102
|
-
with_input_for @user, :active, :check_boxes, :
|
|
107
|
+
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
108
|
+
with_input_for @user, :active, :check_boxes, collection_wrapper_class: 'items-list'
|
|
103
109
|
|
|
104
|
-
assert_select 'form ul.items-list input[type=checkbox]', :
|
|
110
|
+
assert_select 'form ul.items-list input[type=checkbox]', count: 2
|
|
105
111
|
end
|
|
106
112
|
end
|
|
107
113
|
|
|
108
114
|
test 'input check boxes uses both configured and given wrapper classes for wrapper tag' do
|
|
109
|
-
swap SimpleForm, :
|
|
110
|
-
with_input_for @user, :active, :check_boxes, :
|
|
115
|
+
swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
|
|
116
|
+
with_input_for @user, :active, :check_boxes, collection_wrapper_class: 'items-list'
|
|
111
117
|
|
|
112
|
-
assert_select 'form ul.inputs-list.items-list input[type=checkbox]', :
|
|
118
|
+
assert_select 'form ul.inputs-list.items-list input[type=checkbox]', count: 2
|
|
113
119
|
end
|
|
114
120
|
end
|
|
115
121
|
|
|
116
122
|
test 'input check boxes wraps each item in the configured item wrapper tag' do
|
|
117
|
-
swap SimpleForm, :
|
|
123
|
+
swap SimpleForm, item_wrapper_tag: :li do
|
|
118
124
|
with_input_for @user, :active, :check_boxes
|
|
119
125
|
|
|
120
|
-
assert_select 'form li input[type=checkbox]', :
|
|
126
|
+
assert_select 'form li input[type=checkbox]', count: 2
|
|
121
127
|
end
|
|
122
128
|
end
|
|
123
129
|
|
|
124
130
|
test 'input check boxes does not wrap items when configured with falsy values' do
|
|
125
|
-
swap SimpleForm, :
|
|
131
|
+
swap SimpleForm, item_wrapper_tag: false do
|
|
126
132
|
with_input_for @user, :active, :check_boxes
|
|
127
133
|
|
|
128
|
-
assert_select 'form input[type=checkbox]', :
|
|
134
|
+
assert_select 'form input[type=checkbox]', count: 2
|
|
129
135
|
assert_no_select 'form li'
|
|
130
136
|
end
|
|
131
137
|
end
|
|
132
138
|
|
|
133
139
|
test 'input check boxes allows overriding the item wrapper tag at input level' do
|
|
134
|
-
swap SimpleForm, :
|
|
135
|
-
with_input_for @user, :active, :check_boxes, :
|
|
140
|
+
swap SimpleForm, item_wrapper_tag: :li do
|
|
141
|
+
with_input_for @user, :active, :check_boxes, item_wrapper_tag: :dl
|
|
136
142
|
|
|
137
|
-
assert_select 'form dl input[type=checkbox]', :
|
|
143
|
+
assert_select 'form dl input[type=checkbox]', count: 2
|
|
138
144
|
assert_no_select 'form li'
|
|
139
145
|
end
|
|
140
146
|
end
|
|
141
147
|
|
|
142
148
|
test 'input check boxes allows disabling the item wrapper tag at input level' do
|
|
143
|
-
swap SimpleForm, :
|
|
144
|
-
with_input_for @user, :active, :check_boxes, :
|
|
149
|
+
swap SimpleForm, item_wrapper_tag: :ul do
|
|
150
|
+
with_input_for @user, :active, :check_boxes, item_wrapper_tag: false
|
|
145
151
|
|
|
146
|
-
assert_select 'form input[type=checkbox]', :
|
|
152
|
+
assert_select 'form input[type=checkbox]', count: 2
|
|
147
153
|
assert_no_select 'form li'
|
|
148
154
|
end
|
|
149
155
|
end
|
|
@@ -151,41 +157,41 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
151
157
|
test 'input check boxes wraps items in a span tag by default' do
|
|
152
158
|
with_input_for @user, :active, :check_boxes
|
|
153
159
|
|
|
154
|
-
assert_select 'form span input[type=checkbox]', :
|
|
160
|
+
assert_select 'form span input[type=checkbox]', count: 2
|
|
155
161
|
end
|
|
156
162
|
|
|
157
163
|
test 'input check boxes renders the item wrapper tag with a default class "checkbox"' do
|
|
158
|
-
with_input_for @user, :active, :check_boxes, :
|
|
164
|
+
with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
|
|
159
165
|
|
|
160
|
-
assert_select 'form li.checkbox input[type=checkbox]', :
|
|
166
|
+
assert_select 'form li.checkbox input[type=checkbox]', count: 2
|
|
161
167
|
end
|
|
162
168
|
|
|
163
169
|
test 'input check boxes renders the item wrapper tag with the configured item wrapper class' do
|
|
164
|
-
swap SimpleForm, :
|
|
170
|
+
swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
|
|
165
171
|
with_input_for @user, :active, :check_boxes
|
|
166
172
|
|
|
167
|
-
assert_select 'form li.checkbox.item input[type=checkbox]', :
|
|
173
|
+
assert_select 'form li.checkbox.item input[type=checkbox]', count: 2
|
|
168
174
|
end
|
|
169
175
|
end
|
|
170
176
|
|
|
171
177
|
test 'input check boxes allows giving item wrapper class at input level only' do
|
|
172
|
-
swap SimpleForm, :
|
|
173
|
-
with_input_for @user, :active, :check_boxes, :
|
|
178
|
+
swap SimpleForm, item_wrapper_tag: :li do
|
|
179
|
+
with_input_for @user, :active, :check_boxes, item_wrapper_class: 'item'
|
|
174
180
|
|
|
175
|
-
assert_select 'form li.checkbox.item input[type=checkbox]', :
|
|
181
|
+
assert_select 'form li.checkbox.item input[type=checkbox]', count: 2
|
|
176
182
|
end
|
|
177
183
|
end
|
|
178
184
|
|
|
179
185
|
test 'input check boxes uses both configured and given item wrapper classes for item wrapper tag' do
|
|
180
|
-
swap SimpleForm, :
|
|
181
|
-
with_input_for @user, :active, :check_boxes, :
|
|
186
|
+
swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
|
|
187
|
+
with_input_for @user, :active, :check_boxes, item_wrapper_class: 'inline'
|
|
182
188
|
|
|
183
|
-
assert_select 'form li.checkbox.item.inline input[type=checkbox]', :
|
|
189
|
+
assert_select 'form li.checkbox.item.inline input[type=checkbox]', count: 2
|
|
184
190
|
end
|
|
185
191
|
end
|
|
186
192
|
|
|
187
193
|
test 'input check boxes respects the nested boolean style config, generating nested label > input' do
|
|
188
|
-
swap SimpleForm, :
|
|
194
|
+
swap SimpleForm, boolean_style: :nested do
|
|
189
195
|
with_input_for @user, :active, :check_boxes
|
|
190
196
|
|
|
191
197
|
assert_select 'label.checkbox > input#user_active_true[type=checkbox]'
|
|
@@ -197,7 +203,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
197
203
|
end
|
|
198
204
|
|
|
199
205
|
test 'input check boxes with nested style overrides configured item wrapper tag, forcing the :label' do
|
|
200
|
-
swap SimpleForm, :
|
|
206
|
+
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
|
|
201
207
|
with_input_for @user, :active, :check_boxes
|
|
202
208
|
|
|
203
209
|
assert_select 'label.checkbox > input'
|
|
@@ -206,8 +212,8 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
206
212
|
end
|
|
207
213
|
|
|
208
214
|
test 'input check boxes with nested style overrides given item wrapper tag, forcing the :label' do
|
|
209
|
-
swap SimpleForm, :
|
|
210
|
-
with_input_for @user, :active, :check_boxes, :
|
|
215
|
+
swap SimpleForm, boolean_style: :nested do
|
|
216
|
+
with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
|
|
211
217
|
|
|
212
218
|
assert_select 'label.checkbox > input'
|
|
213
219
|
assert_no_select 'li'
|
|
@@ -215,8 +221,8 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
|
215
221
|
end
|
|
216
222
|
|
|
217
223
|
test 'input check boxes with nested style accepts giving extra wrapper classes' do
|
|
218
|
-
swap SimpleForm, :
|
|
219
|
-
with_input_for @user, :active, :check_boxes, :
|
|
224
|
+
swap SimpleForm, boolean_style: :nested do
|
|
225
|
+
with_input_for @user, :active, :check_boxes, item_wrapper_class: "inline"
|
|
220
226
|
|
|
221
227
|
assert_select 'label.checkbox.inline > input'
|
|
222
228
|
end
|