simple_form 3.1.0.rc1 → 3.1.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +37 -6
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +6 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +37 -14
- data/lib/simple_form.rb +8 -0
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/form_builder.rb +29 -15
- data/lib/simple_form/inputs/boolean_input.rb +7 -4
- data/lib/simple_form/tags.rb +1 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +2 -2
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/test/action_view_extensions/builder_test.rb +3 -3
- data/test/action_view_extensions/form_helper_test.rb +13 -13
- data/test/components/label_test.rb +35 -35
- data/test/form_builder/association_test.rb +4 -4
- data/test/form_builder/button_test.rb +5 -5
- data/test/form_builder/error_test.rb +18 -18
- data/test/form_builder/general_test.rb +65 -60
- data/test/form_builder/hint_test.rb +15 -15
- data/test/form_builder/input_field_test.rb +16 -16
- data/test/form_builder/label_test.rb +22 -13
- data/test/form_builder/wrapper_test.rb +54 -20
- data/test/inputs/boolean_input_test.rb +8 -8
- data/test/inputs/collection_check_boxes_input_test.rb +24 -7
- data/test/inputs/collection_radio_buttons_input_test.rb +40 -23
- data/test/inputs/collection_select_input_test.rb +45 -45
- data/test/inputs/datetime_input_test.rb +23 -23
- data/test/inputs/disabled_test.rb +15 -15
- data/test/inputs/discovery_test.rb +44 -5
- 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 +2 -2
- data/test/inputs/hidden_input_test.rb +4 -4
- data/test/inputs/numeric_input_test.rb +24 -24
- data/test/inputs/priority_input_test.rb +7 -7
- data/test/inputs/readonly_test.rb +19 -19
- data/test/inputs/required_test.rb +13 -13
- data/test/inputs/string_input_test.rb +23 -23
- data/test/inputs/text_input_test.rb +4 -4
- data/test/support/discovery_inputs.rb +20 -0
- data/test/support/misc_helpers.rb +22 -0
- data/test/support/models.rb +2 -1
- metadata +2 -2
@@ -8,17 +8,17 @@ class FormHelperTest < ActionView::TestCase
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
test 'SimpleForm
|
11
|
+
test 'SimpleForm adds default class to form' do
|
12
12
|
with_concat_form_for(:user)
|
13
13
|
assert_select 'form.simple_form'
|
14
14
|
end
|
15
15
|
|
16
|
-
test 'SimpleForm
|
16
|
+
test 'SimpleForm uses default browser validations by default' do
|
17
17
|
with_concat_form_for(:user)
|
18
18
|
assert_no_select 'form[novalidate]'
|
19
19
|
end
|
20
20
|
|
21
|
-
test 'SimpleForm
|
21
|
+
test 'SimpleForm does not use default browser validations if specified in the configuration options' do
|
22
22
|
swap SimpleForm, browser_validations: false do
|
23
23
|
with_concat_form_for(:user)
|
24
24
|
assert_select 'form[novalidate="novalidate"]'
|
@@ -37,54 +37,54 @@ class FormHelperTest < ActionView::TestCase
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
test 'SimpleForm
|
40
|
+
test 'SimpleForm adds object name as css class to form when object is not present' do
|
41
41
|
with_concat_form_for(:user, html: { novalidate: true })
|
42
42
|
assert_select 'form.simple_form.user'
|
43
43
|
end
|
44
44
|
|
45
|
-
test 'SimpleForm
|
45
|
+
test 'SimpleForm adds :as option as css class to form when object is not present' do
|
46
46
|
with_concat_form_for(:user, as: 'superuser')
|
47
47
|
assert_select 'form.simple_form.superuser'
|
48
48
|
end
|
49
49
|
|
50
|
-
test 'SimpleForm
|
50
|
+
test 'SimpleForm adds object class name with new prefix as css class to form if record is not persisted' do
|
51
51
|
@user.new_record!
|
52
52
|
with_concat_form_for(@user)
|
53
53
|
assert_select 'form.simple_form.new_user'
|
54
54
|
end
|
55
55
|
|
56
|
-
test 'SimpleForm
|
56
|
+
test 'SimpleForm adds :as option with new prefix as css class to form if record is not persisted' do
|
57
57
|
@user.new_record!
|
58
58
|
with_concat_form_for(@user, as: 'superuser')
|
59
59
|
assert_select 'form.simple_form.new_superuser'
|
60
60
|
end
|
61
61
|
|
62
|
-
test 'SimpleForm
|
62
|
+
test 'SimpleForm adds edit class prefix as css class to form if record is persisted' do
|
63
63
|
with_concat_form_for(@user)
|
64
64
|
assert_select 'form.simple_form.edit_user'
|
65
65
|
end
|
66
66
|
|
67
|
-
test 'SimpleForm
|
67
|
+
test 'SimpleForm adds :as options with edit prefix as css class to form if record is persisted' do
|
68
68
|
with_concat_form_for(@user, as: 'superuser')
|
69
69
|
assert_select 'form.simple_form.edit_superuser'
|
70
70
|
end
|
71
71
|
|
72
|
-
test 'SimpleForm
|
72
|
+
test 'SimpleForm adds last object name as css class to form when there is array of objects' do
|
73
73
|
with_concat_form_for([Company.new, @user])
|
74
74
|
assert_select 'form.simple_form.edit_user'
|
75
75
|
end
|
76
76
|
|
77
|
-
test 'SimpleForm
|
77
|
+
test 'SimpleForm does not add object class to form if css_class is specified' do
|
78
78
|
with_concat_form_for(:user, html: { class: nil })
|
79
79
|
assert_no_select 'form.user'
|
80
80
|
end
|
81
81
|
|
82
|
-
test 'SimpleForm
|
82
|
+
test 'SimpleForm adds custom class to form if css_class is specified' do
|
83
83
|
with_concat_form_for(:user, html: { class: 'my_class' })
|
84
84
|
assert_select 'form.my_class'
|
85
85
|
end
|
86
86
|
|
87
|
-
test '
|
87
|
+
test 'passes options to SimpleForm' do
|
88
88
|
with_concat_form_for(:user, url: '/account', html: { id: 'my_form' })
|
89
89
|
assert_select 'form#my_form'
|
90
90
|
assert_select 'form[action=/account]'
|
@@ -14,27 +14,27 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
test 'label
|
17
|
+
test 'label generates a default humanized description' do
|
18
18
|
with_label_for @user, :name, :string
|
19
19
|
assert_select 'label[for=user_name]', /Name/
|
20
20
|
end
|
21
21
|
|
22
|
-
test 'label
|
22
|
+
test 'label allows a customized description' do
|
23
23
|
with_label_for @user, :name, :string, label: 'My label!'
|
24
24
|
assert_select 'label[for=user_name]', /My label!/
|
25
25
|
end
|
26
26
|
|
27
|
-
test 'label
|
27
|
+
test 'label uses human attribute name from object when available' do
|
28
28
|
with_label_for @user, :description, :text
|
29
29
|
assert_select 'label[for=user_description]', /User Description!/
|
30
30
|
end
|
31
31
|
|
32
|
-
test 'label
|
32
|
+
test 'label uses human attribute name based on association name' do
|
33
33
|
with_label_for @user, :company_id, :string, setup_association: true
|
34
34
|
assert_select 'label', /Company Human Name!/
|
35
35
|
end
|
36
36
|
|
37
|
-
test 'label
|
37
|
+
test 'label uses i18n based on model, action, and attribute to lookup translation' do
|
38
38
|
@controller.action_name = "new"
|
39
39
|
store_translations(:en, simple_form: { labels: { user: {
|
40
40
|
new: { description: 'Nova descrição' }
|
@@ -44,7 +44,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
test 'label
|
47
|
+
test 'label fallbacks to new when action is create' do
|
48
48
|
@controller.action_name = "create"
|
49
49
|
store_translations(:en, simple_form: { labels: { user: {
|
50
50
|
new: { description: 'Nova descrição' }
|
@@ -54,7 +54,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
test 'label
|
57
|
+
test 'label does not explode while looking for i18n translation when action is not set' do
|
58
58
|
def @controller.action_name; nil; end
|
59
59
|
|
60
60
|
assert_nothing_raised do
|
@@ -63,7 +63,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
63
63
|
assert_select 'label[for=user_description]'
|
64
64
|
end
|
65
65
|
|
66
|
-
test 'label
|
66
|
+
test 'label uses i18n based on model and attribute to lookup translation' do
|
67
67
|
store_translations(:en, simple_form: { labels: { user: {
|
68
68
|
description: 'Descrição'
|
69
69
|
} } }) do
|
@@ -72,14 +72,14 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
test 'label
|
75
|
+
test 'label uses i18n under defaults to lookup translation' do
|
76
76
|
store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
|
77
77
|
with_label_for @user, :age, :integer
|
78
78
|
assert_select 'label[for=user_age]', /Idade/
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
test 'label
|
82
|
+
test 'label does not use i18n label if translate is false' do
|
83
83
|
swap SimpleForm, translate_labels: false do
|
84
84
|
store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
|
85
85
|
with_label_for @user, :age, :integer
|
@@ -107,7 +107,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
test 'label
|
110
|
+
test 'label does correct i18n lookup for nested models with nested translation' do
|
111
111
|
@user.company = Company.new(1, 'Empresa')
|
112
112
|
|
113
113
|
store_translations(:en, simple_form: { labels: {
|
@@ -125,7 +125,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
test 'label
|
128
|
+
test 'label does correct i18n lookup for nested models with no nested translation' do
|
129
129
|
@user.company = Company.new(1, 'Empresa')
|
130
130
|
|
131
131
|
store_translations(:en, simple_form: { labels: {
|
@@ -144,7 +144,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
-
test 'label
|
147
|
+
test 'label does correct i18n lookup for nested has_many models with no nested translation' do
|
148
148
|
@user.tags = [Tag.new(1, 'Empresa')]
|
149
149
|
|
150
150
|
store_translations(:en, simple_form: { labels: {
|
@@ -163,7 +163,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
-
test 'label
|
166
|
+
test 'label has css class from type' do
|
167
167
|
with_label_for @user, :name, :string
|
168
168
|
assert_select 'label.string'
|
169
169
|
with_label_for @user, :description, :text
|
@@ -176,7 +176,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
176
176
|
assert_select 'label.datetime'
|
177
177
|
end
|
178
178
|
|
179
|
-
test 'label
|
179
|
+
test 'label does not have css class from type when generate_additional_classes_for does not include :label' do
|
180
180
|
swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
|
181
181
|
with_label_for @user, :name, :string
|
182
182
|
assert_no_select 'label.string'
|
@@ -191,21 +191,21 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
-
test 'label
|
194
|
+
test 'label does not generate empty css class' do
|
195
195
|
swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
|
196
196
|
with_label_for @user, :name, :string
|
197
197
|
assert_no_select 'label[class]'
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
-
test 'label
|
201
|
+
test 'label obtains required from ActiveModel::Validations when it is included' do
|
202
202
|
with_label_for @validating_user, :name, :string
|
203
203
|
assert_select 'label.required'
|
204
204
|
with_label_for @validating_user, :status, :string
|
205
205
|
assert_select 'label.optional'
|
206
206
|
end
|
207
207
|
|
208
|
-
test 'label
|
208
|
+
test 'label does not obtain required from ActiveModel::Validations when generate_additional_classes_for does not include :label' do
|
209
209
|
swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
|
210
210
|
with_label_for @validating_user, :name, :string
|
211
211
|
assert_no_select 'label.required'
|
@@ -214,48 +214,48 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
|
-
test 'label
|
217
|
+
test 'label allows overriding required when ActiveModel::Validations is included' do
|
218
218
|
with_label_for @validating_user, :name, :string, required: false
|
219
219
|
assert_select 'label.optional'
|
220
220
|
with_label_for @validating_user, :status, :string, required: true
|
221
221
|
assert_select 'label.required'
|
222
222
|
end
|
223
223
|
|
224
|
-
test 'label
|
224
|
+
test 'label is required by default when ActiveModel::Validations is not included' do
|
225
225
|
with_label_for @user, :name, :string
|
226
226
|
assert_select 'label.required'
|
227
227
|
end
|
228
228
|
|
229
|
-
test 'label
|
229
|
+
test 'label is able to disable required when ActiveModel::Validations is not included' do
|
230
230
|
with_label_for @user, :name, :string, required: false
|
231
231
|
assert_no_select 'label.required'
|
232
232
|
end
|
233
233
|
|
234
|
-
test 'label
|
234
|
+
test 'label adds required text when required' do
|
235
235
|
with_label_for @user, :name, :string
|
236
236
|
assert_select 'label.required abbr[title=required]', '*'
|
237
237
|
end
|
238
238
|
|
239
|
-
test 'label
|
239
|
+
test 'label does not have required text in no required inputs' do
|
240
240
|
with_label_for @user, :name, :string, required: false
|
241
241
|
assert_no_select 'form label abbr'
|
242
242
|
end
|
243
243
|
|
244
|
-
test 'label
|
244
|
+
test 'label uses i18n to find required text' do
|
245
245
|
store_translations(:en, simple_form: { required: { text: 'campo requerido' } }) do
|
246
246
|
with_label_for @user, :name, :string
|
247
247
|
assert_select 'form label abbr[title=campo requerido]', '*'
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
251
|
-
test 'label
|
251
|
+
test 'label uses i18n to find required mark' do
|
252
252
|
store_translations(:en, simple_form: { required: { mark: '*-*' } }) do
|
253
253
|
with_label_for @user, :name, :string
|
254
254
|
assert_select 'form label abbr', '*-*'
|
255
255
|
end
|
256
256
|
end
|
257
257
|
|
258
|
-
test 'label
|
258
|
+
test 'label uses i18n to find required string tag' do
|
259
259
|
store_translations(:en, simple_form: { required: { html: '<span class="required" title="requerido">*</span>' } }) do
|
260
260
|
with_label_for @user, :name, :string
|
261
261
|
assert_no_select 'form label abbr'
|
@@ -263,37 +263,37 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
266
|
-
test 'label
|
266
|
+
test 'label allows overwriting input id' do
|
267
267
|
with_label_for @user, :name, :string, input_html: { id: 'my_new_id' }
|
268
268
|
assert_select 'label[for=my_new_id]'
|
269
269
|
end
|
270
270
|
|
271
|
-
test 'label
|
271
|
+
test 'label allows overwriting of for attribute' do
|
272
272
|
with_label_for @user, :name, :string, label_html: { for: 'my_new_id' }
|
273
273
|
assert_select 'label[for=my_new_id]'
|
274
274
|
end
|
275
275
|
|
276
|
-
test 'label
|
276
|
+
test 'label allows overwriting of for attribute with input_html not containing id' do
|
277
277
|
with_label_for @user, :name, :string, label_html: { for: 'my_new_id' }, input_html: { class: 'foo' }
|
278
278
|
assert_select 'label[for=my_new_id]'
|
279
279
|
end
|
280
280
|
|
281
|
-
test 'label
|
281
|
+
test 'label uses default input id when it was not overridden' do
|
282
282
|
with_label_for @user, :name, :string, input_html: { class: 'my_new_id' }
|
283
283
|
assert_select 'label[for=user_name]'
|
284
284
|
end
|
285
285
|
|
286
|
-
test 'label
|
286
|
+
test 'label is generated properly when object is not present' do
|
287
287
|
with_label_for :project, :name, :string
|
288
288
|
assert_select 'label[for=project_name]', /Name/
|
289
289
|
end
|
290
290
|
|
291
|
-
test 'label
|
291
|
+
test 'label includes for attribute for select collection' do
|
292
292
|
with_label_for @user, :sex, :select, collection: [:male, :female]
|
293
293
|
assert_select 'label[for=user_sex]'
|
294
294
|
end
|
295
295
|
|
296
|
-
test 'label
|
296
|
+
test 'label uses i18n properly when object is not present' do
|
297
297
|
store_translations(:en, simple_form: { labels: {
|
298
298
|
project: { name: 'Nome' }
|
299
299
|
} }) do
|
@@ -302,14 +302,14 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
|
-
test 'label
|
305
|
+
test 'label adds required by default when object is not present' do
|
306
306
|
with_label_for :project, :name, :string
|
307
307
|
assert_select 'label.required[for=project_name]'
|
308
308
|
with_label_for :project, :description, :string, required: false
|
309
309
|
assert_no_select 'label.required[for=project_description]'
|
310
310
|
end
|
311
311
|
|
312
|
-
test 'label
|
312
|
+
test 'label adds chosen label class' do
|
313
313
|
swap SimpleForm, label_class: :my_custom_class do
|
314
314
|
with_label_for @user, :name, :string
|
315
315
|
assert_select 'label.my_custom_class'
|
@@ -8,7 +8,7 @@ class AssociationTest < ActionView::TestCase
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
test 'builder
|
11
|
+
test 'builder does not allow creating an association input when no object exists' do
|
12
12
|
assert_raise ArgumentError do
|
13
13
|
with_association_for :post, :author
|
14
14
|
end
|
@@ -130,7 +130,7 @@ class AssociationTest < ActionView::TestCase
|
|
130
130
|
end
|
131
131
|
|
132
132
|
# ASSOCIATIONS - FINDERS
|
133
|
-
test 'builder
|
133
|
+
test 'builder uses reflection conditions to find collection' do
|
134
134
|
with_association_for @user, :special_company
|
135
135
|
assert_select 'form select.select#user_special_company_id'
|
136
136
|
assert_select 'form select option[value=1]'
|
@@ -138,7 +138,7 @@ class AssociationTest < ActionView::TestCase
|
|
138
138
|
assert_no_select 'form select option[value=3]'
|
139
139
|
end
|
140
140
|
|
141
|
-
test 'builder
|
141
|
+
test 'builder allows overriding collection to association input' do
|
142
142
|
with_association_for @user, :company, include_blank: false,
|
143
143
|
collection: [Company.new(999, 'Teste')]
|
144
144
|
assert_select 'form select.select#user_company_id'
|
@@ -209,7 +209,7 @@ class AssociationTest < ActionView::TestCase
|
|
209
209
|
assert_select 'form ul li', count: 3
|
210
210
|
end
|
211
211
|
|
212
|
-
test 'builder with collection support
|
212
|
+
test 'builder with collection support does not change the options hash' do
|
213
213
|
options = { as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li}
|
214
214
|
with_association_for @user, :tags, options
|
215
215
|
|
@@ -8,30 +8,30 @@ class ButtonTest < ActionView::TestCase
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
test 'builder
|
11
|
+
test 'builder creates buttons' do
|
12
12
|
with_button_for :post, :submit
|
13
13
|
assert_select 'form input.button[type=submit][value=Save Post]'
|
14
14
|
end
|
15
15
|
|
16
|
-
test 'builder
|
16
|
+
test 'builder creates buttons with options' do
|
17
17
|
with_button_for :post, :submit, class: 'my_button'
|
18
18
|
assert_select 'form input.button.my_button[type=submit][value=Save Post]'
|
19
19
|
end
|
20
20
|
|
21
|
-
test 'builder
|
21
|
+
test 'builder does not modify the options hash' do
|
22
22
|
options = { class: 'my_button' }
|
23
23
|
with_button_for :post, :submit, options
|
24
24
|
assert_select 'form input.button.my_button[type=submit][value=Save Post]'
|
25
25
|
assert_equal({ class: 'my_button' }, options)
|
26
26
|
end
|
27
27
|
|
28
|
-
test 'builder
|
28
|
+
test 'builder creates buttons for records' do
|
29
29
|
@user.new_record!
|
30
30
|
with_button_for @user, :submit
|
31
31
|
assert_select 'form input.button[type=submit][value=Create User]'
|
32
32
|
end
|
33
33
|
|
34
|
-
test "builder
|
34
|
+
test "builder uses the default class from the configuration" do
|
35
35
|
swap SimpleForm, button_class: 'btn' do
|
36
36
|
with_button_for :post, :submit
|
37
37
|
assert_select 'form input.btn[type=submit][value=Save Post]'
|
@@ -14,65 +14,65 @@ class ErrorTest < ActionView::TestCase
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
test 'error
|
17
|
+
test 'error does not generate content for attribute without errors' do
|
18
18
|
with_error_for @user, :active
|
19
19
|
assert_no_select 'span.error'
|
20
20
|
end
|
21
21
|
|
22
|
-
test 'error
|
22
|
+
test 'error does not generate messages when object is not present' do
|
23
23
|
with_error_for :project, :name
|
24
24
|
assert_no_select 'span.error'
|
25
25
|
end
|
26
26
|
|
27
|
-
test "error
|
27
|
+
test "error does not generate messages when object doesn't respond to errors method" do
|
28
28
|
@user.instance_eval { undef errors }
|
29
29
|
with_error_for @user, :name
|
30
30
|
assert_no_select 'span.error'
|
31
31
|
end
|
32
32
|
|
33
|
-
test 'error
|
33
|
+
test 'error generates messages for attribute with single error' do
|
34
34
|
with_error_for @user, :name
|
35
35
|
assert_select 'span.error', "can't be blank"
|
36
36
|
end
|
37
37
|
|
38
|
-
test 'error
|
38
|
+
test 'error generates messages for attribute with one error when using first' do
|
39
39
|
swap SimpleForm, error_method: :first do
|
40
40
|
with_error_for @user, :age
|
41
41
|
assert_select 'span.error', 'is not a number'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
test 'error
|
45
|
+
test 'error generates messages for attribute with several errors when using to_sentence' do
|
46
46
|
swap SimpleForm, error_method: :to_sentence do
|
47
47
|
with_error_for @user, :age
|
48
48
|
assert_select 'span.error', 'is not a number and must be greater than 18'
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
test 'error
|
52
|
+
test 'error is able to pass html options' do
|
53
53
|
with_error_for @user, :name, id: 'error', class: 'yay'
|
54
54
|
assert_select 'span#error.error.yay'
|
55
55
|
end
|
56
56
|
|
57
|
-
test 'error
|
57
|
+
test 'error does not modify the options hash' do
|
58
58
|
options = { id: 'error', class: 'yay' }
|
59
59
|
with_error_for @user, :name, options
|
60
60
|
assert_select 'span#error.error.yay'
|
61
61
|
assert_equal({ id: 'error', class: 'yay' }, options)
|
62
62
|
end
|
63
63
|
|
64
|
-
test 'error
|
64
|
+
test 'error finds errors on attribute and association' do
|
65
65
|
with_error_for @user, :company_id, as: :select,
|
66
66
|
error_method: :to_sentence, reflection: Association.new(Company, :company, {})
|
67
67
|
assert_select 'span.error', 'must be valid and company must be present'
|
68
68
|
end
|
69
69
|
|
70
|
-
test 'error
|
70
|
+
test 'error generates an error tag with a clean HTML' do
|
71
71
|
with_error_for @user, :name
|
72
72
|
assert_no_select 'span.error[error_html]'
|
73
73
|
end
|
74
74
|
|
75
|
-
test 'error
|
75
|
+
test 'error generates an error tag with a clean HTML when errors options are present' do
|
76
76
|
with_error_for @user, :name, error_tag: :p, error_prefix: 'Name', error_method: :first
|
77
77
|
assert_no_select 'p.error[error_html]'
|
78
78
|
assert_no_select 'p.error[error_tag]'
|
@@ -80,12 +80,12 @@ class ErrorTest < ActionView::TestCase
|
|
80
80
|
assert_no_select 'p.error[error_method]'
|
81
81
|
end
|
82
82
|
|
83
|
-
test 'error
|
83
|
+
test 'error escapes error prefix text' do
|
84
84
|
with_error_for @user, :name, error_prefix: '<b>Name</b>'
|
85
85
|
assert_select 'span.error', "<b>Name</b> can't be blank"
|
86
86
|
end
|
87
87
|
|
88
|
-
test 'error
|
88
|
+
test 'error generates an error message with raw HTML tags' do
|
89
89
|
with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
|
90
90
|
assert_select 'span.error', "Name can't be blank"
|
91
91
|
assert_select 'span.error b', "Name"
|
@@ -93,22 +93,22 @@ class ErrorTest < ActionView::TestCase
|
|
93
93
|
|
94
94
|
# FULL ERRORS
|
95
95
|
|
96
|
-
test 'full error
|
96
|
+
test 'full error generates a full error tag for the attribute' do
|
97
97
|
with_full_error_for @user, :name
|
98
98
|
assert_select 'span.error', "Super User Name! can't be blank"
|
99
99
|
end
|
100
100
|
|
101
|
-
test 'full error
|
101
|
+
test 'full error generates a full error tag with a clean HTML' do
|
102
102
|
with_full_error_for @user, :name
|
103
103
|
assert_no_select 'span.error[error_html]'
|
104
104
|
end
|
105
105
|
|
106
|
-
test 'full error
|
106
|
+
test 'full error allows passing options to full error tag' do
|
107
107
|
with_full_error_for @user, :name, id: 'name_error', error_prefix: "Your name"
|
108
108
|
assert_select 'span.error#name_error', "Your name can't be blank"
|
109
109
|
end
|
110
110
|
|
111
|
-
test 'full error
|
111
|
+
test 'full error does not modify the options hash' do
|
112
112
|
options = { id: 'name_error' }
|
113
113
|
with_full_error_for @user, :name, options
|
114
114
|
assert_select 'span.error#name_error', "Super User Name! can't be blank"
|
@@ -126,7 +126,7 @@ class ErrorTest < ActionView::TestCase
|
|
126
126
|
|
127
127
|
# FULL_ERROR_WRAPPER
|
128
128
|
|
129
|
-
test 'full error
|
129
|
+
test 'full error finds errors on association' do
|
130
130
|
swap_wrapper :default, self.custom_wrapper_with_full_error do
|
131
131
|
with_form_for @user, :company_id, as: :select
|
132
132
|
assert_select 'span.error', 'Company must be valid'
|