simple_form 3.1.0.rc1 → 3.1.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +37 -6
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +6 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +37 -14
- data/lib/simple_form.rb +8 -0
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/form_builder.rb +29 -15
- data/lib/simple_form/inputs/boolean_input.rb +7 -4
- data/lib/simple_form/tags.rb +1 -0
- 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/test/action_view_extensions/builder_test.rb +3 -3
- data/test/action_view_extensions/form_helper_test.rb +13 -13
- data/test/components/label_test.rb +35 -35
- data/test/form_builder/association_test.rb +4 -4
- data/test/form_builder/button_test.rb +5 -5
- data/test/form_builder/error_test.rb +18 -18
- data/test/form_builder/general_test.rb +65 -60
- data/test/form_builder/hint_test.rb +15 -15
- data/test/form_builder/input_field_test.rb +16 -16
- data/test/form_builder/label_test.rb +22 -13
- data/test/form_builder/wrapper_test.rb +54 -20
- data/test/inputs/boolean_input_test.rb +8 -8
- data/test/inputs/collection_check_boxes_input_test.rb +24 -7
- data/test/inputs/collection_radio_buttons_input_test.rb +40 -23
- data/test/inputs/collection_select_input_test.rb +45 -45
- data/test/inputs/datetime_input_test.rb +23 -23
- 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 +2 -2
- data/test/inputs/hidden_input_test.rb +4 -4
- data/test/inputs/numeric_input_test.rb +24 -24
- data/test/inputs/priority_input_test.rb +7 -7
- data/test/inputs/readonly_test.rb +19 -19
- data/test/inputs/required_test.rb +13 -13
- data/test/inputs/string_input_test.rb +23 -23
- data/test/inputs/text_input_test.rb +4 -4
- data/test/support/discovery_inputs.rb +20 -0
- data/test/support/misc_helpers.rb +22 -0
- data/test/support/models.rb +2 -1
- metadata +2 -2
@@ -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,
|
@@ -167,7 +167,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
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,32 +2,32 @@
|
|
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
|
|
@@ -35,7 +35,7 @@ class NumericInputTest < ActionView::TestCase
|
|
35
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
|
|
@@ -43,7 +43,7 @@ class NumericInputTest < ActionView::TestCase
|
|
43
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
48
|
assert_select 'input[min=1]'
|
49
49
|
|
@@ -51,7 +51,7 @@ class NumericInputTest < ActionView::TestCase
|
|
51
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
|
|
@@ -59,7 +59,7 @@ class NumericInputTest < ActionView::TestCase
|
|
59
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
64
|
assert_select 'input[min=19]'
|
65
65
|
|
@@ -67,7 +67,7 @@ class NumericInputTest < ActionView::TestCase
|
|
67
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
|
|
@@ -75,7 +75,7 @@ class NumericInputTest < ActionView::TestCase
|
|
75
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
|
|
@@ -83,7 +83,7 @@ class NumericInputTest < ActionView::TestCase
|
|
83
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
88
|
assert_select 'input[max=100]'
|
89
89
|
|
@@ -91,7 +91,7 @@ class NumericInputTest < ActionView::TestCase
|
|
91
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
|
|
@@ -99,7 +99,7 @@ class NumericInputTest < ActionView::TestCase
|
|
99
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
104
|
assert_select 'input[max=119]'
|
105
105
|
|
@@ -107,7 +107,7 @@ class NumericInputTest < ActionView::TestCase
|
|
107
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
|
|
@@ -115,17 +115,17 @@ class NumericInputTest < ActionView::TestCase
|
|
115
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
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
|
@@ -135,7 +135,7 @@ class NumericInputTest < ActionView::TestCase
|
|
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
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
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,46 +2,46 @@
|
|
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
9
|
assert_no_select 'select option[value=][disabled=disabled]'
|
10
10
|
end
|
11
11
|
|
12
|
-
test 'input
|
12
|
+
test 'input generates a country select with SimpleForm default' do
|
13
13
|
swap SimpleForm, country_priority: [ 'Brazil' ] do
|
14
14
|
with_input_for @user, :country, :country
|
15
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
23
|
assert_no_select 'select option[value=][disabled=disabled]'
|
24
24
|
end
|
25
25
|
|
26
|
-
test 'input
|
26
|
+
test 'input generates a time zone select field with default' do
|
27
27
|
with_input_for @user, :time_zone, :time_zone, default: 'Brasilia'
|
28
28
|
assert_select 'select option[value=Brasilia][selected=selected]'
|
29
29
|
assert_no_select 'select option[value=]'
|
30
30
|
end
|
31
31
|
|
32
|
-
test 'input
|
32
|
+
test 'input generates a time zone select using options priority' do
|
33
33
|
with_input_for @user, :time_zone, :time_zone, priority: /Brasilia/
|
34
34
|
assert_select 'select option[value=][disabled=disabled]'
|
35
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
43
|
|
44
|
-
test 'priority input
|
44
|
+
test 'priority input does not generate invalid aria-required html attribute' do
|
45
45
|
with_input_for @user, :country, :country
|
46
46
|
assert_select 'select.required'
|
47
47
|
assert_no_select 'select[aria-required]'
|
@@ -1,98 +1,98 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ReadonlyTest < ActionView::TestCase
|
4
|
-
test 'string input
|
4
|
+
test 'string input generates readonly elements when readonly option is true' do
|
5
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
|
9
|
+
test 'text input generates readonly elements when readonly option is true' do
|
10
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
|
14
|
+
test 'numeric input generates readonly elements when readonly option is true' do
|
15
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
|
19
|
+
test 'date input generates readonly elements when readonly option is true' do
|
20
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
|
24
|
+
test 'datetime input generates readonly elements when readonly option is true' do
|
25
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
|
29
|
+
test 'string input generates readonly elements when readonly option is false' do
|
30
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
|
34
|
+
test 'text input generates readonly elements when readonly option is false' do
|
35
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
|
39
|
+
test 'numeric input generates readonly elements when readonly option is false' do
|
40
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
|
44
|
+
test 'date input generates readonly elements when readonly option is false' do
|
45
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
|
49
|
+
test 'datetime input generates readonly elements when readonly option is false' do
|
50
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
|
79
|
+
test 'input generates readonly attribute when the field is readonly and the object is persisted' do
|
80
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
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]'
|
@@ -2,26 +2,26 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class RequiredTest < ActionView::TestCase
|
4
4
|
# REQUIRED AND PRESENCE VALIDATION
|
5
|
-
test 'builder input
|
5
|
+
test 'builder input obtains required from ActiveModel::Validations when it is included' do
|
6
6
|
with_form_for @validating_user, :name
|
7
7
|
assert_select 'input.required[required]#validating_user_name'
|
8
8
|
with_form_for @validating_user, :status
|
9
9
|
assert_select 'input.optional#validating_user_status'
|
10
10
|
end
|
11
11
|
|
12
|
-
test 'builder input
|
12
|
+
test 'builder input allows overriding required when ActiveModel::Validations is included' do
|
13
13
|
with_form_for @validating_user, :name, required: false
|
14
14
|
assert_select 'input.optional#validating_user_name'
|
15
15
|
with_form_for @validating_user, :status, required: true
|
16
16
|
assert_select 'input.required[required]#validating_user_status'
|
17
17
|
end
|
18
18
|
|
19
|
-
test 'builder input
|
19
|
+
test 'builder input is required by default when ActiveModel::Validations is not included' do
|
20
20
|
with_form_for @user, :name
|
21
21
|
assert_select 'input.required[required]#user_name'
|
22
22
|
end
|
23
23
|
|
24
|
-
test 'builder input
|
24
|
+
test 'builder input does not be required by default when ActiveModel::Validations is not included if option is set to false' do
|
25
25
|
swap SimpleForm, required_by_default: false do
|
26
26
|
with_form_for @user, :name
|
27
27
|
assert_select 'input.optional#user_name'
|
@@ -29,7 +29,7 @@ class RequiredTest < ActionView::TestCase
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
test 'when not using browser validations, input
|
32
|
+
test 'when not using browser validations, input does not generate required html attribute' do
|
33
33
|
swap SimpleForm, browser_validations: false do
|
34
34
|
with_input_for @user, :name, :string
|
35
35
|
assert_select 'input[type=text].required'
|
@@ -37,7 +37,7 @@ class RequiredTest < ActionView::TestCase
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
test 'builder input
|
40
|
+
test 'builder input allows disabling required when ActiveModel::Validations is not included' do
|
41
41
|
with_form_for @user, :name, required: false
|
42
42
|
assert_no_select 'input.required'
|
43
43
|
assert_no_select 'input[required]'
|
@@ -53,14 +53,14 @@ class RequiredTest < ActionView::TestCase
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# VALIDATORS :if :unless
|
56
|
-
test 'builder input
|
56
|
+
test 'builder input does not be required when ActiveModel::Validations is included and if option is present' do
|
57
57
|
with_form_for @validating_user, :age
|
58
58
|
assert_no_select 'input.required'
|
59
59
|
assert_no_select 'input[required]'
|
60
60
|
assert_select 'input.optional#validating_user_age'
|
61
61
|
end
|
62
62
|
|
63
|
-
test 'builder input
|
63
|
+
test 'builder input does not be required when ActiveModel::Validations is included and unless option is present' do
|
64
64
|
with_form_for @validating_user, :amount
|
65
65
|
assert_no_select 'input.required'
|
66
66
|
assert_no_select 'input[required]'
|
@@ -68,7 +68,7 @@ class RequiredTest < ActionView::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# VALIDATORS :on
|
71
|
-
test 'builder input
|
71
|
+
test 'builder input is required when validation is on create and is not persisted' do
|
72
72
|
@validating_user.new_record!
|
73
73
|
with_form_for @validating_user, :action
|
74
74
|
assert_select 'input.required'
|
@@ -76,14 +76,14 @@ class RequiredTest < ActionView::TestCase
|
|
76
76
|
assert_select 'input.required[required]#validating_user_action'
|
77
77
|
end
|
78
78
|
|
79
|
-
test 'builder input
|
79
|
+
test 'builder input does not be required when validation is on create and is persisted' do
|
80
80
|
with_form_for @validating_user, :action
|
81
81
|
assert_no_select 'input.required'
|
82
82
|
assert_no_select 'input[required]'
|
83
83
|
assert_select 'input.optional#validating_user_action'
|
84
84
|
end
|
85
85
|
|
86
|
-
test 'builder input
|
86
|
+
test 'builder input is required when validation is on save' do
|
87
87
|
with_form_for @validating_user, :credit_limit
|
88
88
|
assert_select 'input.required'
|
89
89
|
assert_select 'input[required]'
|
@@ -96,14 +96,14 @@ class RequiredTest < ActionView::TestCase
|
|
96
96
|
assert_select 'input.required[required]#validating_user_credit_limit'
|
97
97
|
end
|
98
98
|
|
99
|
-
test 'builder input
|
99
|
+
test 'builder input is required when validation is on update and is persisted' do
|
100
100
|
with_form_for @validating_user, :phone_number
|
101
101
|
assert_select 'input.required'
|
102
102
|
assert_select 'input[required]'
|
103
103
|
assert_select 'input.required[required]#validating_user_phone_number'
|
104
104
|
end
|
105
105
|
|
106
|
-
test 'builder input
|
106
|
+
test 'builder input does not be required when validation is on update and is not persisted' do
|
107
107
|
@validating_user.new_record!
|
108
108
|
with_form_for @validating_user, :phone_number
|
109
109
|
assert_no_select 'input.required'
|