simple_form 5.0.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 +49 -8
- data/MIT-LICENSE +2 -1
- data/README.md +96 -51
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +2 -3
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +127 -195
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/simple_form/components/label_input.rb +1 -1
- data/lib/simple_form/components/labels.rb +3 -5
- data/lib/simple_form/components/maxlength.rb +0 -4
- data/lib/simple_form/components/minlength.rb +0 -4
- data/lib/simple_form/form_builder.rb +7 -10
- data/lib/simple_form/inputs/base.rb +0 -3
- data/lib/simple_form/inputs/boolean_input.rb +6 -2
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +1 -1
- data/lib/simple_form/inputs/collection_input.rb +3 -5
- 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/inputs/rich_text_area_input.rb +12 -0
- data/lib/simple_form/inputs.rb +1 -0
- 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/wrappers/root.rb +8 -3
- data/lib/simple_form.rb +10 -6
- metadata +22 -93
- data/lib/simple_form/i18n_cache.rb +0 -23
- 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 -356
- 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 -534
- 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 -371
- 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 -327
- data/test/inputs/collection_radio_buttons_input_test.rb +0 -450
- data/test/inputs/collection_select_input_test.rb +0 -378
- 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/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 -353
- data/test/test_helper.rb +0 -95
|
@@ -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
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
# encoding: UTF-8
|
|
3
|
-
require 'test_helper'
|
|
4
|
-
|
|
5
|
-
class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
6
|
-
setup do
|
|
7
|
-
SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
test 'input check boxes does not include for attribute by default' do
|
|
11
|
-
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
|
12
|
-
assert_select 'label'
|
|
13
|
-
assert_no_select 'label[for=user_gender]'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
test 'input check boxes includes for attribute when giving as html option' do
|
|
17
|
-
with_input_for @user, :gender, :check_boxes, collection: %i[male female], label_html: { for: 'gender' }
|
|
18
|
-
assert_select 'label[for=gender]'
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
test 'collection input with check_boxes type does not generate required html attribute' do
|
|
22
|
-
with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
|
|
23
|
-
assert_select 'input.required'
|
|
24
|
-
assert_no_select 'input[required]'
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
test 'collection input with check_boxes type does not generate aria-required html attribute' do
|
|
28
|
-
with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
|
|
29
|
-
assert_select 'input.required'
|
|
30
|
-
assert_no_select 'input[aria-required]'
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test 'input does automatic collection translation for check_box types using defaults key' do
|
|
34
|
-
store_translations(:en, simple_form: { options: { defaults: {
|
|
35
|
-
gender: { male: 'Male', female: 'Female' }
|
|
36
|
-
} } } ) do
|
|
37
|
-
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
|
38
|
-
assert_select 'input[type=checkbox][value=male]'
|
|
39
|
-
assert_select 'input[type=checkbox][value=female]'
|
|
40
|
-
assert_select 'label.collection_check_boxes', 'Male'
|
|
41
|
-
assert_select 'label.collection_check_boxes', 'Female'
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
test 'input does automatic collection translation for check_box types using specific object key' do
|
|
46
|
-
store_translations(:en, simple_form: { options: { user: {
|
|
47
|
-
gender: { male: 'Male', female: 'Female' }
|
|
48
|
-
} } } ) do
|
|
49
|
-
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
|
50
|
-
assert_select 'input[type=checkbox][value=male]'
|
|
51
|
-
assert_select 'input[type=checkbox][value=female]'
|
|
52
|
-
assert_select 'label.collection_check_boxes', 'Male'
|
|
53
|
-
assert_select 'label.collection_check_boxes', 'Female'
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
test 'input that uses automatic collection translation for check_boxes properly sets checked values' do
|
|
58
|
-
store_translations(:en, simple_form: { options: { defaults: {
|
|
59
|
-
gender: { male: 'Male', female: 'Female' }
|
|
60
|
-
} } } ) do
|
|
61
|
-
@user.gender = 'male'
|
|
62
|
-
|
|
63
|
-
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
|
64
|
-
assert_select 'input[type=checkbox][value=male][checked=checked]'
|
|
65
|
-
assert_select 'input[type=checkbox][value=female]'
|
|
66
|
-
assert_select 'label.collection_check_boxes', 'Male'
|
|
67
|
-
assert_select 'label.collection_check_boxes', 'Female'
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
test 'input check boxes does not wrap the collection by default' do
|
|
72
|
-
with_input_for @user, :active, :check_boxes
|
|
73
|
-
|
|
74
|
-
assert_select 'form input[type=checkbox]', count: 2
|
|
75
|
-
assert_no_select 'form ul'
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
test 'input check boxes accepts html options as the last element of collection' do
|
|
79
|
-
with_input_for @user, :name, :check_boxes, collection: [['Jose', 'jose', class: 'foo']]
|
|
80
|
-
assert_select 'input.foo[type=checkbox][value=jose]'
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
test 'input check boxes wraps the collection in the configured collection wrapper tag' do
|
|
84
|
-
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
85
|
-
with_input_for @user, :active, :check_boxes
|
|
86
|
-
|
|
87
|
-
assert_select 'form ul input[type=checkbox]', count: 2
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
test 'input check boxes does not wrap the collection when configured with falsy values' do
|
|
92
|
-
swap SimpleForm, collection_wrapper_tag: false do
|
|
93
|
-
with_input_for @user, :active, :check_boxes
|
|
94
|
-
|
|
95
|
-
assert_select 'form input[type=checkbox]', count: 2
|
|
96
|
-
assert_no_select 'form ul'
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
test 'input check boxes allows overriding the collection wrapper tag at input level' do
|
|
101
|
-
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
102
|
-
with_input_for @user, :active, :check_boxes, collection_wrapper_tag: :section
|
|
103
|
-
|
|
104
|
-
assert_select 'form section input[type=checkbox]', count: 2
|
|
105
|
-
assert_no_select 'form ul'
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
test 'input check boxes allows disabling the collection wrapper tag at input level' do
|
|
110
|
-
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
111
|
-
with_input_for @user, :active, :check_boxes, collection_wrapper_tag: false
|
|
112
|
-
|
|
113
|
-
assert_select 'form input[type=checkbox]', count: 2
|
|
114
|
-
assert_no_select 'form ul'
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
test 'input check boxes renders the wrapper tag with the configured wrapper class' do
|
|
119
|
-
swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
|
|
120
|
-
with_input_for @user, :active, :check_boxes
|
|
121
|
-
|
|
122
|
-
assert_select 'form ul.inputs-list input[type=checkbox]', count: 2
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
test 'input check boxes allows giving wrapper class at input level only' do
|
|
127
|
-
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
128
|
-
with_input_for @user, :active, :check_boxes, collection_wrapper_class: 'items-list'
|
|
129
|
-
|
|
130
|
-
assert_select 'form ul.items-list input[type=checkbox]', count: 2
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
test 'input check boxes uses both configured and given wrapper classes for wrapper tag' do
|
|
135
|
-
swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
|
|
136
|
-
with_input_for @user, :active, :check_boxes, collection_wrapper_class: 'items-list'
|
|
137
|
-
|
|
138
|
-
assert_select 'form ul.inputs-list.items-list input[type=checkbox]', count: 2
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
test 'input check boxes wraps each item in the configured item wrapper tag' do
|
|
143
|
-
swap SimpleForm, item_wrapper_tag: :li do
|
|
144
|
-
with_input_for @user, :active, :check_boxes
|
|
145
|
-
|
|
146
|
-
assert_select 'form li input[type=checkbox]', count: 2
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
test 'input check boxes does not wrap items when configured with falsy values' do
|
|
151
|
-
swap SimpleForm, item_wrapper_tag: false do
|
|
152
|
-
with_input_for @user, :active, :check_boxes
|
|
153
|
-
|
|
154
|
-
assert_select 'form input[type=checkbox]', count: 2
|
|
155
|
-
assert_no_select 'form li'
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
test 'input check boxes allows overriding the item wrapper tag at input level' do
|
|
160
|
-
swap SimpleForm, item_wrapper_tag: :li do
|
|
161
|
-
with_input_for @user, :active, :check_boxes, item_wrapper_tag: :dl
|
|
162
|
-
|
|
163
|
-
assert_select 'form dl input[type=checkbox]', count: 2
|
|
164
|
-
assert_no_select 'form li'
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
test 'input check boxes allows disabling the item wrapper tag at input level' do
|
|
169
|
-
swap SimpleForm, item_wrapper_tag: :ul do
|
|
170
|
-
with_input_for @user, :active, :check_boxes, item_wrapper_tag: false
|
|
171
|
-
|
|
172
|
-
assert_select 'form input[type=checkbox]', count: 2
|
|
173
|
-
assert_no_select 'form li'
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
test 'input check boxes wraps items in a span tag by default' do
|
|
178
|
-
with_input_for @user, :active, :check_boxes
|
|
179
|
-
|
|
180
|
-
assert_select 'form span input[type=checkbox]', count: 2
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
test 'input check boxes renders the item wrapper tag with a default class "checkbox"' do
|
|
184
|
-
with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
|
|
185
|
-
|
|
186
|
-
assert_select 'form li.checkbox input[type=checkbox]', count: 2
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
test 'input check boxes renders the item wrapper tag with the configured item wrapper class' do
|
|
190
|
-
swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
|
|
191
|
-
with_input_for @user, :active, :check_boxes
|
|
192
|
-
|
|
193
|
-
assert_select 'form li.checkbox.item input[type=checkbox]', count: 2
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
test 'input check boxes allows giving item wrapper class at input level only' do
|
|
198
|
-
swap SimpleForm, item_wrapper_tag: :li do
|
|
199
|
-
with_input_for @user, :active, :check_boxes, item_wrapper_class: 'item'
|
|
200
|
-
|
|
201
|
-
assert_select 'form li.checkbox.item input[type=checkbox]', count: 2
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
test 'input check boxes uses both configured and given item wrapper classes for item wrapper tag' do
|
|
206
|
-
swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
|
|
207
|
-
with_input_for @user, :active, :check_boxes, item_wrapper_class: 'inline'
|
|
208
|
-
|
|
209
|
-
assert_select 'form li.checkbox.item.inline input[type=checkbox]', count: 2
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
test 'input check boxes respects the nested boolean style config, generating nested label > input' do
|
|
214
|
-
swap SimpleForm, boolean_style: :nested do
|
|
215
|
-
with_input_for @user, :active, :check_boxes
|
|
216
|
-
|
|
217
|
-
assert_select 'span.checkbox > label > input#user_active_true[type=checkbox]'
|
|
218
|
-
assert_select 'span.checkbox > label', 'Yes'
|
|
219
|
-
assert_select 'span.checkbox > label > input#user_active_false[type=checkbox]'
|
|
220
|
-
assert_select 'span.checkbox > label', 'No'
|
|
221
|
-
assert_no_select 'label.collection_radio_buttons'
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
test 'input check boxes with nested style does not overrides configured item wrapper tag' do
|
|
226
|
-
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
|
|
227
|
-
with_input_for @user, :active, :check_boxes
|
|
228
|
-
|
|
229
|
-
assert_select 'li.checkbox > label > input'
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
test 'input check boxes with nested style does not overrides given item wrapper tag' do
|
|
234
|
-
swap SimpleForm, boolean_style: :nested do
|
|
235
|
-
with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
|
|
236
|
-
|
|
237
|
-
assert_select 'li.checkbox > label > input'
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
test 'input check boxes with nested style accepts giving extra wrapper classes' do
|
|
242
|
-
swap SimpleForm, boolean_style: :nested do
|
|
243
|
-
with_input_for @user, :active, :check_boxes, item_wrapper_class: "inline"
|
|
244
|
-
|
|
245
|
-
assert_select 'span.checkbox.inline > label > input'
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
test 'input check boxes with nested style renders item labels with specified class' do
|
|
250
|
-
swap SimpleForm, boolean_style: :nested do
|
|
251
|
-
with_input_for @user, :active, :check_boxes, item_label_class: "test"
|
|
252
|
-
|
|
253
|
-
assert_select 'span.checkbox > label.test > input'
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
test 'input check boxes with nested style and falsey input wrapper renders item labels with specified class' do
|
|
258
|
-
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: false do
|
|
259
|
-
with_input_for @user, :active, :check_boxes, item_label_class: "checkbox-inline"
|
|
260
|
-
|
|
261
|
-
assert_select 'label.checkbox-inline > input'
|
|
262
|
-
assert_no_select 'span.checkbox'
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
test 'input check boxes wrapper class are not included when set to falsey' do
|
|
267
|
-
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
268
|
-
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
|
269
|
-
|
|
270
|
-
assert_no_select 'label.checkbox'
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
|
|
275
|
-
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
276
|
-
with_input_for @user, :gender, :check_boxes, collection: %i[male female], item_wrapper_class: 'custom'
|
|
277
|
-
|
|
278
|
-
assert_no_select 'label.checkbox'
|
|
279
|
-
assert_select 'span.custom'
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
test 'input check boxes with nested style and namespace uses the right for attribute' do
|
|
284
|
-
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
285
|
-
with_concat_form_for @user, namespace: :foo do |f|
|
|
286
|
-
concat f.input :gender, as: :check_boxes, collection: %i[male female]
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
assert_select 'label[for=foo_user_gender_male]'
|
|
290
|
-
assert_select 'label[for=foo_user_gender_female]'
|
|
291
|
-
end
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
test 'input check boxes with nested style and index uses the right for attribute' do
|
|
295
|
-
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
296
|
-
with_concat_form_for @user, index: 1 do |f|
|
|
297
|
-
concat f.input :gender, as: :check_boxes, collection: %i[male female]
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
assert_select 'label[for=user_1_gender_male]'
|
|
301
|
-
assert_select 'label[for=user_1_gender_female]'
|
|
302
|
-
end
|
|
303
|
-
end
|
|
304
|
-
|
|
305
|
-
test 'input check boxes with nested style accepts non-string attribute as label' do
|
|
306
|
-
swap SimpleForm, boolean_style: :nested do
|
|
307
|
-
with_input_for @user, :amount,
|
|
308
|
-
:check_boxes,
|
|
309
|
-
collection: { 100 => 'hundred', 200 => 'two_hundred' },
|
|
310
|
-
label_method: :first,
|
|
311
|
-
value_method: :second
|
|
312
|
-
|
|
313
|
-
assert_select 'input[type=checkbox][value=hundred]'
|
|
314
|
-
assert_select 'input[type=checkbox][value=two_hundred]'
|
|
315
|
-
assert_select 'span.checkbox > label', '100'
|
|
316
|
-
assert_select 'span.checkbox > label', '200'
|
|
317
|
-
end
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
test 'input check boxes with inline style support label custom classes' do
|
|
321
|
-
swap SimpleForm, boolean_style: :inline do
|
|
322
|
-
with_input_for @user, :gender, :check_boxes, collection: %i[male female], item_label_class: 'beautiful-label'
|
|
323
|
-
|
|
324
|
-
assert_select 'label.beautiful-label', count: 2
|
|
325
|
-
end
|
|
326
|
-
end
|
|
327
|
-
end
|