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
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class WrapperTest < ActionView::TestCase
|
4
|
-
test 'wrapper
|
4
|
+
test 'wrapper does not have error class for attribute without errors' do
|
5
5
|
with_form_for @user, :active
|
6
6
|
assert_no_select 'div.field_with_errors'
|
7
7
|
end
|
8
8
|
|
9
|
-
test 'wrapper
|
9
|
+
test 'wrapper does not have error class when object is not present' do
|
10
10
|
with_form_for :project, :name
|
11
11
|
assert_no_select 'div.field_with_errors'
|
12
12
|
end
|
13
13
|
|
14
|
-
test 'wrapper
|
14
|
+
test 'wrapper adds the attribute name class' do
|
15
15
|
with_form_for @user, :name
|
16
16
|
assert_select 'div.user_name'
|
17
17
|
end
|
18
18
|
|
19
|
-
test 'wrapper
|
19
|
+
test 'wrapper adds the attribute name class for nested forms' do
|
20
20
|
@user.company = Company.new(1, 'Empresa')
|
21
21
|
with_concat_form_for @user do |f|
|
22
22
|
concat(f.simple_fields_for(:company) do |company_form|
|
@@ -27,69 +27,69 @@ class WrapperTest < ActionView::TestCase
|
|
27
27
|
assert_select 'div.user_company_name'
|
28
28
|
end
|
29
29
|
|
30
|
-
test 'wrapper
|
30
|
+
test 'wrapper adds the association name class' do
|
31
31
|
with_form_for @user, :company
|
32
32
|
assert_select 'div.user_company'
|
33
33
|
end
|
34
34
|
|
35
|
-
test 'wrapper
|
35
|
+
test 'wrapper adds error class for attribute with errors' do
|
36
36
|
with_form_for @user, :name
|
37
37
|
assert_select 'div.field_with_errors'
|
38
38
|
end
|
39
39
|
|
40
|
-
test 'wrapper
|
41
|
-
with_form_for @user, :name, :
|
40
|
+
test 'wrapper adds hint class for attribute with a hint' do
|
41
|
+
with_form_for @user, :name, hint: 'hint'
|
42
42
|
assert_select 'div.field_with_hint'
|
43
43
|
end
|
44
44
|
|
45
|
-
test 'wrapper
|
45
|
+
test 'wrapper does not have disabled class by default' do
|
46
46
|
with_form_for @user, :active
|
47
47
|
assert_no_select 'div.disabled'
|
48
48
|
end
|
49
49
|
|
50
|
-
test 'wrapper
|
51
|
-
with_form_for @user, :active, :
|
50
|
+
test 'wrapper has disabled class when input is disabled' do
|
51
|
+
with_form_for @user, :active, disabled: true
|
52
52
|
assert_select 'div.disabled'
|
53
53
|
end
|
54
54
|
|
55
|
-
test 'wrapper
|
56
|
-
with_form_for @user, :name, :
|
55
|
+
test 'wrapper supports no wrapping when wrapper is false' do
|
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
|
-
test 'wrapper
|
62
|
-
with_form_for @user, :name, :
|
61
|
+
test 'wrapper supports no wrapping when wrapper tag is false' do
|
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
|
66
66
|
|
67
|
-
test 'wrapper
|
67
|
+
test 'wrapper wraps tag adds required/optional css classes' do
|
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
|
-
test 'wrapper
|
76
|
-
with_form_for @user, :name, :
|
75
|
+
test 'wrapper allows custom options to be given' do
|
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
|
-
test 'wrapper
|
81
|
-
with_form_for @user, :name, :
|
80
|
+
test 'wrapper allows tag to be given on demand' do
|
81
|
+
with_form_for @user, :name, wrapper_tag: :b
|
82
82
|
assert_select 'form b.required.string'
|
83
83
|
end
|
84
84
|
|
85
|
-
test 'wrapper
|
86
|
-
with_form_for @user, :name, :
|
85
|
+
test 'wrapper allows wrapper class to be given on demand' do
|
86
|
+
with_form_for @user, :name, wrapper_class: :wrapper
|
87
87
|
assert_select 'form div.wrapper.required.string'
|
88
88
|
end
|
89
89
|
|
90
|
-
test 'wrapper
|
91
|
-
swap SimpleForm, :
|
92
|
-
with_form_for @user, :name, :
|
90
|
+
test 'wrapper skips additional classes when configured' do
|
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'
|
@@ -97,8 +97,8 @@ class WrapperTest < ActionView::TestCase
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
test 'wrapper
|
101
|
-
swap SimpleForm, :
|
100
|
+
test 'wrapper does not generate empty css class' do
|
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,13 +121,28 @@ 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"
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
+
test 'custom wrappers can have additional attributes' do
|
132
|
+
swap_wrapper :default, custom_wrapper_with_additional_attributes do
|
133
|
+
with_form_for @user, :name
|
134
|
+
|
135
|
+
assert_select "div.custom_wrapper[title='some title'][data-wrapper='test']"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
test 'custom wrappers can have full error message on attributes' do
|
140
|
+
swap_wrapper :default, custom_wrapper_with_full_error do
|
141
|
+
with_form_for @user, :name
|
142
|
+
assert_select 'span.error', "Name cannot be blank"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
131
146
|
test 'custom wrappers on a form basis' do
|
132
147
|
swap_wrapper :another do
|
133
148
|
with_concat_form_for(@user) do |f|
|
@@ -137,7 +152,7 @@ class WrapperTest < ActionView::TestCase
|
|
137
152
|
assert_no_select "section.custom_wrapper div.another_wrapper label"
|
138
153
|
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
139
154
|
|
140
|
-
with_concat_form_for(@user, :
|
155
|
+
with_concat_form_for(@user, wrapper: :another) do |f|
|
141
156
|
f.input :name
|
142
157
|
end
|
143
158
|
|
@@ -153,30 +168,30 @@ class WrapperTest < ActionView::TestCase
|
|
153
168
|
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
154
169
|
output_buffer.replace ""
|
155
170
|
|
156
|
-
with_form_for @user, :name, :
|
171
|
+
with_form_for @user, :name, wrapper: :another
|
157
172
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
158
173
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
159
174
|
output_buffer.replace ""
|
160
175
|
end
|
161
176
|
|
162
|
-
with_form_for @user, :name, :
|
177
|
+
with_form_for @user, :name, wrapper: custom_wrapper
|
163
178
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
164
179
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
165
180
|
end
|
166
181
|
|
167
182
|
test 'access wrappers with indifferent access' do
|
168
183
|
swap_wrapper :another do
|
169
|
-
with_form_for @user, :name, :
|
184
|
+
with_form_for @user, :name, wrapper: "another"
|
170
185
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
171
186
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
172
187
|
end
|
173
188
|
end
|
174
189
|
|
175
|
-
test '
|
176
|
-
swap_wrapper :default,
|
190
|
+
test 'does not duplicate label classes for different inputs' do
|
191
|
+
swap_wrapper :default, custom_wrapper_with_label_html_option do
|
177
192
|
with_concat_form_for(@user) do |f|
|
178
|
-
concat f.input :name, :
|
179
|
-
concat f.input :email, :
|
193
|
+
concat f.input :name, required: false
|
194
|
+
concat f.input :email, as: :email, required: true
|
180
195
|
end
|
181
196
|
|
182
197
|
assert_select "label.string.optional.extra-label-class[for='user_name']"
|
@@ -187,17 +202,118 @@ class WrapperTest < ActionView::TestCase
|
|
187
202
|
|
188
203
|
test 'raise error when wrapper not found' do
|
189
204
|
assert_raise SimpleForm::WrapperNotFound do
|
190
|
-
with_form_for @user, :name, :
|
205
|
+
with_form_for @user, :name, wrapper: :not_found
|
191
206
|
end
|
192
207
|
end
|
193
208
|
|
194
|
-
test '
|
209
|
+
test 'uses wrapper for specified in config mapping' do
|
195
210
|
swap_wrapper :another do
|
196
|
-
swap SimpleForm, :
|
211
|
+
swap SimpleForm, wrapper_mappings: { string: :another } do
|
197
212
|
with_form_for @user, :name
|
198
213
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
199
214
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
200
215
|
end
|
201
216
|
end
|
202
217
|
end
|
218
|
+
|
219
|
+
test 'uses custom wrapper mapping per form basis' do
|
220
|
+
swap_wrapper :another do
|
221
|
+
with_concat_form_for @user, wrapper_mappings: { string: :another } do |f|
|
222
|
+
concat f.input :name
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
assert_select "section.custom_wrapper div.another_wrapper label"
|
227
|
+
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
228
|
+
end
|
229
|
+
|
230
|
+
test 'simple_fields_form reuses custom wrapper mapping per form basis' do
|
231
|
+
@user.company = Company.new(1, 'Empresa')
|
232
|
+
|
233
|
+
swap_wrapper :another do
|
234
|
+
with_concat_form_for @user, wrapper_mappings: { string: :another } do |f|
|
235
|
+
concat(f.simple_fields_for(:company) do |company_form|
|
236
|
+
concat(company_form.input(:name))
|
237
|
+
end)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
assert_select "section.custom_wrapper div.another_wrapper label"
|
242
|
+
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
243
|
+
end
|
244
|
+
|
245
|
+
test 'input accepts attributes in the DSL' do
|
246
|
+
swap_wrapper :default, custom_wrapper_with_input_class do
|
247
|
+
with_concat_form_for @user do |f|
|
248
|
+
concat f.input :name
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
assert_select "div.custom_wrapper input.string.inline-class"
|
253
|
+
end
|
254
|
+
|
255
|
+
test 'label accepts attributes in the DSL' do
|
256
|
+
swap_wrapper :default, custom_wrapper_with_label_class do
|
257
|
+
with_concat_form_for @user do |f|
|
258
|
+
concat f.input :name
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
assert_select "div.custom_wrapper label.string.inline-class"
|
263
|
+
end
|
264
|
+
|
265
|
+
test 'label_input accepts attributes in the DSL' do
|
266
|
+
swap_wrapper :default, custom_wrapper_with_label_input_class do
|
267
|
+
with_concat_form_for @user do |f|
|
268
|
+
concat f.input :name
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
assert_select "div.custom_wrapper label.string.inline-class"
|
273
|
+
assert_select "div.custom_wrapper input.string.inline-class"
|
274
|
+
end
|
275
|
+
|
276
|
+
test 'input accepts data attributes in the DSL' do
|
277
|
+
swap_wrapper :default, custom_wrapper_with_input_attributes do
|
278
|
+
with_concat_form_for @user do |f|
|
279
|
+
concat f.input :name
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
assert_select "div.custom_wrapper input.string[data-modal=true]"
|
284
|
+
end
|
285
|
+
|
286
|
+
test 'inline wrapper displays when there is content' do
|
287
|
+
swap_wrapper :default, custom_wrapper_with_wrapped_optional_component do
|
288
|
+
with_form_for @user, :name, hint: "cannot be blank"
|
289
|
+
assert_select 'section.custom_wrapper div.no_output_wrapper p.omg_hint', "cannot be blank"
|
290
|
+
assert_select 'p.omg_hint'
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
test 'inline wrapper does not display when there is no content' do
|
295
|
+
swap_wrapper :default, custom_wrapper_with_wrapped_optional_component do
|
296
|
+
with_form_for @user, :name
|
297
|
+
assert_select 'section.custom_wrapper div.no_output_wrapper'
|
298
|
+
assert_no_select 'p.omg_hint'
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
test 'optional wrapper does not display when there is content' do
|
303
|
+
swap_wrapper :default, custom_wrapper_with_unless_blank do
|
304
|
+
with_form_for @user, :name, hint: "can't be blank"
|
305
|
+
assert_select 'section.custom_wrapper div.no_output_wrapper'
|
306
|
+
assert_select 'div.no_output_wrapper'
|
307
|
+
assert_select 'p.omg_hint'
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
test 'optional wrapper does not display when there is no content' do
|
312
|
+
swap_wrapper :default, custom_wrapper_with_unless_blank do
|
313
|
+
with_form_for @user, :name
|
314
|
+
assert_no_select 'section.custom_wrapper div.no_output_wrapper'
|
315
|
+
assert_no_select 'div.no_output_wrapper'
|
316
|
+
assert_no_select 'p.omg_hint'
|
317
|
+
end
|
318
|
+
end
|
203
319
|
end
|
@@ -21,16 +21,16 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
|
21
21
|
run_generator %w(--bootstrap)
|
22
22
|
assert_file 'config/initializers/simple_form.rb',
|
23
23
|
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
24
|
-
assert_file 'config/initializers/simple_form_bootstrap.rb', /config\.wrappers :
|
25
|
-
/config\.default_wrapper = :
|
24
|
+
assert_file 'config/initializers/simple_form_bootstrap.rb', /config\.wrappers :vertical_form/,
|
25
|
+
/config\.wrappers :horizontal_form/, /config\.default_wrapper = :vertical_form/
|
26
26
|
end
|
27
27
|
|
28
28
|
test 'generates the simple_form initializer with the foundation wrappers' do
|
29
29
|
run_generator %w(--foundation)
|
30
30
|
assert_file 'config/initializers/simple_form.rb',
|
31
31
|
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
32
|
-
assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :
|
33
|
-
/config\.default_wrapper = :
|
32
|
+
assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :vertical_form/,
|
33
|
+
/config\.default_wrapper = :vertical_form/, /config\.item_wrapper_tag = :div/
|
34
34
|
end
|
35
35
|
|
36
36
|
%W(erb haml slim).each do |engine|
|
@@ -2,33 +2,33 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
class BooleanInputTest < ActionView::TestCase
|
5
|
-
test 'input
|
5
|
+
test 'input generates a checkbox by default for boolean attributes' do
|
6
6
|
with_input_for @user, :active, :boolean
|
7
7
|
assert_select 'input[type=checkbox].boolean#user_active'
|
8
8
|
assert_select 'label.boolean.optional', 'Active'
|
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,49 @@ 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, inline_label: 'I am so inline.'
|
53
|
+
assert_select 'label.checkbox', text: ' I am so inline.'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'input boolean with nested escapes :inline_label with HTML' do
|
58
|
+
swap SimpleForm, boolean_style: :nested do
|
59
|
+
with_input_for @user, :active, :boolean, inline_label: '<b>I am so inline.</b>'
|
60
|
+
assert_no_select 'label.checkbox b'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'input boolean with nested allows :inline_label with HTML when safe' do
|
65
|
+
swap SimpleForm, boolean_style: :nested do
|
66
|
+
with_input_for @user, :active, :boolean, inline_label: '<b>I am so inline.</b>'.html_safe
|
67
|
+
assert_select 'label.checkbox b', text: 'I am so inline.'
|
54
68
|
end
|
55
69
|
end
|
56
70
|
|
57
71
|
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', :
|
72
|
+
swap SimpleForm, boolean_style: :nested do
|
73
|
+
with_input_for @user, :active, :boolean, inline_label: true
|
74
|
+
assert_select 'label.checkbox', text: ' Active'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'input boolean with nested style creates an inline label using the label text when inline_label option set to true' do
|
79
|
+
swap SimpleForm, boolean_style: :nested do
|
80
|
+
with_input_for @user, :active, :boolean, inline_label: true, label_text: proc { 'New Active' }
|
81
|
+
assert_select 'label.checkbox', text: ' New Active'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'input boolean with nested style creates an inline label using the label html when inline_label option set to true' do
|
86
|
+
swap SimpleForm, boolean_style: :nested do
|
87
|
+
with_input_for @user, :active, :boolean, inline_label: true, label_text: proc { '<b>New Active</b>' }
|
88
|
+
assert_select 'label.checkbox', text: ' New Active'
|
61
89
|
end
|
62
90
|
end
|
63
91
|
|
64
92
|
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, :
|
93
|
+
swap SimpleForm, boolean_style: :nested do
|
66
94
|
with_input_for @user, :active, :boolean
|
67
95
|
|
68
96
|
assert_select "input[type=hidden][name='user[active]'] + label.boolean > input.boolean"
|
@@ -71,23 +99,23 @@ class BooleanInputTest < ActionView::TestCase
|
|
71
99
|
end
|
72
100
|
|
73
101
|
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, :
|
102
|
+
swap SimpleForm, boolean_style: :nested do
|
103
|
+
with_input_for @user, :active, :boolean, disabled: true
|
76
104
|
|
77
105
|
assert_select "input[type=hidden][name='user[active]'][disabled] + label.boolean > input.boolean[disabled]"
|
78
106
|
end
|
79
107
|
end
|
80
108
|
|
81
109
|
test 'input accepts changing boolean style to nested through given options' do
|
82
|
-
with_input_for @user, :active, :boolean, :
|
110
|
+
with_input_for @user, :active, :boolean, boolean_style: :nested
|
83
111
|
assert_select 'label[for=user_active]', 'Active'
|
84
112
|
assert_select 'label.boolean > input.boolean'
|
85
113
|
assert_no_select 'input[type=checkbox] + label'
|
86
114
|
end
|
87
115
|
|
88
116
|
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, :
|
117
|
+
swap SimpleForm, boolean_style: :nested do
|
118
|
+
with_input_for @user, :active, :boolean, boolean_style: :inline
|
91
119
|
assert_select 'label[for=user_active]', 'Active'
|
92
120
|
assert_select 'input.boolean + label.boolean'
|
93
121
|
assert_no_select 'label > input'
|
@@ -95,16 +123,16 @@ class BooleanInputTest < ActionView::TestCase
|
|
95
123
|
end
|
96
124
|
|
97
125
|
test 'input with nested style allows disabling label' do
|
98
|
-
swap SimpleForm, :
|
99
|
-
with_input_for @user, :active, :boolean, :
|
126
|
+
swap SimpleForm, boolean_style: :nested do
|
127
|
+
with_input_for @user, :active, :boolean, label: false
|
100
128
|
assert_select 'input.boolean'
|
101
129
|
assert_no_select 'label.boolean'
|
102
130
|
end
|
103
131
|
end
|
104
132
|
|
105
133
|
test 'input with nested style allows customizing input_html' do
|
106
|
-
swap SimpleForm, :
|
107
|
-
with_input_for @user, :active, :boolean, :
|
134
|
+
swap SimpleForm, boolean_style: :nested do
|
135
|
+
with_input_for @user, :active, :boolean, input_html: { name: 'active_user' }
|
108
136
|
assert_select "input[type=hidden][name=active_user] + label.boolean > input.boolean[name=active_user]"
|
109
137
|
end
|
110
138
|
end
|
@@ -120,7 +148,7 @@ class BooleanInputTest < ActionView::TestCase
|
|
120
148
|
|
121
149
|
test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra "checkbox" label wrapper' do
|
122
150
|
swap_wrapper do
|
123
|
-
swap SimpleForm, :
|
151
|
+
swap SimpleForm, boolean_style: :nested do
|
124
152
|
with_input_for @user, :active, :boolean
|
125
153
|
|
126
154
|
assert_select 'label.boolean + input[type=hidden] + label.checkbox > input.boolean'
|
@@ -128,13 +156,53 @@ class BooleanInputTest < ActionView::TestCase
|
|
128
156
|
end
|
129
157
|
end
|
130
158
|
|
159
|
+
test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra label wrapper with custom class' do
|
160
|
+
swap_wrapper do
|
161
|
+
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
162
|
+
with_input_for @user, :active, :boolean
|
163
|
+
|
164
|
+
assert_select 'label.boolean + input[type=hidden] + label.foo > input.boolean'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
131
169
|
test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
|
132
170
|
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
133
|
-
swap SimpleForm, :
|
171
|
+
swap SimpleForm, boolean_style: :nested do
|
134
172
|
with_input_for @user, :active, :boolean
|
135
173
|
|
136
174
|
assert_select 'input[type=hidden] + label.boolean.checkbox > input.boolean'
|
137
175
|
end
|
138
176
|
end
|
139
177
|
end
|
178
|
+
|
179
|
+
test 'input boolean with nested style works using :label_input in wrapper config, adding custom class to label' do
|
180
|
+
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
181
|
+
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
182
|
+
with_input_for @user, :active, :boolean
|
183
|
+
|
184
|
+
assert_select 'input[type=hidden] + label.boolean.foo > input.boolean'
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
test 'input boolean without additional classes adds "checkbox" class to label' do
|
190
|
+
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
191
|
+
swap SimpleForm, boolean_style: :nested, generate_additional_classes_for: [:input] do
|
192
|
+
with_input_for @user, :active, :boolean
|
193
|
+
|
194
|
+
assert_select 'label'
|
195
|
+
assert_select 'label.checkbox'
|
196
|
+
assert_no_select 'label.boolean'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
test 'input boolean works with wrapper config defining a class for the input' do
|
202
|
+
swap_wrapper :default, self.custom_wrapper_with_input_class do
|
203
|
+
with_input_for @user, :active, :boolean
|
204
|
+
|
205
|
+
assert_select 'input.boolean.inline-class'
|
206
|
+
end
|
207
|
+
end
|
140
208
|
end
|