simple_form 3.1.0.rc2 → 3.2.1
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 +45 -1
- data/MIT-LICENSE +1 -1
- data/README.md +76 -24
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +4 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +22 -2
- 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/html5.rb +4 -4
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/form_builder.rb +9 -7
- data/lib/simple_form/inputs/base.rb +1 -5
- data/lib/simple_form/inputs/boolean_input.rb +1 -1
- data/lib/simple_form/inputs/collection_input.rb +2 -4
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +1 -1
- data/lib/simple_form/inputs/date_time_input.rb +12 -8
- data/lib/simple_form/tags.rb +2 -4
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form.rb +13 -2
- data/test/action_view_extensions/builder_test.rb +31 -31
- data/test/action_view_extensions/form_helper_test.rb +20 -1
- data/test/components/label_test.rb +1 -1
- data/test/form_builder/association_test.rb +37 -37
- data/test/form_builder/button_test.rb +5 -5
- data/test/form_builder/error_test.rb +75 -16
- data/test/form_builder/general_test.rb +42 -11
- data/test/form_builder/hint_test.rb +3 -3
- data/test/form_builder/input_field_test.rb +59 -53
- data/test/form_builder/label_test.rb +13 -3
- data/test/form_builder/wrapper_test.rb +29 -14
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +9 -1
- data/test/inputs/collection_check_boxes_input_test.rb +22 -0
- data/test/inputs/collection_radio_buttons_input_test.rb +25 -3
- data/test/inputs/collection_select_input_test.rb +17 -17
- data/test/inputs/datetime_input_test.rb +6 -1
- data/test/inputs/grouped_collection_select_input_test.rb +8 -8
- data/test/inputs/numeric_input_test.rb +19 -19
- data/test/inputs/priority_input_test.rb +6 -6
- data/test/inputs/required_test.rb +12 -0
- data/test/inputs/string_input_test.rb +10 -19
- data/test/inputs/text_input_test.rb +10 -3
- data/test/support/misc_helpers.rb +14 -1
- data/test/support/models.rb +11 -1
- data/test/test_helper.rb +9 -1
- metadata +25 -13
|
@@ -99,7 +99,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
99
99
|
|
|
100
100
|
test 'input automatically sets include blank' do
|
|
101
101
|
with_input_for @user, :age, :select, collection: 18..30
|
|
102
|
-
assert_select 'select option[value=]', ''
|
|
102
|
+
assert_select 'select option[value=""]', ''
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
test 'input translates include blank when set to :translate' do
|
|
@@ -107,7 +107,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
107
107
|
age: 'Rather not say'
|
|
108
108
|
} } }) do
|
|
109
109
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
|
110
|
-
assert_select 'select option[value=]', 'Rather not say'
|
|
110
|
+
assert_select 'select option[value=""]', 'Rather not say'
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
113
|
|
|
@@ -116,7 +116,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
116
116
|
age: 'Rather not say',
|
|
117
117
|
} } }) do
|
|
118
118
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
|
119
|
-
assert_select 'select option[value=]', 'Rather not say'
|
|
119
|
+
assert_select 'select option[value=""]', 'Rather not say'
|
|
120
120
|
end
|
|
121
121
|
end
|
|
122
122
|
|
|
@@ -125,7 +125,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
125
125
|
age: 'Rather not say'
|
|
126
126
|
} } }) do
|
|
127
127
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: 'Young at heart'
|
|
128
|
-
assert_select 'select option[value=]', 'Young at heart'
|
|
128
|
+
assert_select 'select option[value=""]', 'Young at heart'
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
|
|
@@ -134,7 +134,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
134
134
|
age: 'Rather not say'
|
|
135
135
|
} } }) do
|
|
136
136
|
with_input_for @user, :age, :select, collection: 18..30
|
|
137
|
-
assert_select 'select option[value=]', ''
|
|
137
|
+
assert_select 'select option[value=""]', ''
|
|
138
138
|
end
|
|
139
139
|
end
|
|
140
140
|
|
|
@@ -143,7 +143,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
143
143
|
age: 'Rather not say'
|
|
144
144
|
} } }) do
|
|
145
145
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: true
|
|
146
|
-
assert_select 'select option[value=]', ''
|
|
146
|
+
assert_select 'select option[value=""]', ''
|
|
147
147
|
end
|
|
148
148
|
end
|
|
149
149
|
|
|
@@ -152,23 +152,23 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
152
152
|
age: 'Rather not say'
|
|
153
153
|
} } }) do
|
|
154
154
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
|
155
|
-
assert_no_select 'select option[value=]'
|
|
155
|
+
assert_no_select 'select option[value=""]'
|
|
156
156
|
end
|
|
157
157
|
end
|
|
158
158
|
|
|
159
159
|
test 'input does not set include blank if otherwise is told' do
|
|
160
160
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
|
161
|
-
assert_no_select 'select option[value=]'
|
|
161
|
+
assert_no_select 'select option[value=""]'
|
|
162
162
|
end
|
|
163
163
|
|
|
164
164
|
test 'input does not set include blank if prompt is given' do
|
|
165
165
|
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
|
166
|
-
assert_no_select 'select option[value=]', ''
|
|
166
|
+
assert_no_select 'select option[value=""]', ''
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
test 'input does not set include blank if multiple is given' do
|
|
170
170
|
with_input_for @user, :age, :select, collection: 18..30, input_html: { multiple: true }
|
|
171
|
-
assert_no_select 'select option[value=]', ''
|
|
171
|
+
assert_no_select 'select option[value=""]', ''
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
test 'input translates prompt when set to :translate' do
|
|
@@ -176,7 +176,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
176
176
|
age: 'Select age:'
|
|
177
177
|
} } }) do
|
|
178
178
|
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
179
|
-
assert_select 'select option[value=]', 'Select age:'
|
|
179
|
+
assert_select 'select option[value=""]', 'Select age:'
|
|
180
180
|
end
|
|
181
181
|
end
|
|
182
182
|
|
|
@@ -185,7 +185,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
185
185
|
age: 'Select age:',
|
|
186
186
|
} } }) do
|
|
187
187
|
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
188
|
-
assert_select 'select option[value=]', 'Select age:'
|
|
188
|
+
assert_select 'select option[value=""]', 'Select age:'
|
|
189
189
|
end
|
|
190
190
|
end
|
|
191
191
|
|
|
@@ -194,7 +194,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
194
194
|
age: 'Select age:'
|
|
195
195
|
} } }) do
|
|
196
196
|
with_input_for @user, :age, :select, collection: 18..30, prompt: 'Do it:'
|
|
197
|
-
assert_select 'select option[value=]', 'Do it:'
|
|
197
|
+
assert_select 'select option[value=""]', 'Do it:'
|
|
198
198
|
end
|
|
199
199
|
end
|
|
200
200
|
|
|
@@ -203,7 +203,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
203
203
|
age: 'Select age:'
|
|
204
204
|
} } }) do
|
|
205
205
|
with_input_for @user, :age, :select, collection: 18..30, prompt: false
|
|
206
|
-
assert_no_select 'select option[value=]'
|
|
206
|
+
assert_no_select 'select option[value=""]'
|
|
207
207
|
end
|
|
208
208
|
end
|
|
209
209
|
|
|
@@ -212,15 +212,15 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
|
212
212
|
prompt: 'Select value:'
|
|
213
213
|
} }) do
|
|
214
214
|
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
|
215
|
-
assert_select 'select option[value=]', "Select value:"
|
|
215
|
+
assert_select 'select option[value=""]', "Select value:"
|
|
216
216
|
end
|
|
217
217
|
end
|
|
218
218
|
|
|
219
219
|
test 'input detects label and value on collections' do
|
|
220
220
|
users = [User.build(id: 1, name: "Jose"), User.build(id: 2, name: "Carlos")]
|
|
221
221
|
with_input_for @user, :description, :select, collection: users
|
|
222
|
-
assert_select 'select option[value=1]', 'Jose'
|
|
223
|
-
assert_select 'select option[value=2]', 'Carlos'
|
|
222
|
+
assert_select 'select option[value="1"]', 'Jose'
|
|
223
|
+
assert_select 'select option[value="2"]', 'Carlos'
|
|
224
224
|
end
|
|
225
225
|
|
|
226
226
|
test 'input disables the anothers components when the option is a object' do
|
|
@@ -102,7 +102,7 @@ class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
|
|
102
102
|
|
|
103
103
|
test 'input is able to pass :default to date select' do
|
|
104
104
|
with_input_for @user, :born_at, :date, default: Date.today, html5: false
|
|
105
|
-
assert_select "select.date option[value
|
|
105
|
+
assert_select "select.date option[value='#{Date.today.year}'][selected=selected]"
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enabled' do
|
|
@@ -169,4 +169,9 @@ class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
|
|
169
169
|
with_input_for :project, :created_at, :time, html5: false
|
|
170
170
|
assert_select 'label[for=project_created_at_4i]'
|
|
171
171
|
end
|
|
172
|
+
|
|
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]'
|
|
176
|
+
end
|
|
172
177
|
end
|
|
@@ -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
|
|
@@ -155,14 +155,14 @@ 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
|
|
@@ -32,7 +32,7 @@ class NumericInputTest < ActionView::TestCase
|
|
|
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
38
|
test 'input infers min value from integer attributes with greater than validation using symbol' do
|
|
@@ -40,15 +40,15 @@ class NumericInputTest < ActionView::TestCase
|
|
|
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
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
54
|
test 'input infers min value from integer attributes with greater than validation using proc' do
|
|
@@ -56,15 +56,15 @@ class NumericInputTest < ActionView::TestCase
|
|
|
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
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
70
|
test 'input infers max value from attributes with less than validation' do
|
|
@@ -72,7 +72,7 @@ class NumericInputTest < ActionView::TestCase
|
|
|
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
78
|
test 'input infers max value from attributes with less than validation using symbol' do
|
|
@@ -80,15 +80,15 @@ class NumericInputTest < ActionView::TestCase
|
|
|
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
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
94
|
test 'input infers max value from attributes with less than validation using proc' do
|
|
@@ -96,15 +96,15 @@ class NumericInputTest < ActionView::TestCase
|
|
|
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
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
110
|
test 'input has step value of any except for integer attribute' do
|
|
@@ -112,7 +112,7 @@ class NumericInputTest < ActionView::TestCase
|
|
|
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
118
|
test 'numeric input does not generate placeholder by default' do
|
|
@@ -122,7 +122,7 @@ class NumericInputTest < ActionView::TestCase
|
|
|
122
122
|
|
|
123
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
128
|
test 'numeric input uses i18n to translate placeholder text' do
|
|
@@ -130,7 +130,7 @@ class NumericInputTest < ActionView::TestCase
|
|
|
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
|
|
|
@@ -156,12 +156,12 @@ class NumericInputTest < ActionView::TestCase
|
|
|
156
156
|
[:integer, :float, :decimal].each do |type|
|
|
157
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
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
|
|
|
@@ -6,13 +6,13 @@ class PriorityInputTest < ActionView::TestCase
|
|
|
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
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
|
-
assert_select 'select option[value=][disabled=disabled]'
|
|
15
|
+
assert_select 'select option[value=""][disabled=disabled]'
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -20,19 +20,19 @@ class PriorityInputTest < ActionView::TestCase
|
|
|
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
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
|
-
assert_no_select 'select option[value=]'
|
|
29
|
+
assert_no_select 'select option[value=""]'
|
|
30
30
|
end
|
|
31
31
|
|
|
32
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
|
-
assert_select 'select option[value=][disabled=disabled]'
|
|
35
|
-
assert_no_select 'select option[value=]', /^$/
|
|
34
|
+
assert_select 'select option[value=""][disabled=disabled]'
|
|
35
|
+
assert_no_select 'select option[value=""]', /^$/
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
test 'priority input does not generate invalid required html attribute' do
|
|
@@ -110,4 +110,16 @@ class RequiredTest < ActionView::TestCase
|
|
|
110
110
|
assert_no_select 'input[required]'
|
|
111
111
|
assert_select 'input.optional#validating_user_phone_number'
|
|
112
112
|
end
|
|
113
|
+
|
|
114
|
+
test 'builder input does not generate required html attribute when option is set to false when it is set to true in wrapper' do
|
|
115
|
+
swap SimpleForm, browser_validations: true do
|
|
116
|
+
swap_wrapper :default, self.custom_wrapper_with_required_input do
|
|
117
|
+
with_concat_form_for(@user) do |f|
|
|
118
|
+
concat f.input :name, required: false
|
|
119
|
+
end
|
|
120
|
+
assert_no_select 'input[type=text][required]'
|
|
121
|
+
assert_no_select 'input[type=text][aria-required]'
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
113
125
|
end
|
|
@@ -4,7 +4,7 @@ require 'test_helper'
|
|
|
4
4
|
class StringInputTest < ActionView::TestCase
|
|
5
5
|
test 'input maps text field to string attribute' do
|
|
6
6
|
with_input_for @user, :name, :string
|
|
7
|
-
assert_select "input#user_name[type=text][name='user[name]'][value=New in SimpleForm!]"
|
|
7
|
+
assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
test 'input generates a password field for password attributes' do
|
|
@@ -14,7 +14,7 @@ class StringInputTest < ActionView::TestCase
|
|
|
14
14
|
|
|
15
15
|
test 'input gets maxlength from column definition for string attributes' do
|
|
16
16
|
with_input_for @user, :name, :string
|
|
17
|
-
assert_select 'input.string[maxlength=100]'
|
|
17
|
+
assert_select 'input.string[maxlength="100"]'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
test 'input does not get maxlength from column without size definition for string attributes' do
|
|
@@ -24,12 +24,12 @@ class StringInputTest < ActionView::TestCase
|
|
|
24
24
|
|
|
25
25
|
test 'input gets maxlength from column definition for password attributes' do
|
|
26
26
|
with_input_for @user, :password, :password
|
|
27
|
-
assert_select 'input.password[type=password][maxlength=100]'
|
|
27
|
+
assert_select 'input.password[type=password][maxlength="100"]'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
test 'input infers maxlength column definition from validation when present' do
|
|
31
31
|
with_input_for @validating_user, :name, :string
|
|
32
|
-
assert_select 'input.string[maxlength=25]'
|
|
32
|
+
assert_select 'input.string[maxlength="25"]'
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
test 'input does not get maxlength from validation when tokenizer present' do
|
|
@@ -39,13 +39,13 @@ class StringInputTest < ActionView::TestCase
|
|
|
39
39
|
|
|
40
40
|
test 'input gets maxlength from validation when :is option present' do
|
|
41
41
|
with_input_for @validating_user, :home_picture, :string
|
|
42
|
-
assert_select 'input.string[maxlength=12]'
|
|
42
|
+
assert_select 'input.string[maxlength="12"]'
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
test 'input maxlength is the column limit plus one to make room for decimal point' do
|
|
46
46
|
with_input_for @user, :credit_limit, :string
|
|
47
47
|
|
|
48
|
-
assert_select
|
|
48
|
+
assert_select 'input.string[maxlength="16"]'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
test 'input does not generate placeholder by default' do
|
|
@@ -55,12 +55,12 @@ class StringInputTest < ActionView::TestCase
|
|
|
55
55
|
|
|
56
56
|
test 'input accepts the placeholder option' do
|
|
57
57
|
with_input_for @user, :name, :string, placeholder: 'Put in some text'
|
|
58
|
-
assert_select 'input.string[placeholder=Put in some text]'
|
|
58
|
+
assert_select 'input.string[placeholder="Put in some text"]'
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
test 'input generates a password field for password attributes that accept placeholder' do
|
|
62
62
|
with_input_for @user, :password, :password, placeholder: 'Password Confirmation'
|
|
63
|
-
assert_select 'input[type=password].password[placeholder=Password Confirmation]#user_password'
|
|
63
|
+
assert_select 'input[type=password].password[placeholder="Password Confirmation"]#user_password'
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
test 'input does not infer pattern from attributes by default' do
|
|
@@ -100,7 +100,7 @@ class StringInputTest < ActionView::TestCase
|
|
|
100
100
|
name: 'Name goes here'
|
|
101
101
|
} } }) do
|
|
102
102
|
with_input_for @user, :name, :string
|
|
103
|
-
assert_select 'input.string[placeholder=Name goes here]'
|
|
103
|
+
assert_select 'input.string[placeholder="Name goes here"]'
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
|
|
@@ -110,20 +110,11 @@ class StringInputTest < ActionView::TestCase
|
|
|
110
110
|
} } }) do
|
|
111
111
|
swap SimpleForm, i18n_scope: :my_scope do
|
|
112
112
|
with_input_for @user, :name, :string
|
|
113
|
-
assert_select 'input.string[placeholder=Name goes here]'
|
|
113
|
+
assert_select 'input.string[placeholder="Name goes here"]'
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
test 'input translates a key prefixed with _html and return the html markup' do
|
|
119
|
-
store_translations(:en, simple_form: { labels: { user: {
|
|
120
|
-
name_html: '<b>Name</b>'
|
|
121
|
-
} } }) do
|
|
122
|
-
with_input_for @user, :name, :string
|
|
123
|
-
assert_select 'label b', 'Name'
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
118
|
[:email, :url, :search, :tel].each do |type|
|
|
128
119
|
test "input allows type #{type}" do
|
|
129
120
|
with_input_for @user, :name, type
|
|
@@ -9,16 +9,23 @@ class TextInputTest < ActionView::TestCase
|
|
|
9
9
|
|
|
10
10
|
test 'input generates a text area for text attributes that accept placeholder' do
|
|
11
11
|
with_input_for @user, :description, :text, placeholder: 'Put in some text'
|
|
12
|
-
assert_select 'textarea.text[placeholder=Put in some text]'
|
|
12
|
+
assert_select 'textarea.text[placeholder="Put in some text"]'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test 'input generates a placeholder from the translations' do
|
|
16
|
+
store_translations(:en, simple_form: { placeholders: { user: { name: "placeholder from i18n en.simple_form.placeholders.user.name" } } }) do
|
|
17
|
+
with_input_for @user, :name, :text
|
|
18
|
+
assert_select 'textarea.text[placeholder="placeholder from i18n en.simple_form.placeholders.user.name"]'
|
|
19
|
+
end
|
|
13
20
|
end
|
|
14
21
|
|
|
15
22
|
test 'input gets maxlength from column definition for text attributes' do
|
|
16
23
|
with_input_for @user, :description, :text
|
|
17
|
-
assert_select 'textarea.text[maxlength=200]'
|
|
24
|
+
assert_select 'textarea.text[maxlength="200"]'
|
|
18
25
|
end
|
|
19
26
|
|
|
20
27
|
test 'input infers maxlength column definition from validation when present for text attributes' do
|
|
21
28
|
with_input_for @validating_user, :description, :text
|
|
22
|
-
assert_select 'textarea.text[maxlength=50]'
|
|
29
|
+
assert_select 'textarea.text[maxlength="50"]'
|
|
23
30
|
end
|
|
24
31
|
end
|
|
@@ -46,7 +46,7 @@ module MiscHelpers
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def swap_wrapper(name = :default, wrapper =
|
|
49
|
+
def swap_wrapper(name = :default, wrapper = custom_wrapper)
|
|
50
50
|
old = SimpleForm.wrappers[name.to_s]
|
|
51
51
|
SimpleForm.wrappers[name.to_s] = wrapper
|
|
52
52
|
yield
|
|
@@ -178,6 +178,19 @@ module MiscHelpers
|
|
|
178
178
|
end
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
+
def custom_wrapper_with_html5_components
|
|
182
|
+
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
|
|
183
|
+
b.use :label_text
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def custom_wrapper_with_required_input
|
|
188
|
+
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
|
|
189
|
+
b.use :html5
|
|
190
|
+
b.use :input, required: true
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
181
194
|
def custom_form_for(object, *args, &block)
|
|
182
195
|
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
|
183
196
|
end
|
data/test/support/models.rb
CHANGED
|
@@ -130,6 +130,16 @@ class User
|
|
|
130
130
|
Column.new(attribute, column_type, limit)
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
+
def has_attribute?(attribute)
|
|
134
|
+
case attribute.to_sym
|
|
135
|
+
when :name, :status, :password, :description, :age,
|
|
136
|
+
:credit_limit, :active, :born_at, :delivery_time,
|
|
137
|
+
:created_at, :updated_at, :lock_version, :home_picture,
|
|
138
|
+
:amount, :attempts, :action, :credit_card, :uuid then true
|
|
139
|
+
else false
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
133
143
|
def self.human_attribute_name(attribute, options = {})
|
|
134
144
|
case attribute
|
|
135
145
|
when 'name'
|
|
@@ -165,7 +175,7 @@ class User
|
|
|
165
175
|
def errors
|
|
166
176
|
@errors ||= begin
|
|
167
177
|
errors = ActiveModel::Errors.new(self)
|
|
168
|
-
errors.add(:name, "
|
|
178
|
+
errors.add(:name, "cannot be blank")
|
|
169
179
|
errors.add(:description, 'must be longer than 15 characters')
|
|
170
180
|
errors.add(:age, 'is not a number')
|
|
171
181
|
errors.add(:age, 'must be greater than 18')
|
data/test/test_helper.rb
CHANGED
|
@@ -30,7 +30,15 @@ I18n.default_locale = :en
|
|
|
30
30
|
|
|
31
31
|
require 'country_select'
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
if defined?(HTMLSelector::NO_STRIP)
|
|
34
|
+
HTMLSelector::NO_STRIP << "label"
|
|
35
|
+
else
|
|
36
|
+
ActionDispatch::Assertions::NO_STRIP << "label"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
if ActiveSupport::TestCase.respond_to?(:test_order=)
|
|
40
|
+
ActiveSupport::TestCase.test_order = :random
|
|
41
|
+
end
|
|
34
42
|
|
|
35
43
|
class ActionView::TestCase
|
|
36
44
|
include MiscHelpers
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1
|
|
4
|
+
version: 3.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- José Valim
|
|
@@ -10,36 +10,48 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2015-12-20 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activemodel
|
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
|
18
18
|
requirements:
|
|
19
|
-
- - "
|
|
19
|
+
- - ">"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '4
|
|
21
|
+
version: '4'
|
|
22
|
+
- - "<"
|
|
23
|
+
- !ruby/object:Gem::Version
|
|
24
|
+
version: '5.1'
|
|
22
25
|
type: :runtime
|
|
23
26
|
prerelease: false
|
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
28
|
requirements:
|
|
26
|
-
- - "
|
|
29
|
+
- - ">"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '4'
|
|
32
|
+
- - "<"
|
|
27
33
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: '
|
|
34
|
+
version: '5.1'
|
|
29
35
|
- !ruby/object:Gem::Dependency
|
|
30
36
|
name: actionpack
|
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|
|
32
38
|
requirements:
|
|
33
|
-
- - "
|
|
39
|
+
- - ">"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '4'
|
|
42
|
+
- - "<"
|
|
34
43
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: '
|
|
44
|
+
version: '5.1'
|
|
36
45
|
type: :runtime
|
|
37
46
|
prerelease: false
|
|
38
47
|
version_requirements: !ruby/object:Gem::Requirement
|
|
39
48
|
requirements:
|
|
40
|
-
- - "
|
|
49
|
+
- - ">"
|
|
41
50
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: '4
|
|
51
|
+
version: '4'
|
|
52
|
+
- - "<"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.1'
|
|
43
55
|
description: Forms made easy!
|
|
44
56
|
email: opensource@plataformatec.com.br
|
|
45
57
|
executables: []
|
|
@@ -161,12 +173,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
161
173
|
version: '0'
|
|
162
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
175
|
requirements:
|
|
164
|
-
- - "
|
|
176
|
+
- - ">="
|
|
165
177
|
- !ruby/object:Gem::Version
|
|
166
|
-
version:
|
|
178
|
+
version: '0'
|
|
167
179
|
requirements: []
|
|
168
180
|
rubyforge_project: simple_form
|
|
169
|
-
rubygems_version: 2.
|
|
181
|
+
rubygems_version: 2.4.5.1
|
|
170
182
|
signing_key:
|
|
171
183
|
specification_version: 4
|
|
172
184
|
summary: Forms made easy!
|