simple_form 2.1.0 → 3.2.0
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.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +77 -33
- data/MIT-LICENSE +1 -1
- data/README.md +387 -187
- data/lib/generators/simple_form/install_generator.rb +4 -4
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +45 -22
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +128 -24
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +87 -6
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +2 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +8 -11
- data/lib/simple_form/components/errors.rb +28 -2
- data/lib/simple_form/components/hints.rb +8 -3
- data/lib/simple_form/components/html5.rb +6 -3
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +14 -10
- data/lib/simple_form/components/maxlength.rb +2 -9
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +3 -3
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +262 -107
- data/lib/simple_form/helpers.rb +6 -6
- data/lib/simple_form/inputs/base.rb +37 -16
- data/lib/simple_form/inputs/block_input.rb +2 -2
- data/lib/simple_form/inputs/boolean_input.rb +33 -18
- data/lib/simple_form/inputs/collection_input.rb +34 -13
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +7 -12
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +23 -9
- 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 +3 -8
- data/lib/simple_form/inputs/password_input.rb +4 -3
- 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 -3
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +14 -0
- data/lib/simple_form/tags.rb +68 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +11 -35
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +7 -7
- data/lib/simple_form/wrappers/root.rb +2 -2
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +2 -1
- data/lib/simple_form.rb +99 -52
- data/test/action_view_extensions/builder_test.rb +113 -127
- data/test/action_view_extensions/form_helper_test.rb +58 -30
- data/test/components/label_test.rb +83 -83
- data/test/form_builder/association_test.rb +96 -61
- data/test/form_builder/button_test.rb +14 -14
- data/test/form_builder/error_notification_test.rb +9 -9
- data/test/form_builder/error_test.rb +159 -34
- data/test/form_builder/general_test.rb +176 -121
- data/test/form_builder/hint_test.rb +43 -37
- data/test/form_builder/input_field_test.rb +99 -52
- data/test/form_builder/label_test.rb +67 -15
- data/test/form_builder/wrapper_test.rb +157 -41
- data/test/generators/simple_form_generator_test.rb +4 -4
- data/test/inputs/boolean_input_test.rb +92 -24
- data/test/inputs/collection_check_boxes_input_test.rb +150 -71
- data/test/inputs/collection_radio_buttons_input_test.rb +213 -113
- data/test/inputs/collection_select_input_test.rb +221 -85
- data/test/inputs/datetime_input_test.rb +125 -47
- data/test/inputs/disabled_test.rb +25 -25
- data/test/inputs/discovery_test.rb +60 -10
- data/test/inputs/file_input_test.rb +3 -3
- data/test/inputs/general_test.rb +48 -32
- data/test/inputs/grouped_collection_select_input_test.rb +76 -27
- data/test/inputs/hidden_input_test.rb +6 -5
- data/test/inputs/numeric_input_test.rb +46 -46
- data/test/inputs/priority_input_test.rb +21 -15
- data/test/inputs/readonly_test.rb +31 -31
- data/test/inputs/required_test.rb +30 -18
- data/test/inputs/string_input_test.rb +53 -52
- data/test/inputs/text_input_test.rb +15 -8
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +32 -2
- data/test/support/misc_helpers.rb +130 -29
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +125 -71
- data/test/test_helper.rb +28 -35
- metadata +17 -29
- 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
@@ -6,246 +6,292 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
6
6
|
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
7
7
|
end
|
8
8
|
|
9
|
-
test 'input
|
10
|
-
assert_deprecated "[SIMPLE_FORM] Using `:as => :radio` as " \
|
11
|
-
"input type is deprecated, please change it to `:as => :radio_buttons`." do
|
12
|
-
with_input_for @user, :active, :radio
|
13
|
-
end
|
14
|
-
|
15
|
-
assert_select 'input[type=radio].radio_buttons', :count => 2
|
16
|
-
end
|
17
|
-
|
18
|
-
test 'input should generate boolean radio buttons by default for radio types' do
|
9
|
+
test 'input generates boolean radio buttons by default for radio types' do
|
19
10
|
with_input_for @user, :active, :radio_buttons
|
20
11
|
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
21
12
|
assert_select 'input[type=radio][value=false].radio_buttons#user_active_false'
|
22
13
|
end
|
23
14
|
|
24
|
-
test 'input as radio
|
15
|
+
test 'input as radio generates internal labels by default' do
|
25
16
|
with_input_for @user, :active, :radio_buttons
|
26
17
|
assert_select 'label[for=user_active_true]', 'Yes'
|
27
18
|
assert_select 'label[for=user_active_false]', 'No'
|
28
19
|
end
|
29
20
|
|
30
|
-
test 'input as radio
|
31
|
-
|
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
|
38
|
+
store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do
|
32
39
|
with_input_for @user, :active, :radio_buttons
|
33
40
|
assert_select 'label[for=user_active_true]', 'Sim'
|
34
41
|
assert_select 'label[for=user_active_false]', 'Não'
|
35
42
|
end
|
36
43
|
end
|
37
44
|
|
38
|
-
test 'input radio
|
39
|
-
with_input_for @user, :gender, :radio_buttons, :
|
45
|
+
test 'input radio does not include for attribute by default' do
|
46
|
+
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
40
47
|
assert_select 'label'
|
41
48
|
assert_no_select 'label[for=user_gender]'
|
42
49
|
end
|
43
50
|
|
44
|
-
test 'input radio
|
45
|
-
with_input_for @user, :gender, :radio_buttons, :
|
51
|
+
test 'input radio includes for attribute when giving as html option' do
|
52
|
+
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], label_html: { for: 'gender' }
|
46
53
|
assert_select 'label[for=gender]'
|
47
54
|
end
|
48
55
|
|
49
|
-
test 'input
|
56
|
+
test 'input marks the checked value when using boolean and radios' do
|
50
57
|
@user.active = false
|
51
58
|
with_input_for @user, :active, :radio_buttons
|
52
59
|
assert_no_select 'input[type=radio][value=true][checked]'
|
53
60
|
assert_select 'input[type=radio][value=false][checked]'
|
54
61
|
end
|
55
62
|
|
56
|
-
test 'input
|
57
|
-
with_input_for @user, :name, :radio_buttons, :
|
63
|
+
test 'input allows overriding collection for radio types' do
|
64
|
+
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
58
65
|
assert_select 'input[type=radio][value=Jose]'
|
59
66
|
assert_select 'input[type=radio][value=Carlos]'
|
60
|
-
assert_select 'label.collection_radio_buttons', 'Jose'
|
61
|
-
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'
|
62
69
|
end
|
63
70
|
|
64
|
-
test 'input
|
65
|
-
store_translations(:en, :
|
66
|
-
:
|
71
|
+
test 'input does automatic collection translation for radio types using defaults key' do
|
72
|
+
store_translations(:en, simple_form: { options: { defaults: {
|
73
|
+
gender: { male: 'Male', female: 'Female'}
|
67
74
|
} } } ) do
|
68
|
-
with_input_for @user, :gender, :radio_buttons, :
|
75
|
+
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
69
76
|
assert_select 'input[type=radio][value=male]'
|
70
77
|
assert_select 'input[type=radio][value=female]'
|
71
|
-
assert_select 'label.collection_radio_buttons', 'Male'
|
72
|
-
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'
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
76
|
-
test 'input
|
77
|
-
store_translations(:en, :
|
78
|
-
:
|
83
|
+
test 'input does automatic collection translation for radio types using specific object key' do
|
84
|
+
store_translations(:en, simple_form: { options: { user: {
|
85
|
+
gender: { male: 'Male', female: 'Female'}
|
79
86
|
} } } ) do
|
80
|
-
with_input_for @user, :gender, :radio_buttons, :
|
87
|
+
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
81
88
|
assert_select 'input[type=radio][value=male]'
|
82
89
|
assert_select 'input[type=radio][value=female]'
|
83
|
-
assert_select 'label.collection_radio_buttons', 'Male'
|
84
|
-
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] strong', 'Male'
|
104
|
+
assert_select 'label[for=user_gender_female] strong', '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
|
85
120
|
end
|
86
121
|
end
|
87
122
|
|
88
|
-
test 'input
|
123
|
+
test 'input marks the current radio value by default' do
|
89
124
|
@user.name = "Carlos"
|
90
|
-
with_input_for @user, :name, :radio_buttons, :
|
125
|
+
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
91
126
|
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
92
127
|
end
|
93
128
|
|
94
|
-
test 'input
|
95
|
-
with_input_for @user, :name, :radio_buttons, :
|
129
|
+
test 'input accepts html options as the last element of collection' do
|
130
|
+
with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose', class: 'foo']]
|
131
|
+
assert_select 'input.foo[type=radio][value=jose]'
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'input allows using a collection with text/value arrays' do
|
135
|
+
with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose'], ['Carlos', 'carlos']]
|
96
136
|
assert_select 'input[type=radio][value=jose]'
|
97
137
|
assert_select 'input[type=radio][value=carlos]'
|
98
138
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
99
139
|
assert_select 'label.collection_radio_buttons', 'Carlos'
|
100
140
|
end
|
101
141
|
|
102
|
-
test 'input
|
103
|
-
with_input_for @user, :name, :radio_buttons, :
|
142
|
+
test 'input allows using a collection with a Proc' do
|
143
|
+
with_input_for @user, :name, :radio_buttons, collection: Proc.new { ['Jose', 'Carlos' ] }
|
104
144
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
105
145
|
assert_select 'label.collection_radio_buttons', 'Carlos'
|
106
146
|
end
|
107
147
|
|
108
|
-
test 'input
|
148
|
+
test 'input allows overriding only label method for collections' do
|
109
149
|
with_input_for @user, :name, :radio_buttons,
|
110
|
-
:
|
111
|
-
:
|
150
|
+
collection: ['Jose', 'Carlos'],
|
151
|
+
label_method: :upcase
|
112
152
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
113
153
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
114
154
|
end
|
115
155
|
|
116
|
-
test 'input
|
156
|
+
test 'input allows overriding only value method for collections' do
|
117
157
|
with_input_for @user, :name, :radio_buttons,
|
118
|
-
:
|
119
|
-
:
|
158
|
+
collection: ['Jose', 'Carlos'],
|
159
|
+
value_method: :upcase
|
120
160
|
assert_select 'input[type=radio][value=JOSE]'
|
121
161
|
assert_select 'input[type=radio][value=CARLOS]'
|
122
162
|
end
|
123
163
|
|
124
|
-
test 'input
|
164
|
+
test 'input allows overriding label and value method for collections' do
|
125
165
|
with_input_for @user, :name, :radio_buttons,
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
166
|
+
collection: ['Jose', 'Carlos'],
|
167
|
+
label_method: :upcase,
|
168
|
+
value_method: :downcase
|
129
169
|
assert_select 'input[type=radio][value=jose]'
|
130
170
|
assert_select 'input[type=radio][value=carlos]'
|
131
171
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
132
172
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
133
173
|
end
|
134
174
|
|
135
|
-
test 'input
|
175
|
+
test 'input allows overriding label and value method using a lambda for collections' do
|
136
176
|
with_input_for @user, :name, :radio_buttons,
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
177
|
+
collection: ['Jose', 'Carlos'],
|
178
|
+
label_method: lambda { |i| i.upcase },
|
179
|
+
value_method: lambda { |i| i.downcase }
|
140
180
|
assert_select 'input[type=radio][value=jose]'
|
141
181
|
assert_select 'input[type=radio][value=carlos]'
|
142
182
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
143
183
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
144
184
|
end
|
145
185
|
|
146
|
-
test 'collection input with radio type
|
147
|
-
with_input_for @user, :name, :radio_buttons, :
|
186
|
+
test 'collection input with radio type generates required html attribute' do
|
187
|
+
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
148
188
|
assert_select 'input[type=radio].required'
|
149
189
|
assert_select 'input[type=radio][required]'
|
150
190
|
end
|
151
191
|
|
192
|
+
test 'collection input with radio type generates aria-required html attribute' do
|
193
|
+
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
194
|
+
assert_select 'input[type=radio].required'
|
195
|
+
assert_select 'input[type=radio][aria-required=true]'
|
196
|
+
end
|
197
|
+
|
152
198
|
test 'input radio does not wrap the collection by default' do
|
153
199
|
with_input_for @user, :active, :radio_buttons
|
154
200
|
|
155
|
-
assert_select 'form input[type=radio]', :
|
201
|
+
assert_select 'form input[type=radio]', count: 2
|
156
202
|
assert_no_select 'form ul'
|
157
203
|
end
|
158
204
|
|
159
205
|
test 'input radio wraps the collection in the configured collection wrapper tag' do
|
160
|
-
swap SimpleForm, :
|
206
|
+
swap SimpleForm, collection_wrapper_tag: :ul do
|
161
207
|
with_input_for @user, :active, :radio_buttons
|
162
208
|
|
163
|
-
assert_select 'form ul input[type=radio]', :
|
209
|
+
assert_select 'form ul input[type=radio]', count: 2
|
164
210
|
end
|
165
211
|
end
|
166
212
|
|
167
213
|
test 'input radio does not wrap the collection when configured with falsy values' do
|
168
|
-
swap SimpleForm, :
|
214
|
+
swap SimpleForm, collection_wrapper_tag: false do
|
169
215
|
with_input_for @user, :active, :radio_buttons
|
170
216
|
|
171
|
-
assert_select 'form input[type=radio]', :
|
217
|
+
assert_select 'form input[type=radio]', count: 2
|
172
218
|
assert_no_select 'form ul'
|
173
219
|
end
|
174
220
|
end
|
175
221
|
|
176
222
|
test 'input radio allows overriding the collection wrapper tag at input level' do
|
177
|
-
swap SimpleForm, :
|
178
|
-
with_input_for @user, :active, :radio_buttons, :
|
223
|
+
swap SimpleForm, collection_wrapper_tag: :ul do
|
224
|
+
with_input_for @user, :active, :radio_buttons, collection_wrapper_tag: :section
|
179
225
|
|
180
|
-
assert_select 'form section input[type=radio]', :
|
226
|
+
assert_select 'form section input[type=radio]', count: 2
|
181
227
|
assert_no_select 'form ul'
|
182
228
|
end
|
183
229
|
end
|
184
230
|
|
185
231
|
test 'input radio allows disabling the collection wrapper tag at input level' do
|
186
|
-
swap SimpleForm, :
|
187
|
-
with_input_for @user, :active, :radio_buttons, :
|
232
|
+
swap SimpleForm, collection_wrapper_tag: :ul do
|
233
|
+
with_input_for @user, :active, :radio_buttons, collection_wrapper_tag: false
|
188
234
|
|
189
|
-
assert_select 'form input[type=radio]', :
|
235
|
+
assert_select 'form input[type=radio]', count: 2
|
190
236
|
assert_no_select 'form ul'
|
191
237
|
end
|
192
238
|
end
|
193
239
|
|
194
240
|
test 'input radio renders the wrapper tag with the configured wrapper class' do
|
195
|
-
swap SimpleForm, :
|
241
|
+
swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
|
196
242
|
with_input_for @user, :active, :radio_buttons
|
197
243
|
|
198
|
-
assert_select 'form ul.inputs-list input[type=radio]', :
|
244
|
+
assert_select 'form ul.inputs-list input[type=radio]', count: 2
|
199
245
|
end
|
200
246
|
end
|
201
247
|
|
202
248
|
test 'input radio allows giving wrapper class at input level only' do
|
203
|
-
swap SimpleForm, :
|
204
|
-
with_input_for @user, :active, :radio_buttons, :
|
249
|
+
swap SimpleForm, collection_wrapper_tag: :ul do
|
250
|
+
with_input_for @user, :active, :radio_buttons, collection_wrapper_class: 'items-list'
|
205
251
|
|
206
|
-
assert_select 'form ul.items-list input[type=radio]', :
|
252
|
+
assert_select 'form ul.items-list input[type=radio]', count: 2
|
207
253
|
end
|
208
254
|
end
|
209
255
|
|
210
256
|
test 'input radio uses both configured and given wrapper classes for wrapper tag' do
|
211
|
-
swap SimpleForm, :
|
212
|
-
with_input_for @user, :active, :radio_buttons, :
|
257
|
+
swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
|
258
|
+
with_input_for @user, :active, :radio_buttons, collection_wrapper_class: 'items-list'
|
213
259
|
|
214
|
-
assert_select 'form ul.inputs-list.items-list input[type=radio]', :
|
260
|
+
assert_select 'form ul.inputs-list.items-list input[type=radio]', count: 2
|
215
261
|
end
|
216
262
|
end
|
217
263
|
|
218
264
|
test 'input radio wraps each item in the configured item wrapper tag' do
|
219
|
-
swap SimpleForm, :
|
265
|
+
swap SimpleForm, item_wrapper_tag: :li do
|
220
266
|
with_input_for @user, :active, :radio_buttons
|
221
267
|
|
222
|
-
assert_select 'form li input[type=radio]', :
|
268
|
+
assert_select 'form li input[type=radio]', count: 2
|
223
269
|
end
|
224
270
|
end
|
225
271
|
|
226
272
|
test 'input radio does not wrap items when configured with falsy values' do
|
227
|
-
swap SimpleForm, :
|
273
|
+
swap SimpleForm, item_wrapper_tag: false do
|
228
274
|
with_input_for @user, :active, :radio_buttons
|
229
275
|
|
230
|
-
assert_select 'form input[type=radio]', :
|
276
|
+
assert_select 'form input[type=radio]', count: 2
|
231
277
|
assert_no_select 'form li'
|
232
278
|
end
|
233
279
|
end
|
234
280
|
|
235
281
|
test 'input radio allows overriding the item wrapper tag at input level' do
|
236
|
-
swap SimpleForm, :
|
237
|
-
with_input_for @user, :active, :radio_buttons, :
|
282
|
+
swap SimpleForm, item_wrapper_tag: :li do
|
283
|
+
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :dl
|
238
284
|
|
239
|
-
assert_select 'form dl input[type=radio]', :
|
285
|
+
assert_select 'form dl input[type=radio]', count: 2
|
240
286
|
assert_no_select 'form li'
|
241
287
|
end
|
242
288
|
end
|
243
289
|
|
244
290
|
test 'input radio allows disabling the item wrapper tag at input level' do
|
245
|
-
swap SimpleForm, :
|
246
|
-
with_input_for @user, :active, :radio_buttons, :
|
291
|
+
swap SimpleForm, item_wrapper_tag: :ul do
|
292
|
+
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: false
|
247
293
|
|
248
|
-
assert_select 'form input[type=radio]', :
|
294
|
+
assert_select 'form input[type=radio]', count: 2
|
249
295
|
assert_no_select 'form li'
|
250
296
|
end
|
251
297
|
end
|
@@ -253,74 +299,128 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
253
299
|
test 'input radio wraps items in a span tag by default' do
|
254
300
|
with_input_for @user, :active, :radio_buttons
|
255
301
|
|
256
|
-
assert_select 'form span input[type=radio]', :
|
302
|
+
assert_select 'form span input[type=radio]', count: 2
|
257
303
|
end
|
258
304
|
|
259
305
|
test 'input radio renders the item wrapper tag with a default class "radio"' do
|
260
|
-
with_input_for @user, :active, :radio_buttons, :
|
306
|
+
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :li
|
261
307
|
|
262
|
-
assert_select 'form li.radio input[type=radio]', :
|
308
|
+
assert_select 'form li.radio input[type=radio]', count: 2
|
263
309
|
end
|
264
310
|
|
265
311
|
test 'input radio renders the item wrapper tag with the configured item wrapper class' do
|
266
|
-
swap SimpleForm, :
|
312
|
+
swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
|
267
313
|
with_input_for @user, :active, :radio_buttons
|
268
314
|
|
269
|
-
assert_select 'form li.radio.item input[type=radio]', :
|
315
|
+
assert_select 'form li.radio.item input[type=radio]', count: 2
|
270
316
|
end
|
271
317
|
end
|
272
318
|
|
273
319
|
test 'input radio allows giving item wrapper class at input level only' do
|
274
|
-
swap SimpleForm, :
|
275
|
-
with_input_for @user, :active, :radio_buttons, :
|
320
|
+
swap SimpleForm, item_wrapper_tag: :li do
|
321
|
+
with_input_for @user, :active, :radio_buttons, item_wrapper_class: 'item'
|
276
322
|
|
277
|
-
assert_select 'form li.radio.item input[type=radio]', :
|
323
|
+
assert_select 'form li.radio.item input[type=radio]', count: 2
|
278
324
|
end
|
279
325
|
end
|
280
326
|
|
281
327
|
test 'input radio uses both configured and given item wrapper classes for item wrapper tag' do
|
282
|
-
swap SimpleForm, :
|
283
|
-
with_input_for @user, :active, :radio_buttons, :
|
328
|
+
swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
|
329
|
+
with_input_for @user, :active, :radio_buttons, item_wrapper_class: 'inline'
|
284
330
|
|
285
|
-
assert_select 'form li.radio.item.inline input[type=radio]', :
|
331
|
+
assert_select 'form li.radio.item.inline input[type=radio]', count: 2
|
286
332
|
end
|
287
333
|
end
|
288
334
|
|
289
335
|
test 'input radio respects the nested boolean style config, generating nested label > input' do
|
290
|
-
swap SimpleForm, :
|
336
|
+
swap SimpleForm, boolean_style: :nested do
|
291
337
|
with_input_for @user, :active, :radio_buttons
|
292
338
|
|
293
|
-
assert_select '
|
294
|
-
assert_select '
|
295
|
-
assert_select '
|
296
|
-
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'
|
297
343
|
assert_no_select 'label.collection_radio_buttons'
|
298
344
|
end
|
299
345
|
end
|
300
346
|
|
301
|
-
test 'input radio with nested style overrides configured item wrapper tag
|
302
|
-
swap SimpleForm, :
|
347
|
+
test 'input radio with nested style does not overrides configured item wrapper tag' do
|
348
|
+
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
|
303
349
|
with_input_for @user, :active, :radio_buttons
|
304
350
|
|
305
|
-
assert_select '
|
306
|
-
assert_no_select 'li'
|
351
|
+
assert_select 'li.radio > label > input'
|
307
352
|
end
|
308
353
|
end
|
309
354
|
|
310
|
-
test 'input radio with nested style overrides given item wrapper tag
|
311
|
-
swap SimpleForm, :
|
312
|
-
with_input_for @user, :active, :radio_buttons, :
|
355
|
+
test 'input radio with nested style does not overrides given item wrapper tag' do
|
356
|
+
swap SimpleForm, boolean_style: :nested do
|
357
|
+
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :li
|
313
358
|
|
314
|
-
assert_select '
|
315
|
-
assert_no_select 'li'
|
359
|
+
assert_select 'li.radio > label > input'
|
316
360
|
end
|
317
361
|
end
|
318
362
|
|
319
363
|
test 'input radio with nested style accepts giving extra wrapper classes' do
|
320
|
-
swap SimpleForm, :
|
321
|
-
with_input_for @user, :active, :radio_buttons, :
|
364
|
+
swap SimpleForm, boolean_style: :nested do
|
365
|
+
with_input_for @user, :active, :radio_buttons, item_wrapper_class: "inline"
|
366
|
+
|
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 radio 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'
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
test 'input radio with nested style and namespace uses the right for attribute' do
|
406
|
+
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
407
|
+
with_concat_form_for @user, namespace: :foo do |f|
|
408
|
+
concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
|
409
|
+
end
|
410
|
+
|
411
|
+
assert_select 'label[for=foo_user_gender_male]'
|
412
|
+
assert_select 'label[for=foo_user_gender_female]'
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
test 'input radio with nested style and index uses the right for attribute' do
|
417
|
+
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
418
|
+
with_concat_form_for @user, index: 1 do |f|
|
419
|
+
concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
|
420
|
+
end
|
322
421
|
|
323
|
-
assert_select 'label
|
422
|
+
assert_select 'label[for=user_1_gender_male]'
|
423
|
+
assert_select 'label[for=user_1_gender_female]'
|
324
424
|
end
|
325
425
|
end
|
326
426
|
end
|