simple_form 2.0.0 → 3.5.1
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 +97 -198
- data/MIT-LICENSE +1 -1
- data/README.md +572 -296
- data/lib/generators/simple_form/install_generator.rb +17 -7
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/_form.html.erb +1 -0
- data/lib/generators/simple_form/templates/_form.html.haml +1 -0
- data/lib/generators/simple_form/templates/config/initializers/{simple_form.rb.tt → simple_form.rb} +57 -63
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +155 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +111 -0
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +14 -7
- data/lib/simple_form/action_view_extensions/builder.rb +5 -305
- data/lib/simple_form/action_view_extensions/form_helper.rb +18 -20
- data/lib/simple_form/components/errors.rb +30 -3
- data/lib/simple_form/components/hints.rb +10 -3
- data/lib/simple_form/components/html5.rb +17 -3
- data/lib/simple_form/components/label_input.rb +21 -2
- data/lib/simple_form/components/labels.rb +16 -11
- data/lib/simple_form/components/maxlength.rb +19 -12
- data/lib/simple_form/components/min_max.rb +4 -2
- data/lib/simple_form/components/minlength.rb +48 -0
- data/lib/simple_form/components/pattern.rb +5 -4
- data/lib/simple_form/components/placeholders.rb +3 -2
- data/lib/simple_form/components/readonly.rb +3 -2
- data/lib/simple_form/components.rb +15 -11
- data/lib/simple_form/error_notification.rb +4 -3
- data/lib/simple_form/form_builder.rb +283 -105
- data/lib/simple_form/helpers/autofocus.rb +1 -0
- data/lib/simple_form/helpers/disabled.rb +1 -0
- data/lib/simple_form/helpers/readonly.rb +1 -0
- data/lib/simple_form/helpers/required.rb +1 -0
- data/lib/simple_form/helpers/validators.rb +4 -3
- data/lib/simple_form/helpers.rb +7 -6
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +76 -23
- data/lib/simple_form/inputs/block_input.rb +3 -2
- data/lib/simple_form/inputs/boolean_input.rb +55 -16
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +41 -18
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +11 -19
- data/lib/simple_form/inputs/collection_select_input.rb +5 -2
- data/lib/simple_form/inputs/date_time_input.rb +23 -12
- data/lib/simple_form/inputs/file_input.rb +5 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
- data/lib/simple_form/inputs/hidden_input.rb +5 -2
- data/lib/simple_form/inputs/numeric_input.rb +4 -8
- data/lib/simple_form/inputs/password_input.rb +6 -4
- data/lib/simple_form/inputs/priority_input.rb +5 -2
- data/lib/simple_form/inputs/range_input.rb +2 -1
- data/lib/simple_form/inputs/string_input.rb +6 -4
- data/lib/simple_form/inputs/text_input.rb +6 -3
- data/lib/simple_form/inputs.rb +20 -17
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +15 -0
- data/lib/simple_form/tags.rb +69 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +12 -35
- data/lib/simple_form/wrappers/leaf.rb +29 -0
- data/lib/simple_form/wrappers/many.rb +12 -7
- data/lib/simple_form/wrappers/root.rb +7 -4
- data/lib/simple_form/wrappers/single.rb +12 -3
- data/lib/simple_form/wrappers.rb +3 -1
- data/lib/simple_form.rb +118 -63
- data/test/action_view_extensions/builder_test.rb +230 -164
- data/test/action_view_extensions/form_helper_test.rb +107 -39
- data/test/components/label_test.rb +105 -87
- data/test/form_builder/association_test.rb +131 -62
- data/test/form_builder/button_test.rb +15 -14
- data/test/form_builder/error_notification_test.rb +11 -10
- data/test/form_builder/error_test.rb +188 -34
- data/test/form_builder/general_test.rb +247 -102
- data/test/form_builder/hint_test.rb +59 -32
- data/test/form_builder/input_field_test.rb +138 -25
- data/test/form_builder/label_test.rb +84 -13
- data/test/form_builder/wrapper_test.rb +236 -33
- data/test/generators/simple_form_generator_test.rb +15 -4
- data/test/inputs/boolean_input_test.rb +147 -13
- data/test/inputs/collection_check_boxes_input_test.rb +166 -71
- data/test/inputs/collection_radio_buttons_input_test.rb +229 -113
- data/test/inputs/collection_select_input_test.rb +222 -85
- data/test/inputs/datetime_input_test.rb +134 -47
- data/test/inputs/disabled_test.rb +62 -21
- data/test/inputs/discovery_test.rb +70 -10
- data/test/inputs/file_input_test.rb +4 -3
- data/test/inputs/general_test.rb +90 -26
- data/test/inputs/grouped_collection_select_input_test.rb +88 -23
- data/test/inputs/hidden_input_test.rb +7 -5
- data/test/inputs/numeric_input_test.rb +56 -46
- data/test/inputs/priority_input_test.rb +31 -16
- data/test/inputs/readonly_test.rb +68 -27
- data/test/inputs/required_test.rb +63 -18
- data/test/inputs/string_input_test.rb +76 -51
- data/test/inputs/text_input_test.rb +21 -8
- data/test/simple_form_test.rb +9 -0
- data/test/support/discovery_inputs.rb +39 -2
- data/test/support/misc_helpers.rb +176 -20
- data/test/support/mock_controller.rb +13 -7
- data/test/support/models.rb +187 -71
- data/test/test_helper.rb +38 -39
- metadata +53 -39
- data/lib/simple_form/core_ext/hash.rb +0 -16
- data/test/support/mock_response.rb +0 -14
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class FormHelperTest < ActionView::TestCase
|
|
@@ -8,97 +9,164 @@ class FormHelperTest < ActionView::TestCase
|
|
|
8
9
|
end
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
test 'SimpleForm
|
|
12
|
-
|
|
12
|
+
test 'SimpleForm adds default class to form' do
|
|
13
|
+
with_concat_form_for(:user)
|
|
13
14
|
assert_select 'form.simple_form'
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
test 'SimpleForm
|
|
17
|
-
|
|
17
|
+
test 'SimpleForm allows overriding default form class' do
|
|
18
|
+
swap SimpleForm, default_form_class: "my_custom_class" do
|
|
19
|
+
with_concat_form_for :user, html: { class: "override_class" }
|
|
20
|
+
assert_no_select 'form.my_custom_class'
|
|
21
|
+
assert_select 'form.override_class'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Remove this test when SimpleForm.form_class is removed in 4.x
|
|
26
|
+
test 'SimpleForm allows overriding default form class, but not form class' do
|
|
27
|
+
ActiveSupport::Deprecation.silence do
|
|
28
|
+
swap SimpleForm, form_class: "fixed_class", default_form_class: "my_custom_class" do
|
|
29
|
+
with_concat_form_for :user, html: { class: "override_class" }
|
|
30
|
+
assert_no_select 'form.my_custom_class'
|
|
31
|
+
assert_select 'form.fixed_class.override_class'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test 'SimpleForm uses default browser validations by default' do
|
|
37
|
+
with_concat_form_for(:user)
|
|
18
38
|
assert_no_select 'form[novalidate]'
|
|
19
39
|
end
|
|
20
40
|
|
|
21
|
-
test 'SimpleForm
|
|
22
|
-
swap SimpleForm, :
|
|
23
|
-
|
|
41
|
+
test 'SimpleForm does not use default browser validations if specified in the configuration options' do
|
|
42
|
+
swap SimpleForm, browser_validations: false do
|
|
43
|
+
with_concat_form_for(:user)
|
|
24
44
|
assert_select 'form[novalidate="novalidate"]'
|
|
25
45
|
end
|
|
26
46
|
end
|
|
27
47
|
|
|
28
|
-
test '
|
|
29
|
-
|
|
48
|
+
test 'disabled browser validations overrides default configuration' do
|
|
49
|
+
with_concat_form_for(:user, html: { novalidate: true })
|
|
30
50
|
assert_select 'form[novalidate="novalidate"]'
|
|
31
51
|
end
|
|
32
52
|
|
|
33
|
-
test '
|
|
34
|
-
swap SimpleForm, :
|
|
35
|
-
|
|
53
|
+
test 'enabled browser validations overrides disabled configuration' do
|
|
54
|
+
swap SimpleForm, browser_validations: false do
|
|
55
|
+
with_concat_form_for(:user, html: { novalidate: false })
|
|
36
56
|
assert_no_select 'form[novalidate]'
|
|
37
57
|
end
|
|
38
58
|
end
|
|
39
59
|
|
|
40
|
-
test 'SimpleForm
|
|
41
|
-
|
|
60
|
+
test 'SimpleForm adds object name as css class to form when object is not present' do
|
|
61
|
+
with_concat_form_for(:user, html: { novalidate: true })
|
|
42
62
|
assert_select 'form.simple_form.user'
|
|
43
63
|
end
|
|
44
64
|
|
|
45
|
-
test 'SimpleForm
|
|
46
|
-
|
|
65
|
+
test 'SimpleForm adds :as option as css class to form when object is not present' do
|
|
66
|
+
with_concat_form_for(:user, as: 'superuser')
|
|
47
67
|
assert_select 'form.simple_form.superuser'
|
|
48
68
|
end
|
|
49
69
|
|
|
50
|
-
test 'SimpleForm
|
|
70
|
+
test 'SimpleForm adds object class name with new prefix as css class to form if record is not persisted' do
|
|
51
71
|
@user.new_record!
|
|
52
|
-
|
|
72
|
+
with_concat_form_for(@user)
|
|
53
73
|
assert_select 'form.simple_form.new_user'
|
|
54
74
|
end
|
|
55
75
|
|
|
56
|
-
test 'SimpleForm
|
|
76
|
+
test 'SimpleForm adds :as option with new prefix as css class to form if record is not persisted' do
|
|
57
77
|
@user.new_record!
|
|
58
|
-
|
|
78
|
+
with_concat_form_for(@user, as: 'superuser')
|
|
59
79
|
assert_select 'form.simple_form.new_superuser'
|
|
60
80
|
end
|
|
61
81
|
|
|
62
|
-
test 'SimpleForm
|
|
63
|
-
|
|
82
|
+
test 'SimpleForm adds edit class prefix as css class to form if record is persisted' do
|
|
83
|
+
with_concat_form_for(@user)
|
|
64
84
|
assert_select 'form.simple_form.edit_user'
|
|
65
85
|
end
|
|
66
86
|
|
|
67
|
-
test 'SimpleForm
|
|
68
|
-
|
|
87
|
+
test 'SimpleForm adds :as options with edit prefix as css class to form if record is persisted' do
|
|
88
|
+
with_concat_form_for(@user, as: 'superuser')
|
|
69
89
|
assert_select 'form.simple_form.edit_superuser'
|
|
70
90
|
end
|
|
71
91
|
|
|
72
|
-
test 'SimpleForm
|
|
73
|
-
|
|
92
|
+
test 'SimpleForm adds last object name as css class to form when there is array of objects' do
|
|
93
|
+
with_concat_form_for([Company.new, @user])
|
|
94
|
+
assert_select 'form.simple_form.edit_user'
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
test 'SimpleForm does not add object class to form if css_class is specified' do
|
|
98
|
+
with_concat_form_for(:user, html: { class: nil })
|
|
74
99
|
assert_no_select 'form.user'
|
|
75
100
|
end
|
|
76
101
|
|
|
77
|
-
test 'SimpleForm
|
|
78
|
-
|
|
102
|
+
test 'SimpleForm adds custom class to form if css_class is specified' do
|
|
103
|
+
with_concat_form_for(:user, html: { class: 'my_class' })
|
|
79
104
|
assert_select 'form.my_class'
|
|
80
105
|
end
|
|
81
106
|
|
|
82
|
-
test '
|
|
83
|
-
|
|
107
|
+
test 'passes options to SimpleForm' do
|
|
108
|
+
with_concat_form_for(:user, url: '/account', html: { id: 'my_form' })
|
|
84
109
|
assert_select 'form#my_form'
|
|
85
|
-
assert_select 'form[action
|
|
110
|
+
assert_select 'form[action="/account"]'
|
|
86
111
|
end
|
|
87
112
|
|
|
88
|
-
test '
|
|
89
|
-
|
|
113
|
+
test 'form_for yields an instance of FormBuilder' do
|
|
114
|
+
with_concat_form_for(:user) do |f|
|
|
90
115
|
assert f.instance_of?(SimpleForm::FormBuilder)
|
|
91
|
-
end
|
|
116
|
+
end
|
|
92
117
|
end
|
|
93
118
|
|
|
94
|
-
test '
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
concat(simple_fields_for(:author, @hash_backed_author) do |f|
|
|
119
|
+
test 'fields_for with a hash like model yields an instance of FormBuilder' do
|
|
120
|
+
with_concat_fields_for(:author, HashBackedAuthor.new) do |f|
|
|
98
121
|
assert f.instance_of?(SimpleForm::FormBuilder)
|
|
99
122
|
f.input :name
|
|
100
|
-
end
|
|
123
|
+
end
|
|
101
124
|
|
|
102
125
|
assert_select "input[name='author[name]'][value='hash backed author']"
|
|
103
126
|
end
|
|
127
|
+
|
|
128
|
+
test 'custom error proc is not destructive' do
|
|
129
|
+
swap_field_error_proc do
|
|
130
|
+
result = nil
|
|
131
|
+
simple_form_for :user do |f|
|
|
132
|
+
result = simple_fields_for 'address' do
|
|
133
|
+
'hello'
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
assert_equal 'hello', result
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
test 'custom error proc survives an exception' do
|
|
142
|
+
swap_field_error_proc do
|
|
143
|
+
begin
|
|
144
|
+
simple_form_for :user do |f|
|
|
145
|
+
simple_fields_for 'address' do
|
|
146
|
+
raise 'an exception'
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
rescue StandardError
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
test 'SimpleForm for swaps default action view field_error_proc' do
|
|
155
|
+
expected_error_proc = -> {}
|
|
156
|
+
swap SimpleForm, field_error_proc: expected_error_proc do
|
|
157
|
+
simple_form_for :user do |f|
|
|
158
|
+
assert_equal expected_error_proc, ::ActionView::Base.field_error_proc
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
private
|
|
164
|
+
|
|
165
|
+
def swap_field_error_proc(expected_error_proc = -> {})
|
|
166
|
+
swap ActionView::Base, field_error_proc: expected_error_proc do
|
|
167
|
+
yield
|
|
168
|
+
|
|
169
|
+
assert_equal expected_error_proc, ActionView::Base.field_error_proc
|
|
170
|
+
end
|
|
171
|
+
end
|
|
104
172
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
require 'test_helper'
|
|
3
4
|
|
|
@@ -7,54 +8,54 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
|
7
8
|
SimpleForm::Inputs::Base.reset_i18n_cache :translate_required_html
|
|
8
9
|
end
|
|
9
10
|
|
|
10
|
-
def with_label_for(object, attribute_name, type, options={})
|
|
11
|
+
def with_label_for(object, attribute_name, type, options = {})
|
|
11
12
|
with_concat_form_for(object) do |f|
|
|
12
13
|
options[:reflection] = Association.new(Company, :company, {}) if options.delete(:setup_association)
|
|
13
14
|
SimpleForm::Inputs::Base.new(f, attribute_name, nil, type, options).label
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
test 'label
|
|
18
|
+
test 'label generates a default humanized description' do
|
|
18
19
|
with_label_for @user, :name, :string
|
|
19
20
|
assert_select 'label[for=user_name]', /Name/
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
test 'label
|
|
23
|
-
with_label_for @user, :name, :string, :
|
|
23
|
+
test 'label allows a customized description' do
|
|
24
|
+
with_label_for @user, :name, :string, label: 'My label!'
|
|
24
25
|
assert_select 'label[for=user_name]', /My label!/
|
|
25
26
|
end
|
|
26
27
|
|
|
27
|
-
test 'label
|
|
28
|
+
test 'label uses human attribute name from object when available' do
|
|
28
29
|
with_label_for @user, :description, :text
|
|
29
30
|
assert_select 'label[for=user_description]', /User Description!/
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
test 'label
|
|
33
|
-
with_label_for @user, :company_id, :string, :
|
|
33
|
+
test 'label uses human attribute name based on association name' do
|
|
34
|
+
with_label_for @user, :company_id, :string, setup_association: true
|
|
34
35
|
assert_select 'label', /Company Human Name!/
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
test 'label
|
|
38
|
+
test 'label uses i18n based on model, action, and attribute to lookup translation' do
|
|
38
39
|
@controller.action_name = "new"
|
|
39
|
-
store_translations(:en, :
|
|
40
|
-
:
|
|
41
|
-
} } }
|
|
40
|
+
store_translations(:en, simple_form: { labels: { user: {
|
|
41
|
+
new: { description: 'Nova descrição' }
|
|
42
|
+
} } }) do
|
|
42
43
|
with_label_for @user, :description, :text
|
|
43
44
|
assert_select 'label[for=user_description]', /Nova descrição/
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
test 'label
|
|
48
|
+
test 'label fallbacks to new when action is create' do
|
|
48
49
|
@controller.action_name = "create"
|
|
49
|
-
store_translations(:en, :
|
|
50
|
-
:
|
|
51
|
-
} } }
|
|
50
|
+
store_translations(:en, simple_form: { labels: { user: {
|
|
51
|
+
new: { description: 'Nova descrição' }
|
|
52
|
+
} } }) do
|
|
52
53
|
with_label_for @user, :description, :text
|
|
53
54
|
assert_select 'label[for=user_description]', /Nova descrição/
|
|
54
55
|
end
|
|
55
56
|
end
|
|
56
57
|
|
|
57
|
-
test 'label
|
|
58
|
+
test 'label does not explode while looking for i18n translation when action is not set' do
|
|
58
59
|
def @controller.action_name; nil; end
|
|
59
60
|
|
|
60
61
|
assert_nothing_raised do
|
|
@@ -63,46 +64,56 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
|
63
64
|
assert_select 'label[for=user_description]'
|
|
64
65
|
end
|
|
65
66
|
|
|
66
|
-
test 'label
|
|
67
|
-
store_translations(:en, :
|
|
68
|
-
:
|
|
69
|
-
} } }
|
|
67
|
+
test 'label uses i18n based on model and attribute to lookup translation' do
|
|
68
|
+
store_translations(:en, simple_form: { labels: { user: {
|
|
69
|
+
description: 'Descrição'
|
|
70
|
+
} } }) do
|
|
70
71
|
with_label_for @user, :description, :text
|
|
71
72
|
assert_select 'label[for=user_description]', /Descrição/
|
|
72
73
|
end
|
|
73
74
|
end
|
|
74
75
|
|
|
75
|
-
test '
|
|
76
|
-
store_translations(:en, :
|
|
76
|
+
test 'label uses i18n under defaults to lookup translation' do
|
|
77
|
+
store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
|
|
77
78
|
with_label_for @user, :age, :integer
|
|
78
79
|
assert_select 'label[for=user_age]', /Idade/
|
|
79
80
|
end
|
|
80
81
|
end
|
|
81
82
|
|
|
82
|
-
test '
|
|
83
|
-
swap SimpleForm, :
|
|
84
|
-
store_translations(:en, :
|
|
83
|
+
test 'label does not use i18n label if translate is false' do
|
|
84
|
+
swap SimpleForm, translate_labels: false do
|
|
85
|
+
store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
|
|
85
86
|
with_label_for @user, :age, :integer
|
|
86
87
|
assert_select 'label[for=user_age]', /Age/
|
|
87
88
|
end
|
|
88
89
|
end
|
|
89
90
|
end
|
|
90
91
|
|
|
91
|
-
test 'label
|
|
92
|
-
store_translations(:en, :
|
|
93
|
-
:
|
|
94
|
-
} }
|
|
95
|
-
with_label_for @user, :company_id, :string, :
|
|
92
|
+
test 'label uses i18n with lookup for association name' do
|
|
93
|
+
store_translations(:en, simple_form: { labels: {
|
|
94
|
+
user: { company: 'My company!' }
|
|
95
|
+
} }) do
|
|
96
|
+
with_label_for @user, :company_id, :string, setup_association: true
|
|
96
97
|
assert_select 'label[for=user_company_id]', /My company!/
|
|
97
98
|
end
|
|
98
99
|
end
|
|
99
100
|
|
|
100
|
-
test 'label
|
|
101
|
+
test 'label uses i18n under defaults namespace to lookup for association name' do
|
|
102
|
+
store_translations(:en, simple_form: { labels: {
|
|
103
|
+
defaults: { company: 'Plataformatec' }
|
|
104
|
+
} }) do
|
|
105
|
+
with_label_for @user, :company, :string, setup_association: true
|
|
106
|
+
|
|
107
|
+
assert_select 'form label', /Plataformatec/
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
test 'label does correct i18n lookup for nested models with nested translation' do
|
|
101
112
|
@user.company = Company.new(1, 'Empresa')
|
|
102
113
|
|
|
103
|
-
store_translations(:en, :
|
|
104
|
-
:
|
|
105
|
-
} }
|
|
114
|
+
store_translations(:en, simple_form: { labels: {
|
|
115
|
+
user: { name: 'Usuario', company: { name: 'Nome da empresa' } }
|
|
116
|
+
} }) do
|
|
106
117
|
with_concat_form_for @user do |f|
|
|
107
118
|
concat f.input :name
|
|
108
119
|
concat(f.simple_fields_for(:company) do |company_form|
|
|
@@ -115,13 +126,13 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
|
115
126
|
end
|
|
116
127
|
end
|
|
117
128
|
|
|
118
|
-
test 'label
|
|
129
|
+
test 'label does correct i18n lookup for nested models with no nested translation' do
|
|
119
130
|
@user.company = Company.new(1, 'Empresa')
|
|
120
131
|
|
|
121
|
-
store_translations(:en, :
|
|
122
|
-
:
|
|
123
|
-
:
|
|
124
|
-
} }
|
|
132
|
+
store_translations(:en, simple_form: { labels: {
|
|
133
|
+
user: { name: 'Usuario' },
|
|
134
|
+
company: { name: 'Nome da empresa' }
|
|
135
|
+
} }) do
|
|
125
136
|
with_concat_form_for @user do |f|
|
|
126
137
|
concat f.input :name
|
|
127
138
|
concat(f.simple_fields_for(:company) do |company_form|
|
|
@@ -134,16 +145,16 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
|
134
145
|
end
|
|
135
146
|
end
|
|
136
147
|
|
|
137
|
-
test 'label
|
|
148
|
+
test 'label does correct i18n lookup for nested has_many models with no nested translation' do
|
|
138
149
|
@user.tags = [Tag.new(1, 'Empresa')]
|
|
139
150
|
|
|
140
|
-
store_translations(:en, :
|
|
141
|
-
:
|
|
142
|
-
:
|
|
143
|
-
} }
|
|
151
|
+
store_translations(:en, simple_form: { labels: {
|
|
152
|
+
user: { name: 'Usuario' },
|
|
153
|
+
tags: { name: 'Nome da empresa' }
|
|
154
|
+
} }) do
|
|
144
155
|
with_concat_form_for @user do |f|
|
|
145
156
|
concat f.input :name
|
|
146
|
-
concat(f.simple_fields_for(:tags, :
|
|
157
|
+
concat(f.simple_fields_for(:tags, child_index: "new_index") do |tags_form|
|
|
147
158
|
concat(tags_form.input :name)
|
|
148
159
|
end)
|
|
149
160
|
end
|
|
@@ -153,7 +164,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
|
153
164
|
end
|
|
154
165
|
end
|
|
155
166
|
|
|
156
|
-
test 'label
|
|
167
|
+
test 'label has css class from type' do
|
|
157
168
|
with_label_for @user, :name, :string
|
|
158
169
|
assert_select 'label.string'
|
|
159
170
|
with_label_for @user, :description, :text
|
|
@@ -166,8 +177,8 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
|
166
177
|
assert_select 'label.datetime'
|
|
167
178
|
end
|
|
168
179
|
|
|
169
|
-
test 'label
|
|
170
|
-
swap SimpleForm, :
|
|
180
|
+
test 'label does not have css class from type when generate_additional_classes_for does not include :label' do
|
|
181
|
+
swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
|
|
171
182
|
with_label_for @user, :name, :string
|
|
172
183
|
assert_no_select 'label.string'
|
|
173
184
|
with_label_for @user, :description, :text
|
|
@@ -181,15 +192,22 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
|
181
192
|
end
|
|
182
193
|
end
|
|
183
194
|
|
|
184
|
-
test 'label
|
|
195
|
+
test 'label does not generate empty css class' do
|
|
196
|
+
swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
|
|
197
|
+
with_label_for @user, :name, :string
|
|
198
|
+
assert_no_select 'label[class]'
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
test 'label obtains required from ActiveModel::Validations when it is included' do
|
|
185
203
|
with_label_for @validating_user, :name, :string
|
|
186
204
|
assert_select 'label.required'
|
|
187
205
|
with_label_for @validating_user, :status, :string
|
|
188
206
|
assert_select 'label.optional'
|
|
189
207
|
end
|
|
190
208
|
|
|
191
|
-
test 'label
|
|
192
|
-
swap SimpleForm, :
|
|
209
|
+
test 'label does not obtain required from ActiveModel::Validations when generate_additional_classes_for does not include :label' do
|
|
210
|
+
swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
|
|
193
211
|
with_label_for @validating_user, :name, :string
|
|
194
212
|
assert_no_select 'label.required'
|
|
195
213
|
with_label_for @validating_user, :status, :string
|
|
@@ -197,110 +215,110 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
|
197
215
|
end
|
|
198
216
|
end
|
|
199
217
|
|
|
200
|
-
test 'label
|
|
201
|
-
with_label_for @validating_user, :name, :string, :
|
|
218
|
+
test 'label allows overriding required when ActiveModel::Validations is included' do
|
|
219
|
+
with_label_for @validating_user, :name, :string, required: false
|
|
202
220
|
assert_select 'label.optional'
|
|
203
|
-
with_label_for @validating_user, :status, :string, :
|
|
221
|
+
with_label_for @validating_user, :status, :string, required: true
|
|
204
222
|
assert_select 'label.required'
|
|
205
223
|
end
|
|
206
224
|
|
|
207
|
-
test 'label
|
|
225
|
+
test 'label is required by default when ActiveModel::Validations is not included' do
|
|
208
226
|
with_label_for @user, :name, :string
|
|
209
227
|
assert_select 'label.required'
|
|
210
228
|
end
|
|
211
229
|
|
|
212
|
-
test 'label
|
|
213
|
-
with_label_for @user, :name, :string, :
|
|
230
|
+
test 'label is able to disable required when ActiveModel::Validations is not included' do
|
|
231
|
+
with_label_for @user, :name, :string, required: false
|
|
214
232
|
assert_no_select 'label.required'
|
|
215
233
|
end
|
|
216
234
|
|
|
217
|
-
test 'label
|
|
235
|
+
test 'label adds required text when required' do
|
|
218
236
|
with_label_for @user, :name, :string
|
|
219
237
|
assert_select 'label.required abbr[title=required]', '*'
|
|
220
238
|
end
|
|
221
239
|
|
|
222
|
-
test 'label
|
|
223
|
-
with_label_for @user, :name, :string, :
|
|
240
|
+
test 'label does not have required text in no required inputs' do
|
|
241
|
+
with_label_for @user, :name, :string, required: false
|
|
224
242
|
assert_no_select 'form label abbr'
|
|
225
243
|
end
|
|
226
244
|
|
|
227
|
-
test 'label
|
|
228
|
-
store_translations(:en, :
|
|
245
|
+
test 'label uses i18n to find required text' do
|
|
246
|
+
store_translations(:en, simple_form: { required: { text: 'campo requerido' } }) do
|
|
229
247
|
with_label_for @user, :name, :string
|
|
230
|
-
assert_select 'form label abbr[title=campo requerido]', '*'
|
|
248
|
+
assert_select 'form label abbr[title="campo requerido"]', '*'
|
|
231
249
|
end
|
|
232
250
|
end
|
|
233
251
|
|
|
234
|
-
test 'label
|
|
235
|
-
store_translations(:en, :
|
|
252
|
+
test 'label uses i18n to find required mark' do
|
|
253
|
+
store_translations(:en, simple_form: { required: { mark: '*-*' } }) do
|
|
236
254
|
with_label_for @user, :name, :string
|
|
237
255
|
assert_select 'form label abbr', '*-*'
|
|
238
256
|
end
|
|
239
257
|
end
|
|
240
258
|
|
|
241
|
-
test 'label
|
|
242
|
-
store_translations(:en, :
|
|
259
|
+
test 'label uses i18n to find required string tag' do
|
|
260
|
+
store_translations(:en, simple_form: { required: { html: '<span class="required" title="requerido">*</span>' } }) do
|
|
243
261
|
with_label_for @user, :name, :string
|
|
244
262
|
assert_no_select 'form label abbr'
|
|
245
263
|
assert_select 'form label span.required[title=requerido]', '*'
|
|
246
264
|
end
|
|
247
265
|
end
|
|
248
266
|
|
|
249
|
-
test 'label
|
|
250
|
-
with_label_for @user, :name, :string, :
|
|
267
|
+
test 'label allows overwriting input id' do
|
|
268
|
+
with_label_for @user, :name, :string, input_html: { id: 'my_new_id' }
|
|
251
269
|
assert_select 'label[for=my_new_id]'
|
|
252
270
|
end
|
|
253
271
|
|
|
254
|
-
test 'label
|
|
255
|
-
with_label_for @user, :name, :string, :
|
|
272
|
+
test 'label allows overwriting of for attribute' do
|
|
273
|
+
with_label_for @user, :name, :string, label_html: { for: 'my_new_id' }
|
|
256
274
|
assert_select 'label[for=my_new_id]'
|
|
257
275
|
end
|
|
258
276
|
|
|
259
|
-
test 'label
|
|
260
|
-
with_label_for @user, :name, :string, :
|
|
277
|
+
test 'label allows overwriting of for attribute with input_html not containing id' do
|
|
278
|
+
with_label_for @user, :name, :string, label_html: { for: 'my_new_id' }, input_html: { class: 'foo' }
|
|
261
279
|
assert_select 'label[for=my_new_id]'
|
|
262
280
|
end
|
|
263
281
|
|
|
264
|
-
test 'label
|
|
265
|
-
with_label_for @user, :name, :string, :
|
|
282
|
+
test 'label uses default input id when it was not overridden' do
|
|
283
|
+
with_label_for @user, :name, :string, input_html: { class: 'my_new_id' }
|
|
266
284
|
assert_select 'label[for=user_name]'
|
|
267
285
|
end
|
|
268
286
|
|
|
269
|
-
test 'label
|
|
287
|
+
test 'label is generated properly when object is not present' do
|
|
270
288
|
with_label_for :project, :name, :string
|
|
271
289
|
assert_select 'label[for=project_name]', /Name/
|
|
272
290
|
end
|
|
273
291
|
|
|
274
|
-
test 'label
|
|
275
|
-
with_label_for @user, :sex, :select, :
|
|
292
|
+
test 'label includes for attribute for select collection' do
|
|
293
|
+
with_label_for @user, :sex, :select, collection: %i[male female]
|
|
276
294
|
assert_select 'label[for=user_sex]'
|
|
277
295
|
end
|
|
278
296
|
|
|
279
|
-
test 'label
|
|
280
|
-
store_translations(:en, :
|
|
281
|
-
:
|
|
282
|
-
} }
|
|
297
|
+
test 'label uses i18n properly when object is not present' do
|
|
298
|
+
store_translations(:en, simple_form: { labels: {
|
|
299
|
+
project: { name: 'Nome' }
|
|
300
|
+
} }) do
|
|
283
301
|
with_label_for :project, :name, :string
|
|
284
302
|
assert_select 'label[for=project_name]', /Nome/
|
|
285
303
|
end
|
|
286
304
|
end
|
|
287
305
|
|
|
288
|
-
test 'label
|
|
306
|
+
test 'label adds required by default when object is not present' do
|
|
289
307
|
with_label_for :project, :name, :string
|
|
290
308
|
assert_select 'label.required[for=project_name]'
|
|
291
|
-
with_label_for :project, :description, :string, :
|
|
309
|
+
with_label_for :project, :description, :string, required: false
|
|
292
310
|
assert_no_select 'label.required[for=project_description]'
|
|
293
311
|
end
|
|
294
312
|
|
|
295
|
-
test 'label
|
|
296
|
-
swap SimpleForm, :
|
|
313
|
+
test 'label adds chosen label class' do
|
|
314
|
+
swap SimpleForm, label_class: :my_custom_class do
|
|
297
315
|
with_label_for @user, :name, :string
|
|
298
316
|
assert_select 'label.my_custom_class'
|
|
299
317
|
end
|
|
300
318
|
end
|
|
301
319
|
|
|
302
320
|
test 'label strips extra classes even when label_class is nil' do
|
|
303
|
-
swap SimpleForm, :
|
|
321
|
+
swap SimpleForm, label_class: nil do
|
|
304
322
|
with_label_for @user, :name, :string
|
|
305
323
|
assert_select "label[class='string required']"
|
|
306
324
|
assert_no_select "label[class='string required ']"
|