simple_form_awesome 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +327 -0
- data/MIT-LICENSE +20 -0
- data/README.md +25 -0
- data/lib/generators/simple_form/USAGE +3 -0
- data/lib/generators/simple_form/install_generator.rb +48 -0
- data/lib/generators/simple_form/templates/AUI_README +19 -0
- data/lib/generators/simple_form/templates/README +12 -0
- data/lib/generators/simple_form/templates/_form.html.erb +13 -0
- data/lib/generators/simple_form/templates/_form.html.haml +10 -0
- data/lib/generators/simple_form/templates/_form.html.slim +10 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +142 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_aui.rb +21 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +26 -0
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +26 -0
- data/lib/simple_form/action_view_extensions/builder.rb +340 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +72 -0
- data/lib/simple_form/components/errors.rb +35 -0
- data/lib/simple_form/components/hints.rb +18 -0
- data/lib/simple_form/components/html5.rb +26 -0
- data/lib/simple_form/components/label_input.rb +15 -0
- data/lib/simple_form/components/labels.rb +79 -0
- data/lib/simple_form/components/maxlength.rb +41 -0
- data/lib/simple_form/components/min_max.rb +50 -0
- data/lib/simple_form/components/pattern.rb +34 -0
- data/lib/simple_form/components/placeholders.rb +16 -0
- data/lib/simple_form/components/readonly.rb +22 -0
- data/lib/simple_form/components.rb +20 -0
- data/lib/simple_form/core_ext/hash.rb +16 -0
- data/lib/simple_form/error_notification.rb +48 -0
- data/lib/simple_form/form_builder.rb +482 -0
- data/lib/simple_form/helpers/autofocus.rb +11 -0
- data/lib/simple_form/helpers/disabled.rb +15 -0
- data/lib/simple_form/helpers/readonly.rb +15 -0
- data/lib/simple_form/helpers/required.rb +35 -0
- data/lib/simple_form/helpers/validators.rb +44 -0
- data/lib/simple_form/helpers.rb +12 -0
- data/lib/simple_form/i18n_cache.rb +22 -0
- data/lib/simple_form/inputs/aui_string_input.rb +10 -0
- data/lib/simple_form/inputs/base.rb +184 -0
- data/lib/simple_form/inputs/block_input.rb +14 -0
- data/lib/simple_form/inputs/boolean_input.rb +78 -0
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
- data/lib/simple_form/inputs/collection_input.rb +101 -0
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +63 -0
- data/lib/simple_form/inputs/collection_select_input.rb +14 -0
- data/lib/simple_form/inputs/date_time_input.rb +28 -0
- data/lib/simple_form/inputs/file_input.rb +9 -0
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
- data/lib/simple_form/inputs/hidden_input.rb +17 -0
- data/lib/simple_form/inputs/numeric_input.rb +24 -0
- data/lib/simple_form/inputs/password_input.rb +12 -0
- data/lib/simple_form/inputs/priority_input.rb +24 -0
- data/lib/simple_form/inputs/range_input.rb +14 -0
- data/lib/simple_form/inputs/string_input.rb +23 -0
- data/lib/simple_form/inputs/text_area_input.rb +12 -0
- data/lib/simple_form/inputs/text_input.rb +11 -0
- data/lib/simple_form/inputs.rb +23 -0
- data/lib/simple_form/map_type.rb +16 -0
- data/lib/simple_form/version.rb +3 -0
- data/lib/simple_form/wrappers/builder.rb +103 -0
- data/lib/simple_form/wrappers/many.rb +73 -0
- data/lib/simple_form/wrappers/root.rb +36 -0
- data/lib/simple_form/wrappers/single.rb +24 -0
- data/lib/simple_form/wrappers.rb +8 -0
- data/lib/simple_form.rb +221 -0
- data/test/action_view_extensions/builder_test.rb +583 -0
- data/test/action_view_extensions/form_helper_test.rb +143 -0
- data/test/components/label_test.rb +327 -0
- data/test/form_builder/association_test.rb +186 -0
- data/test/form_builder/button_test.rb +47 -0
- data/test/form_builder/error_notification_test.rb +79 -0
- data/test/form_builder/error_test.rb +121 -0
- data/test/form_builder/general_test.rb +402 -0
- data/test/form_builder/hint_test.rb +138 -0
- data/test/form_builder/input_field_test.rb +63 -0
- data/test/form_builder/label_test.rb +71 -0
- data/test/form_builder/wrapper_test.rb +203 -0
- data/test/generators/simple_form_generator_test.rb +42 -0
- data/test/inputs/boolean_input_test.rb +140 -0
- data/test/inputs/collection_check_boxes_input_test.rb +224 -0
- data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
- data/test/inputs/collection_select_input_test.rb +241 -0
- data/test/inputs/datetime_input_test.rb +99 -0
- data/test/inputs/disabled_test.rb +78 -0
- data/test/inputs/discovery_test.rb +69 -0
- data/test/inputs/file_input_test.rb +16 -0
- data/test/inputs/general_test.rb +116 -0
- data/test/inputs/grouped_collection_select_input_test.rb +118 -0
- data/test/inputs/hidden_input_test.rb +30 -0
- data/test/inputs/numeric_input_test.rb +173 -0
- data/test/inputs/priority_input_test.rb +43 -0
- data/test/inputs/readonly_test.rb +101 -0
- data/test/inputs/required_test.rb +113 -0
- data/test/inputs/string_input_test.rb +146 -0
- data/test/inputs/text_input_test.rb +24 -0
- data/test/simple_form_test.rb +9 -0
- data/test/support/discovery_inputs.rb +27 -0
- data/test/support/misc_helpers.rb +138 -0
- data/test/support/mock_controller.rb +24 -0
- data/test/support/models.rb +216 -0
- data/test/test_helper.rb +95 -0
- metadata +217 -0
@@ -0,0 +1,224 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CollectionCheckBoxesInputTest < ActionView::TestCase
|
5
|
+
setup do
|
6
|
+
SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'input check boxes should not include for attribute by default' do
|
10
|
+
with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
|
11
|
+
assert_select 'label'
|
12
|
+
assert_no_select 'label[for=user_gender]'
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'input check boxes should include for attribute when giving as html option' do
|
16
|
+
with_input_for @user, :gender, :check_boxes, :collection => [:male, :female], :label_html => { :for => 'gender' }
|
17
|
+
assert_select 'label[for=gender]'
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'collection input with check_boxes type should not generate required html attribute' do
|
21
|
+
with_input_for @user, :name, :check_boxes, :collection => ['Jose' , 'Carlos']
|
22
|
+
assert_select 'input.required'
|
23
|
+
assert_no_select 'input[required]'
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'input should do automatic collection translation for check_box types using defaults key' do
|
27
|
+
store_translations(:en, :simple_form => { :options => { :defaults => {
|
28
|
+
:gender => { :male => 'Male', :female => 'Female'}
|
29
|
+
} } } ) do
|
30
|
+
with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
|
31
|
+
assert_select 'input[type=checkbox][value=male]'
|
32
|
+
assert_select 'input[type=checkbox][value=female]'
|
33
|
+
assert_select 'label.collection_check_boxes', 'Male'
|
34
|
+
assert_select 'label.collection_check_boxes', 'Female'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'input should do automatic collection translation for check_box types using specific object key' do
|
39
|
+
store_translations(:en, :simple_form => { :options => { :user => {
|
40
|
+
:gender => { :male => 'Male', :female => 'Female'}
|
41
|
+
} } } ) do
|
42
|
+
with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
|
43
|
+
assert_select 'input[type=checkbox][value=male]'
|
44
|
+
assert_select 'input[type=checkbox][value=female]'
|
45
|
+
assert_select 'label.collection_check_boxes', 'Male'
|
46
|
+
assert_select 'label.collection_check_boxes', 'Female'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'input check boxes does not wrap the collection by default' do
|
51
|
+
with_input_for @user, :active, :check_boxes
|
52
|
+
|
53
|
+
assert_select 'form input[type=checkbox]', :count => 2
|
54
|
+
assert_no_select 'form ul'
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'input check boxes wraps the collection in the configured collection wrapper tag' do
|
58
|
+
swap SimpleForm, :collection_wrapper_tag => :ul do
|
59
|
+
with_input_for @user, :active, :check_boxes
|
60
|
+
|
61
|
+
assert_select 'form ul input[type=checkbox]', :count => 2
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'input check boxes does not wrap the collection when configured with falsy values' do
|
66
|
+
swap SimpleForm, :collection_wrapper_tag => false do
|
67
|
+
with_input_for @user, :active, :check_boxes
|
68
|
+
|
69
|
+
assert_select 'form input[type=checkbox]', :count => 2
|
70
|
+
assert_no_select 'form ul'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'input check boxes allows overriding the collection wrapper tag at input level' do
|
75
|
+
swap SimpleForm, :collection_wrapper_tag => :ul do
|
76
|
+
with_input_for @user, :active, :check_boxes, :collection_wrapper_tag => :section
|
77
|
+
|
78
|
+
assert_select 'form section input[type=checkbox]', :count => 2
|
79
|
+
assert_no_select 'form ul'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'input check boxes allows disabling the collection wrapper tag at input level' do
|
84
|
+
swap SimpleForm, :collection_wrapper_tag => :ul do
|
85
|
+
with_input_for @user, :active, :check_boxes, :collection_wrapper_tag => false
|
86
|
+
|
87
|
+
assert_select 'form input[type=checkbox]', :count => 2
|
88
|
+
assert_no_select 'form ul'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
test 'input check boxes renders the wrapper tag with the configured wrapper class' do
|
93
|
+
swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
|
94
|
+
with_input_for @user, :active, :check_boxes
|
95
|
+
|
96
|
+
assert_select 'form ul.inputs-list input[type=checkbox]', :count => 2
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'input check boxes allows giving wrapper class at input level only' do
|
101
|
+
swap SimpleForm, :collection_wrapper_tag => :ul do
|
102
|
+
with_input_for @user, :active, :check_boxes, :collection_wrapper_class => 'items-list'
|
103
|
+
|
104
|
+
assert_select 'form ul.items-list input[type=checkbox]', :count => 2
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'input check boxes uses both configured and given wrapper classes for wrapper tag' do
|
109
|
+
swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
|
110
|
+
with_input_for @user, :active, :check_boxes, :collection_wrapper_class => 'items-list'
|
111
|
+
|
112
|
+
assert_select 'form ul.inputs-list.items-list input[type=checkbox]', :count => 2
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
test 'input check boxes wraps each item in the configured item wrapper tag' do
|
117
|
+
swap SimpleForm, :item_wrapper_tag => :li do
|
118
|
+
with_input_for @user, :active, :check_boxes
|
119
|
+
|
120
|
+
assert_select 'form li input[type=checkbox]', :count => 2
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
test 'input check boxes does not wrap items when configured with falsy values' do
|
125
|
+
swap SimpleForm, :item_wrapper_tag => false do
|
126
|
+
with_input_for @user, :active, :check_boxes
|
127
|
+
|
128
|
+
assert_select 'form input[type=checkbox]', :count => 2
|
129
|
+
assert_no_select 'form li'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
test 'input check boxes allows overriding the item wrapper tag at input level' do
|
134
|
+
swap SimpleForm, :item_wrapper_tag => :li do
|
135
|
+
with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :dl
|
136
|
+
|
137
|
+
assert_select 'form dl input[type=checkbox]', :count => 2
|
138
|
+
assert_no_select 'form li'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
test 'input check boxes allows disabling the item wrapper tag at input level' do
|
143
|
+
swap SimpleForm, :item_wrapper_tag => :ul do
|
144
|
+
with_input_for @user, :active, :check_boxes, :item_wrapper_tag => false
|
145
|
+
|
146
|
+
assert_select 'form input[type=checkbox]', :count => 2
|
147
|
+
assert_no_select 'form li'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
test 'input check boxes wraps items in a span tag by default' do
|
152
|
+
with_input_for @user, :active, :check_boxes
|
153
|
+
|
154
|
+
assert_select 'form span input[type=checkbox]', :count => 2
|
155
|
+
end
|
156
|
+
|
157
|
+
test 'input check boxes renders the item wrapper tag with a default class "checkbox"' do
|
158
|
+
with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :li
|
159
|
+
|
160
|
+
assert_select 'form li.checkbox input[type=checkbox]', :count => 2
|
161
|
+
end
|
162
|
+
|
163
|
+
test 'input check boxes renders the item wrapper tag with the configured item wrapper class' do
|
164
|
+
swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
|
165
|
+
with_input_for @user, :active, :check_boxes
|
166
|
+
|
167
|
+
assert_select 'form li.checkbox.item input[type=checkbox]', :count => 2
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
test 'input check boxes allows giving item wrapper class at input level only' do
|
172
|
+
swap SimpleForm, :item_wrapper_tag => :li do
|
173
|
+
with_input_for @user, :active, :check_boxes, :item_wrapper_class => 'item'
|
174
|
+
|
175
|
+
assert_select 'form li.checkbox.item input[type=checkbox]', :count => 2
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
test 'input check boxes uses both configured and given item wrapper classes for item wrapper tag' do
|
180
|
+
swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
|
181
|
+
with_input_for @user, :active, :check_boxes, :item_wrapper_class => 'inline'
|
182
|
+
|
183
|
+
assert_select 'form li.checkbox.item.inline input[type=checkbox]', :count => 2
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
test 'input check boxes respects the nested boolean style config, generating nested label > input' do
|
188
|
+
swap SimpleForm, :boolean_style => :nested do
|
189
|
+
with_input_for @user, :active, :check_boxes
|
190
|
+
|
191
|
+
assert_select 'label.checkbox > input#user_active_true[type=checkbox]'
|
192
|
+
assert_select 'label.checkbox', 'Yes'
|
193
|
+
assert_select 'label.checkbox > input#user_active_false[type=checkbox]'
|
194
|
+
assert_select 'label.checkbox', 'No'
|
195
|
+
assert_no_select 'label.collection_radio_buttons'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
test 'input check boxes with nested style overrides configured item wrapper tag, forcing the :label' do
|
200
|
+
swap SimpleForm, :boolean_style => :nested, :item_wrapper_tag => :li do
|
201
|
+
with_input_for @user, :active, :check_boxes
|
202
|
+
|
203
|
+
assert_select 'label.checkbox > input'
|
204
|
+
assert_no_select 'li'
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
test 'input check boxes with nested style overrides given item wrapper tag, forcing the :label' do
|
209
|
+
swap SimpleForm, :boolean_style => :nested do
|
210
|
+
with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :li
|
211
|
+
|
212
|
+
assert_select 'label.checkbox > input'
|
213
|
+
assert_no_select 'li'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
test 'input check boxes with nested style accepts giving extra wrapper classes' do
|
218
|
+
swap SimpleForm, :boolean_style => :nested do
|
219
|
+
with_input_for @user, :active, :check_boxes, :item_wrapper_class => "inline"
|
220
|
+
|
221
|
+
assert_select 'label.checkbox.inline > input'
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,326 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CollectionRadioButtonsInputTest < ActionView::TestCase
|
5
|
+
setup do
|
6
|
+
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'input :as => :radio is deprecated in favor of :as => :radio_buttons' do
|
10
|
+
assert_deprecated "[SIMPLE_FORM] Using `:as => :radio` as " \
|
11
|
+
"input type is deprecated, please change it to `:as => :radio_buttons`." do
|
12
|
+
with_input_for @user, :active, :radio
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_select 'input[type=radio].radio_buttons', :count => 2
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'input should generate boolean radio buttons by default for radio types' do
|
19
|
+
with_input_for @user, :active, :radio_buttons
|
20
|
+
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
21
|
+
assert_select 'input[type=radio][value=false].radio_buttons#user_active_false'
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'input as radio should generate internal labels by default' do
|
25
|
+
with_input_for @user, :active, :radio_buttons
|
26
|
+
assert_select 'label[for=user_active_true]', 'Yes'
|
27
|
+
assert_select 'label[for=user_active_false]', 'No'
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'input as radio should use i18n to translate internal labels' do
|
31
|
+
store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
|
32
|
+
with_input_for @user, :active, :radio_buttons
|
33
|
+
assert_select 'label[for=user_active_true]', 'Sim'
|
34
|
+
assert_select 'label[for=user_active_false]', 'Não'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'input radio should not include for attribute by default' do
|
39
|
+
with_input_for @user, :gender, :radio_buttons, :collection => [:male, :female]
|
40
|
+
assert_select 'label'
|
41
|
+
assert_no_select 'label[for=user_gender]'
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'input radio should include for attribute when giving as html option' do
|
45
|
+
with_input_for @user, :gender, :radio_buttons, :collection => [:male, :female], :label_html => { :for => 'gender' }
|
46
|
+
assert_select 'label[for=gender]'
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'input should mark the checked value when using boolean and radios' do
|
50
|
+
@user.active = false
|
51
|
+
with_input_for @user, :active, :radio_buttons
|
52
|
+
assert_no_select 'input[type=radio][value=true][checked]'
|
53
|
+
assert_select 'input[type=radio][value=false][checked]'
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'input should allow overriding collection for radio types' do
|
57
|
+
with_input_for @user, :name, :radio_buttons, :collection => ['Jose', 'Carlos']
|
58
|
+
assert_select 'input[type=radio][value=Jose]'
|
59
|
+
assert_select 'input[type=radio][value=Carlos]'
|
60
|
+
assert_select 'label.collection_radio_buttons', 'Jose'
|
61
|
+
assert_select 'label.collection_radio_buttons', 'Carlos'
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'input should do automatic collection translation for radio types using defaults key' do
|
65
|
+
store_translations(:en, :simple_form => { :options => { :defaults => {
|
66
|
+
:gender => { :male => 'Male', :female => 'Female'}
|
67
|
+
} } } ) do
|
68
|
+
with_input_for @user, :gender, :radio_buttons, :collection => [:male, :female]
|
69
|
+
assert_select 'input[type=radio][value=male]'
|
70
|
+
assert_select 'input[type=radio][value=female]'
|
71
|
+
assert_select 'label.collection_radio_buttons', 'Male'
|
72
|
+
assert_select 'label.collection_radio_buttons', 'Female'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'input should do automatic collection translation for radio types using specific object key' do
|
77
|
+
store_translations(:en, :simple_form => { :options => { :user => {
|
78
|
+
:gender => { :male => 'Male', :female => 'Female'}
|
79
|
+
} } } ) do
|
80
|
+
with_input_for @user, :gender, :radio_buttons, :collection => [:male, :female]
|
81
|
+
assert_select 'input[type=radio][value=male]'
|
82
|
+
assert_select 'input[type=radio][value=female]'
|
83
|
+
assert_select 'label.collection_radio_buttons', 'Male'
|
84
|
+
assert_select 'label.collection_radio_buttons', 'Female'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'input should mark the current radio value by default' do
|
89
|
+
@user.name = "Carlos"
|
90
|
+
with_input_for @user, :name, :radio_buttons, :collection => ['Jose', 'Carlos']
|
91
|
+
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'input should allow using a collection with text/value arrays' do
|
95
|
+
with_input_for @user, :name, :radio_buttons, :collection => [['Jose', 'jose'], ['Carlos', 'carlos']]
|
96
|
+
assert_select 'input[type=radio][value=jose]'
|
97
|
+
assert_select 'input[type=radio][value=carlos]'
|
98
|
+
assert_select 'label.collection_radio_buttons', 'Jose'
|
99
|
+
assert_select 'label.collection_radio_buttons', 'Carlos'
|
100
|
+
end
|
101
|
+
|
102
|
+
test 'input should allow using a collection with a Proc' do
|
103
|
+
with_input_for @user, :name, :radio_buttons, :collection => Proc.new { ['Jose', 'Carlos' ] }
|
104
|
+
assert_select 'label.collection_radio_buttons', 'Jose'
|
105
|
+
assert_select 'label.collection_radio_buttons', 'Carlos'
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'input should allow overriding only label method for collections' do
|
109
|
+
with_input_for @user, :name, :radio_buttons,
|
110
|
+
:collection => ['Jose' , 'Carlos'],
|
111
|
+
:label_method => :upcase
|
112
|
+
assert_select 'label.collection_radio_buttons', 'JOSE'
|
113
|
+
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
114
|
+
end
|
115
|
+
|
116
|
+
test 'input should allow overriding only value method for collections' do
|
117
|
+
with_input_for @user, :name, :radio_buttons,
|
118
|
+
:collection => ['Jose' , 'Carlos'],
|
119
|
+
:value_method => :upcase
|
120
|
+
assert_select 'input[type=radio][value=JOSE]'
|
121
|
+
assert_select 'input[type=radio][value=CARLOS]'
|
122
|
+
end
|
123
|
+
|
124
|
+
test 'input should allow overriding label and value method for collections' do
|
125
|
+
with_input_for @user, :name, :radio_buttons,
|
126
|
+
:collection => ['Jose' , 'Carlos'],
|
127
|
+
:label_method => :upcase,
|
128
|
+
:value_method => :downcase
|
129
|
+
assert_select 'input[type=radio][value=jose]'
|
130
|
+
assert_select 'input[type=radio][value=carlos]'
|
131
|
+
assert_select 'label.collection_radio_buttons', 'JOSE'
|
132
|
+
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
133
|
+
end
|
134
|
+
|
135
|
+
test 'input should allow overriding label and value method using a lambda for collections' do
|
136
|
+
with_input_for @user, :name, :radio_buttons,
|
137
|
+
:collection => ['Jose' , 'Carlos'],
|
138
|
+
:label_method => lambda { |i| i.upcase },
|
139
|
+
:value_method => lambda { |i| i.downcase }
|
140
|
+
assert_select 'input[type=radio][value=jose]'
|
141
|
+
assert_select 'input[type=radio][value=carlos]'
|
142
|
+
assert_select 'label.collection_radio_buttons', 'JOSE'
|
143
|
+
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
144
|
+
end
|
145
|
+
|
146
|
+
test 'collection input with radio type should generate required html attribute' do
|
147
|
+
with_input_for @user, :name, :radio_buttons, :collection => ['Jose' , 'Carlos']
|
148
|
+
assert_select 'input[type=radio].required'
|
149
|
+
assert_select 'input[type=radio][required]'
|
150
|
+
end
|
151
|
+
|
152
|
+
test 'input radio does not wrap the collection by default' do
|
153
|
+
with_input_for @user, :active, :radio_buttons
|
154
|
+
|
155
|
+
assert_select 'form input[type=radio]', :count => 2
|
156
|
+
assert_no_select 'form ul'
|
157
|
+
end
|
158
|
+
|
159
|
+
test 'input radio wraps the collection in the configured collection wrapper tag' do
|
160
|
+
swap SimpleForm, :collection_wrapper_tag => :ul do
|
161
|
+
with_input_for @user, :active, :radio_buttons
|
162
|
+
|
163
|
+
assert_select 'form ul input[type=radio]', :count => 2
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
test 'input radio does not wrap the collection when configured with falsy values' do
|
168
|
+
swap SimpleForm, :collection_wrapper_tag => false do
|
169
|
+
with_input_for @user, :active, :radio_buttons
|
170
|
+
|
171
|
+
assert_select 'form input[type=radio]', :count => 2
|
172
|
+
assert_no_select 'form ul'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
test 'input radio allows overriding the collection wrapper tag at input level' do
|
177
|
+
swap SimpleForm, :collection_wrapper_tag => :ul do
|
178
|
+
with_input_for @user, :active, :radio_buttons, :collection_wrapper_tag => :section
|
179
|
+
|
180
|
+
assert_select 'form section input[type=radio]', :count => 2
|
181
|
+
assert_no_select 'form ul'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
test 'input radio allows disabling the collection wrapper tag at input level' do
|
186
|
+
swap SimpleForm, :collection_wrapper_tag => :ul do
|
187
|
+
with_input_for @user, :active, :radio_buttons, :collection_wrapper_tag => false
|
188
|
+
|
189
|
+
assert_select 'form input[type=radio]', :count => 2
|
190
|
+
assert_no_select 'form ul'
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
test 'input radio renders the wrapper tag with the configured wrapper class' do
|
195
|
+
swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
|
196
|
+
with_input_for @user, :active, :radio_buttons
|
197
|
+
|
198
|
+
assert_select 'form ul.inputs-list input[type=radio]', :count => 2
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
test 'input radio allows giving wrapper class at input level only' do
|
203
|
+
swap SimpleForm, :collection_wrapper_tag => :ul do
|
204
|
+
with_input_for @user, :active, :radio_buttons, :collection_wrapper_class => 'items-list'
|
205
|
+
|
206
|
+
assert_select 'form ul.items-list input[type=radio]', :count => 2
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
test 'input radio uses both configured and given wrapper classes for wrapper tag' do
|
211
|
+
swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
|
212
|
+
with_input_for @user, :active, :radio_buttons, :collection_wrapper_class => 'items-list'
|
213
|
+
|
214
|
+
assert_select 'form ul.inputs-list.items-list input[type=radio]', :count => 2
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
test 'input radio wraps each item in the configured item wrapper tag' do
|
219
|
+
swap SimpleForm, :item_wrapper_tag => :li do
|
220
|
+
with_input_for @user, :active, :radio_buttons
|
221
|
+
|
222
|
+
assert_select 'form li input[type=radio]', :count => 2
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
test 'input radio does not wrap items when configured with falsy values' do
|
227
|
+
swap SimpleForm, :item_wrapper_tag => false do
|
228
|
+
with_input_for @user, :active, :radio_buttons
|
229
|
+
|
230
|
+
assert_select 'form input[type=radio]', :count => 2
|
231
|
+
assert_no_select 'form li'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
test 'input radio allows overriding the item wrapper tag at input level' do
|
236
|
+
swap SimpleForm, :item_wrapper_tag => :li do
|
237
|
+
with_input_for @user, :active, :radio_buttons, :item_wrapper_tag => :dl
|
238
|
+
|
239
|
+
assert_select 'form dl input[type=radio]', :count => 2
|
240
|
+
assert_no_select 'form li'
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
test 'input radio allows disabling the item wrapper tag at input level' do
|
245
|
+
swap SimpleForm, :item_wrapper_tag => :ul do
|
246
|
+
with_input_for @user, :active, :radio_buttons, :item_wrapper_tag => false
|
247
|
+
|
248
|
+
assert_select 'form input[type=radio]', :count => 2
|
249
|
+
assert_no_select 'form li'
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
test 'input radio wraps items in a span tag by default' do
|
254
|
+
with_input_for @user, :active, :radio_buttons
|
255
|
+
|
256
|
+
assert_select 'form span input[type=radio]', :count => 2
|
257
|
+
end
|
258
|
+
|
259
|
+
test 'input radio renders the item wrapper tag with a default class "radio"' do
|
260
|
+
with_input_for @user, :active, :radio_buttons, :item_wrapper_tag => :li
|
261
|
+
|
262
|
+
assert_select 'form li.radio input[type=radio]', :count => 2
|
263
|
+
end
|
264
|
+
|
265
|
+
test 'input radio renders the item wrapper tag with the configured item wrapper class' do
|
266
|
+
swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
|
267
|
+
with_input_for @user, :active, :radio_buttons
|
268
|
+
|
269
|
+
assert_select 'form li.radio.item input[type=radio]', :count => 2
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
test 'input radio allows giving item wrapper class at input level only' do
|
274
|
+
swap SimpleForm, :item_wrapper_tag => :li do
|
275
|
+
with_input_for @user, :active, :radio_buttons, :item_wrapper_class => 'item'
|
276
|
+
|
277
|
+
assert_select 'form li.radio.item input[type=radio]', :count => 2
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
test 'input radio uses both configured and given item wrapper classes for item wrapper tag' do
|
282
|
+
swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
|
283
|
+
with_input_for @user, :active, :radio_buttons, :item_wrapper_class => 'inline'
|
284
|
+
|
285
|
+
assert_select 'form li.radio.item.inline input[type=radio]', :count => 2
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
test 'input radio respects the nested boolean style config, generating nested label > input' do
|
290
|
+
swap SimpleForm, :boolean_style => :nested do
|
291
|
+
with_input_for @user, :active, :radio_buttons
|
292
|
+
|
293
|
+
assert_select 'label.radio > input#user_active_true[type=radio]'
|
294
|
+
assert_select 'label.radio', 'Yes'
|
295
|
+
assert_select 'label.radio > input#user_active_false[type=radio]'
|
296
|
+
assert_select 'label.radio', 'No'
|
297
|
+
assert_no_select 'label.collection_radio_buttons'
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
test 'input radio with nested style overrides configured item wrapper tag, forcing the :label' do
|
302
|
+
swap SimpleForm, :boolean_style => :nested, :item_wrapper_tag => :li do
|
303
|
+
with_input_for @user, :active, :radio_buttons
|
304
|
+
|
305
|
+
assert_select 'label.radio > input'
|
306
|
+
assert_no_select 'li'
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
test 'input radio with nested style overrides given item wrapper tag, forcing the :label' do
|
311
|
+
swap SimpleForm, :boolean_style => :nested do
|
312
|
+
with_input_for @user, :active, :radio_buttons, :item_wrapper_tag => :li
|
313
|
+
|
314
|
+
assert_select 'label.radio > input'
|
315
|
+
assert_no_select 'li'
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
test 'input radio with nested style accepts giving extra wrapper classes' do
|
320
|
+
swap SimpleForm, :boolean_style => :nested do
|
321
|
+
with_input_for @user, :active, :radio_buttons, :item_wrapper_class => "inline"
|
322
|
+
|
323
|
+
assert_select 'label.radio.inline > input'
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|