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