simple_form 5.2.0 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/MIT-LICENSE +1 -1
- data/README.md +3 -4
- data/lib/simple_form/components/label_input.rb +1 -1
- data/lib/simple_form/form_builder.rb +1 -5
- 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 +8 -4
- metadata +5 -85
- 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 -256
- 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/country_input_test.rb +0 -36
- 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 -196
- data/test/inputs/hidden_input_test.rb +0 -32
- data/test/inputs/numeric_input_test.rb +0 -177
- 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/inputs/time_zone_input_test.rb +0 -36
- 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.to_s.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.to_s.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,256 +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 allows skipping hidden input when setting :include_hidden to false' do
|
37
|
-
with_input_for @user, :active, :boolean, include_hidden: false
|
38
|
-
assert_no_select "input[type=hidden][name='user[active]']"
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'input uses inline boolean style by default' do
|
42
|
-
with_input_for @user, :active, :boolean
|
43
|
-
assert_select 'input.boolean + label.boolean.optional'
|
44
|
-
assert_no_select 'label > input'
|
45
|
-
end
|
46
|
-
|
47
|
-
test 'input allows changing default boolean style config to nested, generating a default label and a manual hidden field for checkbox' do
|
48
|
-
swap SimpleForm, boolean_style: :nested do
|
49
|
-
with_input_for @user, :active, :boolean
|
50
|
-
assert_select 'label[for=user_active]', 'Active'
|
51
|
-
assert_select 'label.boolean > input.boolean'
|
52
|
-
assert_no_select 'input[type=checkbox] + label'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
test 'input boolean with nested allows :inline_label' do
|
57
|
-
swap SimpleForm, boolean_style: :nested do
|
58
|
-
with_input_for @user, :active, :boolean, inline_label: 'I am so inline.'
|
59
|
-
assert_select 'label.checkbox', text: ' I am so inline.'
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
test 'input boolean with nested escapes :inline_label with HTML' do
|
64
|
-
swap SimpleForm, boolean_style: :nested do
|
65
|
-
with_input_for @user, :active, :boolean, inline_label: '<b>I am so inline.</b>'
|
66
|
-
assert_no_select 'label.checkbox b'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
test 'input boolean with nested allows :inline_label with HTML when safe' do
|
71
|
-
swap SimpleForm, boolean_style: :nested do
|
72
|
-
with_input_for @user, :active, :boolean, inline_label: '<b>I am so inline.</b>'.html_safe
|
73
|
-
assert_select 'label.checkbox b', text: 'I am so inline.'
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
test 'input boolean with nested style creates an inline label using the default label text when inline_label option set to true' do
|
78
|
-
swap SimpleForm, boolean_style: :nested do
|
79
|
-
with_input_for @user, :active, :boolean, inline_label: true
|
80
|
-
assert_select 'label.checkbox', text: ' Active'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'input boolean with nested style creates an inline label using the label text when inline_label option set to true' do
|
85
|
-
swap SimpleForm, boolean_style: :nested do
|
86
|
-
with_input_for @user, :active, :boolean, inline_label: true, label_text: proc { 'New Active' }
|
87
|
-
assert_select 'label.checkbox', text: ' New Active'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
test 'input boolean with nested style creates an inline label using the label html when inline_label option set to true' do
|
92
|
-
swap SimpleForm, boolean_style: :nested do
|
93
|
-
with_input_for @user, :active, :boolean, inline_label: true, label_text: proc { '<b>New Active</b>' }
|
94
|
-
assert_select 'label.checkbox', text: ' New Active'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
test 'input boolean with nested generates a manual hidden field for checkbox outside the label, to recreate Rails functionality with valid html5' do
|
99
|
-
swap SimpleForm, boolean_style: :nested do
|
100
|
-
with_input_for @user, :active, :boolean
|
101
|
-
|
102
|
-
assert_select "input[type=hidden][name='user[active]'] + label.boolean > input.boolean"
|
103
|
-
assert_no_select 'input[type=checkbox] + label'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'input boolean with nested generates a disabled hidden field for checkbox outside the label, if the field is disabled' do
|
108
|
-
swap SimpleForm, boolean_style: :nested do
|
109
|
-
with_input_for @user, :active, :boolean, disabled: true
|
110
|
-
|
111
|
-
assert_select "input[type=hidden][name='user[active]'][disabled] + label.boolean > input.boolean[disabled]"
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
test 'input boolean with nested generates a disabled hidden field with the form attribute when it is given' do
|
116
|
-
swap SimpleForm, boolean_style: :nested do
|
117
|
-
with_input_for @user, :active, :boolean, input_html: { form: 'form_id' }
|
118
|
-
|
119
|
-
assert_select "input[type=hidden][form=form_id]+ label.boolean > input.boolean"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
test 'input accepts changing boolean style to nested through given options' do
|
124
|
-
with_input_for @user, :active, :boolean, boolean_style: :nested
|
125
|
-
assert_select 'label[for=user_active]', 'Active'
|
126
|
-
assert_select 'label.boolean > input.boolean'
|
127
|
-
assert_no_select 'input[type=checkbox] + label'
|
128
|
-
end
|
129
|
-
|
130
|
-
test 'input accepts changing boolean style to inline through given options, when default is nested' do
|
131
|
-
swap SimpleForm, boolean_style: :nested do
|
132
|
-
with_input_for @user, :active, :boolean, boolean_style: :inline
|
133
|
-
assert_select 'label[for=user_active]', 'Active'
|
134
|
-
assert_select 'input.boolean + label.boolean'
|
135
|
-
assert_no_select 'label > input'
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
test 'input with nested style allows disabling label' do
|
140
|
-
swap SimpleForm, boolean_style: :nested do
|
141
|
-
with_input_for @user, :active, :boolean, label: false
|
142
|
-
assert_select 'input.boolean'
|
143
|
-
assert_no_select 'label.boolean'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
test 'input with nested style allows customizing input_html' do
|
148
|
-
swap SimpleForm, boolean_style: :nested do
|
149
|
-
with_input_for @user, :active, :boolean, input_html: { name: 'active_user' }
|
150
|
-
assert_select "input[type=hidden][name=active_user] + label.boolean > input.boolean[name=active_user]"
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
test 'input with nested style allows disabling hidden field' do
|
155
|
-
swap SimpleForm, boolean_style: :nested do
|
156
|
-
with_input_for @user, :active, :boolean, include_hidden: false
|
157
|
-
assert_select "label.boolean > input.boolean"
|
158
|
-
assert_no_select "input[type=hidden] + label.boolean"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
test 'input with nested style and with single wrapper allows disabling hidden field' do
|
163
|
-
swap SimpleForm, boolean_style: :nested do
|
164
|
-
with_input_for @user, :active, :boolean, include_hidden: false, wrapper: custom_wrapper_with_wrapped_label_input
|
165
|
-
assert_select "label.boolean > input.boolean"
|
166
|
-
assert_no_select "input[type=hidden] + label.boolean"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
test 'input with nested style does not include hidden field when unchecked_value is false' do
|
171
|
-
swap SimpleForm, boolean_style: :nested do
|
172
|
-
with_input_for @user, :active, :boolean, unchecked_value: false
|
173
|
-
assert_select "label.boolean > input.boolean"
|
174
|
-
assert_no_select "input[type=hidden] + label.boolean"
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
test 'input boolean works using :input only in wrapper config (no label_input)' do
|
179
|
-
swap_wrapper do
|
180
|
-
with_input_for @user, :active, :boolean
|
181
|
-
|
182
|
-
assert_select 'label.boolean + input[type=hidden] + input.boolean'
|
183
|
-
assert_no_select 'label.checkbox'
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra "checkbox" label wrapper' do
|
188
|
-
swap_wrapper do
|
189
|
-
swap SimpleForm, boolean_style: :nested do
|
190
|
-
with_input_for @user, :active, :boolean
|
191
|
-
|
192
|
-
assert_select 'label.boolean + input[type=hidden] + label.checkbox > input.boolean'
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
test 'input boolean allows specifying boolean_label_class on a per-input basis' do
|
198
|
-
swap_wrapper do
|
199
|
-
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
200
|
-
with_input_for @user, :active, :boolean, boolean_label_class: 'baz'
|
201
|
-
|
202
|
-
assert_select 'label.boolean + input[type=hidden] + label.baz > input.boolean'
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
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
|
208
|
-
swap_wrapper do
|
209
|
-
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
210
|
-
with_input_for @user, :active, :boolean
|
211
|
-
|
212
|
-
assert_select 'label.boolean + input[type=hidden] + label.foo > input.boolean'
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
|
218
|
-
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
219
|
-
swap SimpleForm, boolean_style: :nested do
|
220
|
-
with_input_for @user, :active, :boolean
|
221
|
-
|
222
|
-
assert_select 'input[type=hidden] + label.boolean.checkbox > input.boolean'
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
test 'input boolean with nested style works using :label_input in wrapper config, adding custom class to label' do
|
228
|
-
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
229
|
-
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
230
|
-
with_input_for @user, :active, :boolean
|
231
|
-
|
232
|
-
assert_select 'input[type=hidden] + label.boolean.foo > input.boolean'
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
test 'input boolean without additional classes adds "checkbox" class to label' do
|
238
|
-
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
239
|
-
swap SimpleForm, boolean_style: :nested, generate_additional_classes_for: [:input] do
|
240
|
-
with_input_for @user, :active, :boolean
|
241
|
-
|
242
|
-
assert_select 'label'
|
243
|
-
assert_select 'label.checkbox'
|
244
|
-
assert_no_select 'label.boolean'
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
test 'input boolean works with wrapper config defining a class for the input' do
|
250
|
-
swap_wrapper :default, self.custom_wrapper_with_input_class do
|
251
|
-
with_input_for @user, :active, :boolean
|
252
|
-
|
253
|
-
assert_select 'input.boolean.inline-class'
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|