simple_form 3.0.4 → 5.0.3
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 +5 -5
- data/CHANGELOG.md +199 -33
- data/MIT-LICENSE +2 -1
- data/README.md +453 -128
- data/lib/generators/simple_form/install_generator.rb +4 -3
- data/lib/generators/simple_form/templates/README +3 -5
- data/lib/generators/simple_form/templates/_form.html.erb +2 -0
- data/lib/generators/simple_form/templates/_form.html.haml +2 -0
- data/lib/generators/simple_form/templates/_form.html.slim +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +47 -16
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +418 -23
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +101 -5
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +2 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +10 -3
- data/lib/simple_form/components/errors.rb +39 -6
- data/lib/simple_form/components/hints.rb +3 -2
- data/lib/simple_form/components/html5.rb +16 -5
- data/lib/simple_form/components/label_input.rb +21 -2
- data/lib/simple_form/components/labels.rb +22 -11
- data/lib/simple_form/components/maxlength.rb +9 -5
- data/lib/simple_form/components/min_max.rb +2 -1
- data/lib/simple_form/components/minlength.rb +38 -0
- data/lib/simple_form/components/pattern.rb +2 -1
- data/lib/simple_form/components/placeholders.rb +4 -3
- data/lib/simple_form/components/readonly.rb +2 -1
- data/lib/simple_form/components.rb +2 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +220 -89
- 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 +2 -1
- data/lib/simple_form/helpers.rb +6 -5
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +62 -16
- data/lib/simple_form/inputs/block_input.rb +2 -1
- data/lib/simple_form/inputs/boolean_input.rb +40 -16
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +3 -2
- data/lib/simple_form/inputs/collection_input.rb +37 -14
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +9 -13
- data/lib/simple_form/inputs/collection_select_input.rb +5 -2
- data/lib/simple_form/inputs/color_input.rb +14 -0
- data/lib/simple_form/inputs/date_time_input.rb +24 -9
- 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 +6 -4
- data/lib/simple_form/inputs/password_input.rb +6 -3
- data/lib/simple_form/inputs/priority_input.rb +5 -6
- data/lib/simple_form/inputs/range_input.rb +2 -1
- data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
- data/lib/simple_form/inputs/string_input.rb +7 -4
- data/lib/simple_form/inputs/text_input.rb +6 -3
- data/lib/simple_form/inputs.rb +3 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +8 -0
- data/lib/simple_form/tags.rb +13 -2
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +7 -6
- data/lib/simple_form/wrappers/leaf.rb +29 -0
- data/lib/simple_form/wrappers/many.rb +7 -6
- data/lib/simple_form/wrappers/root.rb +10 -3
- data/lib/simple_form/wrappers/single.rb +7 -4
- data/lib/simple_form/wrappers.rb +2 -0
- data/lib/simple_form.rb +137 -21
- data/test/action_view_extensions/builder_test.rb +64 -45
- data/test/action_view_extensions/form_helper_test.rb +36 -16
- data/test/components/custom_components_test.rb +62 -0
- data/test/components/label_test.rb +70 -41
- data/test/form_builder/association_test.rb +85 -37
- data/test/form_builder/button_test.rb +11 -10
- data/test/form_builder/error_notification_test.rb +2 -1
- data/test/form_builder/error_test.rb +146 -33
- data/test/form_builder/general_test.rb +183 -81
- data/test/form_builder/hint_test.rb +24 -18
- data/test/form_builder/input_field_test.rb +105 -75
- data/test/form_builder/label_test.rb +68 -13
- data/test/form_builder/wrapper_test.rb +197 -22
- data/test/generators/simple_form_generator_test.rb +8 -7
- data/test/inputs/boolean_input_test.rb +97 -6
- data/test/inputs/collection_check_boxes_input_test.rb +117 -25
- data/test/inputs/collection_radio_buttons_input_test.rb +176 -54
- data/test/inputs/collection_select_input_test.rb +189 -77
- data/test/inputs/color_input_test.rb +10 -0
- data/test/inputs/datetime_input_test.rb +121 -50
- data/test/inputs/disabled_test.rb +29 -15
- data/test/inputs/discovery_test.rb +79 -6
- data/test/inputs/file_input_test.rb +3 -2
- data/test/inputs/general_test.rb +23 -22
- data/test/inputs/grouped_collection_select_input_test.rb +54 -17
- data/test/inputs/hidden_input_test.rb +5 -4
- data/test/inputs/numeric_input_test.rb +48 -44
- data/test/inputs/priority_input_test.rb +17 -16
- data/test/inputs/readonly_test.rb +20 -19
- data/test/inputs/required_test.rb +58 -13
- data/test/inputs/rich_text_area_input_test.rb +15 -0
- data/test/inputs/string_input_test.rb +58 -36
- data/test/inputs/text_input_test.rb +20 -7
- data/test/simple_form_test.rb +9 -0
- data/test/support/discovery_inputs.rb +40 -2
- data/test/support/misc_helpers.rb +113 -5
- data/test/support/mock_controller.rb +7 -1
- data/test/support/models.rb +162 -39
- data/test/test_helper.rb +19 -4
- metadata +51 -43
@@ -1,18 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
4
|
-
# Tests for
|
5
|
-
class
|
6
|
-
|
7
|
-
|
5
|
+
# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
|
6
|
+
class DateTimeInputWithHtml5Test < ActionView::TestCase
|
7
|
+
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enbled' do
|
8
|
+
with_input_for @user, :created_at, :datetime, html5: true
|
9
|
+
assert_select 'input[type="datetime-local"]'
|
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,25 @@ 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
|
-
assert_no_select 'select.date#user_born_at_4i'
|
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
|
+
assert_select 'input[type="datetime-local"]'
|
79
|
+
end
|
30
80
|
end
|
31
81
|
|
32
|
-
test 'input
|
33
|
-
|
82
|
+
test 'input generates a date select for date attributes' do
|
83
|
+
swap_wrapper do
|
84
|
+
with_input_for @user, :born_at, :date
|
85
|
+
assert_select 'select.date#user_born_at_1i'
|
86
|
+
assert_select 'select.date#user_born_at_2i'
|
87
|
+
assert_select 'select.date#user_born_at_3i'
|
88
|
+
assert_no_select 'select.date#user_born_at_4i'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
test 'input is able to pass options to date select' do
|
93
|
+
with_input_for @user, :born_at, :date, as: :date, html5: false,
|
34
94
|
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
35
95
|
|
36
96
|
assert_select 'select.date[disabled=disabled]'
|
@@ -39,22 +99,32 @@ class DateTimeInputTest < ActionView::TestCase
|
|
39
99
|
assert_select 'select.date option', 'dia'
|
40
100
|
end
|
41
101
|
|
42
|
-
test 'input
|
43
|
-
with_input_for @user, :born_at, :date, default: Date.today
|
44
|
-
assert_select "select.date option[value
|
102
|
+
test 'input is able to pass :default to date select' do
|
103
|
+
with_input_for @user, :born_at, :date, default: Date.today, html5: false
|
104
|
+
assert_select "select.date option[value='#{Date.today.year}'][selected=selected]"
|
45
105
|
end
|
46
106
|
|
47
|
-
test 'input
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
assert_select 'select.time#user_delivery_time_5i'
|
107
|
+
test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enabled' do
|
108
|
+
swap_wrapper do
|
109
|
+
with_input_for @user, :born_at, :date, html5: true
|
110
|
+
|
111
|
+
assert_select 'input[type="date"]'
|
112
|
+
end
|
54
113
|
end
|
55
114
|
|
56
|
-
test 'input
|
57
|
-
|
115
|
+
test 'input generates a time select for time attributes' do
|
116
|
+
swap_wrapper do
|
117
|
+
with_input_for @user, :delivery_time, :time
|
118
|
+
assert_select 'input[type=hidden]#user_delivery_time_1i'
|
119
|
+
assert_select 'input[type=hidden]#user_delivery_time_2i'
|
120
|
+
assert_select 'input[type=hidden]#user_delivery_time_3i'
|
121
|
+
assert_select 'select.time#user_delivery_time_4i'
|
122
|
+
assert_select 'select.time#user_delivery_time_5i'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'input is able to pass options to time select' do
|
127
|
+
with_input_for @user, :delivery_time, :time, required: true, html5: false,
|
58
128
|
disabled: true, prompt: { hour: 'hora', minute: 'minuto' }
|
59
129
|
|
60
130
|
assert_select 'select.time[disabled=disabled]'
|
@@ -62,44 +132,45 @@ class DateTimeInputTest < ActionView::TestCase
|
|
62
132
|
assert_select 'select.time option', 'minuto'
|
63
133
|
end
|
64
134
|
|
65
|
-
test '
|
66
|
-
|
67
|
-
with_input_for :
|
135
|
+
test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enabled' do
|
136
|
+
swap_wrapper do
|
137
|
+
with_input_for @user, :delivery_time, :time, html5: true
|
138
|
+
|
139
|
+
assert_select 'input[type="time"]'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'label uses i18n to get target for date input type' do
|
144
|
+
store_translations(:en, date: { order: %w[month day year] }) do
|
145
|
+
with_input_for :project, :created_at, :date, html5: false
|
68
146
|
assert_select 'label[for=project_created_at_2i]'
|
69
147
|
end
|
70
148
|
end
|
71
149
|
|
72
|
-
test 'label
|
73
|
-
store_translations(:en, date: { order: [
|
74
|
-
with_input_for :project, :created_at, :datetime
|
150
|
+
test 'label uses i18n to get target for datetime input type' do
|
151
|
+
store_translations(:en, date: { order: %w[month day year] }) do
|
152
|
+
with_input_for :project, :created_at, :datetime, html5: false
|
75
153
|
assert_select 'label[for=project_created_at_2i]'
|
76
154
|
end
|
77
155
|
end
|
78
156
|
|
79
|
-
test 'label
|
80
|
-
with_input_for :project, :created_at, :date, order: [
|
157
|
+
test 'label uses order to get target when date input type' do
|
158
|
+
with_input_for :project, :created_at, :date, order: %w[month year day], html5: false
|
81
159
|
assert_select 'label[for=project_created_at_2i]'
|
82
160
|
end
|
83
161
|
|
84
|
-
test 'label
|
85
|
-
with_input_for :project, :created_at, :datetime, order: [
|
162
|
+
test 'label uses order to get target when datetime input type' do
|
163
|
+
with_input_for :project, :created_at, :datetime, order: %w[month year day], html5: false
|
86
164
|
assert_select 'label[for=project_created_at_2i]'
|
87
165
|
end
|
88
166
|
|
89
|
-
test 'label
|
90
|
-
with_input_for :project, :created_at, :time
|
167
|
+
test 'label points to first option when time input type' do
|
168
|
+
with_input_for :project, :created_at, :time, html5: false
|
91
169
|
assert_select 'label[for=project_created_at_4i]'
|
92
170
|
end
|
93
171
|
|
94
|
-
test '
|
95
|
-
with_input_for
|
96
|
-
assert_select '
|
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]'
|
172
|
+
test 'label points to attribute name if HTML5 compatibility is explicitly enabled' do
|
173
|
+
with_input_for :project, :created_at, :date, html5: true
|
174
|
+
assert_select 'label[for=project_created_at]'
|
104
175
|
end
|
105
176
|
end
|
@@ -1,78 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class DisabledTest < ActionView::TestCase
|
4
|
-
test 'string input
|
5
|
+
test 'string input is disabled when disabled option is true' do
|
5
6
|
with_input_for @user, :name, :string, disabled: true
|
6
7
|
assert_select 'input.string.disabled[disabled]'
|
7
8
|
end
|
8
9
|
|
9
|
-
test 'text input
|
10
|
+
test 'text input is disabled when disabled option is true' do
|
10
11
|
with_input_for @user, :description, :text, disabled: true
|
11
12
|
assert_select 'textarea.text.disabled[disabled]'
|
12
13
|
end
|
13
14
|
|
14
|
-
test 'numeric input
|
15
|
+
test 'numeric input is disabled when disabled option is true' do
|
15
16
|
with_input_for @user, :age, :integer, disabled: true
|
16
17
|
assert_select 'input.integer.disabled[disabled]'
|
17
18
|
end
|
18
19
|
|
19
|
-
test 'date input
|
20
|
+
test 'date input is disabled when disabled option is true' do
|
20
21
|
with_input_for @user, :born_at, :date, disabled: true
|
21
22
|
assert_select 'select.date.disabled[disabled]'
|
22
23
|
end
|
23
24
|
|
24
|
-
test 'datetime input
|
25
|
+
test 'datetime input is disabled when disabled option is true' do
|
25
26
|
with_input_for @user, :created_at, :datetime, disabled: true
|
26
27
|
assert_select 'select.datetime.disabled[disabled]'
|
27
28
|
end
|
28
29
|
|
29
|
-
test 'string input
|
30
|
+
test 'string input does not be disabled when disabled option is false' do
|
30
31
|
with_input_for @user, :name, :string, disabled: false
|
31
32
|
assert_no_select 'input.string.disabled[disabled]'
|
32
33
|
end
|
33
34
|
|
34
|
-
test 'text input
|
35
|
+
test 'text input does not be disabled when disabled option is false' do
|
35
36
|
with_input_for @user, :description, :text, disabled: false
|
36
37
|
assert_no_select 'textarea.text.disabled[disabled]'
|
37
38
|
end
|
38
39
|
|
39
|
-
test 'numeric input
|
40
|
+
test 'numeric input does not be disabled when disabled option is false' do
|
40
41
|
with_input_for @user, :age, :integer, disabled: false
|
41
42
|
assert_no_select 'input.integer.disabled[disabled]'
|
42
43
|
end
|
43
44
|
|
44
|
-
test 'date input
|
45
|
+
test 'date input does not be disabled when disabled option is false' do
|
45
46
|
with_input_for @user, :born_at, :date, disabled: false
|
46
47
|
assert_no_select 'select.date.disabled[disabled]'
|
47
48
|
end
|
48
49
|
|
49
|
-
test 'datetime input
|
50
|
+
test 'datetime input does not be disabled when disabled option is false' do
|
50
51
|
with_input_for @user, :created_at, :datetime, disabled: false
|
51
52
|
assert_no_select 'select.datetime.disabled[disabled]'
|
52
53
|
end
|
53
54
|
|
54
|
-
test 'string input
|
55
|
+
test 'string input does not be disabled when disabled option is not present' do
|
55
56
|
with_input_for @user, :name, :string
|
56
57
|
assert_no_select 'input.string.disabled[disabled]'
|
57
58
|
end
|
58
59
|
|
59
|
-
test 'text input
|
60
|
+
test 'text input does not be disabled when disabled option is not present' do
|
60
61
|
with_input_for @user, :description, :text
|
61
62
|
assert_no_select 'textarea.text.disabled[disabled]'
|
62
63
|
end
|
63
64
|
|
64
|
-
test 'numeric input
|
65
|
+
test 'numeric input does not be disabled when disabled option is not present' do
|
65
66
|
with_input_for @user, :age, :integer
|
66
67
|
assert_no_select 'input.integer.disabled[disabled]'
|
67
68
|
end
|
68
69
|
|
69
|
-
test 'date input
|
70
|
+
test 'date input does not be disabled when disabled option is not present' do
|
70
71
|
with_input_for @user, :born_at, :date
|
71
72
|
assert_no_select 'select.date.disabled[disabled]'
|
72
73
|
end
|
73
74
|
|
74
|
-
test 'datetime input
|
75
|
+
test 'datetime input does not be disabled when disabled option is not present' do
|
75
76
|
with_input_for @user, :created_at, :datetime
|
76
77
|
assert_no_select 'select.datetime.disabled[disabled]'
|
77
78
|
end
|
79
|
+
|
80
|
+
test 'input_field collection allows disabled select' do
|
81
|
+
with_input_field_for @user, :description, collection: ['foo', 'bar'], disabled: true
|
82
|
+
assert_select 'select[disabled]'
|
83
|
+
assert_no_select 'option[disabled]'
|
84
|
+
end
|
85
|
+
|
86
|
+
test 'input_field collection allows individual disabled options' do
|
87
|
+
with_input_field_for @user, :description, collection: ['foo', 'bar'], disabled: 'bar'
|
88
|
+
assert_no_select 'select[disabled]'
|
89
|
+
assert_no_select 'option[disabled][value=foo]'
|
90
|
+
assert_select 'option[disabled][value=bar]'
|
91
|
+
end
|
78
92
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class DiscoveryTest < ActionView::TestCase
|
4
5
|
# Setup new inputs and remove them after the test.
|
5
|
-
def discovery(value=false)
|
6
|
+
def discovery(value = false)
|
6
7
|
swap SimpleForm, cache_discovery: value do
|
7
8
|
begin
|
8
9
|
load "support/discovery_inputs.rb"
|
@@ -12,12 +13,17 @@ class DiscoveryTest < ActionView::TestCase
|
|
12
13
|
Object.send :remove_const, :StringInput
|
13
14
|
Object.send :remove_const, :NumericInput
|
14
15
|
Object.send :remove_const, :CustomizedInput
|
16
|
+
Object.send :remove_const, :DeprecatedInput
|
15
17
|
Object.send :remove_const, :CollectionSelectInput
|
18
|
+
Object.send :remove_const, :FileInput
|
19
|
+
CustomInputs.send :remove_const, :CustomizedInput
|
20
|
+
CustomInputs.send :remove_const, :PasswordInput
|
21
|
+
CustomInputs.send :remove_const, :NumericInput
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
|
-
test 'builder
|
26
|
+
test 'builder does not discover new inputs if cached' do
|
21
27
|
with_form_for @user, :name
|
22
28
|
assert_select 'form input#user_name.string'
|
23
29
|
|
@@ -27,14 +33,14 @@ class DiscoveryTest < ActionView::TestCase
|
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
|
-
test 'builder
|
36
|
+
test 'builder discovers new inputs' do
|
31
37
|
discovery do
|
32
38
|
with_form_for @user, :name, as: :customized
|
33
39
|
assert_select 'form section input#user_name.string'
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
37
|
-
test 'builder
|
43
|
+
test 'builder does not discover new inputs if discovery is off' do
|
38
44
|
with_form_for @user, :name
|
39
45
|
assert_select 'form input#user_name.string'
|
40
46
|
|
@@ -46,24 +52,91 @@ class DiscoveryTest < ActionView::TestCase
|
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
|
-
test 'builder
|
55
|
+
test 'builder discovers new inputs from mappings if not cached' do
|
50
56
|
discovery do
|
51
57
|
with_form_for @user, :name
|
52
58
|
assert_select 'form section input#user_name.string'
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
56
|
-
test 'builder
|
62
|
+
test 'builder discovers new inputs from internal fallbacks if not cached' do
|
57
63
|
discovery do
|
58
64
|
with_form_for @user, :age
|
59
65
|
assert_select 'form section input#user_age.numeric.integer'
|
60
66
|
end
|
61
67
|
end
|
62
68
|
|
69
|
+
test 'builder discovers new maped inputs from configured namespaces if not cached' do
|
70
|
+
discovery do
|
71
|
+
swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
|
72
|
+
with_form_for @user, :password
|
73
|
+
assert_select 'form input#user_password.password-custom-input'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'builder discovers new maped inputs from configured namespaces before the ones from top level namespace' do
|
79
|
+
discovery do
|
80
|
+
swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
|
81
|
+
with_form_for @user, :age
|
82
|
+
assert_select 'form input#user_age.numeric-custom-input'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'builder discovers new custom inputs from configured namespace before the ones from top level namespace' do
|
88
|
+
discovery do
|
89
|
+
swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
|
90
|
+
with_form_for @user, :name, as: 'customized'
|
91
|
+
assert_select 'form input#user_name.customized-namespace-custom-input'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'raises error when configured namespace does not exists' do
|
97
|
+
discovery do
|
98
|
+
swap SimpleForm, custom_inputs_namespaces: ['InvalidNamespace'] do
|
99
|
+
assert_raise NameError do
|
100
|
+
with_form_for @user, :age
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
63
106
|
test 'new inputs can override the input_html_options' do
|
64
107
|
discovery do
|
65
108
|
with_form_for @user, :active, as: :select
|
66
109
|
assert_select 'form select#user_active.select.chosen'
|
67
110
|
end
|
68
111
|
end
|
112
|
+
|
113
|
+
test 'does not duplicate the html classes giving a extra class' do
|
114
|
+
discovery do
|
115
|
+
swap SimpleForm, input_class: 'custom-default-input-class' do
|
116
|
+
with_form_for @user, :active, as: :select
|
117
|
+
assert_select 'form select#user_active.select' do
|
118
|
+
# Make sure class list contains 'chosen' only once.
|
119
|
+
assert_select ":match('class', ?)", /^(?!.*\bchosen\b.*\bchosen\b).*\bchosen\b.*$/
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'new inputs can override the default input_html_classes' do
|
126
|
+
discovery do
|
127
|
+
with_form_for @user, :avatar, as: :file
|
128
|
+
assert_no_select 'form input[type=file]#user_avatar.file.file-upload'
|
129
|
+
assert_select 'form input[type=file]#user_avatar.file-upload'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
test 'inputs method without wrapper_options are deprecated' do
|
134
|
+
discovery do
|
135
|
+
assert_deprecated do
|
136
|
+
with_form_for @user, :name, as: :deprecated
|
137
|
+
end
|
138
|
+
|
139
|
+
assert_select 'form section input#user_name.string'
|
140
|
+
end
|
141
|
+
end
|
69
142
|
end
|
@@ -1,13 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
4
5
|
class FileInputTest < ActionView::TestCase
|
5
|
-
test 'input
|
6
|
+
test 'input generates a file field' do
|
6
7
|
with_input_for @user, :name, :file
|
7
8
|
assert_select 'input#user_name[type=file]'
|
8
9
|
end
|
9
10
|
|
10
|
-
test "input
|
11
|
+
test "input generates a file field that doesn't accept placeholder" do
|
11
12
|
store_translations(:en, simple_form: { placeholders: { user: { name: "text" } } }) do
|
12
13
|
with_input_for @user, :name, :file
|
13
14
|
assert_no_select 'input[placeholder]'
|
data/test/inputs/general_test.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'test_helper'
|
3
4
|
|
4
5
|
class InputTest < ActionView::TestCase
|
5
|
-
test 'input
|
6
|
+
test 'input generates css class based on default input type' do
|
6
7
|
with_input_for @user, :name, :string
|
7
8
|
assert_select 'input.string'
|
8
9
|
with_input_for @user, :description, :text
|
@@ -15,7 +16,7 @@ class InputTest < ActionView::TestCase
|
|
15
16
|
assert_select 'select.datetime'
|
16
17
|
end
|
17
18
|
|
18
|
-
test 'string input
|
19
|
+
test 'string input generates autofocus attribute when autofocus option is true' do
|
19
20
|
with_input_for @user, :name, :string, autofocus: true
|
20
21
|
assert_select 'input.string[autofocus]'
|
21
22
|
end
|
@@ -36,95 +37,95 @@ class InputTest < ActionView::TestCase
|
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
|
-
test 'text input
|
40
|
+
test 'text input generates autofocus attribute when autofocus option is true' do
|
40
41
|
with_input_for @user, :description, :text, autofocus: true
|
41
42
|
assert_select 'textarea.text[autofocus]'
|
42
43
|
end
|
43
44
|
|
44
|
-
test 'numeric input
|
45
|
+
test 'numeric input generates autofocus attribute when autofocus option is true' do
|
45
46
|
with_input_for @user, :age, :integer, autofocus: true
|
46
47
|
assert_select 'input.integer[autofocus]'
|
47
48
|
end
|
48
49
|
|
49
|
-
test 'date input
|
50
|
+
test 'date input generates autofocus attribute when autofocus option is true' do
|
50
51
|
with_input_for @user, :born_at, :date, autofocus: true
|
51
52
|
assert_select 'select.date[autofocus]'
|
52
53
|
end
|
53
54
|
|
54
|
-
test 'datetime input
|
55
|
+
test 'datetime input generates autofocus attribute when autofocus option is true' do
|
55
56
|
with_input_for @user, :created_at, :datetime, autofocus: true
|
56
57
|
assert_select 'select.datetime[autofocus]'
|
57
58
|
end
|
58
59
|
|
59
|
-
test 'string input
|
60
|
+
test 'string input generates autofocus attribute when autofocus option is false' do
|
60
61
|
with_input_for @user, :name, :string, autofocus: false
|
61
62
|
assert_no_select 'input.string[autofocus]'
|
62
63
|
end
|
63
64
|
|
64
|
-
test 'text input
|
65
|
+
test 'text input generates autofocus attribute when autofocus option is false' do
|
65
66
|
with_input_for @user, :description, :text, autofocus: false
|
66
67
|
assert_no_select 'textarea.text[autofocus]'
|
67
68
|
end
|
68
69
|
|
69
|
-
test 'numeric input
|
70
|
+
test 'numeric input generates autofocus attribute when autofocus option is false' do
|
70
71
|
with_input_for @user, :age, :integer, autofocus: false
|
71
72
|
assert_no_select 'input.integer[autofocus]'
|
72
73
|
end
|
73
74
|
|
74
|
-
test 'date input
|
75
|
+
test 'date input generates autofocus attribute when autofocus option is false' do
|
75
76
|
with_input_for @user, :born_at, :date, autofocus: false
|
76
77
|
assert_no_select 'select.date[autofocus]'
|
77
78
|
end
|
78
79
|
|
79
|
-
test 'datetime input
|
80
|
+
test 'datetime input generates autofocus attribute when autofocus option is false' do
|
80
81
|
with_input_for @user, :created_at, :datetime, autofocus: false
|
81
82
|
assert_no_select 'select.datetime[autofocus]'
|
82
83
|
end
|
83
84
|
|
84
|
-
test 'string input
|
85
|
+
test 'string input generates autofocus attribute when autofocus option is not present' do
|
85
86
|
with_input_for @user, :name, :string
|
86
87
|
assert_no_select 'input.string[autofocus]'
|
87
88
|
end
|
88
89
|
|
89
|
-
test 'text input
|
90
|
+
test 'text input generates autofocus attribute when autofocus option is not present' do
|
90
91
|
with_input_for @user, :description, :text
|
91
92
|
assert_no_select 'textarea.text[autofocus]'
|
92
93
|
end
|
93
94
|
|
94
|
-
test 'numeric input
|
95
|
+
test 'numeric input generates autofocus attribute when autofocus option is not present' do
|
95
96
|
with_input_for @user, :age, :integer
|
96
97
|
assert_no_select 'input.integer[autofocus]'
|
97
98
|
end
|
98
99
|
|
99
|
-
test 'date input
|
100
|
+
test 'date input generates autofocus attribute when autofocus option is not present' do
|
100
101
|
with_input_for @user, :born_at, :date
|
101
102
|
assert_no_select 'select.date[autofocus]'
|
102
103
|
end
|
103
104
|
|
104
|
-
test 'datetime input
|
105
|
+
test 'datetime input generates autofocus attribute when autofocus option is not present' do
|
105
106
|
with_input_for @user, :created_at, :datetime
|
106
107
|
assert_no_select 'select.datetime[autofocus]'
|
107
108
|
end
|
108
109
|
|
109
110
|
# With no object
|
110
|
-
test 'input
|
111
|
+
test 'input is generated properly when object is not present' do
|
111
112
|
with_input_for :project, :name, :string
|
112
113
|
assert_select 'input.string.required#project_name'
|
113
114
|
end
|
114
115
|
|
115
|
-
test 'input as radio
|
116
|
+
test 'input as radio is generated properly when object is not present ' do
|
116
117
|
with_input_for :project, :name, :radio_buttons
|
117
118
|
assert_select 'input.radio_buttons#project_name_true'
|
118
119
|
assert_select 'input.radio_buttons#project_name_false'
|
119
120
|
end
|
120
121
|
|
121
|
-
test 'input as select with collection
|
122
|
-
with_input_for :project, :name, :select, collection: [
|
122
|
+
test 'input as select with collection is generated properly when object is not present' do
|
123
|
+
with_input_for :project, :name, :select, collection: %w[Jose Carlos]
|
123
124
|
assert_select 'select.select#project_name'
|
124
125
|
end
|
125
126
|
|
126
|
-
test 'input
|
127
|
-
swap SimpleForm, generate_additional_classes_for: [
|
127
|
+
test 'input does not generate empty css class' do
|
128
|
+
swap SimpleForm, generate_additional_classes_for: %i[wrapper label] do
|
128
129
|
with_input_for :project, :name, :string
|
129
130
|
assert_no_select 'input#project_name[class]'
|
130
131
|
end
|