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
@@ -4,8 +4,8 @@ require 'test_helper'
|
|
4
4
|
class GroupedCollectionSelectInputTest < ActionView::TestCase
|
5
5
|
test 'grouped collection accepts array collection form' do
|
6
6
|
with_input_for @user, :tag_ids, :grouped_select,
|
7
|
-
:
|
8
|
-
:
|
7
|
+
collection: [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]],
|
8
|
+
group_method: :last
|
9
9
|
|
10
10
|
assert_select 'select.grouped_select#user_tag_ids' do
|
11
11
|
assert_select 'optgroup[label=Authors]' do
|
@@ -22,8 +22,8 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
22
22
|
|
23
23
|
test 'grouped collection accepts empty array collection form' do
|
24
24
|
with_input_for @user, :tag_ids, :grouped_select,
|
25
|
-
:
|
26
|
-
:
|
25
|
+
collection: [],
|
26
|
+
group_method: :last
|
27
27
|
|
28
28
|
assert_select 'select.grouped_select#user_tag_ids'
|
29
29
|
end
|
@@ -31,8 +31,8 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
31
31
|
|
32
32
|
test 'grouped collection accepts proc as collection' do
|
33
33
|
with_input_for @user, :tag_ids, :grouped_select,
|
34
|
-
:
|
35
|
-
:
|
34
|
+
collection: Proc.new { [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]] },
|
35
|
+
group_method: :last
|
36
36
|
|
37
37
|
assert_select 'select.grouped_select#user_tag_ids' do
|
38
38
|
assert_select 'optgroup[label=Authors]' do
|
@@ -49,8 +49,8 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
49
49
|
|
50
50
|
test 'grouped collection accepts hash collection form' do
|
51
51
|
with_input_for @user, :tag_ids, :grouped_select,
|
52
|
-
:
|
53
|
-
:
|
52
|
+
collection: { 'Authors' => ['Jose', 'Carlos'], 'General' => ['Bob', 'John'] },
|
53
|
+
group_method: :last
|
54
54
|
|
55
55
|
assert_select 'select.grouped_select#user_tag_ids' do
|
56
56
|
assert_select 'optgroup[label=Authors]' do
|
@@ -67,9 +67,9 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
67
67
|
|
68
68
|
test 'grouped collection accepts group_label_method option' do
|
69
69
|
with_input_for @user, :tag_ids, :grouped_select,
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
70
|
+
collection: { ['Jose', 'Carlos'] => 'Authors' },
|
71
|
+
group_method: :first,
|
72
|
+
group_label_method: :last
|
73
73
|
|
74
74
|
assert_select 'select.grouped_select#user_tag_ids' do
|
75
75
|
assert_select 'optgroup[label=Authors]' do
|
@@ -79,12 +79,48 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
test 'grouped collection finds default label methods on the group objects' do
|
83
|
+
option_list = ['Jose', 'Carlos']
|
84
|
+
|
85
|
+
GroupedClass = Struct.new(:to_label, :options)
|
86
|
+
group = GroupedClass.new("Authors", option_list)
|
87
|
+
|
88
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
89
|
+
collection: [group],
|
90
|
+
group_method: :options
|
91
|
+
|
92
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
93
|
+
assert_select 'optgroup[label=Authors]' do
|
94
|
+
assert_select 'option', 'Jose'
|
95
|
+
assert_select 'option', 'Carlos'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'grouped collections finds the default label method from the first non-empty object' do
|
101
|
+
Agent = Struct.new(:id, :name)
|
102
|
+
agents = [["First", []], ["Second", [Agent.new(7, 'Bond'), Agent.new(47, 'Hitman')]]]
|
103
|
+
|
104
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
105
|
+
collection: agents,
|
106
|
+
group_label_method: :first,
|
107
|
+
group_method: :last,
|
108
|
+
include_blank: false
|
109
|
+
|
110
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
111
|
+
assert_select 'optgroup[label=Second]' do
|
112
|
+
assert_select 'option[value="7"]', 'Bond'
|
113
|
+
assert_select 'option[value="47"]', 'Hitman'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
82
118
|
test 'grouped collection accepts label and value methods options' do
|
83
119
|
with_input_for @user, :tag_ids, :grouped_select,
|
84
|
-
:
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
120
|
+
collection: { 'Authors' => ['Jose', 'Carlos'] },
|
121
|
+
group_method: :last,
|
122
|
+
label_method: :upcase,
|
123
|
+
value_method: :downcase
|
88
124
|
|
89
125
|
assert_select 'select.grouped_select#user_tag_ids' do
|
90
126
|
assert_select 'optgroup[label=Authors]' do
|
@@ -94,12 +130,12 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
94
130
|
end
|
95
131
|
end
|
96
132
|
|
97
|
-
test 'grouped collection
|
133
|
+
test 'grouped collection allows overriding label and value methods using a lambda' do
|
98
134
|
with_input_for @user, :tag_ids, :grouped_select,
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
135
|
+
collection: { 'Authors' => ['Jose', 'Carlos'] },
|
136
|
+
group_method: :last,
|
137
|
+
label_method: lambda { |i| i.upcase },
|
138
|
+
value_method: lambda { |i| i.downcase }
|
103
139
|
|
104
140
|
assert_select 'select.grouped_select#user_tag_ids' do
|
105
141
|
assert_select 'optgroup[label=Authors]' do
|
@@ -116,17 +152,30 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
116
152
|
]
|
117
153
|
|
118
154
|
with_input_for @user, :tag_ids, :grouped_select,
|
119
|
-
:
|
155
|
+
collection: tag_groups, group_method: :tags
|
120
156
|
|
121
157
|
assert_select 'select.grouped_select#user_tag_ids' do
|
122
|
-
assert_select 'optgroup[label=Group of Tags]' do
|
123
|
-
assert_select 'option[value=1]', 'Tag 1'
|
124
|
-
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
|
+
end
|
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'
|
125
166
|
end
|
167
|
+
end
|
168
|
+
end
|
126
169
|
|
127
|
-
|
128
|
-
|
129
|
-
|
170
|
+
test 'grouped collection accepts html options as the last element of collection' do
|
171
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
172
|
+
collection: [['Authors', [['Jose', 'jose', class: 'foo'], ['Carlos', 'carlos', class: 'bar']]]],
|
173
|
+
group_method: :last
|
174
|
+
|
175
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
176
|
+
assert_select 'optgroup[label=Authors]' do
|
177
|
+
assert_select 'option.foo', 'Jose'
|
178
|
+
assert_select 'option.bar', 'Carlos'
|
130
179
|
end
|
131
180
|
end
|
132
181
|
end
|
@@ -2,28 +2,29 @@
|
|
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
|
12
|
-
store_translations(:en, :
|
11
|
+
test 'hint does not be generated for hidden fields' do
|
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/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]'
|
27
|
+
assert_no_select 'input[aria-required]'
|
27
28
|
assert_no_select 'input.optional'
|
28
29
|
assert_select 'input.hidden#user_name'
|
29
30
|
end
|
@@ -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
|
124
|
-
with_input_for @user, :age, :integer, :
|
125
|
-
assert_select 'input.integer[placeholder=Put in your age]'
|
123
|
+
test 'numeric input accepts the placeholder option' do
|
124
|
+
with_input_for @user, :age, :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
|
129
|
-
store_translations(:en, :
|
130
|
-
:
|
128
|
+
test 'numeric input uses i18n to translate placeholder text' do
|
129
|
+
store_translations(:en, simple_form: { placeholders: { user: {
|
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}
|
@@ -2,42 +2,48 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
class PriorityInputTest < ActionView::TestCase
|
5
|
-
test 'input
|
5
|
+
test 'input generates a country select field' do
|
6
6
|
with_input_for @user, :country, :country
|
7
7
|
assert_select 'select#user_country'
|
8
8
|
assert_select 'select option[value=Brazil]', 'Brazil'
|
9
|
-
assert_no_select 'select option[value=][disabled=disabled]'
|
9
|
+
assert_no_select 'select option[value=""][disabled=disabled]'
|
10
10
|
end
|
11
11
|
|
12
|
-
test 'input
|
13
|
-
swap SimpleForm, :
|
12
|
+
test 'input generates a country select with SimpleForm default' do
|
13
|
+
swap SimpleForm, country_priority: [ 'Brazil' ] do
|
14
14
|
with_input_for @user, :country, :country
|
15
|
-
assert_select 'select option[value=][disabled=disabled]'
|
15
|
+
assert_select 'select option[value=""][disabled=disabled]'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
test 'input
|
19
|
+
test 'input generates a time zone select field' do
|
20
20
|
with_input_for @user, :time_zone, :time_zone
|
21
21
|
assert_select 'select#user_time_zone'
|
22
22
|
assert_select 'select option[value=Brasilia]', '(GMT-03:00) Brasilia'
|
23
|
-
assert_no_select 'select option[value=][disabled=disabled]'
|
23
|
+
assert_no_select 'select option[value=""][disabled=disabled]'
|
24
24
|
end
|
25
25
|
|
26
|
-
test 'input
|
27
|
-
with_input_for @user, :time_zone, :time_zone, :
|
26
|
+
test 'input generates a time zone select field with default' do
|
27
|
+
with_input_for @user, :time_zone, :time_zone, default: 'Brasilia'
|
28
28
|
assert_select 'select option[value=Brasilia][selected=selected]'
|
29
|
-
assert_no_select 'select option[value=]'
|
29
|
+
assert_no_select 'select option[value=""]'
|
30
30
|
end
|
31
31
|
|
32
|
-
test 'input
|
33
|
-
with_input_for @user, :time_zone, :time_zone, :
|
34
|
-
assert_select 'select option[value=][disabled=disabled]'
|
35
|
-
assert_no_select 'select option[value=]', /^$/
|
32
|
+
test 'input generates a time zone select using options priority' do
|
33
|
+
with_input_for @user, :time_zone, :time_zone, priority: /Brasilia/
|
34
|
+
assert_select 'select option[value=""][disabled=disabled]'
|
35
|
+
assert_no_select 'select option[value=""]', /^$/
|
36
36
|
end
|
37
37
|
|
38
|
-
test 'priority input
|
38
|
+
test 'priority input does not generate invalid required html attribute' do
|
39
39
|
with_input_for @user, :country, :country
|
40
40
|
assert_select 'select.required'
|
41
41
|
assert_no_select 'select[required]'
|
42
42
|
end
|
43
|
+
|
44
|
+
test 'priority input does not generate invalid aria-required html attribute' do
|
45
|
+
with_input_for @user, :country, :country
|
46
|
+
assert_select 'select.required'
|
47
|
+
assert_no_select 'select[aria-required]'
|
48
|
+
end
|
43
49
|
end
|
@@ -1,98 +1,98 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ReadonlyTest < ActionView::TestCase
|
4
|
-
test 'string input
|
5
|
-
with_input_for @user, :name, :string, :
|
4
|
+
test 'string input generates readonly elements when readonly option is true' do
|
5
|
+
with_input_for @user, :name, :string, readonly: true
|
6
6
|
assert_select 'input.string.readonly[readonly]'
|
7
7
|
end
|
8
8
|
|
9
|
-
test 'text input
|
10
|
-
with_input_for @user, :description, :text, :
|
9
|
+
test 'text input generates readonly elements when readonly option is true' do
|
10
|
+
with_input_for @user, :description, :text, readonly: true
|
11
11
|
assert_select 'textarea.text.readonly[readonly]'
|
12
12
|
end
|
13
13
|
|
14
|
-
test 'numeric input
|
15
|
-
with_input_for @user, :age, :integer, :
|
14
|
+
test 'numeric input generates readonly elements when readonly option is true' do
|
15
|
+
with_input_for @user, :age, :integer, readonly: true
|
16
16
|
assert_select 'input.integer.readonly[readonly]'
|
17
17
|
end
|
18
18
|
|
19
|
-
test 'date input
|
20
|
-
with_input_for @user, :born_at, :date, :
|
19
|
+
test 'date input generates readonly elements when readonly option is true' do
|
20
|
+
with_input_for @user, :born_at, :date, readonly: true
|
21
21
|
assert_select 'select.date.readonly[readonly]'
|
22
22
|
end
|
23
23
|
|
24
|
-
test 'datetime input
|
25
|
-
with_input_for @user, :created_at, :datetime, :
|
24
|
+
test 'datetime input generates readonly elements when readonly option is true' do
|
25
|
+
with_input_for @user, :created_at, :datetime, readonly: true
|
26
26
|
assert_select 'select.datetime.readonly[readonly]'
|
27
27
|
end
|
28
28
|
|
29
|
-
test 'string input
|
30
|
-
with_input_for @user, :name, :string, :
|
29
|
+
test 'string input generates readonly elements when readonly option is false' do
|
30
|
+
with_input_for @user, :name, :string, readonly: false
|
31
31
|
assert_no_select 'input.string.readonly[readonly]'
|
32
32
|
end
|
33
33
|
|
34
|
-
test 'text input
|
35
|
-
with_input_for @user, :description, :text, :
|
34
|
+
test 'text input generates readonly elements when readonly option is false' do
|
35
|
+
with_input_for @user, :description, :text, readonly: false
|
36
36
|
assert_no_select 'textarea.text.readonly[readonly]'
|
37
37
|
end
|
38
38
|
|
39
|
-
test 'numeric input
|
40
|
-
with_input_for @user, :age, :integer, :
|
39
|
+
test 'numeric input generates readonly elements when readonly option is false' do
|
40
|
+
with_input_for @user, :age, :integer, readonly: false
|
41
41
|
assert_no_select 'input.integer.readonly[readonly]'
|
42
42
|
end
|
43
43
|
|
44
|
-
test 'date input
|
45
|
-
with_input_for @user, :born_at, :date, :
|
44
|
+
test 'date input generates readonly elements when readonly option is false' do
|
45
|
+
with_input_for @user, :born_at, :date, readonly: false
|
46
46
|
assert_no_select 'select.date.readonly[readonly]'
|
47
47
|
end
|
48
48
|
|
49
|
-
test 'datetime input
|
50
|
-
with_input_for @user, :created_at, :datetime, :
|
49
|
+
test 'datetime input generates readonly elements when readonly option is false' do
|
50
|
+
with_input_for @user, :created_at, :datetime, readonly: false
|
51
51
|
assert_no_select 'select.datetime.readonly[readonly]'
|
52
52
|
end
|
53
53
|
|
54
|
-
test 'string input
|
54
|
+
test 'string input generates readonly elements when readonly option is not present' do
|
55
55
|
with_input_for @user, :name, :string
|
56
56
|
assert_no_select 'input.string.readonly[readonly]'
|
57
57
|
end
|
58
58
|
|
59
|
-
test 'text input
|
59
|
+
test 'text input generates readonly elements when readonly option is not present' do
|
60
60
|
with_input_for @user, :description, :text
|
61
61
|
assert_no_select 'textarea.text.readonly[readonly]'
|
62
62
|
end
|
63
63
|
|
64
|
-
test 'numeric input
|
64
|
+
test 'numeric input generates readonly elements when readonly option is not present' do
|
65
65
|
with_input_for @user, :age, :integer
|
66
66
|
assert_no_select 'input.integer.readonly[readonly]'
|
67
67
|
end
|
68
68
|
|
69
|
-
test 'date input
|
69
|
+
test 'date input generates readonly elements when readonly option is not present' do
|
70
70
|
with_input_for @user, :born_at, :date
|
71
71
|
assert_no_select 'select.date.readonly[readonly]'
|
72
72
|
end
|
73
73
|
|
74
|
-
test 'datetime input
|
74
|
+
test 'datetime input generates readonly elements when readonly option is not present' do
|
75
75
|
with_input_for @user, :created_at, :datetime
|
76
76
|
assert_no_select 'select.datetime.readonly[readonly]'
|
77
77
|
end
|
78
78
|
|
79
|
-
test 'input
|
80
|
-
with_input_for @user, :credit_card, :string, :
|
79
|
+
test 'input generates readonly attribute when the field is readonly and the object is persisted' do
|
80
|
+
with_input_for @user, :credit_card, :string, readonly: :lookup
|
81
81
|
assert_select 'input.string.readonly[readonly]'
|
82
82
|
end
|
83
83
|
|
84
|
-
test 'input
|
84
|
+
test 'input does not generate readonly attribute when the field is readonly and the object is not persisted' do
|
85
85
|
@user.new_record!
|
86
|
-
with_input_for @user, :credit_card, :string, :
|
86
|
+
with_input_for @user, :credit_card, :string, readonly: :lookup
|
87
87
|
assert_no_select 'input.string.readonly[readonly]'
|
88
88
|
end
|
89
89
|
|
90
|
-
test 'input
|
90
|
+
test 'input does not generate readonly attribute when the field is not readonly and the object is persisted' do
|
91
91
|
with_input_for @user, :name, :string
|
92
92
|
assert_no_select 'input.string.readonly[readonly]'
|
93
93
|
end
|
94
94
|
|
95
|
-
test 'input
|
95
|
+
test 'input does not generate readonly attribute when the component is not used' do
|
96
96
|
swap_wrapper do
|
97
97
|
with_input_for @user, :credit_card, :string
|
98
98
|
assert_no_select 'input.string.readonly[readonly]'
|