simple_form 3.0.1 → 4.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +149 -25
- data/MIT-LICENSE +1 -1
- data/README.md +441 -107
- data/lib/generators/simple_form/install_generator.rb +4 -3
- data/lib/generators/simple_form/templates/README +4 -5
- data/lib/generators/simple_form/templates/_form.html.erb +2 -0
- data/lib/generators/simple_form/templates/_form.html.haml +2 -0
- data/lib/generators/simple_form/templates/_form.html.slim +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +48 -11
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +417 -23
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +101 -5
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +2 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +10 -3
- data/lib/simple_form/components/errors.rb +38 -3
- data/lib/simple_form/components/hints.rb +3 -2
- data/lib/simple_form/components/html5.rb +16 -5
- data/lib/simple_form/components/label_input.rb +21 -2
- data/lib/simple_form/components/labels.rb +22 -11
- data/lib/simple_form/components/maxlength.rb +9 -5
- data/lib/simple_form/components/min_max.rb +2 -1
- data/lib/simple_form/components/minlength.rb +38 -0
- data/lib/simple_form/components/pattern.rb +2 -1
- data/lib/simple_form/components/placeholders.rb +4 -3
- data/lib/simple_form/components/readonly.rb +2 -1
- data/lib/simple_form/components.rb +2 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +193 -80
- data/lib/simple_form/helpers/autofocus.rb +1 -0
- data/lib/simple_form/helpers/disabled.rb +1 -0
- data/lib/simple_form/helpers/readonly.rb +1 -0
- data/lib/simple_form/helpers/required.rb +1 -0
- data/lib/simple_form/helpers/validators.rb +2 -1
- data/lib/simple_form/helpers.rb +6 -5
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +57 -14
- data/lib/simple_form/inputs/block_input.rb +2 -1
- data/lib/simple_form/inputs/boolean_input.rb +39 -16
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +37 -14
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +9 -13
- data/lib/simple_form/inputs/collection_select_input.rb +5 -2
- data/lib/simple_form/inputs/date_time_input.rb +24 -9
- data/lib/simple_form/inputs/file_input.rb +5 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
- data/lib/simple_form/inputs/hidden_input.rb +5 -2
- data/lib/simple_form/inputs/numeric_input.rb +6 -4
- data/lib/simple_form/inputs/password_input.rb +6 -3
- data/lib/simple_form/inputs/priority_input.rb +5 -2
- data/lib/simple_form/inputs/range_input.rb +2 -1
- data/lib/simple_form/inputs/string_input.rb +6 -3
- data/lib/simple_form/inputs/text_input.rb +6 -3
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +8 -0
- data/lib/simple_form/tags.rb +7 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +7 -6
- data/lib/simple_form/wrappers/leaf.rb +29 -0
- data/lib/simple_form/wrappers/many.rb +7 -6
- data/lib/simple_form/wrappers/root.rb +3 -1
- data/lib/simple_form/wrappers/single.rb +7 -4
- data/lib/simple_form/wrappers.rb +2 -0
- data/lib/simple_form.rb +117 -18
- data/test/action_view_extensions/builder_test.rb +42 -41
- data/test/action_view_extensions/form_helper_test.rb +36 -16
- data/test/components/custom_components_test.rb +62 -0
- data/test/components/label_test.rb +70 -41
- data/test/form_builder/association_test.rb +79 -37
- data/test/form_builder/button_test.rb +11 -10
- data/test/form_builder/error_notification_test.rb +2 -1
- data/test/form_builder/error_test.rb +173 -24
- data/test/form_builder/general_test.rb +171 -73
- data/test/form_builder/hint_test.rb +24 -18
- data/test/form_builder/input_field_test.rb +132 -56
- data/test/form_builder/label_test.rb +68 -13
- data/test/form_builder/wrapper_test.rb +190 -22
- data/test/generators/simple_form_generator_test.rb +8 -7
- data/test/inputs/boolean_input_test.rb +89 -6
- data/test/inputs/collection_check_boxes_input_test.rb +109 -25
- data/test/inputs/collection_radio_buttons_input_test.rb +168 -54
- data/test/inputs/collection_select_input_test.rb +183 -77
- data/test/inputs/datetime_input_test.rb +131 -50
- data/test/inputs/disabled_test.rb +16 -15
- data/test/inputs/discovery_test.rb +58 -6
- data/test/inputs/file_input_test.rb +3 -2
- data/test/inputs/general_test.rb +23 -22
- data/test/inputs/grouped_collection_select_input_test.rb +54 -17
- data/test/inputs/hidden_input_test.rb +5 -4
- data/test/inputs/numeric_input_test.rb +48 -44
- data/test/inputs/priority_input_test.rb +23 -14
- data/test/inputs/readonly_test.rb +20 -19
- data/test/inputs/required_test.rb +58 -13
- data/test/inputs/string_input_test.rb +62 -33
- data/test/inputs/text_input_test.rb +20 -7
- data/test/simple_form_test.rb +9 -0
- data/test/support/discovery_inputs.rb +33 -2
- data/test/support/misc_helpers.rb +113 -5
- data/test/support/mock_controller.rb +7 -1
- data/test/support/models.rb +137 -37
- data/test/test_helper.rb +15 -1
- metadata +25 -33
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class WrapperTest < ActionView::TestCase
|
|
4
|
-
test 'wrapper
|
|
5
|
+
test 'wrapper does not have error class for attribute without errors' do
|
|
5
6
|
with_form_for @user, :active
|
|
6
7
|
assert_no_select 'div.field_with_errors'
|
|
7
8
|
end
|
|
8
9
|
|
|
9
|
-
test 'wrapper
|
|
10
|
+
test 'wrapper does not have error class when object is not present' do
|
|
10
11
|
with_form_for :project, :name
|
|
11
12
|
assert_no_select 'div.field_with_errors'
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
test 'wrapper
|
|
15
|
+
test 'wrapper adds the attribute name class' do
|
|
15
16
|
with_form_for @user, :name
|
|
16
17
|
assert_select 'div.user_name'
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
test 'wrapper
|
|
20
|
+
test 'wrapper adds the attribute name class for nested forms' do
|
|
20
21
|
@user.company = Company.new(1, 'Empresa')
|
|
21
22
|
with_concat_form_for @user do |f|
|
|
22
23
|
concat(f.simple_fields_for(:company) do |company_form|
|
|
@@ -27,44 +28,65 @@ class WrapperTest < ActionView::TestCase
|
|
|
27
28
|
assert_select 'div.user_company_name'
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
test 'wrapper
|
|
31
|
+
test 'wrapper adds the association name class' do
|
|
31
32
|
with_form_for @user, :company
|
|
32
33
|
assert_select 'div.user_company'
|
|
33
34
|
end
|
|
34
35
|
|
|
35
|
-
test 'wrapper
|
|
36
|
+
test 'wrapper adds error class for attribute with errors' do
|
|
36
37
|
with_form_for @user, :name
|
|
37
38
|
assert_select 'div.field_with_errors'
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
test 'wrapper
|
|
41
|
+
test 'wrapper adds error class to input for attribute with errors' do
|
|
42
|
+
with_form_for @user, :name, wrapper: custom_wrapper_with_input_error_class
|
|
43
|
+
assert_select 'div.field_with_errors'
|
|
44
|
+
assert_select 'input.is-invalid'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test 'wrapper does not add error class to input when the attribute is valid' do
|
|
48
|
+
with_form_for @user, :phone_number, wrapper: custom_wrapper_with_input_error_class
|
|
49
|
+
assert_no_select 'div.field_with_errors'
|
|
50
|
+
assert_no_select 'input.is-invalid'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test 'wrapper adds valid class for present attribute without errors' do
|
|
54
|
+
@user.instance_eval { undef errors }
|
|
55
|
+
with_form_for @user, :name, wrapper: custom_wrapper_with_input_valid_class
|
|
56
|
+
assert_select 'div.field_without_errors'
|
|
57
|
+
assert_select 'input.is-valid'
|
|
58
|
+
assert_no_select 'div.field_with_errors'
|
|
59
|
+
assert_no_select 'input.is-invalid'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test 'wrapper adds hint class for attribute with a hint' do
|
|
41
63
|
with_form_for @user, :name, hint: 'hint'
|
|
42
64
|
assert_select 'div.field_with_hint'
|
|
43
65
|
end
|
|
44
66
|
|
|
45
|
-
test 'wrapper
|
|
67
|
+
test 'wrapper does not have disabled class by default' do
|
|
46
68
|
with_form_for @user, :active
|
|
47
69
|
assert_no_select 'div.disabled'
|
|
48
70
|
end
|
|
49
71
|
|
|
50
|
-
test 'wrapper
|
|
72
|
+
test 'wrapper has disabled class when input is disabled' do
|
|
51
73
|
with_form_for @user, :active, disabled: true
|
|
52
74
|
assert_select 'div.disabled'
|
|
53
75
|
end
|
|
54
76
|
|
|
55
|
-
test 'wrapper
|
|
77
|
+
test 'wrapper supports no wrapping when wrapper is false' do
|
|
56
78
|
with_form_for @user, :name, wrapper: false
|
|
57
79
|
assert_select 'form > label[for=user_name]'
|
|
58
80
|
assert_select 'form > input#user_name.string'
|
|
59
81
|
end
|
|
60
82
|
|
|
61
|
-
test 'wrapper
|
|
83
|
+
test 'wrapper supports no wrapping when wrapper tag is false' do
|
|
62
84
|
with_form_for @user, :name, wrapper: custom_wrapper_without_top_level
|
|
63
85
|
assert_select 'form > label[for=user_name]'
|
|
64
86
|
assert_select 'form > input#user_name.string'
|
|
65
87
|
end
|
|
66
88
|
|
|
67
|
-
test 'wrapper
|
|
89
|
+
test 'wrapper wraps tag adds required/optional css classes' do
|
|
68
90
|
with_form_for @user, :name
|
|
69
91
|
assert_select 'form div.input.required.string'
|
|
70
92
|
|
|
@@ -72,23 +94,23 @@ class WrapperTest < ActionView::TestCase
|
|
|
72
94
|
assert_select 'form div.input.optional.integer'
|
|
73
95
|
end
|
|
74
96
|
|
|
75
|
-
test 'wrapper
|
|
97
|
+
test 'wrapper allows custom options to be given' do
|
|
76
98
|
with_form_for @user, :name, wrapper_html: { id: "super_cool", class: 'yay' }
|
|
77
99
|
assert_select 'form #super_cool.required.string.yay'
|
|
78
100
|
end
|
|
79
101
|
|
|
80
|
-
test 'wrapper
|
|
102
|
+
test 'wrapper allows tag to be given on demand' do
|
|
81
103
|
with_form_for @user, :name, wrapper_tag: :b
|
|
82
104
|
assert_select 'form b.required.string'
|
|
83
105
|
end
|
|
84
106
|
|
|
85
|
-
test 'wrapper
|
|
107
|
+
test 'wrapper allows wrapper class to be given on demand' do
|
|
86
108
|
with_form_for @user, :name, wrapper_class: :wrapper
|
|
87
109
|
assert_select 'form div.wrapper.required.string'
|
|
88
110
|
end
|
|
89
111
|
|
|
90
|
-
test 'wrapper
|
|
91
|
-
swap SimpleForm, generate_additional_classes_for: [
|
|
112
|
+
test 'wrapper skips additional classes when configured' do
|
|
113
|
+
swap SimpleForm, generate_additional_classes_for: %i[input label] do
|
|
92
114
|
with_form_for @user, :name, wrapper_class: :wrapper
|
|
93
115
|
assert_select 'form div.wrapper'
|
|
94
116
|
assert_no_select 'div.required'
|
|
@@ -97,8 +119,8 @@ class WrapperTest < ActionView::TestCase
|
|
|
97
119
|
end
|
|
98
120
|
end
|
|
99
121
|
|
|
100
|
-
test 'wrapper
|
|
101
|
-
swap SimpleForm, generate_additional_classes_for: [
|
|
122
|
+
test 'wrapper does not generate empty css class' do
|
|
123
|
+
swap SimpleForm, generate_additional_classes_for: %i[input label] do
|
|
102
124
|
swap_wrapper :default, custom_wrapper_without_class do
|
|
103
125
|
with_form_for @user, :name
|
|
104
126
|
assert_no_select 'div#custom_wrapper_without_class[class]'
|
|
@@ -128,6 +150,21 @@ class WrapperTest < ActionView::TestCase
|
|
|
128
150
|
end
|
|
129
151
|
end
|
|
130
152
|
|
|
153
|
+
test 'custom wrappers can have additional attributes' do
|
|
154
|
+
swap_wrapper :default, custom_wrapper_with_additional_attributes do
|
|
155
|
+
with_form_for @user, :name
|
|
156
|
+
|
|
157
|
+
assert_select "div.custom_wrapper[title='some title'][data-wrapper='test']"
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
test 'custom wrappers can have full error message on attributes' do
|
|
162
|
+
swap_wrapper :default, custom_wrapper_with_full_error do
|
|
163
|
+
with_form_for @user, :name
|
|
164
|
+
assert_select 'span.error', "Name cannot be blank"
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
131
168
|
test 'custom wrappers on a form basis' do
|
|
132
169
|
swap_wrapper :another do
|
|
133
170
|
with_concat_form_for(@user) do |f|
|
|
@@ -172,8 +209,8 @@ class WrapperTest < ActionView::TestCase
|
|
|
172
209
|
end
|
|
173
210
|
end
|
|
174
211
|
|
|
175
|
-
test '
|
|
176
|
-
swap_wrapper :default,
|
|
212
|
+
test 'does not duplicate label classes for different inputs' do
|
|
213
|
+
swap_wrapper :default, custom_wrapper_with_label_html_option do
|
|
177
214
|
with_concat_form_for(@user) do |f|
|
|
178
215
|
concat f.input :name, required: false
|
|
179
216
|
concat f.input :email, as: :email, required: true
|
|
@@ -191,7 +228,7 @@ class WrapperTest < ActionView::TestCase
|
|
|
191
228
|
end
|
|
192
229
|
end
|
|
193
230
|
|
|
194
|
-
test '
|
|
231
|
+
test 'uses wrapper for specified in config mapping' do
|
|
195
232
|
swap_wrapper :another do
|
|
196
233
|
swap SimpleForm, wrapper_mappings: { string: :another } do
|
|
197
234
|
with_form_for @user, :name
|
|
@@ -200,4 +237,135 @@ class WrapperTest < ActionView::TestCase
|
|
|
200
237
|
end
|
|
201
238
|
end
|
|
202
239
|
end
|
|
240
|
+
|
|
241
|
+
test 'uses custom wrapper mapping per form basis' do
|
|
242
|
+
swap_wrapper :another do
|
|
243
|
+
with_concat_form_for @user, wrapper_mappings: { string: :another } do |f|
|
|
244
|
+
concat f.input :name
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
assert_select "section.custom_wrapper div.another_wrapper label"
|
|
249
|
+
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
test 'simple_fields_form reuses custom wrapper mapping per form basis' do
|
|
253
|
+
@user.company = Company.new(1, 'Empresa')
|
|
254
|
+
|
|
255
|
+
swap_wrapper :another do
|
|
256
|
+
with_concat_form_for @user, wrapper_mappings: { string: :another } do |f|
|
|
257
|
+
concat(f.simple_fields_for(:company) do |company_form|
|
|
258
|
+
concat(company_form.input(:name))
|
|
259
|
+
end)
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
assert_select "section.custom_wrapper div.another_wrapper label"
|
|
264
|
+
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
test "input attributes class will merge with wrapper_options' classes" do
|
|
268
|
+
swap_wrapper :default, custom_wrapper_with_input_class do
|
|
269
|
+
with_concat_form_for @user do |f|
|
|
270
|
+
concat f.input :name, input_html: { class: 'another-class' }
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
assert_select "div.custom_wrapper input.string.inline-class.another-class"
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
test "input with data attributes will merge with wrapper_options' data" do
|
|
278
|
+
swap_wrapper :default, custom_wrapper_with_input_data_modal do
|
|
279
|
+
with_concat_form_for @user do |f|
|
|
280
|
+
concat f.input :name, input_html: { data: { modal: 'another-data', target: 'merge-data' } }
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
assert_select "input[data-wrapper='data-wrapper'][data-modal='another-data'][data-target='merge-data']"
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
test "input with aria attributes will merge with wrapper_options' aria" do
|
|
288
|
+
swap_wrapper :default, custom_wrapper_with_input_aria_modal do
|
|
289
|
+
with_concat_form_for @user do |f|
|
|
290
|
+
concat f.input :name, input_html: { aria: { modal: 'another-aria', target: 'merge-aria' } }
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
assert_select "input[aria-wrapper='aria-wrapper'][aria-modal='another-aria'][aria-target='merge-aria']"
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
test 'input accepts attributes in the DSL' do
|
|
298
|
+
swap_wrapper :default, custom_wrapper_with_input_class do
|
|
299
|
+
with_concat_form_for @user do |f|
|
|
300
|
+
concat f.input :name
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
assert_select "div.custom_wrapper input.string.inline-class"
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
test 'label accepts attributes in the DSL' do
|
|
308
|
+
swap_wrapper :default, custom_wrapper_with_label_class do
|
|
309
|
+
with_concat_form_for @user do |f|
|
|
310
|
+
concat f.input :name
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
assert_select "div.custom_wrapper label.string.inline-class"
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
test 'label_input accepts attributes in the DSL' do
|
|
318
|
+
swap_wrapper :default, custom_wrapper_with_label_input_class do
|
|
319
|
+
with_concat_form_for @user do |f|
|
|
320
|
+
concat f.input :name
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
assert_select "div.custom_wrapper label.string.inline-class"
|
|
325
|
+
assert_select "div.custom_wrapper input.string.inline-class"
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
test 'input accepts data attributes in the DSL' do
|
|
329
|
+
swap_wrapper :default, custom_wrapper_with_input_attributes do
|
|
330
|
+
with_concat_form_for @user do |f|
|
|
331
|
+
concat f.input :name
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
assert_select "div.custom_wrapper input.string[data-modal=true]"
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
test 'inline wrapper displays when there is content' do
|
|
339
|
+
swap_wrapper :default, custom_wrapper_with_wrapped_optional_component do
|
|
340
|
+
with_form_for @user, :name, hint: "cannot be blank"
|
|
341
|
+
assert_select 'section.custom_wrapper div.no_output_wrapper p.omg_hint', "cannot be blank"
|
|
342
|
+
assert_select 'p.omg_hint'
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
test 'inline wrapper does not display when there is no content' do
|
|
347
|
+
swap_wrapper :default, custom_wrapper_with_wrapped_optional_component do
|
|
348
|
+
with_form_for @user, :name
|
|
349
|
+
assert_select 'section.custom_wrapper div.no_output_wrapper'
|
|
350
|
+
assert_no_select 'p.omg_hint'
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
test 'optional wrapper does not display when there is content' do
|
|
355
|
+
swap_wrapper :default, custom_wrapper_with_unless_blank do
|
|
356
|
+
with_form_for @user, :name, hint: "can't be blank"
|
|
357
|
+
assert_select 'section.custom_wrapper div.no_output_wrapper'
|
|
358
|
+
assert_select 'div.no_output_wrapper'
|
|
359
|
+
assert_select 'p.omg_hint'
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
test 'optional wrapper does not display when there is no content' do
|
|
364
|
+
swap_wrapper :default, custom_wrapper_with_unless_blank do
|
|
365
|
+
with_form_for @user, :name
|
|
366
|
+
assert_no_select 'section.custom_wrapper div.no_output_wrapper'
|
|
367
|
+
assert_no_select 'div.no_output_wrapper'
|
|
368
|
+
assert_no_select 'p.omg_hint'
|
|
369
|
+
end
|
|
370
|
+
end
|
|
203
371
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
|
@@ -18,22 +19,22 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
test 'generates the simple_form initializer with the bootstrap wrappers' do
|
|
21
|
-
run_generator %w
|
|
22
|
+
run_generator %w[--bootstrap]
|
|
22
23
|
assert_file 'config/initializers/simple_form.rb',
|
|
23
24
|
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
|
24
|
-
assert_file 'config/initializers/simple_form_bootstrap.rb', /config\.wrappers :
|
|
25
|
-
/config\.default_wrapper = :
|
|
25
|
+
assert_file 'config/initializers/simple_form_bootstrap.rb', /config\.wrappers :vertical_form/,
|
|
26
|
+
/config\.wrappers :horizontal_form/, /config\.default_wrapper = :vertical_form/
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
test 'generates the simple_form initializer with the foundation wrappers' do
|
|
29
|
-
run_generator %w
|
|
30
|
+
run_generator %w[--foundation]
|
|
30
31
|
assert_file 'config/initializers/simple_form.rb',
|
|
31
32
|
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
|
32
|
-
assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :
|
|
33
|
-
/config\.default_wrapper = :
|
|
33
|
+
assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :vertical_form/,
|
|
34
|
+
/config\.default_wrapper = :vertical_form/, /config\.item_wrapper_tag = :div/
|
|
34
35
|
end
|
|
35
36
|
|
|
36
|
-
%
|
|
37
|
+
%w[erb haml slim].each do |engine|
|
|
37
38
|
test "generates the scaffold template when using #{engine}" do
|
|
38
39
|
run_generator ['-e', engine]
|
|
39
40
|
assert_file "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
require 'test_helper'
|
|
3
4
|
|
|
4
5
|
class BooleanInputTest < ActionView::TestCase
|
|
5
|
-
test 'input
|
|
6
|
+
test 'input generates a checkbox by default for boolean attributes' do
|
|
6
7
|
with_input_for @user, :active, :boolean
|
|
7
8
|
assert_select 'input[type=checkbox].boolean#user_active'
|
|
8
9
|
assert_select 'label.boolean.optional', 'Active'
|
|
@@ -49,15 +50,43 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
49
50
|
|
|
50
51
|
test 'input boolean with nested allows :inline_label' do
|
|
51
52
|
swap SimpleForm, boolean_style: :nested do
|
|
52
|
-
with_input_for @user, :active, :boolean,
|
|
53
|
-
assert_select 'label.checkbox', text: 'I am so inline.'
|
|
53
|
+
with_input_for @user, :active, :boolean, inline_label: 'I am so inline.'
|
|
54
|
+
assert_select 'label.checkbox', text: ' I am so inline.'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
test 'input boolean with nested escapes :inline_label with HTML' do
|
|
59
|
+
swap SimpleForm, boolean_style: :nested do
|
|
60
|
+
with_input_for @user, :active, :boolean, inline_label: '<b>I am so inline.</b>'
|
|
61
|
+
assert_no_select 'label.checkbox b'
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test 'input boolean with nested allows :inline_label with HTML when safe' do
|
|
66
|
+
swap SimpleForm, boolean_style: :nested do
|
|
67
|
+
with_input_for @user, :active, :boolean, inline_label: '<b>I am so inline.</b>'.html_safe
|
|
68
|
+
assert_select 'label.checkbox b', text: 'I am so inline.'
|
|
54
69
|
end
|
|
55
70
|
end
|
|
56
71
|
|
|
57
72
|
test 'input boolean with nested style creates an inline label using the default label text when inline_label option set to true' do
|
|
58
73
|
swap SimpleForm, boolean_style: :nested do
|
|
59
|
-
with_input_for @user, :active, :boolean,
|
|
60
|
-
assert_select 'label.checkbox', text: 'Active'
|
|
74
|
+
with_input_for @user, :active, :boolean, inline_label: true
|
|
75
|
+
assert_select 'label.checkbox', text: ' Active'
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
test 'input boolean with nested style creates an inline label using the label text when inline_label option set to true' do
|
|
80
|
+
swap SimpleForm, boolean_style: :nested do
|
|
81
|
+
with_input_for @user, :active, :boolean, inline_label: true, label_text: proc { 'New Active' }
|
|
82
|
+
assert_select 'label.checkbox', text: ' New Active'
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
test 'input boolean with nested style creates an inline label using the label html when inline_label option set to true' do
|
|
87
|
+
swap SimpleForm, boolean_style: :nested do
|
|
88
|
+
with_input_for @user, :active, :boolean, inline_label: true, label_text: proc { '<b>New Active</b>' }
|
|
89
|
+
assert_select 'label.checkbox', text: ' New Active'
|
|
61
90
|
end
|
|
62
91
|
end
|
|
63
92
|
|
|
@@ -109,6 +138,22 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
109
138
|
end
|
|
110
139
|
end
|
|
111
140
|
|
|
141
|
+
test 'input with nested style allows disabling hidden field' do
|
|
142
|
+
swap SimpleForm, boolean_style: :nested do
|
|
143
|
+
with_input_for @user, :active, :boolean, include_hidden: false
|
|
144
|
+
assert_select "label.boolean > input.boolean"
|
|
145
|
+
assert_no_select "input[type=hidden] + label.boolean"
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
test 'input with nested style does not include hidden field when unchecked_value is false' do
|
|
150
|
+
swap SimpleForm, boolean_style: :nested do
|
|
151
|
+
with_input_for @user, :active, :boolean, unchecked_value: false
|
|
152
|
+
assert_select "label.boolean > input.boolean"
|
|
153
|
+
assert_no_select "input[type=hidden] + label.boolean"
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
112
157
|
test 'input boolean works using :input only in wrapper config (no label_input)' do
|
|
113
158
|
swap_wrapper do
|
|
114
159
|
with_input_for @user, :active, :boolean
|
|
@@ -128,6 +173,26 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
128
173
|
end
|
|
129
174
|
end
|
|
130
175
|
|
|
176
|
+
test 'input boolean allows specifying boolean_label_class on a per-input basis' do
|
|
177
|
+
swap_wrapper do
|
|
178
|
+
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
|
179
|
+
with_input_for @user, :active, :boolean, boolean_label_class: 'baz'
|
|
180
|
+
|
|
181
|
+
assert_select 'label.boolean + input[type=hidden] + label.baz > input.boolean'
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
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
|
|
187
|
+
swap_wrapper do
|
|
188
|
+
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
|
189
|
+
with_input_for @user, :active, :boolean
|
|
190
|
+
|
|
191
|
+
assert_select 'label.boolean + input[type=hidden] + label.foo > input.boolean'
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
131
196
|
test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
|
|
132
197
|
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
|
133
198
|
swap SimpleForm, boolean_style: :nested do
|
|
@@ -138,7 +203,17 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
138
203
|
end
|
|
139
204
|
end
|
|
140
205
|
|
|
141
|
-
test 'input boolean
|
|
206
|
+
test 'input boolean with nested style works using :label_input in wrapper config, adding custom class to label' do
|
|
207
|
+
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
|
208
|
+
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
|
209
|
+
with_input_for @user, :active, :boolean
|
|
210
|
+
|
|
211
|
+
assert_select 'input[type=hidden] + label.boolean.foo > input.boolean'
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
test 'input boolean without additional classes adds "checkbox" class to label' do
|
|
142
217
|
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
|
143
218
|
swap SimpleForm, boolean_style: :nested, generate_additional_classes_for: [:input] do
|
|
144
219
|
with_input_for @user, :active, :boolean
|
|
@@ -149,4 +224,12 @@ class BooleanInputTest < ActionView::TestCase
|
|
|
149
224
|
end
|
|
150
225
|
end
|
|
151
226
|
end
|
|
227
|
+
|
|
228
|
+
test 'input boolean works with wrapper config defining a class for the input' do
|
|
229
|
+
swap_wrapper :default, self.custom_wrapper_with_input_class do
|
|
230
|
+
with_input_for @user, :active, :boolean
|
|
231
|
+
|
|
232
|
+
assert_select 'input.boolean.inline-class'
|
|
233
|
+
end
|
|
234
|
+
end
|
|
152
235
|
end
|