simple_form 3.0.2 → 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 +45 -34
- data/MIT-LICENSE +1 -1
- data/README.md +204 -81
- data/lib/generators/simple_form/install_generator.rb +3 -3
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +28 -7
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +115 -24
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +86 -5
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +6 -2
- data/lib/simple_form/components/errors.rb +28 -2
- data/lib/simple_form/components/hints.rb +2 -2
- data/lib/simple_form/components/html5.rb +1 -1
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +10 -6
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/form_builder.rb +123 -73
- data/lib/simple_form/helpers.rb +5 -5
- data/lib/simple_form/inputs/base.rb +33 -11
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +28 -15
- data/lib/simple_form/inputs/collection_input.rb +30 -9
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +12 -2
- 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 +5 -4
- data/lib/simple_form/inputs/password_input.rb +4 -2
- 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 -2
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +6 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +6 -6
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +6 -6
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +59 -8
- data/test/action_view_extensions/builder_test.rb +36 -36
- data/test/action_view_extensions/form_helper_test.rb +33 -14
- data/test/components/label_test.rb +37 -37
- data/test/form_builder/association_test.rb +52 -35
- data/test/form_builder/button_test.rb +10 -10
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/error_test.rb +144 -24
- 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 +80 -16
- data/test/form_builder/label_test.rb +45 -13
- data/test/form_builder/wrapper_test.rb +135 -19
- data/test/generators/simple_form_generator_test.rb +4 -4
- data/test/inputs/boolean_input_test.rb +62 -6
- data/test/inputs/collection_check_boxes_input_test.rb +85 -17
- data/test/inputs/collection_radio_buttons_input_test.rb +134 -36
- data/test/inputs/collection_select_input_test.rb +146 -41
- data/test/inputs/datetime_input_test.rb +117 -50
- data/test/inputs/disabled_test.rb +15 -15
- data/test/inputs/discovery_test.rb +56 -6
- 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 +44 -8
- 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 +50 -30
- data/test/inputs/text_input_test.rb +7 -7
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +32 -2
- data/test/support/misc_helpers.rb +77 -5
- data/test/support/models.rb +60 -24
- data/test/test_helper.rb +5 -1
- metadata +4 -3
|
@@ -8,7 +8,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
test 'nested simple fields
|
|
11
|
+
test 'nested simple fields yields an instance of FormBuilder' do
|
|
12
12
|
simple_form_for :user do |f|
|
|
13
13
|
f.simple_fields_for :posts do |posts_form|
|
|
14
14
|
assert posts_form.instance_of?(SimpleForm::FormBuilder)
|
|
@@ -22,7 +22,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
test 'builder
|
|
25
|
+
test 'builder works without controller' do
|
|
26
26
|
stub_any_instance ActionView::TestCase, :controller, nil do
|
|
27
27
|
simple_form_for @user do |f|
|
|
28
28
|
assert f.input(:name)
|
|
@@ -30,7 +30,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
test 'builder input
|
|
33
|
+
test 'builder input allows a block to configure input' do
|
|
34
34
|
with_form_for @user, :name do
|
|
35
35
|
text_field_tag :foo, :bar, id: :cool
|
|
36
36
|
end
|
|
@@ -38,7 +38,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
38
38
|
assert_select 'input#cool'
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
test 'builder
|
|
41
|
+
test 'builder allows adding custom input mappings for default input types' do
|
|
42
42
|
swap SimpleForm, input_mappings: { /count$/ => :integer } do
|
|
43
43
|
with_form_for @user, :post_count
|
|
44
44
|
assert_no_select 'form input#user_post_count.string'
|
|
@@ -46,7 +46,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
test 'builder
|
|
49
|
+
test 'builder allows to skip input_type class' do
|
|
50
50
|
swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
|
|
51
51
|
with_form_for @user, :post_count
|
|
52
52
|
assert_no_select "form input#user_post_count.integer"
|
|
@@ -54,7 +54,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
test 'builder
|
|
57
|
+
test 'builder allows to add additional classes only for wrapper' do
|
|
58
58
|
swap SimpleForm, generate_additional_classes_for: [:wrapper] do
|
|
59
59
|
with_form_for @user, :post_count
|
|
60
60
|
assert_no_select "form input#user_post_count.string"
|
|
@@ -63,7 +63,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
test 'builder
|
|
66
|
+
test 'builder allows adding custom input mappings for integer input types' do
|
|
67
67
|
swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
|
|
68
68
|
with_form_for @user, :lock_version
|
|
69
69
|
assert_no_select 'form input#user_lock_version.integer'
|
|
@@ -101,82 +101,87 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
# INPUT TYPES
|
|
104
|
-
test 'builder
|
|
104
|
+
test 'builder generates text fields for string columns' do
|
|
105
105
|
with_form_for @user, :name
|
|
106
106
|
assert_select 'form input#user_name.string'
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
test 'builder
|
|
109
|
+
test 'builder generates text areas for text columns' do
|
|
110
110
|
with_form_for @user, :description
|
|
111
111
|
assert_select 'form textarea#user_description.text'
|
|
112
112
|
end
|
|
113
113
|
|
|
114
|
-
test 'builder
|
|
114
|
+
test 'builder generates a checkbox for boolean columns' do
|
|
115
115
|
with_form_for @user, :active
|
|
116
116
|
assert_select 'form input[type=checkbox]#user_active.boolean'
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
-
test 'builder
|
|
119
|
+
test 'builder uses integer text field for integer columns' do
|
|
120
120
|
with_form_for @user, :age
|
|
121
121
|
assert_select 'form input#user_age.numeric.integer'
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
test 'builder
|
|
124
|
+
test 'builder generates decimal text field for decimal columns' do
|
|
125
125
|
with_form_for @user, :credit_limit
|
|
126
126
|
assert_select 'form input#user_credit_limit.numeric.decimal'
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
-
test 'builder
|
|
129
|
+
test 'builder generates uuid fields for uuid columns' do
|
|
130
|
+
with_form_for @user, :uuid
|
|
131
|
+
assert_select 'form input#user_uuid.string.uuid'
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
test 'builder generates password fields for columns that matches password' do
|
|
130
135
|
with_form_for @user, :password
|
|
131
136
|
assert_select 'form input#user_password.password'
|
|
132
137
|
end
|
|
133
138
|
|
|
134
|
-
test 'builder
|
|
139
|
+
test 'builder generates country fields for columns that matches country' do
|
|
135
140
|
with_form_for @user, :residence_country
|
|
136
141
|
assert_select 'form select#user_residence_country.country'
|
|
137
142
|
end
|
|
138
143
|
|
|
139
|
-
test 'builder
|
|
144
|
+
test 'builder generates time_zone fields for columns that matches time_zone' do
|
|
140
145
|
with_form_for @user, :time_zone
|
|
141
146
|
assert_select 'form select#user_time_zone.time_zone'
|
|
142
147
|
end
|
|
143
148
|
|
|
144
|
-
test 'builder
|
|
149
|
+
test 'builder generates email fields for columns that matches email' do
|
|
145
150
|
with_form_for @user, :email
|
|
146
151
|
assert_select 'form input#user_email.string.email'
|
|
147
152
|
end
|
|
148
153
|
|
|
149
|
-
test 'builder
|
|
154
|
+
test 'builder generates tel fields for columns that matches phone' do
|
|
150
155
|
with_form_for @user, :phone_number
|
|
151
156
|
assert_select 'form input#user_phone_number.string.tel'
|
|
152
157
|
end
|
|
153
158
|
|
|
154
|
-
test 'builder
|
|
159
|
+
test 'builder generates url fields for columns that matches url' do
|
|
155
160
|
with_form_for @user, :url
|
|
156
161
|
assert_select 'form input#user_url.string.url'
|
|
157
162
|
end
|
|
158
163
|
|
|
159
|
-
test 'builder
|
|
164
|
+
test 'builder generates date select for date columns' do
|
|
160
165
|
with_form_for @user, :born_at
|
|
161
166
|
assert_select 'form select#user_born_at_1i.date'
|
|
162
167
|
end
|
|
163
168
|
|
|
164
|
-
test 'builder
|
|
169
|
+
test 'builder generates time select for time columns' do
|
|
165
170
|
with_form_for @user, :delivery_time
|
|
166
171
|
assert_select 'form select#user_delivery_time_4i.time'
|
|
167
172
|
end
|
|
168
173
|
|
|
169
|
-
test 'builder
|
|
174
|
+
test 'builder generates datetime select for datetime columns' do
|
|
170
175
|
with_form_for @user, :created_at
|
|
171
176
|
assert_select 'form select#user_created_at_1i.datetime'
|
|
172
177
|
end
|
|
173
178
|
|
|
174
|
-
test 'builder
|
|
179
|
+
test 'builder generates datetime select for timestamp columns' do
|
|
175
180
|
with_form_for @user, :updated_at
|
|
176
181
|
assert_select 'form select#user_updated_at_1i.datetime'
|
|
177
182
|
end
|
|
178
183
|
|
|
179
|
-
test 'builder
|
|
184
|
+
test 'builder generates file for file columns' do
|
|
180
185
|
@user.avatar = MiniTest::Mock.new
|
|
181
186
|
@user.avatar.expect(:public_filename, true)
|
|
182
187
|
|
|
@@ -184,7 +189,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
184
189
|
assert_select 'form input#user_avatar.file'
|
|
185
190
|
end
|
|
186
191
|
|
|
187
|
-
test 'builder
|
|
192
|
+
test 'builder generates file for attributes that are real db columns but have file methods' do
|
|
188
193
|
@user.home_picture = MiniTest::Mock.new
|
|
189
194
|
@user.home_picture.expect(:mounted_as, true)
|
|
190
195
|
|
|
@@ -192,12 +197,12 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
192
197
|
assert_select 'form input#user_home_picture.file'
|
|
193
198
|
end
|
|
194
199
|
|
|
195
|
-
test 'build
|
|
200
|
+
test 'build generates select if a collection is given' do
|
|
196
201
|
with_form_for @user, :age, collection: 1..60
|
|
197
202
|
assert_select 'form select#user_age.select'
|
|
198
203
|
end
|
|
199
204
|
|
|
200
|
-
test 'builder
|
|
205
|
+
test 'builder allows overriding default input type for text' do
|
|
201
206
|
with_form_for @user, :name, as: :text
|
|
202
207
|
assert_no_select 'form input#user_name'
|
|
203
208
|
assert_select 'form textarea#user_name.text'
|
|
@@ -212,25 +217,45 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
212
217
|
end
|
|
213
218
|
|
|
214
219
|
# COMMON OPTIONS
|
|
215
|
-
test
|
|
216
|
-
|
|
220
|
+
# Remove this test when SimpleForm.form_class is removed in 4.x
|
|
221
|
+
test 'builder adds chosen form class' do
|
|
222
|
+
ActiveSupport::Deprecation.silence do
|
|
223
|
+
swap SimpleForm, form_class: :my_custom_class do
|
|
224
|
+
with_form_for @user, :name
|
|
225
|
+
assert_select 'form.my_custom_class'
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Remove this test when SimpleForm.form_class is removed in 4.x
|
|
231
|
+
test 'builder adds chosen form class and default form class' do
|
|
232
|
+
ActiveSupport::Deprecation.silence do
|
|
233
|
+
swap SimpleForm, form_class: "my_custom_class", default_form_class: "my_default_class" do
|
|
234
|
+
with_form_for @user, :name
|
|
235
|
+
assert_select 'form.my_custom_class.my_default_class'
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
test 'builder adds default form class' do
|
|
241
|
+
swap SimpleForm, default_form_class: "default_class" do
|
|
217
242
|
with_form_for @user, :name
|
|
218
|
-
assert_select 'form.
|
|
243
|
+
assert_select 'form.default_class'
|
|
219
244
|
end
|
|
220
245
|
end
|
|
221
246
|
|
|
222
|
-
test 'builder
|
|
247
|
+
test 'builder allows passing options to input' do
|
|
223
248
|
with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
|
|
224
249
|
assert_select 'form input#my_input.my_input.string'
|
|
225
250
|
end
|
|
226
251
|
|
|
227
|
-
test 'builder
|
|
252
|
+
test 'builder does not propagate input options to wrapper' do
|
|
228
253
|
with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
|
|
229
254
|
assert_no_select 'form div.input.my_input.string'
|
|
230
255
|
assert_select 'form input#my_input.my_input.string'
|
|
231
256
|
end
|
|
232
257
|
|
|
233
|
-
test 'builder
|
|
258
|
+
test 'builder does not propagate input options to wrapper with custom wrapper' do
|
|
234
259
|
swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
|
|
235
260
|
with_form_for @user, :name, input_html: { class: 'my_input' }
|
|
236
261
|
assert_no_select 'form div.input.my_input'
|
|
@@ -238,7 +263,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
238
263
|
end
|
|
239
264
|
end
|
|
240
265
|
|
|
241
|
-
test 'builder
|
|
266
|
+
test 'builder does not propagate label options to wrapper with custom wrapper' do
|
|
242
267
|
swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
|
|
243
268
|
with_form_for @user, :name, label_html: { class: 'my_label' }
|
|
244
269
|
assert_no_select 'form div.label.my_label'
|
|
@@ -246,42 +271,42 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
246
271
|
end
|
|
247
272
|
end
|
|
248
273
|
|
|
249
|
-
test 'builder
|
|
274
|
+
test 'builder generates an input with label' do
|
|
250
275
|
with_form_for @user, :name
|
|
251
276
|
assert_select 'form label.string[for=user_name]', /Name/
|
|
252
277
|
end
|
|
253
278
|
|
|
254
|
-
test 'builder
|
|
279
|
+
test 'builder is able to disable the label for an input' do
|
|
255
280
|
with_form_for @user, :name, label: false
|
|
256
281
|
assert_no_select 'form label'
|
|
257
282
|
end
|
|
258
283
|
|
|
259
|
-
test 'builder
|
|
284
|
+
test 'builder is able to disable the label for an input and return a html safe string' do
|
|
260
285
|
with_form_for @user, :name, label: false, wrapper: custom_wrapper_with_wrapped_label_input
|
|
261
286
|
assert_select 'form input#user_name'
|
|
262
287
|
end
|
|
263
288
|
|
|
264
|
-
test 'builder
|
|
289
|
+
test 'builder uses custom label' do
|
|
265
290
|
with_form_for @user, :name, label: 'Yay!'
|
|
266
291
|
assert_select 'form label', /Yay!/
|
|
267
292
|
end
|
|
268
293
|
|
|
269
|
-
test 'builder
|
|
294
|
+
test 'builder passes options to label' do
|
|
270
295
|
with_form_for @user, :name, label_html: { id: "cool" }
|
|
271
296
|
assert_select 'form label#cool', /Name/
|
|
272
297
|
end
|
|
273
298
|
|
|
274
|
-
test 'builder
|
|
299
|
+
test 'builder does not generate hints for an input' do
|
|
275
300
|
with_form_for @user, :name
|
|
276
301
|
assert_no_select 'span.hint'
|
|
277
302
|
end
|
|
278
303
|
|
|
279
|
-
test 'builder
|
|
304
|
+
test 'builder is able to add a hint for an input' do
|
|
280
305
|
with_form_for @user, :name, hint: 'test'
|
|
281
306
|
assert_select 'span.hint', 'test'
|
|
282
307
|
end
|
|
283
308
|
|
|
284
|
-
test 'builder
|
|
309
|
+
test 'builder is able to disable a hint even if it exists in i18n' do
|
|
285
310
|
store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
|
|
286
311
|
stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
|
|
287
312
|
with_form_for @user, :name, hint: false
|
|
@@ -290,32 +315,32 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
290
315
|
end
|
|
291
316
|
end
|
|
292
317
|
|
|
293
|
-
test 'builder
|
|
318
|
+
test 'builder passes options to hint' do
|
|
294
319
|
with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }
|
|
295
320
|
assert_select 'span.hint#cool', 'test'
|
|
296
321
|
end
|
|
297
322
|
|
|
298
|
-
test 'builder
|
|
323
|
+
test 'builder generates errors for attribute without errors' do
|
|
299
324
|
with_form_for @user, :credit_limit
|
|
300
325
|
assert_no_select 'span.errors'
|
|
301
326
|
end
|
|
302
327
|
|
|
303
|
-
test 'builder
|
|
328
|
+
test 'builder generates errors for attribute with errors' do
|
|
304
329
|
with_form_for @user, :name
|
|
305
|
-
assert_select 'span.error', "
|
|
330
|
+
assert_select 'span.error', "cannot be blank"
|
|
306
331
|
end
|
|
307
332
|
|
|
308
|
-
test 'builder
|
|
333
|
+
test 'builder is able to disable showing errors for an input' do
|
|
309
334
|
with_form_for @user, :name, error: false
|
|
310
335
|
assert_no_select 'span.error'
|
|
311
336
|
end
|
|
312
337
|
|
|
313
|
-
test 'builder
|
|
338
|
+
test 'builder passes options to errors' do
|
|
314
339
|
with_form_for @user, :name, error_html: { id: "cool" }
|
|
315
|
-
assert_select 'span.error#cool', "
|
|
340
|
+
assert_select 'span.error#cool', "cannot be blank"
|
|
316
341
|
end
|
|
317
342
|
|
|
318
|
-
test 'placeholder
|
|
343
|
+
test 'placeholder does not be generated when set to false' do
|
|
319
344
|
store_translations(:en, simple_form: { placeholders: { user: {
|
|
320
345
|
name: 'Name goes here'
|
|
321
346
|
} } }) do
|
|
@@ -326,14 +351,14 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
326
351
|
|
|
327
352
|
# DEFAULT OPTIONS
|
|
328
353
|
[:input, :input_field].each do |method|
|
|
329
|
-
test "builder
|
|
354
|
+
test "builder receives a default argument and pass it to the inputs when calling '#{method}'" do
|
|
330
355
|
with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
|
|
331
356
|
f.send(method, :name)
|
|
332
357
|
end
|
|
333
358
|
assert_select 'input.default_class'
|
|
334
359
|
end
|
|
335
360
|
|
|
336
|
-
test "builder
|
|
361
|
+
test "builder receives a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
|
|
337
362
|
with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
|
|
338
363
|
concat(f.send(method, :name))
|
|
339
364
|
concat(f.send(method, :credit_limit))
|
|
@@ -343,7 +368,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
343
368
|
assert_no_select "input.string[name='user[credit_limit]']"
|
|
344
369
|
end
|
|
345
370
|
|
|
346
|
-
test "builder
|
|
371
|
+
test "builder receives a default argument and pass it to the inputs and nested form when calling '#{method}'" do
|
|
347
372
|
@user.company = Company.new(1, 'Empresa')
|
|
348
373
|
|
|
349
374
|
with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
|
|
@@ -358,28 +383,28 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
358
383
|
end
|
|
359
384
|
end
|
|
360
385
|
|
|
361
|
-
test "builder
|
|
386
|
+
test "builder receives a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
|
|
362
387
|
with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
|
|
363
388
|
f.input :name, input_html: { id: 'specific_id' }
|
|
364
389
|
end
|
|
365
390
|
assert_select 'input.default_class#specific_id'
|
|
366
391
|
end
|
|
367
392
|
|
|
368
|
-
test "builder
|
|
393
|
+
test "builder receives a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
|
|
369
394
|
with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
|
|
370
395
|
f.input_field :name, id: 'specific_id'
|
|
371
396
|
end
|
|
372
397
|
assert_select 'input.default_class#specific_id'
|
|
373
398
|
end
|
|
374
399
|
|
|
375
|
-
test "builder
|
|
400
|
+
test "builder receives a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
|
|
376
401
|
with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
|
|
377
402
|
f.input :name, input_html: { id: 'specific_id' }
|
|
378
403
|
end
|
|
379
404
|
assert_select 'input.default_class#specific_id'
|
|
380
405
|
end
|
|
381
406
|
|
|
382
|
-
test "builder
|
|
407
|
+
test "builder receives a default argument and pass it to the inputs when calling 'input_field', overwriting the defaults with specific options" do
|
|
383
408
|
with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
|
|
384
409
|
f.input_field :name, id: 'specific_id'
|
|
385
410
|
end
|
|
@@ -387,24 +412,24 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
387
412
|
end
|
|
388
413
|
|
|
389
414
|
# WITHOUT OBJECT
|
|
390
|
-
test 'builder
|
|
415
|
+
test 'builder generates properly when object is not present' do
|
|
391
416
|
with_form_for :project, :name
|
|
392
417
|
assert_select 'form input.string#project_name'
|
|
393
418
|
end
|
|
394
419
|
|
|
395
|
-
test 'builder
|
|
420
|
+
test 'builder generates password fields based on attribute name when object is not present' do
|
|
396
421
|
with_form_for :project, :password_confirmation
|
|
397
422
|
assert_select 'form input[type=password].password#project_password_confirmation'
|
|
398
423
|
end
|
|
399
424
|
|
|
400
|
-
test 'builder
|
|
425
|
+
test 'builder generates text fields by default for all attributes when object is not present' do
|
|
401
426
|
with_form_for :project, :created_at
|
|
402
427
|
assert_select 'form input.string#project_created_at'
|
|
403
428
|
with_form_for :project, :budget
|
|
404
429
|
assert_select 'form input.string#project_budget'
|
|
405
430
|
end
|
|
406
431
|
|
|
407
|
-
test 'builder
|
|
432
|
+
test 'builder allows overriding input type when object is not present' do
|
|
408
433
|
with_form_for :project, :created_at, as: :datetime
|
|
409
434
|
assert_select 'form select.datetime#project_created_at_1i'
|
|
410
435
|
with_form_for :project, :budget, as: :decimal
|
|
@@ -412,24 +437,24 @@ class FormBuilderTest < ActionView::TestCase
|
|
|
412
437
|
end
|
|
413
438
|
|
|
414
439
|
# CUSTOM FORM BUILDER
|
|
415
|
-
test 'custom builder
|
|
440
|
+
test 'custom builder inherits mappings' do
|
|
416
441
|
with_custom_form_for @user, :email
|
|
417
442
|
assert_select 'form input[type=email]#user_email.custom'
|
|
418
443
|
end
|
|
419
444
|
|
|
420
|
-
test 'form with CustomMapTypeFormBuilder
|
|
445
|
+
test 'form with CustomMapTypeFormBuilder uses custom map type builder' do
|
|
421
446
|
with_concat_custom_mapping_form_for(:user) do |user|
|
|
422
447
|
assert user.instance_of?(CustomMapTypeFormBuilder)
|
|
423
448
|
end
|
|
424
449
|
end
|
|
425
450
|
|
|
426
|
-
test 'form with CustomMapTypeFormBuilder
|
|
451
|
+
test 'form with CustomMapTypeFormBuilder uses custom mapping' do
|
|
427
452
|
with_concat_custom_mapping_form_for(:user) do |user|
|
|
428
453
|
assert_equal SimpleForm::Inputs::StringInput, user.class.mappings[:custom_type]
|
|
429
454
|
end
|
|
430
455
|
end
|
|
431
456
|
|
|
432
|
-
test 'form without CustomMapTypeFormBuilder
|
|
457
|
+
test 'form without CustomMapTypeFormBuilder does not use custom mapping' do
|
|
433
458
|
with_concat_form_for(:user) do |user|
|
|
434
459
|
assert_nil user.class.mappings[:custom_type]
|
|
435
460
|
end
|
|
@@ -8,24 +8,24 @@ class HintTest < ActionView::TestCase
|
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
test 'hint
|
|
11
|
+
test 'hint does not be generated by default' do
|
|
12
12
|
with_hint_for @user, :name
|
|
13
13
|
assert_no_select 'span.hint'
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
test 'hint
|
|
16
|
+
test 'hint is generated with optional text' do
|
|
17
17
|
with_hint_for @user, :name, hint: 'Use with care...'
|
|
18
18
|
assert_select 'span.hint', 'Use with care...'
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
test 'hint
|
|
21
|
+
test 'hint does not modify the options hash' do
|
|
22
22
|
options = { hint: 'Use with care...' }
|
|
23
23
|
with_hint_for @user, :name, options
|
|
24
24
|
assert_select 'span.hint', 'Use with care...'
|
|
25
25
|
assert_equal({ hint: 'Use with care...' }, options)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
test 'hint
|
|
28
|
+
test 'hint is generated cleanly with optional text' do
|
|
29
29
|
with_hint_for @user, :name, hint: 'Use with care...', hint_tag: :span
|
|
30
30
|
assert_no_select 'span.hint[hint]'
|
|
31
31
|
assert_no_select 'span.hint[hint_tag]'
|
|
@@ -37,20 +37,20 @@ class HintTest < ActionView::TestCase
|
|
|
37
37
|
assert_select 'p.hint', 'Use with care...'
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
test 'hint
|
|
40
|
+
test 'hint is able to pass html options' do
|
|
41
41
|
with_hint_for @user, :name, hint: 'Yay!', id: 'hint', class: 'yay'
|
|
42
42
|
assert_select 'span#hint.hint.yay'
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
test 'hint
|
|
45
|
+
test 'hint is output as html_safe' do
|
|
46
46
|
with_hint_for @user, :name, hint: '<b>Bold</b> and not...'.html_safe
|
|
47
47
|
assert_select 'span.hint', 'Bold and not...'
|
|
48
48
|
assert_select 'span.hint b', 'Bold'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
test 'builder
|
|
51
|
+
test 'builder escapes hint text' do
|
|
52
52
|
with_hint_for @user, :name, hint: '<script>alert(1337)</script>'
|
|
53
|
-
|
|
53
|
+
assert_no_select 'span.hint script'
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
# Without attribute name
|
|
@@ -60,7 +60,7 @@ class HintTest < ActionView::TestCase
|
|
|
60
60
|
assert_select 'span.hint', 'Hello World!'
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
test 'hint without attribute name
|
|
63
|
+
test 'hint without attribute name generates component tag with a clean HTML' do
|
|
64
64
|
with_hint_for @validating_user, 'Hello World!'
|
|
65
65
|
assert_no_select 'span.hint[hint]'
|
|
66
66
|
assert_no_select 'span.hint[hint_html]'
|
|
@@ -73,14 +73,14 @@ class HintTest < ActionView::TestCase
|
|
|
73
73
|
assert_no_select 'p.hint[hint_tag]'
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
test 'hint without attribute name
|
|
76
|
+
test 'hint without attribute name is able to pass html options' do
|
|
77
77
|
with_hint_for @user, 'Yay', id: 'hint', class: 'yay'
|
|
78
78
|
assert_select 'span#hint.hint.yay', 'Yay'
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
# I18n
|
|
82
82
|
|
|
83
|
-
test 'hint
|
|
83
|
+
test 'hint uses i18n based on model, action, and attribute to lookup translation' do
|
|
84
84
|
store_translations(:en, simple_form: { hints: { user: {
|
|
85
85
|
edit: { name: 'Content of this input will be truncated...' }
|
|
86
86
|
} } }) do
|
|
@@ -89,7 +89,7 @@ class HintTest < ActionView::TestCase
|
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
test 'hint
|
|
92
|
+
test 'hint uses i18n with model and attribute to lookup translation' do
|
|
93
93
|
store_translations(:en, simple_form: { hints: { user: {
|
|
94
94
|
name: 'Content of this input will be capitalized...'
|
|
95
95
|
} } }) do
|
|
@@ -98,7 +98,7 @@ class HintTest < ActionView::TestCase
|
|
|
98
98
|
end
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
test 'hint
|
|
101
|
+
test 'hint uses i18n under defaults namespace to lookup translation' do
|
|
102
102
|
store_translations(:en, simple_form: {
|
|
103
103
|
hints: { defaults: { name: 'Content of this input will be downcased...' } }
|
|
104
104
|
}) do
|
|
@@ -107,7 +107,7 @@ class HintTest < ActionView::TestCase
|
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
test 'hint
|
|
110
|
+
test 'hint uses i18n with lookup for association name' do
|
|
111
111
|
store_translations(:en, simple_form: { hints: {
|
|
112
112
|
user: { company: 'My company!' }
|
|
113
113
|
} } ) do
|
|
@@ -116,7 +116,7 @@ class HintTest < ActionView::TestCase
|
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
-
test 'hint
|
|
119
|
+
test 'hint outputs translations as html_safe' do
|
|
120
120
|
store_translations(:en, simple_form: { hints: { user: {
|
|
121
121
|
edit: { name: '<b>This is bold</b> and this is not...' }
|
|
122
122
|
} } }) do
|
|
@@ -128,7 +128,7 @@ class HintTest < ActionView::TestCase
|
|
|
128
128
|
|
|
129
129
|
# No object
|
|
130
130
|
|
|
131
|
-
test 'hint
|
|
131
|
+
test 'hint generates properly when object is not present' do
|
|
132
132
|
with_hint_for :project, :name, hint: 'Test without object'
|
|
133
133
|
assert_select 'span.hint', 'Test without object'
|
|
134
134
|
end
|
|
@@ -137,8 +137,8 @@ class HintTest < ActionView::TestCase
|
|
|
137
137
|
|
|
138
138
|
test 'hint with custom wrappers works' do
|
|
139
139
|
swap_wrapper do
|
|
140
|
-
with_hint_for @user, :name, hint: "
|
|
141
|
-
assert_select 'div.omg_hint', "
|
|
140
|
+
with_hint_for @user, :name, hint: "cannot be blank"
|
|
141
|
+
assert_select 'div.omg_hint', "cannot be blank"
|
|
142
142
|
end
|
|
143
143
|
end
|
|
144
144
|
end
|