simple_form 3.1.0.rc1 → 3.1.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 +12 -1
- data/README.md +64 -16
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +9 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -15
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +85 -4
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +5 -1
- data/lib/simple_form/components/errors.rb +3 -5
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/form_builder.rb +34 -19
- data/lib/simple_form/inputs/boolean_input.rb +8 -5
- data/lib/simple_form/inputs/collection_input.rb +2 -4
- data/lib/simple_form/tags.rb +3 -4
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +2 -2
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/lib/simple_form.rb +21 -2
- data/test/action_view_extensions/builder_test.rb +34 -34
- data/test/action_view_extensions/form_helper_test.rb +33 -14
- data/test/components/label_test.rb +36 -36
- data/test/form_builder/association_test.rb +41 -41
- data/test/form_builder/button_test.rb +10 -10
- data/test/form_builder/error_test.rb +88 -29
- data/test/form_builder/general_test.rb +89 -64
- data/test/form_builder/hint_test.rb +18 -18
- data/test/form_builder/input_field_test.rb +59 -19
- data/test/form_builder/label_test.rb +23 -14
- data/test/form_builder/wrapper_test.rb +70 -21
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +17 -9
- data/test/inputs/collection_check_boxes_input_test.rb +46 -7
- data/test/inputs/collection_radio_buttons_input_test.rb +65 -26
- data/test/inputs/collection_select_input_test.rb +62 -62
- data/test/inputs/datetime_input_test.rb +24 -24
- data/test/inputs/disabled_test.rb +15 -15
- data/test/inputs/discovery_test.rb +44 -5
- data/test/inputs/file_input_test.rb +2 -2
- data/test/inputs/general_test.rb +20 -20
- data/test/inputs/grouped_collection_select_input_test.rb +10 -10
- data/test/inputs/hidden_input_test.rb +4 -4
- data/test/inputs/numeric_input_test.rb +43 -43
- data/test/inputs/priority_input_test.rb +13 -13
- data/test/inputs/readonly_test.rb +19 -19
- data/test/inputs/required_test.rb +13 -13
- data/test/inputs/string_input_test.rb +33 -33
- data/test/inputs/text_input_test.rb +7 -7
- data/test/support/discovery_inputs.rb +20 -0
- data/test/support/misc_helpers.rb +28 -0
- data/test/support/models.rb +13 -2
- data/test/test_helper.rb +5 -1
- metadata +4 -4
|
@@ -1,77 +1,77 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class DisabledTest < ActionView::TestCase
|
|
4
|
-
test 'string input
|
|
4
|
+
test 'string input is disabled when disabled option is true' do
|
|
5
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
|
|
9
|
+
test 'text input is disabled when disabled option is true' do
|
|
10
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
|
|
14
|
+
test 'numeric input is disabled when disabled option is true' do
|
|
15
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
|
|
19
|
+
test 'date input is disabled when disabled option is true' do
|
|
20
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
|
|
24
|
+
test 'datetime input is disabled when disabled option is true' do
|
|
25
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
|
|
29
|
+
test 'string input does not be disabled when disabled option is false' do
|
|
30
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
|
|
34
|
+
test 'text input does not be disabled when disabled option is false' do
|
|
35
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
|
|
39
|
+
test 'numeric input does not be disabled when disabled option is false' do
|
|
40
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
|
|
44
|
+
test 'date input does not be disabled when disabled option is false' do
|
|
45
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
|
|
49
|
+
test 'datetime input does not be disabled when disabled option is false' do
|
|
50
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
|
|
@@ -14,11 +14,13 @@ class DiscoveryTest < ActionView::TestCase
|
|
|
14
14
|
Object.send :remove_const, :CustomizedInput
|
|
15
15
|
Object.send :remove_const, :DeprecatedInput
|
|
16
16
|
Object.send :remove_const, :CollectionSelectInput
|
|
17
|
+
CustomInputs.send :remove_const, :PasswordInput
|
|
18
|
+
CustomInputs.send :remove_const, :NumericInput
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
test 'builder
|
|
23
|
+
test 'builder does not discover new inputs if cached' do
|
|
22
24
|
with_form_for @user, :name
|
|
23
25
|
assert_select 'form input#user_name.string'
|
|
24
26
|
|
|
@@ -28,14 +30,14 @@ class DiscoveryTest < ActionView::TestCase
|
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
test 'builder
|
|
33
|
+
test 'builder discovers new inputs' do
|
|
32
34
|
discovery do
|
|
33
35
|
with_form_for @user, :name, as: :customized
|
|
34
36
|
assert_select 'form section input#user_name.string'
|
|
35
37
|
end
|
|
36
38
|
end
|
|
37
39
|
|
|
38
|
-
test 'builder
|
|
40
|
+
test 'builder does not discover new inputs if discovery is off' do
|
|
39
41
|
with_form_for @user, :name
|
|
40
42
|
assert_select 'form input#user_name.string'
|
|
41
43
|
|
|
@@ -47,20 +49,57 @@ class DiscoveryTest < ActionView::TestCase
|
|
|
47
49
|
end
|
|
48
50
|
end
|
|
49
51
|
|
|
50
|
-
test 'builder
|
|
52
|
+
test 'builder discovers new inputs from mappings if not cached' do
|
|
51
53
|
discovery do
|
|
52
54
|
with_form_for @user, :name
|
|
53
55
|
assert_select 'form section input#user_name.string'
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
test 'builder
|
|
59
|
+
test 'builder discovers new inputs from internal fallbacks if not cached' do
|
|
58
60
|
discovery do
|
|
59
61
|
with_form_for @user, :age
|
|
60
62
|
assert_select 'form section input#user_age.numeric.integer'
|
|
61
63
|
end
|
|
62
64
|
end
|
|
63
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
|
+
|
|
64
103
|
test 'new inputs can override the input_html_options' do
|
|
65
104
|
discovery do
|
|
66
105
|
with_form_for @user, :active, as: :select
|
|
@@ -2,12 +2,12 @@
|
|
|
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
|
|
10
|
+
test "input generates a file field that doesn't accept placeholder" do
|
|
11
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]'
|
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,7 +15,7 @@ class InputTest < ActionView::TestCase
|
|
|
15
15
|
assert_select 'select.datetime'
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
test 'string input
|
|
18
|
+
test 'string input generates autofocus attribute when autofocus option is true' do
|
|
19
19
|
with_input_for @user, :name, :string, autofocus: true
|
|
20
20
|
assert_select 'input.string[autofocus]'
|
|
21
21
|
end
|
|
@@ -36,94 +36,94 @@ class InputTest < ActionView::TestCase
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
test 'text input
|
|
39
|
+
test 'text input generates autofocus attribute when autofocus option is true' do
|
|
40
40
|
with_input_for @user, :description, :text, autofocus: true
|
|
41
41
|
assert_select 'textarea.text[autofocus]'
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
test 'numeric input
|
|
44
|
+
test 'numeric input generates autofocus attribute when autofocus option is true' do
|
|
45
45
|
with_input_for @user, :age, :integer, autofocus: true
|
|
46
46
|
assert_select 'input.integer[autofocus]'
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
test 'date input
|
|
49
|
+
test 'date input generates autofocus attribute when autofocus option is true' do
|
|
50
50
|
with_input_for @user, :born_at, :date, autofocus: true
|
|
51
51
|
assert_select 'select.date[autofocus]'
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
test 'datetime input
|
|
54
|
+
test 'datetime input generates autofocus attribute when autofocus option is true' do
|
|
55
55
|
with_input_for @user, :created_at, :datetime, autofocus: true
|
|
56
56
|
assert_select 'select.datetime[autofocus]'
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
test 'string input
|
|
59
|
+
test 'string input generates autofocus attribute when autofocus option is false' do
|
|
60
60
|
with_input_for @user, :name, :string, autofocus: false
|
|
61
61
|
assert_no_select 'input.string[autofocus]'
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
test 'text input
|
|
64
|
+
test 'text input generates autofocus attribute when autofocus option is false' do
|
|
65
65
|
with_input_for @user, :description, :text, autofocus: false
|
|
66
66
|
assert_no_select 'textarea.text[autofocus]'
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
test 'numeric input
|
|
69
|
+
test 'numeric input generates autofocus attribute when autofocus option is false' do
|
|
70
70
|
with_input_for @user, :age, :integer, autofocus: false
|
|
71
71
|
assert_no_select 'input.integer[autofocus]'
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
test 'date input
|
|
74
|
+
test 'date input generates autofocus attribute when autofocus option is false' do
|
|
75
75
|
with_input_for @user, :born_at, :date, autofocus: false
|
|
76
76
|
assert_no_select 'select.date[autofocus]'
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
test 'datetime input
|
|
79
|
+
test 'datetime input generates autofocus attribute when autofocus option is false' do
|
|
80
80
|
with_input_for @user, :created_at, :datetime, autofocus: false
|
|
81
81
|
assert_no_select 'select.datetime[autofocus]'
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
test 'string input
|
|
84
|
+
test 'string input generates autofocus attribute when autofocus option is not present' do
|
|
85
85
|
with_input_for @user, :name, :string
|
|
86
86
|
assert_no_select 'input.string[autofocus]'
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
test 'text input
|
|
89
|
+
test 'text input generates autofocus attribute when autofocus option is not present' do
|
|
90
90
|
with_input_for @user, :description, :text
|
|
91
91
|
assert_no_select 'textarea.text[autofocus]'
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
test 'numeric input
|
|
94
|
+
test 'numeric input generates autofocus attribute when autofocus option is not present' do
|
|
95
95
|
with_input_for @user, :age, :integer
|
|
96
96
|
assert_no_select 'input.integer[autofocus]'
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
test 'date input
|
|
99
|
+
test 'date input generates autofocus attribute when autofocus option is not present' do
|
|
100
100
|
with_input_for @user, :born_at, :date
|
|
101
101
|
assert_no_select 'select.date[autofocus]'
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
test 'datetime input
|
|
104
|
+
test 'datetime input generates autofocus attribute when autofocus option is not present' do
|
|
105
105
|
with_input_for @user, :created_at, :datetime
|
|
106
106
|
assert_no_select 'select.datetime[autofocus]'
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
# With no object
|
|
110
|
-
test 'input
|
|
110
|
+
test 'input is generated properly when object is not present' do
|
|
111
111
|
with_input_for :project, :name, :string
|
|
112
112
|
assert_select 'input.string.required#project_name'
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
test 'input as radio
|
|
115
|
+
test 'input as radio is generated properly when object is not present ' do
|
|
116
116
|
with_input_for :project, :name, :radio_buttons
|
|
117
117
|
assert_select 'input.radio_buttons#project_name_true'
|
|
118
118
|
assert_select 'input.radio_buttons#project_name_false'
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
-
test 'input as select with collection
|
|
121
|
+
test 'input as select with collection is generated properly when object is not present' do
|
|
122
122
|
with_input_for :project, :name, :select, collection: ['Jose', 'Carlos']
|
|
123
123
|
assert_select 'select.select#project_name'
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
-
test 'input
|
|
126
|
+
test 'input does not generate empty css class' do
|
|
127
127
|
swap SimpleForm, generate_additional_classes_for: [:wrapper, :label] do
|
|
128
128
|
with_input_for :project, :name, :string
|
|
129
129
|
assert_no_select 'input#project_name[class]'
|
|
@@ -109,8 +109,8 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
|
109
109
|
|
|
110
110
|
assert_select 'select.grouped_select#user_tag_ids' do
|
|
111
111
|
assert_select 'optgroup[label=Second]' do
|
|
112
|
-
assert_select 'option[value=7]', 'Bond'
|
|
113
|
-
assert_select 'option[value=47]', 'Hitman'
|
|
112
|
+
assert_select 'option[value="7"]', 'Bond'
|
|
113
|
+
assert_select 'option[value="47"]', 'Hitman'
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
116
|
end
|
|
@@ -130,7 +130,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
-
test 'grouped collection
|
|
133
|
+
test 'grouped collection allows overriding label and value methods using a lambda' do
|
|
134
134
|
with_input_for @user, :tag_ids, :grouped_select,
|
|
135
135
|
collection: { 'Authors' => ['Jose', 'Carlos'] },
|
|
136
136
|
group_method: :last,
|
|
@@ -155,19 +155,19 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
|
155
155
|
collection: tag_groups, group_method: :tags
|
|
156
156
|
|
|
157
157
|
assert_select 'select.grouped_select#user_tag_ids' do
|
|
158
|
-
assert_select 'optgroup[label=Group of Tags]' do
|
|
159
|
-
assert_select 'option[value=1]', 'Tag 1'
|
|
160
|
-
assert_select 'option[value=2]', 'Tag 2'
|
|
158
|
+
assert_select 'optgroup[label="Group of Tags"]' do
|
|
159
|
+
assert_select 'option[value="1"]', 'Tag 1'
|
|
160
|
+
assert_select 'option[value="2"]', 'Tag 2'
|
|
161
161
|
end
|
|
162
162
|
|
|
163
|
-
assert_select 'optgroup[label=Other group]' do
|
|
164
|
-
assert_select 'option[value=3]', 'Tag 3'
|
|
165
|
-
assert_select 'option[value=4]', 'Tag 4'
|
|
163
|
+
assert_select 'optgroup[label="Other group"]' do
|
|
164
|
+
assert_select 'option[value="3"]', 'Tag 3'
|
|
165
|
+
assert_select 'option[value="4"]', 'Tag 4'
|
|
166
166
|
end
|
|
167
167
|
end
|
|
168
168
|
end
|
|
169
169
|
|
|
170
|
-
test 'grouped collection
|
|
170
|
+
test 'grouped collection accepts html options as the last element of collection' do
|
|
171
171
|
with_input_for @user, :tag_ids, :grouped_select,
|
|
172
172
|
collection: [['Authors', [['Jose', 'jose', class: 'foo'], ['Carlos', 'carlos', class: 'bar']]]],
|
|
173
173
|
group_method: :last
|
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
require 'test_helper'
|
|
3
3
|
|
|
4
4
|
class HiddenInputTest < ActionView::TestCase
|
|
5
|
-
test 'input
|
|
5
|
+
test 'input generates a hidden field' do
|
|
6
6
|
with_input_for @user, :name, :hidden
|
|
7
7
|
assert_no_select 'input[type=text]'
|
|
8
8
|
assert_select 'input#user_name[type=hidden]'
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
test 'hint
|
|
11
|
+
test 'hint does not be generated for hidden fields' do
|
|
12
12
|
store_translations(:en, simple_form: { hints: { user: { name: "text" } } }) do
|
|
13
13
|
with_input_for @user, :name, :hidden
|
|
14
14
|
assert_no_select 'span.hint'
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
test 'label
|
|
18
|
+
test 'label does not be generated for hidden inputs' do
|
|
19
19
|
with_input_for @user, :name, :hidden
|
|
20
20
|
assert_no_select 'label'
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
test 'required/aria-required/optional options
|
|
23
|
+
test 'required/aria-required/optional options does not be generated for hidden inputs' do
|
|
24
24
|
with_input_for @user, :name, :hidden
|
|
25
25
|
assert_no_select 'input.required'
|
|
26
26
|
assert_no_select 'input[required]'
|
|
@@ -2,140 +2,140 @@
|
|
|
2
2
|
require 'test_helper'
|
|
3
3
|
|
|
4
4
|
class NumericInputTest < ActionView::TestCase
|
|
5
|
-
test 'input
|
|
5
|
+
test 'input generates an integer text field for integer attributes ' do
|
|
6
6
|
with_input_for @user, :age, :integer
|
|
7
7
|
assert_select 'input[type=number].integer#user_age'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
test 'input
|
|
10
|
+
test 'input generates a float text field for float attributes ' do
|
|
11
11
|
with_input_for @user, :age, :float
|
|
12
12
|
assert_select 'input[type=number].float#user_age'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
test 'input
|
|
15
|
+
test 'input generates a decimal text field for decimal attributes ' do
|
|
16
16
|
with_input_for @user, :age, :decimal
|
|
17
17
|
assert_select 'input[type=number].decimal#user_age'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
test 'input
|
|
20
|
+
test 'input does not generate min attribute by default' do
|
|
21
21
|
with_input_for @user, :age, :integer
|
|
22
22
|
assert_no_select 'input[min]'
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
test 'input
|
|
25
|
+
test 'input does not generate max attribute by default' do
|
|
26
26
|
with_input_for @user, :age, :integer
|
|
27
27
|
assert_no_select 'input[max]'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
test 'input
|
|
30
|
+
test 'input infers min value from integer attributes with greater than validation' do
|
|
31
31
|
with_input_for @other_validating_user, :age, :float
|
|
32
32
|
assert_no_select 'input[min]'
|
|
33
33
|
|
|
34
34
|
with_input_for @other_validating_user, :age, :integer
|
|
35
|
-
assert_select 'input[min=18]'
|
|
35
|
+
assert_select 'input[min="18"]'
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
test 'input
|
|
38
|
+
test 'input infers min value from integer attributes with greater than validation using symbol' do
|
|
39
39
|
with_input_for @validating_user, :amount, :float
|
|
40
40
|
assert_no_select 'input[min]'
|
|
41
41
|
|
|
42
42
|
with_input_for @validating_user, :amount, :integer
|
|
43
|
-
assert_select 'input[min=11]'
|
|
43
|
+
assert_select 'input[min="11"]'
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
test 'input
|
|
46
|
+
test 'input infers min value from integer attributes with greater than or equal to validation using symbol' do
|
|
47
47
|
with_input_for @validating_user, :attempts, :float
|
|
48
|
-
assert_select 'input[min=1]'
|
|
48
|
+
assert_select 'input[min="1"]'
|
|
49
49
|
|
|
50
50
|
with_input_for @validating_user, :attempts, :integer
|
|
51
|
-
assert_select 'input[min=1]'
|
|
51
|
+
assert_select 'input[min="1"]'
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
test 'input
|
|
54
|
+
test 'input infers min value from integer attributes with greater than validation using proc' do
|
|
55
55
|
with_input_for @other_validating_user, :amount, :float
|
|
56
56
|
assert_no_select 'input[min]'
|
|
57
57
|
|
|
58
58
|
with_input_for @other_validating_user, :amount, :integer
|
|
59
|
-
assert_select 'input[min=20]'
|
|
59
|
+
assert_select 'input[min="20"]'
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
test 'input
|
|
62
|
+
test 'input infers min value from integer attributes with greater than or equal to validation using proc' do
|
|
63
63
|
with_input_for @other_validating_user, :attempts, :float
|
|
64
|
-
assert_select 'input[min=19]'
|
|
64
|
+
assert_select 'input[min="19"]'
|
|
65
65
|
|
|
66
66
|
with_input_for @other_validating_user, :attempts, :integer
|
|
67
|
-
assert_select 'input[min=19]'
|
|
67
|
+
assert_select 'input[min="19"]'
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
test 'input
|
|
70
|
+
test 'input infers max value from attributes with less than validation' do
|
|
71
71
|
with_input_for @other_validating_user, :age, :float
|
|
72
72
|
assert_no_select 'input[max]'
|
|
73
73
|
|
|
74
74
|
with_input_for @other_validating_user, :age, :integer
|
|
75
|
-
assert_select 'input[max=99]'
|
|
75
|
+
assert_select 'input[max="99"]'
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
test 'input
|
|
78
|
+
test 'input infers max value from attributes with less than validation using symbol' do
|
|
79
79
|
with_input_for @validating_user, :amount, :float
|
|
80
80
|
assert_no_select 'input[max]'
|
|
81
81
|
|
|
82
82
|
with_input_for @validating_user, :amount, :integer
|
|
83
|
-
assert_select 'input[max=99]'
|
|
83
|
+
assert_select 'input[max="99"]'
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
test 'input
|
|
86
|
+
test 'input infers max value from attributes with less than or equal to validation using symbol' do
|
|
87
87
|
with_input_for @validating_user, :attempts, :float
|
|
88
|
-
assert_select 'input[max=100]'
|
|
88
|
+
assert_select 'input[max="100"]'
|
|
89
89
|
|
|
90
90
|
with_input_for @validating_user, :attempts, :integer
|
|
91
|
-
assert_select 'input[max=100]'
|
|
91
|
+
assert_select 'input[max="100"]'
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
test 'input
|
|
94
|
+
test 'input infers max value from attributes with less than validation using proc' do
|
|
95
95
|
with_input_for @other_validating_user, :amount, :float
|
|
96
96
|
assert_no_select 'input[max]'
|
|
97
97
|
|
|
98
98
|
with_input_for @other_validating_user, :amount, :integer
|
|
99
|
-
assert_select 'input[max=118]'
|
|
99
|
+
assert_select 'input[max="118"]'
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
test 'input
|
|
102
|
+
test 'input infers max value from attributes with less than or equal to validation using proc' do
|
|
103
103
|
with_input_for @other_validating_user, :attempts, :float
|
|
104
|
-
assert_select 'input[max=119]'
|
|
104
|
+
assert_select 'input[max="119"]'
|
|
105
105
|
|
|
106
106
|
with_input_for @other_validating_user, :attempts, :integer
|
|
107
|
-
assert_select 'input[max=119]'
|
|
107
|
+
assert_select 'input[max="119"]'
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
test 'input
|
|
110
|
+
test 'input has step value of any except for integer attribute' do
|
|
111
111
|
with_input_for @validating_user, :age, :float
|
|
112
112
|
assert_select 'input[step="any"]'
|
|
113
113
|
|
|
114
114
|
with_input_for @validating_user, :age, :integer
|
|
115
|
-
assert_select 'input[step=1]'
|
|
115
|
+
assert_select 'input[step="1"]'
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
test 'numeric input
|
|
118
|
+
test 'numeric input does not generate placeholder by default' do
|
|
119
119
|
with_input_for @user, :age, :integer
|
|
120
120
|
assert_no_select 'input[placeholder]'
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
-
test 'numeric input
|
|
123
|
+
test 'numeric input accepts the placeholder option' do
|
|
124
124
|
with_input_for @user, :age, :integer, placeholder: 'Put in your age'
|
|
125
|
-
assert_select 'input.integer[placeholder=Put in your age]'
|
|
125
|
+
assert_select 'input.integer[placeholder="Put in your age"]'
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
-
test 'numeric input
|
|
128
|
+
test 'numeric input uses i18n to translate placeholder text' do
|
|
129
129
|
store_translations(:en, simple_form: { placeholders: { user: {
|
|
130
130
|
age: 'Age goes here'
|
|
131
131
|
} } }) do
|
|
132
132
|
with_input_for @user, :age, :integer
|
|
133
|
-
assert_select 'input.integer[placeholder=Age goes here]'
|
|
133
|
+
assert_select 'input.integer[placeholder="Age goes here"]'
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
# Numeric input but HTML5 disabled
|
|
138
|
-
test '
|
|
138
|
+
test 'when not using HTML5 input does not generate field with type number and use text instead' do
|
|
139
139
|
swap_wrapper do
|
|
140
140
|
with_input_for @user, :age, :integer
|
|
141
141
|
assert_no_select "input[type=number]"
|
|
@@ -143,7 +143,7 @@ class NumericInputTest < ActionView::TestCase
|
|
|
143
143
|
end
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
-
test 'when not using HTML5 input
|
|
146
|
+
test 'when not using HTML5 input does not use min or max or step attributes' do
|
|
147
147
|
swap_wrapper do
|
|
148
148
|
with_input_for @validating_user, :age, :integer
|
|
149
149
|
assert_no_select "input[type=number]"
|
|
@@ -154,18 +154,18 @@ class NumericInputTest < ActionView::TestCase
|
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
[:integer, :float, :decimal].each do |type|
|
|
157
|
-
test "#{type} input
|
|
157
|
+
test "#{type} input infers min value from attributes with greater than or equal validation" do
|
|
158
158
|
with_input_for @validating_user, :age, type
|
|
159
|
-
assert_select 'input[min=18]'
|
|
159
|
+
assert_select 'input[min="18"]'
|
|
160
160
|
end
|
|
161
161
|
|
|
162
|
-
test "#{type} input
|
|
162
|
+
test "#{type} input infers the max value from attributes with less than or equal to validation" do
|
|
163
163
|
with_input_for @validating_user, :age, type
|
|
164
|
-
assert_select 'input[max=99]'
|
|
164
|
+
assert_select 'input[max="99"]'
|
|
165
165
|
end
|
|
166
166
|
end
|
|
167
167
|
|
|
168
|
-
test 'min_max
|
|
168
|
+
test 'min_max does not emit max value as bare string' do
|
|
169
169
|
with_input_for @other_validating_user, :age, :integer
|
|
170
170
|
assert_select 'input[max]'
|
|
171
171
|
assert_no_select 'div', %r{^99}
|