simple_form 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -32
- data/README.md +161 -119
- data/lib/generators/simple_form/install_generator.rb +3 -3
- data/lib/generators/simple_form/templates/README +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +16 -13
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
- data/lib/simple_form/components/html5.rb +5 -2
- data/lib/simple_form/components/labels.rb +3 -3
- data/lib/simple_form/components/maxlength.rb +1 -8
- data/lib/simple_form/components/pattern.rb +2 -2
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +155 -51
- data/lib/simple_form/helpers.rb +1 -1
- data/lib/simple_form/inputs/base.rb +6 -6
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +6 -4
- data/lib/simple_form/inputs/collection_input.rb +6 -6
- data/lib/simple_form/inputs/date_time_input.rb +1 -1
- data/lib/simple_form/inputs/numeric_input.rb +0 -6
- data/lib/simple_form/inputs/password_input.rb +0 -1
- data/lib/simple_form/inputs/string_input.rb +0 -1
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +62 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +5 -29
- data/lib/simple_form/wrappers/many.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -1
- data/lib/simple_form.rb +43 -47
- data/test/action_view_extensions/builder_test.rb +78 -92
- data/test/action_view_extensions/form_helper_test.rb +25 -16
- data/test/components/label_test.rb +46 -46
- data/test/form_builder/association_test.rb +47 -29
- data/test/form_builder/button_test.rb +4 -4
- data/test/form_builder/error_notification_test.rb +8 -8
- data/test/form_builder/error_test.rb +12 -12
- data/test/form_builder/general_test.rb +71 -52
- data/test/form_builder/hint_test.rb +22 -22
- data/test/form_builder/input_field_test.rb +29 -12
- data/test/form_builder/label_test.rb +7 -7
- data/test/form_builder/wrapper_test.rb +21 -21
- data/test/inputs/boolean_input_test.rb +35 -23
- data/test/inputs/collection_check_boxes_input_test.rb +66 -55
- data/test/inputs/collection_radio_buttons_input_test.rb +81 -79
- data/test/inputs/collection_select_input_test.rb +76 -45
- data/test/inputs/datetime_input_test.rb +17 -11
- data/test/inputs/disabled_test.rb +10 -10
- data/test/inputs/discovery_test.rb +4 -4
- data/test/inputs/file_input_test.rb +1 -1
- data/test/inputs/general_test.rb +28 -12
- data/test/inputs/grouped_collection_select_input_test.rb +33 -20
- data/test/inputs/hidden_input_test.rb +3 -2
- data/test/inputs/numeric_input_test.rb +3 -3
- data/test/inputs/priority_input_test.rb +9 -3
- data/test/inputs/readonly_test.rb +12 -12
- data/test/inputs/required_test.rb +5 -5
- data/test/inputs/string_input_test.rb +15 -25
- data/test/inputs/text_input_test.rb +1 -1
- data/test/support/misc_helpers.rb +46 -24
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +80 -62
- data/test/test_helper.rb +17 -34
- metadata +31 -29
- data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -14,7 +14,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'input as select should use i18n to translate select boolean options' do
|
17
|
-
store_translations(:en, :
|
17
|
+
store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do
|
18
18
|
with_input_for @user, :active, :select
|
19
19
|
assert_select 'select option[value=true]', 'Sim'
|
20
20
|
assert_select 'select option[value=false]', 'Não'
|
@@ -22,17 +22,17 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
test 'input should allow overriding collection for select types' do
|
25
|
-
with_input_for @user, :name, :select, :
|
25
|
+
with_input_for @user, :name, :select, collection: ['Jose', 'Carlos']
|
26
26
|
assert_select 'select.select#user_name'
|
27
27
|
assert_select 'select option', 'Jose'
|
28
28
|
assert_select 'select option', 'Carlos'
|
29
29
|
end
|
30
30
|
|
31
31
|
test 'input should do automatic collection translation for select types using defaults key' do
|
32
|
-
store_translations(:en, :
|
33
|
-
:
|
32
|
+
store_translations(:en, simple_form: { options: { defaults: {
|
33
|
+
gender: { male: 'Male', female: 'Female'}
|
34
34
|
} } } ) do
|
35
|
-
with_input_for @user, :gender, :select, :
|
35
|
+
with_input_for @user, :gender, :select, collection: [:male, :female]
|
36
36
|
assert_select 'select.select#user_gender'
|
37
37
|
assert_select 'select option', 'Male'
|
38
38
|
assert_select 'select option', 'Female'
|
@@ -40,10 +40,10 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
40
40
|
end
|
41
41
|
|
42
42
|
test 'input should do automatic collection translation for select types using specific object key' do
|
43
|
-
store_translations(:en, :
|
44
|
-
:
|
43
|
+
store_translations(:en, simple_form: { options: { user: {
|
44
|
+
gender: { male: 'Male', female: 'Female'}
|
45
45
|
} } } ) do
|
46
|
-
with_input_for @user, :gender, :select, :
|
46
|
+
with_input_for @user, :gender, :select, collection: [:male, :female]
|
47
47
|
assert_select 'select.select#user_gender'
|
48
48
|
assert_select 'select option', 'Male'
|
49
49
|
assert_select 'select option', 'Female'
|
@@ -52,13 +52,19 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
52
52
|
|
53
53
|
test 'input should mark the selected value by default' do
|
54
54
|
@user.name = "Carlos"
|
55
|
-
with_input_for @user, :name, :select, :
|
55
|
+
with_input_for @user, :name, :select, collection: ['Jose', 'Carlos']
|
56
56
|
assert_select 'select option[selected=selected]', 'Carlos'
|
57
57
|
end
|
58
58
|
|
59
|
+
test 'input should accept html options as the last element of collection' do
|
60
|
+
with_input_for @user, :name, :select, collection: [['Jose', class: 'foo']]
|
61
|
+
assert_select 'select.select#user_name'
|
62
|
+
assert_select 'select option.foo', 'Jose'
|
63
|
+
end
|
64
|
+
|
59
65
|
test 'input should mark the selected value also when using integers' do
|
60
66
|
@user.age = 18
|
61
|
-
with_input_for @user, :age, :select, :
|
67
|
+
with_input_for @user, :age, :select, collection: 18..60
|
62
68
|
assert_select 'select option[selected=selected]', '18'
|
63
69
|
end
|
64
70
|
|
@@ -70,13 +76,13 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
70
76
|
end
|
71
77
|
|
72
78
|
test 'input should set the correct value when using a collection that includes floats' do
|
73
|
-
with_input_for @user, :age, :select, :
|
79
|
+
with_input_for @user, :age, :select, collection: [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
|
74
80
|
assert_select 'select option[value="2.0"]'
|
75
81
|
assert_select 'select option[value="2.5"]'
|
76
82
|
end
|
77
83
|
|
78
84
|
test 'input should set the correct values when using a collection that uses mixed values' do
|
79
|
-
with_input_for @user, :age, :select, :
|
85
|
+
with_input_for @user, :age, :select, collection: ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
|
80
86
|
assert_select 'select option[value="Hello Kitty"]'
|
81
87
|
assert_select 'select option[value="2"]'
|
82
88
|
assert_select 'select option[value="4.5"]'
|
@@ -87,39 +93,39 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
87
93
|
end
|
88
94
|
|
89
95
|
test 'input should include a blank option even if :include_blank is set to false if the collection includes a nil value' do
|
90
|
-
with_input_for @user, :age, :select, :
|
96
|
+
with_input_for @user, :age, :select, collection: [nil], include_blank: false
|
91
97
|
assert_select 'select option[value=""]'
|
92
98
|
end
|
93
99
|
|
94
100
|
test 'input should automatically set include blank' do
|
95
|
-
with_input_for @user, :age, :select, :
|
101
|
+
with_input_for @user, :age, :select, collection: 18..30
|
96
102
|
assert_select 'select option[value=]', ''
|
97
103
|
end
|
98
104
|
|
99
105
|
test 'input should not set include blank if otherwise is told' do
|
100
|
-
with_input_for @user, :age, :select, :
|
106
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
101
107
|
assert_no_select 'select option[value=]', ''
|
102
108
|
end
|
103
109
|
|
104
110
|
test 'input should not set include blank if prompt is given' do
|
105
|
-
with_input_for @user, :age, :select, :
|
111
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
106
112
|
assert_no_select 'select option[value=]', ''
|
107
113
|
end
|
108
114
|
|
109
115
|
test 'input should not set include blank if multiple is given' do
|
110
|
-
with_input_for @user, :age, :select, :
|
116
|
+
with_input_for @user, :age, :select, collection: 18..30, input_html: { multiple: true }
|
111
117
|
assert_no_select 'select option[value=]', ''
|
112
118
|
end
|
113
119
|
|
114
120
|
test 'input should detect label and value on collections' do
|
115
|
-
users = [
|
116
|
-
with_input_for @user, :description, :select, :
|
121
|
+
users = [User.build(id: 1, name: "Jose"), User.build(id: 2, name: "Carlos")]
|
122
|
+
with_input_for @user, :description, :select, collection: users
|
117
123
|
assert_select 'select option[value=1]', 'Jose'
|
118
124
|
assert_select 'select option[value=2]', 'Carlos'
|
119
125
|
end
|
120
126
|
|
121
127
|
test 'input should disable the anothers components when the option is a object' do
|
122
|
-
with_input_for @user, :description, :select, :
|
128
|
+
with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: true
|
123
129
|
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
124
130
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
125
131
|
assert_select 'select[disabled=disabled]'
|
@@ -127,7 +133,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
127
133
|
end
|
128
134
|
|
129
135
|
test 'input should not disable the anothers components when the option is a object' do
|
130
|
-
with_input_for @user, :description, :select, :
|
136
|
+
with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: 'Jose'
|
131
137
|
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
132
138
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
133
139
|
assert_no_select 'select[disabled=disabled]'
|
@@ -136,95 +142,120 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
136
142
|
|
137
143
|
test 'input should allow overriding label and value method using a lambda for collection selects' do
|
138
144
|
with_input_for @user, :name, :select,
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
145
|
+
collection: ['Jose', 'Carlos'],
|
146
|
+
label_method: lambda { |i| i.upcase },
|
147
|
+
value_method: lambda { |i| i.downcase }
|
142
148
|
assert_select 'select option[value=jose]', "JOSE"
|
143
149
|
assert_select 'select option[value=carlos]', "CARLOS"
|
144
150
|
end
|
145
151
|
|
146
152
|
test 'input should allow overriding only label but not value method using a lambda for collection select' do
|
147
153
|
with_input_for @user, :name, :select,
|
148
|
-
:
|
149
|
-
:
|
154
|
+
collection: ['Jose', 'Carlos'],
|
155
|
+
label_method: lambda { |i| i.upcase }
|
150
156
|
assert_select 'select option[value=Jose]', "JOSE"
|
151
157
|
assert_select 'select option[value=Carlos]', "CARLOS"
|
152
158
|
end
|
153
159
|
|
154
160
|
test 'input should allow overriding only value but not label method using a lambda for collection select' do
|
155
161
|
with_input_for @user, :name, :select,
|
156
|
-
:
|
157
|
-
:
|
162
|
+
collection: ['Jose', 'Carlos'],
|
163
|
+
value_method: lambda { |i| i.downcase }
|
158
164
|
assert_select 'select option[value=jose]', "Jose"
|
159
165
|
assert_select 'select option[value=carlos]', "Carlos"
|
160
166
|
end
|
161
167
|
|
162
168
|
test 'input should allow symbols for collections' do
|
163
|
-
with_input_for @user, :name, :select, :
|
169
|
+
with_input_for @user, :name, :select, collection: [:jose, :carlos]
|
164
170
|
assert_select 'select.select#user_name'
|
165
171
|
assert_select 'select option[value=jose]', 'jose'
|
166
172
|
assert_select 'select option[value=carlos]', 'carlos'
|
167
173
|
end
|
168
174
|
|
169
175
|
test 'collection input with select type should generate required html attribute only with blank option' do
|
170
|
-
with_input_for @user, :name, :select, :
|
176
|
+
with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
|
171
177
|
assert_select 'select.required'
|
172
178
|
assert_select 'select[required]'
|
173
179
|
end
|
174
180
|
|
175
181
|
test 'collection input with select type should not generate required html attribute without blank option' do
|
176
|
-
with_input_for @user, :name, :select, :
|
182
|
+
with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
|
177
183
|
assert_select 'select.required'
|
178
184
|
assert_no_select 'select[required]'
|
185
|
+
assert_no_select 'select[aria-required=true]'
|
179
186
|
end
|
180
187
|
|
181
188
|
test 'collection input with select type with multiple attribute should generate required html attribute without blank option' do
|
182
|
-
with_input_for @user, :name, :select, :
|
189
|
+
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
183
190
|
assert_select 'select.required'
|
184
191
|
assert_select 'select[required]'
|
185
192
|
end
|
186
193
|
|
187
194
|
test 'collection input with select type with multiple attribute should generate required html attribute with blank option' do
|
188
|
-
with_input_for @user, :name, :select, :
|
195
|
+
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
189
196
|
assert_select 'select.required'
|
190
197
|
assert_select 'select[required]'
|
191
198
|
end
|
192
199
|
|
200
|
+
test 'with a blank option, a collection input of type select has an aria-required html attribute' do
|
201
|
+
with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
|
202
|
+
assert_select 'select.required'
|
203
|
+
assert_select 'select[aria-required=true]'
|
204
|
+
end
|
205
|
+
|
206
|
+
test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do
|
207
|
+
with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
|
208
|
+
assert_select 'select.required'
|
209
|
+
assert_no_select 'select[aria-required]'
|
210
|
+
end
|
211
|
+
|
212
|
+
test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do
|
213
|
+
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
214
|
+
assert_select 'select.required'
|
215
|
+
assert_select 'select[aria-required=true]'
|
216
|
+
end
|
217
|
+
|
218
|
+
test 'with a blank option and a multiple option, a collection input of type select has an aria-required html attribute' do
|
219
|
+
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
220
|
+
assert_select 'select.required'
|
221
|
+
assert_select 'select[aria-required]'
|
222
|
+
end
|
223
|
+
|
193
224
|
test 'input should allow disabled options with a lambda for collection select' do
|
194
|
-
with_input_for @user, :name, :select, :
|
195
|
-
:
|
225
|
+
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
226
|
+
disabled: lambda { |x| x == "Carlos" }
|
196
227
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
197
228
|
assert_select 'select option[value=Antonio]', 'Antonio'
|
198
229
|
assert_no_select 'select option[value=Antonio][disabled]'
|
199
230
|
end
|
200
231
|
|
201
232
|
test 'input should allow disabled and label method with lambdas for collection select' do
|
202
|
-
with_input_for @user, :name, :select, :
|
203
|
-
:
|
233
|
+
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
234
|
+
disabled: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
|
204
235
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
205
236
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
206
237
|
assert_no_select 'select option[value=Antonio][disabled]'
|
207
238
|
end
|
208
239
|
|
209
240
|
test 'input should allow a non lambda disabled option with lambda label method for collections' do
|
210
|
-
with_input_for @user, :name, :select, :
|
211
|
-
:
|
241
|
+
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
242
|
+
disabled: "Carlos", label_method: lambda { |x| x.upcase }
|
212
243
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
213
244
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
214
245
|
assert_no_select 'select option[value=Antonio][disabled]'
|
215
246
|
end
|
216
247
|
|
217
248
|
test 'input should allow selected and label method with lambdas for collection select' do
|
218
|
-
with_input_for @user, :name, :select, :
|
219
|
-
:
|
249
|
+
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
250
|
+
selected: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
|
220
251
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
221
252
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
222
253
|
assert_no_select 'select option[value=Antonio][selected]'
|
223
254
|
end
|
224
255
|
|
225
256
|
test 'input should allow a non lambda selected option with lambda label method for collection select' do
|
226
|
-
with_input_for @user, :name, :select, :
|
227
|
-
:
|
257
|
+
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
258
|
+
selected: "Carlos", label_method: lambda { |x| x.upcase }
|
228
259
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
229
260
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
230
261
|
assert_no_select 'select option[value=Antonio][selected]'
|
@@ -232,8 +263,8 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
232
263
|
|
233
264
|
test 'input should not override default selection through attribute value with label method as lambda for collection select' do
|
234
265
|
@user.name = "Carlos"
|
235
|
-
with_input_for @user, :name, :select, :
|
236
|
-
:
|
266
|
+
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
267
|
+
label_method: lambda { |x| x.upcase }
|
237
268
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
238
269
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
239
270
|
assert_no_select 'select option[value=Antonio][selected]'
|
@@ -13,7 +13,7 @@ class DateTimeInputTest < ActionView::TestCase
|
|
13
13
|
|
14
14
|
test 'input should be able to pass options to datetime select' do
|
15
15
|
with_input_for @user, :created_at, :datetime,
|
16
|
-
:
|
16
|
+
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
17
17
|
|
18
18
|
assert_select 'select.datetime[disabled=disabled]'
|
19
19
|
assert_select 'select.datetime option', 'ano'
|
@@ -30,8 +30,8 @@ class DateTimeInputTest < ActionView::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
test 'input should be able to pass options to date select' do
|
33
|
-
with_input_for @user, :born_at, :date, :
|
34
|
-
:
|
33
|
+
with_input_for @user, :born_at, :date, as: :date,
|
34
|
+
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
35
35
|
|
36
36
|
assert_select 'select.date[disabled=disabled]'
|
37
37
|
assert_select 'select.date option', 'ano'
|
@@ -40,7 +40,7 @@ class DateTimeInputTest < ActionView::TestCase
|
|
40
40
|
end
|
41
41
|
|
42
42
|
test 'input should be able to pass :default to date select' do
|
43
|
-
with_input_for @user, :born_at, :date, :
|
43
|
+
with_input_for @user, :born_at, :date, default: Date.today
|
44
44
|
assert_select "select.date option[value=#{Date.today.year}][selected=selected]"
|
45
45
|
end
|
46
46
|
|
@@ -54,8 +54,8 @@ class DateTimeInputTest < ActionView::TestCase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
test 'input should be able to pass options to time select' do
|
57
|
-
with_input_for @user, :delivery_time, :time, :
|
58
|
-
:
|
57
|
+
with_input_for @user, :delivery_time, :time, required: true,
|
58
|
+
disabled: true, prompt: { hour: 'hora', minute: 'minuto' }
|
59
59
|
|
60
60
|
assert_select 'select.time[disabled=disabled]'
|
61
61
|
assert_select 'select.time option', 'hora'
|
@@ -63,26 +63,26 @@ class DateTimeInputTest < ActionView::TestCase
|
|
63
63
|
end
|
64
64
|
|
65
65
|
test 'label should use i18n to get target for date input type' do
|
66
|
-
store_translations(:en, :
|
66
|
+
store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
|
67
67
|
with_input_for :project, :created_at, :date
|
68
68
|
assert_select 'label[for=project_created_at_2i]'
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
test 'label should use i18n to get target for datetime input type' do
|
73
|
-
store_translations(:en, :
|
73
|
+
store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
|
74
74
|
with_input_for :project, :created_at, :datetime
|
75
75
|
assert_select 'label[for=project_created_at_2i]'
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
test 'label should use order to get target when date input type' do
|
80
|
-
with_input_for :project, :created_at, :date, :
|
80
|
+
with_input_for :project, :created_at, :date, order: ['month', 'year', 'day']
|
81
81
|
assert_select 'label[for=project_created_at_2i]'
|
82
82
|
end
|
83
83
|
|
84
84
|
test 'label should use order to get target when datetime input type' do
|
85
|
-
with_input_for :project, :created_at, :datetime, :
|
85
|
+
with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day']
|
86
86
|
assert_select 'label[for=project_created_at_2i]'
|
87
87
|
end
|
88
88
|
|
@@ -92,8 +92,14 @@ class DateTimeInputTest < ActionView::TestCase
|
|
92
92
|
end
|
93
93
|
|
94
94
|
test 'date time input should generate required html attribute' do
|
95
|
-
with_input_for @user, :delivery_time, :time, :
|
95
|
+
with_input_for @user, :delivery_time, :time, required: true
|
96
96
|
assert_select 'select.required'
|
97
97
|
assert_select 'select[required]'
|
98
98
|
end
|
99
|
+
|
100
|
+
test 'date time input has an aria-required html attribute' do
|
101
|
+
with_input_for @user, :delivery_time, :time, required: true
|
102
|
+
assert_select 'select.required'
|
103
|
+
assert_select 'select[aria-required=true]'
|
104
|
+
end
|
99
105
|
end
|
@@ -2,52 +2,52 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class DisabledTest < ActionView::TestCase
|
4
4
|
test 'string input should be disabled when disabled option is true' do
|
5
|
-
with_input_for @user, :name, :string, :
|
5
|
+
with_input_for @user, :name, :string, disabled: true
|
6
6
|
assert_select 'input.string.disabled[disabled]'
|
7
7
|
end
|
8
8
|
|
9
9
|
test 'text input should be disabled when disabled option is true' do
|
10
|
-
with_input_for @user, :description, :text, :
|
10
|
+
with_input_for @user, :description, :text, disabled: true
|
11
11
|
assert_select 'textarea.text.disabled[disabled]'
|
12
12
|
end
|
13
13
|
|
14
14
|
test 'numeric input should be disabled when disabled option is true' do
|
15
|
-
with_input_for @user, :age, :integer, :
|
15
|
+
with_input_for @user, :age, :integer, disabled: true
|
16
16
|
assert_select 'input.integer.disabled[disabled]'
|
17
17
|
end
|
18
18
|
|
19
19
|
test 'date input should be disabled when disabled option is true' do
|
20
|
-
with_input_for @user, :born_at, :date, :
|
20
|
+
with_input_for @user, :born_at, :date, disabled: true
|
21
21
|
assert_select 'select.date.disabled[disabled]'
|
22
22
|
end
|
23
23
|
|
24
24
|
test 'datetime input should be disabled when disabled option is true' do
|
25
|
-
with_input_for @user, :created_at, :datetime, :
|
25
|
+
with_input_for @user, :created_at, :datetime, disabled: true
|
26
26
|
assert_select 'select.datetime.disabled[disabled]'
|
27
27
|
end
|
28
28
|
|
29
29
|
test 'string input should not be disabled when disabled option is false' do
|
30
|
-
with_input_for @user, :name, :string, :
|
30
|
+
with_input_for @user, :name, :string, disabled: false
|
31
31
|
assert_no_select 'input.string.disabled[disabled]'
|
32
32
|
end
|
33
33
|
|
34
34
|
test 'text input should not be disabled when disabled option is false' do
|
35
|
-
with_input_for @user, :description, :text, :
|
35
|
+
with_input_for @user, :description, :text, disabled: false
|
36
36
|
assert_no_select 'textarea.text.disabled[disabled]'
|
37
37
|
end
|
38
38
|
|
39
39
|
test 'numeric input should not be disabled when disabled option is false' do
|
40
|
-
with_input_for @user, :age, :integer, :
|
40
|
+
with_input_for @user, :age, :integer, disabled: false
|
41
41
|
assert_no_select 'input.integer.disabled[disabled]'
|
42
42
|
end
|
43
43
|
|
44
44
|
test 'date input should not be disabled when disabled option is false' do
|
45
|
-
with_input_for @user, :born_at, :date, :
|
45
|
+
with_input_for @user, :born_at, :date, disabled: false
|
46
46
|
assert_no_select 'select.date.disabled[disabled]'
|
47
47
|
end
|
48
48
|
|
49
49
|
test 'datetime input should not be disabled when disabled option is false' do
|
50
|
-
with_input_for @user, :created_at, :datetime, :
|
50
|
+
with_input_for @user, :created_at, :datetime, disabled: false
|
51
51
|
assert_no_select 'select.datetime.disabled[disabled]'
|
52
52
|
end
|
53
53
|
|
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
class DiscoveryTest < ActionView::TestCase
|
4
4
|
# Setup new inputs and remove them after the test.
|
5
5
|
def discovery(value=false)
|
6
|
-
swap SimpleForm, :
|
6
|
+
swap SimpleForm, cache_discovery: value do
|
7
7
|
begin
|
8
8
|
load "support/discovery_inputs.rb"
|
9
9
|
yield
|
@@ -29,7 +29,7 @@ class DiscoveryTest < ActionView::TestCase
|
|
29
29
|
|
30
30
|
test 'builder should discover new inputs' do
|
31
31
|
discovery do
|
32
|
-
with_form_for @user, :name, :
|
32
|
+
with_form_for @user, :name, as: :customized
|
33
33
|
assert_select 'form section input#user_name.string'
|
34
34
|
end
|
35
35
|
end
|
@@ -38,7 +38,7 @@ class DiscoveryTest < ActionView::TestCase
|
|
38
38
|
with_form_for @user, :name
|
39
39
|
assert_select 'form input#user_name.string'
|
40
40
|
|
41
|
-
swap SimpleForm, :
|
41
|
+
swap SimpleForm, inputs_discovery: false do
|
42
42
|
discovery do
|
43
43
|
with_form_for @user, :name
|
44
44
|
assert_no_select 'form section input#user_name.string'
|
@@ -62,7 +62,7 @@ class DiscoveryTest < ActionView::TestCase
|
|
62
62
|
|
63
63
|
test 'new inputs can override the input_html_options' do
|
64
64
|
discovery do
|
65
|
-
with_form_for @user, :active, :
|
65
|
+
with_form_for @user, :active, as: :select
|
66
66
|
assert_select 'form select#user_active.select.chosen'
|
67
67
|
end
|
68
68
|
end
|
@@ -8,7 +8,7 @@ class FileInputTest < ActionView::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
test "input should generate a file field that doesn't accept placeholder" do
|
11
|
-
store_translations(:en, :
|
11
|
+
store_translations(:en, simple_form: { placeholders: { user: { name: "text" } } }) do
|
12
12
|
with_input_for @user, :name, :file
|
13
13
|
assert_no_select 'input[placeholder]'
|
14
14
|
end
|
data/test/inputs/general_test.rb
CHANGED
@@ -16,52 +16,68 @@ class InputTest < ActionView::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
test 'string input should generate autofocus attribute when autofocus option is true' do
|
19
|
-
with_input_for @user, :name, :string, :
|
19
|
+
with_input_for @user, :name, :string, autofocus: true
|
20
20
|
assert_select 'input.string[autofocus]'
|
21
21
|
end
|
22
22
|
|
23
|
+
test 'input accepts input_class configuration' do
|
24
|
+
swap SimpleForm, input_class: :xlarge do
|
25
|
+
with_input_for @user, :name, :string
|
26
|
+
assert_select 'input.xlarge'
|
27
|
+
assert_no_select 'div.xlarge'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'input does not add input_class when configured to not generate additional classes for input' do
|
32
|
+
swap SimpleForm, input_class: 'xlarge', generate_additional_classes_for: [:wrapper] do
|
33
|
+
with_input_for @user, :name, :string
|
34
|
+
assert_select 'input'
|
35
|
+
assert_no_select '.xlarge'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
23
39
|
test 'text input should generate autofocus attribute when autofocus option is true' do
|
24
|
-
with_input_for @user, :description, :text, :
|
40
|
+
with_input_for @user, :description, :text, autofocus: true
|
25
41
|
assert_select 'textarea.text[autofocus]'
|
26
42
|
end
|
27
43
|
|
28
44
|
test 'numeric input should generate autofocus attribute when autofocus option is true' do
|
29
|
-
with_input_for @user, :age, :integer, :
|
45
|
+
with_input_for @user, :age, :integer, autofocus: true
|
30
46
|
assert_select 'input.integer[autofocus]'
|
31
47
|
end
|
32
48
|
|
33
49
|
test 'date input should generate autofocus attribute when autofocus option is true' do
|
34
|
-
with_input_for @user, :born_at, :date, :
|
50
|
+
with_input_for @user, :born_at, :date, autofocus: true
|
35
51
|
assert_select 'select.date[autofocus]'
|
36
52
|
end
|
37
53
|
|
38
54
|
test 'datetime input should generate autofocus attribute when autofocus option is true' do
|
39
|
-
with_input_for @user, :created_at, :datetime, :
|
55
|
+
with_input_for @user, :created_at, :datetime, autofocus: true
|
40
56
|
assert_select 'select.datetime[autofocus]'
|
41
57
|
end
|
42
58
|
|
43
59
|
test 'string input should generate autofocus attribute when autofocus option is false' do
|
44
|
-
with_input_for @user, :name, :string, :
|
60
|
+
with_input_for @user, :name, :string, autofocus: false
|
45
61
|
assert_no_select 'input.string[autofocus]'
|
46
62
|
end
|
47
63
|
|
48
64
|
test 'text input should generate autofocus attribute when autofocus option is false' do
|
49
|
-
with_input_for @user, :description, :text, :
|
65
|
+
with_input_for @user, :description, :text, autofocus: false
|
50
66
|
assert_no_select 'textarea.text[autofocus]'
|
51
67
|
end
|
52
68
|
|
53
69
|
test 'numeric input should generate autofocus attribute when autofocus option is false' do
|
54
|
-
with_input_for @user, :age, :integer, :
|
70
|
+
with_input_for @user, :age, :integer, autofocus: false
|
55
71
|
assert_no_select 'input.integer[autofocus]'
|
56
72
|
end
|
57
73
|
|
58
74
|
test 'date input should generate autofocus attribute when autofocus option is false' do
|
59
|
-
with_input_for @user, :born_at, :date, :
|
75
|
+
with_input_for @user, :born_at, :date, autofocus: false
|
60
76
|
assert_no_select 'select.date[autofocus]'
|
61
77
|
end
|
62
78
|
|
63
79
|
test 'datetime input should generate autofocus attribute when autofocus option is false' do
|
64
|
-
with_input_for @user, :created_at, :datetime, :
|
80
|
+
with_input_for @user, :created_at, :datetime, autofocus: false
|
65
81
|
assert_no_select 'select.datetime[autofocus]'
|
66
82
|
end
|
67
83
|
|
@@ -103,12 +119,12 @@ class InputTest < ActionView::TestCase
|
|
103
119
|
end
|
104
120
|
|
105
121
|
test 'input as select with collection should be generated properly when object is not present' do
|
106
|
-
with_input_for :project, :name, :select, :
|
122
|
+
with_input_for :project, :name, :select, collection: ['Jose', 'Carlos']
|
107
123
|
assert_select 'select.select#project_name'
|
108
124
|
end
|
109
125
|
|
110
126
|
test 'input should not generate empty css class' do
|
111
|
-
swap SimpleForm, :
|
127
|
+
swap SimpleForm, generate_additional_classes_for: [:wrapper, :label] do
|
112
128
|
with_input_for :project, :name, :string
|
113
129
|
assert_no_select 'input#project_name[class]'
|
114
130
|
end
|