simple_form 3.0.1 → 3.1.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 +44 -27
- data/MIT-LICENSE +1 -1
- data/README.md +204 -81
- data/lib/generators/simple_form/install_generator.rb +3 -3
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +28 -7
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +115 -24
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +86 -5
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +6 -2
- data/lib/simple_form/components/errors.rb +28 -2
- data/lib/simple_form/components/hints.rb +2 -2
- data/lib/simple_form/components/html5.rb +1 -1
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +10 -6
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/form_builder.rb +123 -73
- data/lib/simple_form/helpers.rb +5 -5
- data/lib/simple_form/inputs/base.rb +33 -11
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +28 -15
- data/lib/simple_form/inputs/collection_input.rb +30 -9
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +12 -2
- data/lib/simple_form/inputs/file_input.rb +4 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
- data/lib/simple_form/inputs/hidden_input.rb +4 -2
- data/lib/simple_form/inputs/numeric_input.rb +5 -4
- data/lib/simple_form/inputs/password_input.rb +4 -2
- data/lib/simple_form/inputs/priority_input.rb +4 -2
- data/lib/simple_form/inputs/range_input.rb +1 -1
- data/lib/simple_form/inputs/string_input.rb +4 -2
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +6 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +6 -6
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +6 -6
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +59 -8
- data/test/action_view_extensions/builder_test.rb +36 -36
- data/test/action_view_extensions/form_helper_test.rb +33 -14
- data/test/components/label_test.rb +37 -37
- data/test/form_builder/association_test.rb +52 -35
- data/test/form_builder/button_test.rb +10 -10
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/error_test.rb +144 -24
- data/test/form_builder/general_test.rb +89 -64
- data/test/form_builder/hint_test.rb +18 -18
- data/test/form_builder/input_field_test.rb +80 -16
- data/test/form_builder/label_test.rb +45 -13
- data/test/form_builder/wrapper_test.rb +135 -19
- data/test/generators/simple_form_generator_test.rb +4 -4
- data/test/inputs/boolean_input_test.rb +62 -6
- data/test/inputs/collection_check_boxes_input_test.rb +85 -17
- data/test/inputs/collection_radio_buttons_input_test.rb +134 -36
- data/test/inputs/collection_select_input_test.rb +146 -41
- data/test/inputs/datetime_input_test.rb +117 -50
- data/test/inputs/disabled_test.rb +15 -15
- data/test/inputs/discovery_test.rb +56 -6
- data/test/inputs/file_input_test.rb +2 -2
- data/test/inputs/general_test.rb +20 -20
- data/test/inputs/grouped_collection_select_input_test.rb +44 -8
- data/test/inputs/hidden_input_test.rb +4 -4
- data/test/inputs/numeric_input_test.rb +43 -43
- data/test/inputs/priority_input_test.rb +13 -13
- data/test/inputs/readonly_test.rb +19 -19
- data/test/inputs/required_test.rb +13 -13
- data/test/inputs/string_input_test.rb +50 -30
- data/test/inputs/text_input_test.rb +7 -7
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +32 -2
- data/test/support/misc_helpers.rb +77 -5
- data/test/support/models.rb +60 -24
- data/test/test_helper.rb +7 -1
- metadata +22 -33
|
@@ -6,14 +6,14 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
6
6
|
SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
test 'input
|
|
9
|
+
test 'input generates a boolean select with options by default for select types' do
|
|
10
10
|
with_input_for @user, :active, :select
|
|
11
11
|
assert_select 'select.select#user_active'
|
|
12
12
|
assert_select 'select option[value=true]', 'Yes'
|
|
13
13
|
assert_select 'select option[value=false]', 'No'
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
test 'input as select
|
|
16
|
+
test 'input as select uses i18n to translate select boolean options' do
|
|
17
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'
|
|
@@ -21,17 +21,17 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
test 'input
|
|
24
|
+
test 'input allows overriding collection for select types' do
|
|
25
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
|
-
test 'input
|
|
31
|
+
test 'input does automatic collection translation for select types using defaults key' do
|
|
32
32
|
store_translations(:en, simple_form: { options: { defaults: {
|
|
33
33
|
gender: { male: 'Male', female: 'Female'}
|
|
34
|
-
} } }
|
|
34
|
+
} } }) do
|
|
35
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'
|
|
@@ -39,10 +39,10 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
test 'input
|
|
42
|
+
test 'input does automatic collection translation for select types using specific object key' do
|
|
43
43
|
store_translations(:en, simple_form: { options: { user: {
|
|
44
44
|
gender: { male: 'Male', female: 'Female'}
|
|
45
|
-
} } }
|
|
45
|
+
} } }) do
|
|
46
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'
|
|
@@ -50,38 +50,38 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
test 'input
|
|
53
|
+
test 'input marks the selected value by default' do
|
|
54
54
|
@user.name = "Carlos"
|
|
55
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
|
|
59
|
+
test 'input accepts html options as the last element of collection' do
|
|
60
60
|
with_input_for @user, :name, :select, collection: [['Jose', class: 'foo']]
|
|
61
61
|
assert_select 'select.select#user_name'
|
|
62
62
|
assert_select 'select option.foo', 'Jose'
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
test 'input
|
|
65
|
+
test 'input marks the selected value also when using integers' do
|
|
66
66
|
@user.age = 18
|
|
67
67
|
with_input_for @user, :age, :select, collection: 18..60
|
|
68
68
|
assert_select 'select option[selected=selected]', '18'
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
test 'input
|
|
71
|
+
test 'input marks the selected value when using booleans and select' do
|
|
72
72
|
@user.active = false
|
|
73
73
|
with_input_for @user, :active, :select
|
|
74
74
|
assert_no_select 'select option[selected][value=true]', 'Yes'
|
|
75
75
|
assert_select 'select option[selected][value=false]', 'No'
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
test 'input
|
|
78
|
+
test 'input sets the correct value when using a collection that includes floats' do
|
|
79
79
|
with_input_for @user, :age, :select, collection: [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
|
|
80
80
|
assert_select 'select option[value="2.0"]'
|
|
81
81
|
assert_select 'select option[value="2.5"]'
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
test 'input
|
|
84
|
+
test 'input sets the correct values when using a collection that uses mixed values' do
|
|
85
85
|
with_input_for @user, :age, :select, collection: ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
|
|
86
86
|
assert_select 'select option[value="Hello Kitty"]'
|
|
87
87
|
assert_select 'select option[value="2"]'
|
|
@@ -92,39 +92,138 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
92
92
|
assert_select 'select option[value="false"]'
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
test 'input
|
|
95
|
+
test 'input includes a blank option even if :include_blank is set to false if the collection includes a nil value' do
|
|
96
96
|
with_input_for @user, :age, :select, collection: [nil], include_blank: false
|
|
97
97
|
assert_select 'select option[value=""]'
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
test 'input
|
|
100
|
+
test 'input automatically sets include blank' do
|
|
101
101
|
with_input_for @user, :age, :select, collection: 18..30
|
|
102
|
-
assert_select 'select option[value=]', ''
|
|
102
|
+
assert_select 'select option[value=""]', ''
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
test 'input
|
|
105
|
+
test 'input translates include blank when set to :translate' do
|
|
106
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
107
|
+
age: 'Rather not say'
|
|
108
|
+
} } }) do
|
|
109
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
|
110
|
+
assert_select 'select option[value=""]', 'Rather not say'
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
test 'input translates include blank with a default' do
|
|
115
|
+
store_translations(:en, simple_form: { include_blanks: { defaults: {
|
|
116
|
+
age: 'Rather not say',
|
|
117
|
+
} } }) do
|
|
118
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
|
119
|
+
assert_select 'select option[value=""]', 'Rather not say'
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
test 'input does not translate include blank when set to a string' do
|
|
124
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
125
|
+
age: 'Rather not say'
|
|
126
|
+
} } }) do
|
|
127
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: 'Young at heart'
|
|
128
|
+
assert_select 'select option[value=""]', 'Young at heart'
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
test 'input does not translate include blank when automatically set' do
|
|
133
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
134
|
+
age: 'Rather not say'
|
|
135
|
+
} } }) do
|
|
136
|
+
with_input_for @user, :age, :select, collection: 18..30
|
|
137
|
+
assert_select 'select option[value=""]', ''
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
test 'input does not translate include blank when set to true' do
|
|
142
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
143
|
+
age: 'Rather not say'
|
|
144
|
+
} } }) do
|
|
145
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: true
|
|
146
|
+
assert_select 'select option[value=""]', ''
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
test 'input does not translate include blank when set to false' do
|
|
151
|
+
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
152
|
+
age: 'Rather not say'
|
|
153
|
+
} } }) do
|
|
154
|
+
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
|
155
|
+
assert_no_select 'select option[value=""]'
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
test 'input does not set include blank if otherwise is told' do
|
|
106
160
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
|
107
|
-
assert_no_select 'select option[value=]'
|
|
161
|
+
assert_no_select 'select option[value=""]'
|
|
108
162
|
end
|
|
109
163
|
|
|
110
|
-
test 'input
|
|
164
|
+
test 'input does not set include blank if prompt is given' do
|
|
111
165
|
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
|
112
|
-
assert_no_select 'select option[value=]', ''
|
|
166
|
+
assert_no_select 'select option[value=""]', ''
|
|
113
167
|
end
|
|
114
168
|
|
|
115
|
-
test 'input
|
|
169
|
+
test 'input does not set include blank if multiple is given' do
|
|
116
170
|
with_input_for @user, :age, :select, collection: 18..30, input_html: { multiple: true }
|
|
117
|
-
assert_no_select 'select option[value=]', ''
|
|
171
|
+
assert_no_select 'select option[value=""]', ''
|
|
118
172
|
end
|
|
119
173
|
|
|
120
|
-
test 'input
|
|
174
|
+
test 'input translates prompt when set to :translate' do
|
|
175
|
+
store_translations(:en, simple_form: { prompts: { user: {
|
|
176
|
+
age: 'Select age:'
|
|
177
|
+
} } }) do
|
|
178
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
179
|
+
assert_select 'select option[value=""]', 'Select age:'
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
test 'input translates prompt with a default' do
|
|
184
|
+
store_translations(:en, simple_form: { prompts: { defaults: {
|
|
185
|
+
age: 'Select age:',
|
|
186
|
+
} } }) do
|
|
187
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
188
|
+
assert_select 'select option[value=""]', 'Select age:'
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
test 'input does not translate prompt when set to a string' do
|
|
193
|
+
store_translations(:en, simple_form: { prompts: { user: {
|
|
194
|
+
age: 'Select age:'
|
|
195
|
+
} } }) do
|
|
196
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: 'Do it:'
|
|
197
|
+
assert_select 'select option[value=""]', 'Do it:'
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
test 'input does not translate prompt when set to false' do
|
|
202
|
+
store_translations(:en, simple_form: { prompts: { user: {
|
|
203
|
+
age: 'Select age:'
|
|
204
|
+
} } }) do
|
|
205
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: false
|
|
206
|
+
assert_no_select 'select option[value=""]'
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
test 'input uses Rails prompt translation as a fallback' do
|
|
211
|
+
store_translations(:en, helpers: { select: {
|
|
212
|
+
prompt: 'Select value:'
|
|
213
|
+
} }) do
|
|
214
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
215
|
+
assert_select 'select option[value=""]', "Select value:"
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
test 'input detects label and value on collections' do
|
|
121
220
|
users = [User.build(id: 1, name: "Jose"), User.build(id: 2, name: "Carlos")]
|
|
122
221
|
with_input_for @user, :description, :select, collection: users
|
|
123
|
-
assert_select 'select option[value=1]', 'Jose'
|
|
124
|
-
assert_select 'select option[value=2]', 'Carlos'
|
|
222
|
+
assert_select 'select option[value="1"]', 'Jose'
|
|
223
|
+
assert_select 'select option[value="2"]', 'Carlos'
|
|
125
224
|
end
|
|
126
225
|
|
|
127
|
-
test 'input
|
|
226
|
+
test 'input disables the anothers components when the option is a object' do
|
|
128
227
|
with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: true
|
|
129
228
|
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
|
130
229
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
@@ -132,7 +231,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
132
231
|
assert_select 'div.disabled'
|
|
133
232
|
end
|
|
134
233
|
|
|
135
|
-
test 'input
|
|
234
|
+
test 'input does not disable the anothers components when the option is a object' do
|
|
136
235
|
with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: 'Jose'
|
|
137
236
|
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
|
138
237
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
@@ -140,7 +239,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
140
239
|
assert_no_select 'div.disabled'
|
|
141
240
|
end
|
|
142
241
|
|
|
143
|
-
test 'input
|
|
242
|
+
test 'input allows overriding label and value method using a lambda for collection selects' do
|
|
144
243
|
with_input_for @user, :name, :select,
|
|
145
244
|
collection: ['Jose', 'Carlos'],
|
|
146
245
|
label_method: lambda { |i| i.upcase },
|
|
@@ -149,7 +248,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
149
248
|
assert_select 'select option[value=carlos]', "CARLOS"
|
|
150
249
|
end
|
|
151
250
|
|
|
152
|
-
test 'input
|
|
251
|
+
test 'input allows overriding only label but not value method using a lambda for collection select' do
|
|
153
252
|
with_input_for @user, :name, :select,
|
|
154
253
|
collection: ['Jose', 'Carlos'],
|
|
155
254
|
label_method: lambda { |i| i.upcase }
|
|
@@ -157,7 +256,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
157
256
|
assert_select 'select option[value=Carlos]', "CARLOS"
|
|
158
257
|
end
|
|
159
258
|
|
|
160
|
-
test 'input
|
|
259
|
+
test 'input allows overriding only value but not label method using a lambda for collection select' do
|
|
161
260
|
with_input_for @user, :name, :select,
|
|
162
261
|
collection: ['Jose', 'Carlos'],
|
|
163
262
|
value_method: lambda { |i| i.downcase }
|
|
@@ -165,33 +264,39 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
165
264
|
assert_select 'select option[value=carlos]', "Carlos"
|
|
166
265
|
end
|
|
167
266
|
|
|
168
|
-
test 'input
|
|
267
|
+
test 'input allows symbols for collections' do
|
|
169
268
|
with_input_for @user, :name, :select, collection: [:jose, :carlos]
|
|
170
269
|
assert_select 'select.select#user_name'
|
|
171
270
|
assert_select 'select option[value=jose]', 'jose'
|
|
172
271
|
assert_select 'select option[value=carlos]', 'carlos'
|
|
173
272
|
end
|
|
174
273
|
|
|
175
|
-
test 'collection input with select type
|
|
274
|
+
test 'collection input with select type generates required html attribute only with blank option' do
|
|
176
275
|
with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
|
|
177
276
|
assert_select 'select.required'
|
|
178
277
|
assert_select 'select[required]'
|
|
179
278
|
end
|
|
180
279
|
|
|
181
|
-
test 'collection input with select type
|
|
280
|
+
test 'collection input with select type generates required html attribute only with blank option or prompt' do
|
|
281
|
+
with_input_for @user, :name, :select, prompt: 'Name...', collection: ['Jose', 'Carlos']
|
|
282
|
+
assert_select 'select.required'
|
|
283
|
+
assert_select 'select[required]'
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
test 'collection input with select type does not generate required html attribute without blank option' do
|
|
182
287
|
with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
|
|
183
288
|
assert_select 'select.required'
|
|
184
289
|
assert_no_select 'select[required]'
|
|
185
290
|
assert_no_select 'select[aria-required=true]'
|
|
186
291
|
end
|
|
187
292
|
|
|
188
|
-
test 'collection input with select type with multiple attribute
|
|
293
|
+
test 'collection input with select type with multiple attribute generates required html attribute without blank option' do
|
|
189
294
|
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
|
190
295
|
assert_select 'select.required'
|
|
191
296
|
assert_select 'select[required]'
|
|
192
297
|
end
|
|
193
298
|
|
|
194
|
-
test 'collection input with select type with multiple attribute
|
|
299
|
+
test 'collection input with select type with multiple attribute generates required html attribute with blank option' do
|
|
195
300
|
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
|
196
301
|
assert_select 'select.required'
|
|
197
302
|
assert_select 'select[required]'
|
|
@@ -221,7 +326,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
221
326
|
assert_select 'select[aria-required]'
|
|
222
327
|
end
|
|
223
328
|
|
|
224
|
-
test 'input
|
|
329
|
+
test 'input allows disabled options with a lambda for collection select' do
|
|
225
330
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
226
331
|
disabled: lambda { |x| x == "Carlos" }
|
|
227
332
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
@@ -229,7 +334,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
229
334
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
230
335
|
end
|
|
231
336
|
|
|
232
|
-
test 'input
|
|
337
|
+
test 'input allows disabled and label method with lambdas for collection select' do
|
|
233
338
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
234
339
|
disabled: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
|
|
235
340
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
|
@@ -237,7 +342,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
237
342
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
238
343
|
end
|
|
239
344
|
|
|
240
|
-
test 'input
|
|
345
|
+
test 'input allows a non lambda disabled option with lambda label method for collections' do
|
|
241
346
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
242
347
|
disabled: "Carlos", label_method: lambda { |x| x.upcase }
|
|
243
348
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
|
@@ -245,7 +350,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
245
350
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
246
351
|
end
|
|
247
352
|
|
|
248
|
-
test 'input
|
|
353
|
+
test 'input allows selected and label method with lambdas for collection select' do
|
|
249
354
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
250
355
|
selected: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
|
|
251
356
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
|
@@ -253,7 +358,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
253
358
|
assert_no_select 'select option[value=Antonio][selected]'
|
|
254
359
|
end
|
|
255
360
|
|
|
256
|
-
test 'input
|
|
361
|
+
test 'input allows a non lambda selected option with lambda label method for collection select' do
|
|
257
362
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
258
363
|
selected: "Carlos", label_method: lambda { |x| x.upcase }
|
|
259
364
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
|
@@ -261,7 +366,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
261
366
|
assert_no_select 'select option[value=Antonio][selected]'
|
|
262
367
|
end
|
|
263
368
|
|
|
264
|
-
test 'input
|
|
369
|
+
test 'input does not override default selection through attribute value with label method as lambda for collection select' do
|
|
265
370
|
@user.name = "Carlos"
|
|
266
371
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
267
372
|
label_method: lambda { |x| x.upcase }
|
|
@@ -1,18 +1,69 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
require 'test_helper'
|
|
3
3
|
|
|
4
|
-
# Tests for
|
|
5
|
-
class
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
|
|
5
|
+
class DateTimeInputWithHtml5Test < ActionView::TestCase
|
|
6
|
+
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enbled' do
|
|
7
|
+
with_input_for @user, :created_at, :datetime, html5: true
|
|
8
|
+
|
|
9
|
+
assert_select 'input[type="datetime"]'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test 'input generates a datetime select for datetime attributes' do
|
|
8
13
|
with_input_for @user, :created_at, :datetime
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
|
|
15
|
+
assert_select 'select.datetime'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enbled' do
|
|
19
|
+
with_input_for @user, :born_at, :date, html5: true
|
|
20
|
+
|
|
21
|
+
assert_select 'input[type="date"]'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test 'input generates a date select for date attributes' do
|
|
25
|
+
with_input_for @user, :born_at, :date
|
|
26
|
+
|
|
27
|
+
assert_select 'select.date'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enbled' do
|
|
31
|
+
with_input_for @user, :delivery_time, :time, html5: true
|
|
32
|
+
|
|
33
|
+
assert_select 'input[type="time"]'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test 'input generates a time select for time attributes' do
|
|
37
|
+
with_input_for @user, :delivery_time, :time
|
|
38
|
+
|
|
39
|
+
assert_select 'select.time'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'input generates required html attribute' do
|
|
43
|
+
with_input_for @user, :delivery_time, :time, required: true, html5: true
|
|
44
|
+
assert_select 'input.required'
|
|
45
|
+
assert_select 'input[required]'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test 'input has an aria-required html attribute' do
|
|
49
|
+
with_input_for @user, :delivery_time, :time, required: true, html5: true
|
|
50
|
+
assert_select 'input[aria-required=true]'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
|
|
55
|
+
class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
|
56
|
+
test 'input generates a datetime select by default for datetime attributes' do
|
|
57
|
+
swap_wrapper do
|
|
58
|
+
with_input_for @user, :created_at, :datetime
|
|
59
|
+
1.upto(5) do |i|
|
|
60
|
+
assert_select "form select.datetime#user_created_at_#{i}i"
|
|
61
|
+
end
|
|
11
62
|
end
|
|
12
63
|
end
|
|
13
64
|
|
|
14
|
-
test 'input
|
|
15
|
-
with_input_for @user, :created_at, :datetime,
|
|
65
|
+
test 'input is able to pass options to datetime select' do
|
|
66
|
+
with_input_for @user, :created_at, :datetime, html5: false,
|
|
16
67
|
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
|
17
68
|
|
|
18
69
|
assert_select 'select.datetime[disabled=disabled]'
|
|
@@ -21,16 +72,26 @@ class DateTimeInputTest < ActionView::TestCase
|
|
|
21
72
|
assert_select 'select.datetime option', 'dia'
|
|
22
73
|
end
|
|
23
74
|
|
|
24
|
-
test 'input
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
75
|
+
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enabled' do
|
|
76
|
+
swap_wrapper do
|
|
77
|
+
with_input_for @user, :created_at, :datetime, html5: true
|
|
78
|
+
|
|
79
|
+
assert_select 'input[type="datetime"]'
|
|
80
|
+
end
|
|
30
81
|
end
|
|
31
82
|
|
|
32
|
-
test 'input
|
|
33
|
-
|
|
83
|
+
test 'input generates a date select for date attributes' do
|
|
84
|
+
swap_wrapper do
|
|
85
|
+
with_input_for @user, :born_at, :date
|
|
86
|
+
assert_select 'select.date#user_born_at_1i'
|
|
87
|
+
assert_select 'select.date#user_born_at_2i'
|
|
88
|
+
assert_select 'select.date#user_born_at_3i'
|
|
89
|
+
assert_no_select 'select.date#user_born_at_4i'
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
test 'input is able to pass options to date select' do
|
|
94
|
+
with_input_for @user, :born_at, :date, as: :date, html5: false,
|
|
34
95
|
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
|
35
96
|
|
|
36
97
|
assert_select 'select.date[disabled=disabled]'
|
|
@@ -39,22 +100,32 @@ class DateTimeInputTest < ActionView::TestCase
|
|
|
39
100
|
assert_select 'select.date option', 'dia'
|
|
40
101
|
end
|
|
41
102
|
|
|
42
|
-
test 'input
|
|
43
|
-
with_input_for @user, :born_at, :date, default: Date.today
|
|
44
|
-
assert_select "select.date option[value
|
|
103
|
+
test 'input is able to pass :default to date select' do
|
|
104
|
+
with_input_for @user, :born_at, :date, default: Date.today, html5: false
|
|
105
|
+
assert_select "select.date option[value='#{Date.today.year}'][selected=selected]"
|
|
45
106
|
end
|
|
46
107
|
|
|
47
|
-
test 'input
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
assert_select 'select.time#user_delivery_time_5i'
|
|
108
|
+
test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enabled' do
|
|
109
|
+
swap_wrapper do
|
|
110
|
+
with_input_for @user, :born_at, :date, html5: true
|
|
111
|
+
|
|
112
|
+
assert_select 'input[type="date"]'
|
|
113
|
+
end
|
|
54
114
|
end
|
|
55
115
|
|
|
56
|
-
test 'input
|
|
57
|
-
|
|
116
|
+
test 'input generates a time select for time attributes' do
|
|
117
|
+
swap_wrapper do
|
|
118
|
+
with_input_for @user, :delivery_time, :time
|
|
119
|
+
assert_select 'input[type=hidden]#user_delivery_time_1i'
|
|
120
|
+
assert_select 'input[type=hidden]#user_delivery_time_2i'
|
|
121
|
+
assert_select 'input[type=hidden]#user_delivery_time_3i'
|
|
122
|
+
assert_select 'select.time#user_delivery_time_4i'
|
|
123
|
+
assert_select 'select.time#user_delivery_time_5i'
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
test 'input is able to pass options to time select' do
|
|
128
|
+
with_input_for @user, :delivery_time, :time, required: true, html5: false,
|
|
58
129
|
disabled: true, prompt: { hour: 'hora', minute: 'minuto' }
|
|
59
130
|
|
|
60
131
|
assert_select 'select.time[disabled=disabled]'
|
|
@@ -62,44 +133,40 @@ class DateTimeInputTest < ActionView::TestCase
|
|
|
62
133
|
assert_select 'select.time option', 'minuto'
|
|
63
134
|
end
|
|
64
135
|
|
|
65
|
-
test '
|
|
136
|
+
test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enabled' do
|
|
137
|
+
swap_wrapper do
|
|
138
|
+
with_input_for @user, :delivery_time, :time, html5: true
|
|
139
|
+
|
|
140
|
+
assert_select 'input[type="time"]'
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
test 'label uses i18n to get target for date input type' do
|
|
66
145
|
store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
|
|
67
|
-
with_input_for :project, :created_at, :date
|
|
146
|
+
with_input_for :project, :created_at, :date, html5: false
|
|
68
147
|
assert_select 'label[for=project_created_at_2i]'
|
|
69
148
|
end
|
|
70
149
|
end
|
|
71
150
|
|
|
72
|
-
test 'label
|
|
151
|
+
test 'label uses i18n to get target for datetime input type' do
|
|
73
152
|
store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
|
|
74
|
-
with_input_for :project, :created_at, :datetime
|
|
153
|
+
with_input_for :project, :created_at, :datetime, html5: false
|
|
75
154
|
assert_select 'label[for=project_created_at_2i]'
|
|
76
155
|
end
|
|
77
156
|
end
|
|
78
157
|
|
|
79
|
-
test 'label
|
|
80
|
-
with_input_for :project, :created_at, :date, order: ['month', 'year', 'day']
|
|
158
|
+
test 'label uses order to get target when date input type' do
|
|
159
|
+
with_input_for :project, :created_at, :date, order: ['month', 'year', 'day'], html5: false
|
|
81
160
|
assert_select 'label[for=project_created_at_2i]'
|
|
82
161
|
end
|
|
83
162
|
|
|
84
|
-
test 'label
|
|
85
|
-
with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day']
|
|
163
|
+
test 'label uses order to get target when datetime input type' do
|
|
164
|
+
with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day'], html5: false
|
|
86
165
|
assert_select 'label[for=project_created_at_2i]'
|
|
87
166
|
end
|
|
88
167
|
|
|
89
|
-
test 'label
|
|
90
|
-
with_input_for :project, :created_at, :time
|
|
168
|
+
test 'label points to first option when time input type' do
|
|
169
|
+
with_input_for :project, :created_at, :time, html5: false
|
|
91
170
|
assert_select 'label[for=project_created_at_4i]'
|
|
92
171
|
end
|
|
93
|
-
|
|
94
|
-
test 'date time input should generate required html attribute' do
|
|
95
|
-
with_input_for @user, :delivery_time, :time, required: true
|
|
96
|
-
assert_select 'select.required'
|
|
97
|
-
assert_select 'select[required]'
|
|
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
|
|
105
172
|
end
|