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