simple_form 5.2.0 → 5.3.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 +5 -1
- data/MIT-LICENSE +1 -1
- data/README.md +3 -4
- data/lib/simple_form/components/label_input.rb +1 -1
- data/lib/simple_form/form_builder.rb +1 -5
- data/lib/simple_form/railtie.rb +4 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/leaf.rb +1 -1
- data/lib/simple_form.rb +8 -4
- metadata +5 -85
- data/test/action_view_extensions/builder_test.rb +0 -634
- data/test/action_view_extensions/form_helper_test.rb +0 -172
- data/test/components/custom_components_test.rb +0 -62
- data/test/components/label_test.rb +0 -352
- data/test/form_builder/association_test.rb +0 -252
- data/test/form_builder/button_test.rb +0 -48
- data/test/form_builder/error_notification_test.rb +0 -80
- data/test/form_builder/error_test.rb +0 -281
- data/test/form_builder/general_test.rb +0 -539
- data/test/form_builder/hint_test.rb +0 -150
- data/test/form_builder/input_field_test.rb +0 -195
- data/test/form_builder/label_test.rb +0 -136
- data/test/form_builder/wrapper_test.rb +0 -378
- data/test/generators/simple_form_generator_test.rb +0 -43
- data/test/inputs/boolean_input_test.rb +0 -256
- data/test/inputs/collection_check_boxes_input_test.rb +0 -323
- data/test/inputs/collection_radio_buttons_input_test.rb +0 -446
- data/test/inputs/collection_select_input_test.rb +0 -380
- data/test/inputs/color_input_test.rb +0 -10
- data/test/inputs/country_input_test.rb +0 -36
- data/test/inputs/datetime_input_test.rb +0 -176
- data/test/inputs/disabled_test.rb +0 -92
- data/test/inputs/discovery_test.rb +0 -142
- data/test/inputs/file_input_test.rb +0 -17
- data/test/inputs/general_test.rb +0 -133
- data/test/inputs/grouped_collection_select_input_test.rb +0 -196
- data/test/inputs/hidden_input_test.rb +0 -32
- data/test/inputs/numeric_input_test.rb +0 -177
- data/test/inputs/readonly_test.rb +0 -102
- data/test/inputs/required_test.rb +0 -158
- data/test/inputs/rich_text_area_input_test.rb +0 -15
- data/test/inputs/string_input_test.rb +0 -158
- data/test/inputs/text_input_test.rb +0 -37
- data/test/inputs/time_zone_input_test.rb +0 -36
- data/test/simple_form_test.rb +0 -18
- data/test/support/discovery_inputs.rb +0 -65
- data/test/support/misc_helpers.rb +0 -274
- data/test/support/mock_controller.rb +0 -30
- data/test/support/models.rb +0 -357
- data/test/test_helper.rb +0 -95
@@ -1,195 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
# Tests for f.input_field
|
5
|
-
class InputFieldTest < ActionView::TestCase
|
6
|
-
test "builder input_field only renders the input tag, nothing else" do
|
7
|
-
with_input_field_for @user, :name
|
8
|
-
|
9
|
-
assert_select 'form > input.required.string'
|
10
|
-
assert_no_select 'div.string'
|
11
|
-
assert_no_select 'label'
|
12
|
-
assert_no_select '.hint'
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'builder input_field allows overriding default input type' do
|
16
|
-
with_input_field_for @user, :name, as: :text
|
17
|
-
|
18
|
-
assert_no_select 'input#user_name'
|
19
|
-
assert_select 'textarea#user_name.text'
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'builder input_field generates input type based on column type' do
|
23
|
-
with_input_field_for @user, :age
|
24
|
-
|
25
|
-
assert_select 'input[type=number].integer#user_age'
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'builder input_field is able to disable any component' do
|
29
|
-
with_input_field_for @user, :age, html5: false
|
30
|
-
|
31
|
-
assert_no_select 'input[html5=false]#user_age'
|
32
|
-
assert_select 'input[type=text].integer#user_age'
|
33
|
-
end
|
34
|
-
|
35
|
-
test 'builder input_field allows passing options to input tag' do
|
36
|
-
with_input_field_for @user, :name, id: 'name_input', class: 'name'
|
37
|
-
|
38
|
-
assert_select 'input.string.name#name_input'
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'builder input_field does not modify the options hash' do
|
42
|
-
options = { id: 'name_input', class: 'name' }
|
43
|
-
with_input_field_for @user, :name, options
|
44
|
-
|
45
|
-
assert_select 'input.string.name#name_input'
|
46
|
-
assert_equal({ id: 'name_input', class: 'name' }, options)
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
test 'builder input_field generates an input tag with a clean HTML' do
|
51
|
-
with_input_field_for @user, :name, as: :integer, class: 'name'
|
52
|
-
|
53
|
-
assert_no_select 'input.integer[input_html]'
|
54
|
-
assert_no_select 'input.integer[as]'
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'builder input_field uses i18n to translate placeholder text' do
|
58
|
-
store_translations(:en, simple_form: { placeholders: { user: {
|
59
|
-
name: 'Name goes here'
|
60
|
-
} } }) do
|
61
|
-
with_input_field_for @user, :name
|
62
|
-
|
63
|
-
assert_select 'input.string[placeholder="Name goes here"]'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
test 'builder input_field uses min_max component' do
|
68
|
-
with_input_field_for @other_validating_user, :age, as: :integer
|
69
|
-
|
70
|
-
assert_select 'input[min="18"]'
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'builder input_field does not use pattern component by default' do
|
74
|
-
with_input_field_for @other_validating_user, :country, as: :string
|
75
|
-
|
76
|
-
assert_no_select 'input[pattern="\w+"]'
|
77
|
-
end
|
78
|
-
|
79
|
-
test 'builder input_field infers pattern from attributes' do
|
80
|
-
with_input_field_for @other_validating_user, :country, as: :string, pattern: true
|
81
|
-
|
82
|
-
assert_select "input:match('pattern', ?)", /\w+/
|
83
|
-
end
|
84
|
-
|
85
|
-
test 'builder input_field accepts custom pattern' do
|
86
|
-
with_input_field_for @other_validating_user, :country, as: :string, pattern: '\d+'
|
87
|
-
|
88
|
-
assert_select "input:match('pattern', ?)", /\\d+/
|
89
|
-
end
|
90
|
-
|
91
|
-
test 'builder input_field uses readonly component' do
|
92
|
-
with_input_field_for @other_validating_user, :age, as: :integer, readonly: true
|
93
|
-
|
94
|
-
assert_select 'input.integer.readonly[readonly]'
|
95
|
-
end
|
96
|
-
|
97
|
-
test 'builder input_field uses maxlength component' do
|
98
|
-
with_input_field_for @validating_user, :name, as: :string
|
99
|
-
|
100
|
-
assert_select 'input.string[maxlength="25"]'
|
101
|
-
end
|
102
|
-
|
103
|
-
test 'builder input_field uses minlength component' do
|
104
|
-
with_input_field_for @validating_user, :name, as: :string
|
105
|
-
|
106
|
-
assert_select 'input.string[minlength="5"]'
|
107
|
-
end
|
108
|
-
|
109
|
-
test 'builder collection input_field generates input tag with a clean HTML' do
|
110
|
-
with_input_field_for @user, :status, collection: %w[Open Closed],
|
111
|
-
class: 'status', label_method: :to_s, value_method: :to_s
|
112
|
-
|
113
|
-
assert_no_select 'select.status[input_html]'
|
114
|
-
assert_no_select 'select.status[collection]'
|
115
|
-
assert_no_select 'select.status[label_method]'
|
116
|
-
assert_no_select 'select.status[value_method]'
|
117
|
-
end
|
118
|
-
|
119
|
-
test 'build input_field does not treat "boolean_style" as a HTML attribute' do
|
120
|
-
with_input_field_for @user, :active, boolean_style: :nested
|
121
|
-
|
122
|
-
assert_no_select 'input.boolean[boolean_style]'
|
123
|
-
end
|
124
|
-
|
125
|
-
test 'build input_field does not treat "prompt" as a HTML attribute' do
|
126
|
-
with_input_field_for @user, :attempts, collection: [1,2,3,4,5], prompt: :translate
|
127
|
-
|
128
|
-
assert_no_select 'select[prompt]'
|
129
|
-
end
|
130
|
-
|
131
|
-
test 'build input_field without pattern component use the pattern string' do
|
132
|
-
swap_wrapper :default, custom_wrapper_with_html5_components do
|
133
|
-
with_input_field_for @user, :name, pattern: '\w+'
|
134
|
-
|
135
|
-
assert_select "input:match('pattern', ?)", /\w+/
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
test 'build input_field without placeholder component use the placeholder string' do
|
140
|
-
swap_wrapper :default, custom_wrapper_with_html5_components do
|
141
|
-
with_input_field_for @user, :name, placeholder: 'Placeholder'
|
142
|
-
|
143
|
-
assert_select 'input[placeholder="Placeholder"]'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
test 'build input_field without maxlength component use the maxlength string' do
|
148
|
-
swap_wrapper :default, custom_wrapper_with_html5_components do
|
149
|
-
with_input_field_for @user, :name, maxlength: 5
|
150
|
-
|
151
|
-
assert_select 'input[maxlength="5"]'
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
test 'build input_field without minlength component use the minlength string' do
|
156
|
-
swap_wrapper :default, custom_wrapper_with_html5_components do
|
157
|
-
with_input_field_for @user, :name, minlength: 5
|
158
|
-
|
159
|
-
assert_select 'input[minlength="5"]'
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
test 'build input_field without readonly component use the readonly string' do
|
164
|
-
swap_wrapper :default, custom_wrapper_with_html5_components do
|
165
|
-
with_input_field_for @user, :name, readonly: true
|
166
|
-
|
167
|
-
assert_select 'input[readonly="readonly"]'
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
test 'adds valid class to input_field when it is configured' do
|
172
|
-
swap SimpleForm, input_field_valid_class: 'is-valid' do
|
173
|
-
@user.instance_eval { undef errors }
|
174
|
-
with_input_field_for @user, :name
|
175
|
-
|
176
|
-
assert_select 'input.string.required.is-valid'
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
test 'adds error class to input_field when it is configured' do
|
181
|
-
swap SimpleForm, input_field_error_class: 'is-invalid' do
|
182
|
-
with_input_field_for @user, :name
|
183
|
-
|
184
|
-
assert_select 'input.string.required.is-invalid'
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
test 'does not add validation classes to input_field when it is not configured' do
|
189
|
-
swap SimpleForm, input_field_error_class: nil, input_field_valid_class: nil do
|
190
|
-
with_input_field_for @user, :name
|
191
|
-
|
192
|
-
assert_select 'input.string.required'
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class LabelTest < ActionView::TestCase
|
6
|
-
def with_label_for(object, *args, &block)
|
7
|
-
with_concat_form_for(object) do |f|
|
8
|
-
f.label(*args, &block)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
test 'builder generates a label for the attribute' do
|
13
|
-
with_label_for @user, :name
|
14
|
-
assert_select 'label.string[for=user_name]', /Name/
|
15
|
-
end
|
16
|
-
|
17
|
-
test 'builder generates a label for the attribute with decorated object responsive to #to_model' do
|
18
|
-
with_label_for @decorated_user, :name
|
19
|
-
assert_select 'label.string[for=user_name]', /Name/
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'builder generates a label for the boolean attribute' do
|
23
|
-
with_label_for @user, :name, as: :boolean
|
24
|
-
assert_select 'label.boolean[for=user_name]', /Name/
|
25
|
-
assert_no_select 'label[as=boolean]'
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'builder generates a label component tag with a clean HTML' do
|
29
|
-
with_label_for @user, :name
|
30
|
-
assert_no_select 'label.string[label_html]'
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'builder adds a required class to label if the attribute is required' do
|
34
|
-
with_label_for @validating_user, :name
|
35
|
-
assert_select 'label.string.required[for=validating_user_name]', /Name/
|
36
|
-
end
|
37
|
-
|
38
|
-
test 'builder adds a disabled class to label if the attribute is disabled' do
|
39
|
-
with_label_for @validating_user, :name, disabled: true
|
40
|
-
assert_select 'label.string.disabled[for=validating_user_name]', /Name/
|
41
|
-
end
|
42
|
-
|
43
|
-
test 'builder does not add a disabled class to label if the attribute is not disabled' do
|
44
|
-
with_label_for @validating_user, :name, disabled: false
|
45
|
-
assert_no_select 'label.string.disabled[for=validating_user_name]', /Name/
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'builder escapes label text' do
|
49
|
-
with_label_for @user, :name, label: '<script>alert(1337)</script>', required: false
|
50
|
-
assert_no_select 'label.string script'
|
51
|
-
end
|
52
|
-
|
53
|
-
test 'builder does not escape label text if it is safe' do
|
54
|
-
with_label_for @user, :name, label: '<script>alert(1337)</script>'.html_safe, required: false
|
55
|
-
assert_select 'label.string script', "alert(1337)"
|
56
|
-
end
|
57
|
-
|
58
|
-
test 'builder allows passing options to label tag' do
|
59
|
-
with_label_for @user, :name, label: 'My label', id: 'name_label'
|
60
|
-
assert_select 'label.string#name_label', /My label/
|
61
|
-
end
|
62
|
-
|
63
|
-
test 'builder label generates label tag with clean HTML' do
|
64
|
-
with_label_for @user, :name, label: 'My label', required: true, id: 'name_label'
|
65
|
-
assert_select 'label.string#name_label', /My label/
|
66
|
-
assert_no_select 'label[label]'
|
67
|
-
assert_no_select 'label[required]'
|
68
|
-
end
|
69
|
-
|
70
|
-
test 'builder does not modify the options hash' do
|
71
|
-
options = { label: 'My label', id: 'name_label' }
|
72
|
-
with_label_for @user, :name, options
|
73
|
-
assert_select 'label.string#name_label', /My label/
|
74
|
-
assert_equal({ label: 'My label', id: 'name_label' }, options)
|
75
|
-
end
|
76
|
-
|
77
|
-
test 'builder fallbacks to default label when string is given' do
|
78
|
-
with_label_for @user, :name, 'Nome do usuário'
|
79
|
-
assert_select 'label', 'Nome do usuário'
|
80
|
-
assert_no_select 'label.string'
|
81
|
-
end
|
82
|
-
|
83
|
-
test 'builder fallbacks to default label when block is given' do
|
84
|
-
with_label_for @user, :name do
|
85
|
-
'Nome do usuário'
|
86
|
-
end
|
87
|
-
assert_select 'label', 'Nome do usuário'
|
88
|
-
assert_no_select 'label.string'
|
89
|
-
end
|
90
|
-
|
91
|
-
test 'builder allows label order to be changed' do
|
92
|
-
swap SimpleForm, label_text: proc { |l, r| "#{l}:" } do
|
93
|
-
with_label_for @user, :age
|
94
|
-
assert_select 'label.integer[for=user_age]', "Age:"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
test 'configuration allow set label text for wrappers' do
|
99
|
-
swap_wrapper :default, custom_wrapper_with_label_text do
|
100
|
-
with_concat_form_for(@user) do |f|
|
101
|
-
concat f.input :age
|
102
|
-
end
|
103
|
-
assert_select "label.integer[for=user_age]", "**Age**"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'configuration allow set rewrited label tag for wrappers' do
|
108
|
-
swap_wrapper :default, custom_wrapper_with_custom_label_component do
|
109
|
-
with_concat_form_for(@user) do |f|
|
110
|
-
concat f.input :age
|
111
|
-
end
|
112
|
-
assert_select "span.integer.user_age", /Age/
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
test 'builder allows custom formatting when label is explicitly specified' do
|
117
|
-
swap SimpleForm, label_text: ->(l, r, explicit_label) { explicit_label ? l : "#{l.titleize}:" } do
|
118
|
-
with_label_for @user, :time_zone, 'What is your home time zone?'
|
119
|
-
assert_select 'label[for=user_time_zone]', 'What is your home time zone?'
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
test 'builder allows custom formatting when label is generated' do
|
124
|
-
swap SimpleForm, label_text: ->(l, r, explicit_label) { explicit_label ? l : "#{l.titleize}:" } do
|
125
|
-
with_label_for @user, :time_zone
|
126
|
-
assert_select 'label[for=user_time_zone]', 'Time Zone:'
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
test 'builder allows label specific `label_text` option' do
|
131
|
-
with_label_for @user, :time_zone, label_text: ->(l, _, _) { "#{l.titleize}:" }
|
132
|
-
|
133
|
-
assert_no_select 'label[label_text]'
|
134
|
-
assert_select 'label[for=user_time_zone]', 'Time Zone:'
|
135
|
-
end
|
136
|
-
end
|