simple_form 2.1.3 → 3.0.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 +4 -4
- data/CHANGELOG.md +21 -51
- data/README.md +195 -161
- data/lib/generators/simple_form/install_generator.rb +4 -4
- data/lib/generators/simple_form/templates/README +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +16 -13
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -320
- data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
- data/lib/simple_form/components/errors.rb +1 -7
- data/lib/simple_form/components/hints.rb +2 -7
- data/lib/simple_form/components/html5.rb +5 -2
- data/lib/simple_form/components/labels.rb +4 -4
- data/lib/simple_form/components/maxlength.rb +1 -8
- data/lib/simple_form/components/pattern.rb +2 -2
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +154 -50
- data/lib/simple_form/form_builder.rb.orig +486 -0
- data/lib/simple_form/helpers.rb +1 -1
- data/lib/simple_form/inputs/base.rb +7 -10
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +6 -5
- data/lib/simple_form/inputs/collection_input.rb +7 -7
- data/lib/simple_form/inputs/date_time_input.rb +1 -1
- data/lib/simple_form/inputs/numeric_input.rb +0 -6
- data/lib/simple_form/inputs/password_input.rb +0 -1
- data/lib/simple_form/inputs/string_input.rb +0 -1
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +62 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/version.rb.orig +7 -0
- data/lib/simple_form/wrappers/builder.rb +5 -29
- data/lib/simple_form/wrappers/many.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -1
- data/lib/simple_form.rb +43 -47
- data/test/action_view_extensions/builder_test.rb +78 -99
- data/test/action_view_extensions/form_helper_test.rb +25 -16
- data/test/components/label_test.rb +46 -46
- data/test/form_builder/association_test.rb +47 -29
- data/test/form_builder/button_test.rb +4 -4
- data/test/form_builder/error_notification_test.rb +8 -8
- data/test/form_builder/error_test.rb +18 -65
- data/test/form_builder/general_test.rb +62 -63
- data/test/form_builder/hint_test.rb +23 -29
- data/test/form_builder/input_field_test.rb +29 -12
- data/test/form_builder/label_test.rb +7 -17
- data/test/form_builder/wrapper_test.rb +21 -21
- data/test/inputs/boolean_input_test.rb +24 -24
- data/test/inputs/collection_check_boxes_input_test.rb +66 -55
- data/test/inputs/collection_radio_buttons_input_test.rb +81 -79
- data/test/inputs/collection_select_input_test.rb +76 -51
- data/test/inputs/datetime_input_test.rb +17 -11
- data/test/inputs/disabled_test.rb +10 -10
- data/test/inputs/discovery_test.rb +4 -4
- data/test/inputs/file_input_test.rb +1 -1
- data/test/inputs/general_test.rb +28 -12
- data/test/inputs/grouped_collection_select_input_test.rb +33 -20
- data/test/inputs/hidden_input_test.rb +3 -2
- data/test/inputs/numeric_input_test.rb +3 -3
- data/test/inputs/priority_input_test.rb +9 -3
- data/test/inputs/readonly_test.rb +12 -12
- data/test/inputs/required_test.rb +5 -5
- data/test/inputs/string_input_test.rb +15 -25
- data/test/inputs/text_input_test.rb +1 -1
- data/test/support/misc_helpers.rb +46 -24
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +77 -62
- data/test/test_helper.rb +17 -34
- metadata +39 -22
- data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -49,8 +49,7 @@ class BuilderTest < ActionView::TestCase
|
|
49
49
|
end
|
50
50
|
|
51
51
|
test "collection radio checks the correct value to local variables" do
|
52
|
-
user = User.
|
53
|
-
user.active = false
|
52
|
+
user = User.build(active: false)
|
54
53
|
with_collection_radio_buttons user, :active, [true, false], :to_s, :to_s
|
55
54
|
|
56
55
|
assert_select 'form input[type=radio][value=true]'
|
@@ -58,21 +57,21 @@ class BuilderTest < ActionView::TestCase
|
|
58
57
|
end
|
59
58
|
|
60
59
|
test "collection radio accepts checked item" do
|
61
|
-
with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :
|
60
|
+
with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: true
|
62
61
|
|
63
62
|
assert_select 'form input[type=radio][value=true][checked=checked]'
|
64
63
|
assert_no_select 'form input[type=radio][value=false][checked=checked]'
|
65
64
|
end
|
66
65
|
|
67
66
|
test "collection radio accepts checked item which has a value of false" do
|
68
|
-
with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :
|
67
|
+
with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: false
|
69
68
|
assert_no_select 'form input[type=radio][value=true][checked=checked]'
|
70
69
|
assert_select 'form input[type=radio][value=false][checked=checked]'
|
71
70
|
end
|
72
71
|
|
73
72
|
test "collection radio accepts multiple disabled items" do
|
74
73
|
collection = [[1, true], [0, false], [2, 'other']]
|
75
|
-
with_collection_radio_buttons @user, :active, collection, :last, :first, :
|
74
|
+
with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: [true, false]
|
76
75
|
|
77
76
|
assert_select 'form input[type=radio][value=true][disabled=disabled]'
|
78
77
|
assert_select 'form input[type=radio][value=false][disabled=disabled]'
|
@@ -81,7 +80,7 @@ class BuilderTest < ActionView::TestCase
|
|
81
80
|
|
82
81
|
test "collection radio accepts single disable item" do
|
83
82
|
collection = [[1, true], [0, false]]
|
84
|
-
with_collection_radio_buttons @user, :active, collection, :last, :first, :
|
83
|
+
with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: true
|
85
84
|
|
86
85
|
assert_select 'form input[type=radio][value=true][disabled=disabled]'
|
87
86
|
assert_no_select 'form input[type=radio][value=false][disabled=disabled]'
|
@@ -89,50 +88,50 @@ class BuilderTest < ActionView::TestCase
|
|
89
88
|
|
90
89
|
test "collection radio accepts html options as input" do
|
91
90
|
collection = [[1, true], [0, false]]
|
92
|
-
with_collection_radio_buttons @user, :active, collection, :last, :first, {}, :
|
91
|
+
with_collection_radio_buttons @user, :active, collection, :last, :first, {}, class: 'special-radio'
|
93
92
|
|
94
93
|
assert_select 'form input[type=radio][value=true].special-radio#user_active_true'
|
95
94
|
assert_select 'form input[type=radio][value=false].special-radio#user_active_false'
|
96
95
|
end
|
97
96
|
|
98
97
|
test "collection radio wraps the collection in the given collection wrapper tag" do
|
99
|
-
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :
|
98
|
+
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
|
100
99
|
|
101
|
-
assert_select 'form ul input[type=radio]', :
|
100
|
+
assert_select 'form ul input[type=radio]', count: 2
|
102
101
|
end
|
103
102
|
|
104
103
|
test "collection radio does not render any wrapper tag by default" do
|
105
104
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
106
105
|
|
107
|
-
assert_select 'form input[type=radio]', :
|
106
|
+
assert_select 'form input[type=radio]', count: 2
|
108
107
|
assert_no_select 'form ul'
|
109
108
|
end
|
110
109
|
|
111
110
|
test "collection radio does not wrap the collection when given falsy values" do
|
112
|
-
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :
|
111
|
+
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
|
113
112
|
|
114
|
-
assert_select 'form input[type=radio]', :
|
113
|
+
assert_select 'form input[type=radio]', count: 2
|
115
114
|
assert_no_select 'form ul'
|
116
115
|
end
|
117
116
|
|
118
117
|
test "collection radio uses the given class for collection wrapper tag" do
|
119
118
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
120
|
-
:
|
119
|
+
collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
|
121
120
|
|
122
|
-
assert_select 'form ul.items-list input[type=radio]', :
|
121
|
+
assert_select 'form ul.items-list input[type=radio]', count: 2
|
123
122
|
end
|
124
123
|
|
125
124
|
test "collection radio uses no class for collection wrapper tag when no wrapper tag is given" do
|
126
125
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
127
|
-
:
|
126
|
+
collection_wrapper_class: "items-list"
|
128
127
|
|
129
|
-
assert_select 'form input[type=radio]', :
|
128
|
+
assert_select 'form input[type=radio]', count: 2
|
130
129
|
assert_no_select 'form ul'
|
131
130
|
assert_no_select '.items-list'
|
132
131
|
end
|
133
132
|
|
134
133
|
test "collection radio uses no class for collection wrapper tag by default" do
|
135
|
-
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :
|
134
|
+
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
|
136
135
|
|
137
136
|
assert_select 'form ul'
|
138
137
|
assert_no_select 'form ul[class]'
|
@@ -146,13 +145,13 @@ class BuilderTest < ActionView::TestCase
|
|
146
145
|
end
|
147
146
|
|
148
147
|
test "collection radio wraps each item in the given item wrapper tag" do
|
149
|
-
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :
|
148
|
+
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
|
150
149
|
|
151
|
-
assert_select 'form li input[type=radio]', :
|
150
|
+
assert_select 'form li input[type=radio]', count: 2
|
152
151
|
end
|
153
152
|
|
154
153
|
test "collection radio does not wrap each item when given explicitly falsy value" do
|
155
|
-
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :
|
154
|
+
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
|
156
155
|
|
157
156
|
assert_select 'form input[type=radio]'
|
158
157
|
assert_no_select 'form span input[type=radio]'
|
@@ -160,25 +159,25 @@ class BuilderTest < ActionView::TestCase
|
|
160
159
|
|
161
160
|
test "collection radio uses the given class for item wrapper tag" do
|
162
161
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
163
|
-
:
|
162
|
+
item_wrapper_tag: :li, item_wrapper_class: "inline"
|
164
163
|
|
165
|
-
assert_select "form li.inline input[type=radio]", :
|
164
|
+
assert_select "form li.inline input[type=radio]", count: 2
|
166
165
|
end
|
167
166
|
|
168
167
|
test "collection radio uses no class for item wrapper tag when no wrapper tag is given" do
|
169
168
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
170
|
-
:
|
169
|
+
item_wrapper_tag: nil, item_wrapper_class: "inline"
|
171
170
|
|
172
|
-
assert_select 'form input[type=radio]', :
|
171
|
+
assert_select 'form input[type=radio]', count: 2
|
173
172
|
assert_no_select 'form li'
|
174
173
|
assert_no_select '.inline'
|
175
174
|
end
|
176
175
|
|
177
176
|
test "collection radio uses no class for item wrapper tag by default" do
|
178
177
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
179
|
-
:
|
178
|
+
item_wrapper_tag: :li
|
180
179
|
|
181
|
-
assert_select "form li", :
|
180
|
+
assert_select "form li", count: 2
|
182
181
|
assert_no_select "form li[class]"
|
183
182
|
end
|
184
183
|
|
@@ -209,7 +208,7 @@ class BuilderTest < ActionView::TestCase
|
|
209
208
|
|
210
209
|
test "collection radio with block helpers accept extra html options" do
|
211
210
|
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
212
|
-
b.label(:
|
211
|
+
b.label(class: "radio_button") + b.radio_button(class: "radio_button")
|
213
212
|
end
|
214
213
|
|
215
214
|
assert_select 'label.radio_button[for=user_active_true] + input#user_active_true.radio_button[type=radio]'
|
@@ -231,7 +230,7 @@ class BuilderTest < ActionView::TestCase
|
|
231
230
|
|
232
231
|
test "collection radio with block helpers allows access to the current object item in the collection to access extra properties" do
|
233
232
|
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
234
|
-
b.label(:
|
233
|
+
b.label(class: b.object) { b.radio_button + b.text }
|
235
234
|
end
|
236
235
|
|
237
236
|
assert_select 'label.true[for=user_active_true]', 'true' do
|
@@ -245,33 +244,20 @@ class BuilderTest < ActionView::TestCase
|
|
245
244
|
test "collection radio with block helpers does not leak the template" do
|
246
245
|
with_concat_form_for(@user) do |f|
|
247
246
|
collection_input = f.collection_radio_buttons :active, [true, false], :to_s, :to_s do |b|
|
248
|
-
b.label(:
|
247
|
+
b.label(class: b.object) { b.radio_button + b.text }
|
249
248
|
end
|
250
249
|
concat collection_input
|
251
250
|
|
252
251
|
concat f.hidden_field :name
|
253
252
|
end
|
254
253
|
|
255
|
-
assert_select 'label.true[for=user_active_true]', :
|
254
|
+
assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
|
256
255
|
assert_select 'input#user_active_true[type=radio]'
|
257
256
|
end
|
258
|
-
assert_select 'label.false[for=user_active_false]', :
|
257
|
+
assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
|
259
258
|
assert_select 'input#user_active_false[type=radio]'
|
260
259
|
end
|
261
260
|
end
|
262
|
-
|
263
|
-
test "collection_radio helper is deprecated in favor of collection_radio_buttons" do
|
264
|
-
assert_deprecated "[SIMPLE_FORM] The `collection_radio` helper is deprecated, " \
|
265
|
-
"please use `collection_radio_buttons` instead" do
|
266
|
-
with_concat_form_for(@user) do |f|
|
267
|
-
f.collection_radio :active, [true, false], :to_s, :to_s
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
assert_select 'input[type=radio][value=true]'
|
272
|
-
assert_select 'input[type=radio][value=false]'
|
273
|
-
end
|
274
|
-
|
275
261
|
# COLLECTION CHECK BOX
|
276
262
|
test "collection check box accepts a collection and generate a serie of checkboxes for value method" do
|
277
263
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
@@ -285,14 +271,7 @@ class BuilderTest < ActionView::TestCase
|
|
285
271
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
286
272
|
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
287
273
|
|
288
|
-
assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", :
|
289
|
-
end
|
290
|
-
|
291
|
-
test "collection check box generates a hidden field using the given :name in :input_html" do
|
292
|
-
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
293
|
-
with_collection_check_boxes @user, :tag_ids, collection, :id, :name, {}, {:name => "user[other_tag_ids][]"}
|
294
|
-
|
295
|
-
assert_select "form input[type=hidden][name='user[other_tag_ids][]'][value=]", :count => 1
|
274
|
+
assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", count: 1
|
296
275
|
end
|
297
276
|
|
298
277
|
test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
|
@@ -317,9 +296,9 @@ class BuilderTest < ActionView::TestCase
|
|
317
296
|
end
|
318
297
|
|
319
298
|
test "collection check box checks the correct value to local variables" do
|
320
|
-
user = User.
|
321
|
-
|
322
|
-
|
299
|
+
user = User.build(tag_ids: [1, 3])
|
300
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
301
|
+
|
323
302
|
with_collection_check_boxes user, :tag_ids, collection, :first, :last
|
324
303
|
|
325
304
|
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
@@ -328,8 +307,8 @@ class BuilderTest < ActionView::TestCase
|
|
328
307
|
end
|
329
308
|
|
330
309
|
test "collection check box accepts selected values as :checked option" do
|
331
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
332
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :
|
310
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
311
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
|
333
312
|
|
334
313
|
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
335
314
|
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
@@ -337,8 +316,8 @@ class BuilderTest < ActionView::TestCase
|
|
337
316
|
end
|
338
317
|
|
339
318
|
test "collection check boxes accepts selected string values as :checked option" do
|
340
|
-
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
341
|
-
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :
|
319
|
+
collection = (1..3).map { |i| [i, "Category #{i}"] }
|
320
|
+
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
|
342
321
|
|
343
322
|
assert_select 'input[type=checkbox][value=1][checked=checked]'
|
344
323
|
assert_select 'input[type=checkbox][value=3][checked=checked]'
|
@@ -346,8 +325,8 @@ class BuilderTest < ActionView::TestCase
|
|
346
325
|
end
|
347
326
|
|
348
327
|
test "collection check box accepts a single checked value" do
|
349
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
350
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :
|
328
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
329
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
|
351
330
|
|
352
331
|
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
353
332
|
assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
|
@@ -355,9 +334,9 @@ class BuilderTest < ActionView::TestCase
|
|
355
334
|
end
|
356
335
|
|
357
336
|
test "collection check box accepts selected values as :checked option and override the model values" do
|
358
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
337
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
359
338
|
@user.tag_ids = [2]
|
360
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :
|
339
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
|
361
340
|
|
362
341
|
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
363
342
|
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
@@ -365,8 +344,8 @@ class BuilderTest < ActionView::TestCase
|
|
365
344
|
end
|
366
345
|
|
367
346
|
test "collection check box accepts multiple disabled items" do
|
368
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
369
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :
|
347
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
348
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
|
370
349
|
|
371
350
|
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
372
351
|
assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
@@ -374,8 +353,8 @@ class BuilderTest < ActionView::TestCase
|
|
374
353
|
end
|
375
354
|
|
376
355
|
test "collection check box accepts single disable item" do
|
377
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
378
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :
|
356
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
357
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
|
379
358
|
|
380
359
|
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
381
360
|
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
@@ -383,8 +362,8 @@ class BuilderTest < ActionView::TestCase
|
|
383
362
|
end
|
384
363
|
|
385
364
|
test "collection check box accepts a proc to disabled items" do
|
386
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
387
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :
|
365
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
366
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
|
388
367
|
|
389
368
|
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
390
369
|
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
@@ -393,7 +372,7 @@ class BuilderTest < ActionView::TestCase
|
|
393
372
|
|
394
373
|
test "collection check box accepts html options" do
|
395
374
|
collection = [[1, 'Tag 1'], [2, 'Tag 2']]
|
396
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, :
|
375
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, class: 'check'
|
397
376
|
|
398
377
|
assert_select 'form input.check[type=checkbox][value=1]'
|
399
378
|
assert_select 'form input.check[type=checkbox][value=2]'
|
@@ -415,43 +394,43 @@ class BuilderTest < ActionView::TestCase
|
|
415
394
|
end
|
416
395
|
|
417
396
|
test "collection check boxes wraps the collection in the given collection wrapper tag" do
|
418
|
-
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :
|
397
|
+
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
|
419
398
|
|
420
|
-
assert_select 'form ul input[type=checkbox]', :
|
399
|
+
assert_select 'form ul input[type=checkbox]', count: 2
|
421
400
|
end
|
422
401
|
|
423
402
|
test "collection check boxes does not render any wrapper tag by default" do
|
424
403
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
425
404
|
|
426
|
-
assert_select 'form input[type=checkbox]', :
|
405
|
+
assert_select 'form input[type=checkbox]', count: 2
|
427
406
|
assert_no_select 'form ul'
|
428
407
|
end
|
429
408
|
|
430
409
|
test "collection check boxes does not wrap the collection when given falsy values" do
|
431
|
-
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :
|
410
|
+
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
|
432
411
|
|
433
|
-
assert_select 'form input[type=checkbox]', :
|
412
|
+
assert_select 'form input[type=checkbox]', count: 2
|
434
413
|
assert_no_select 'form ul'
|
435
414
|
end
|
436
415
|
|
437
416
|
test "collection check boxes uses the given class for collection wrapper tag" do
|
438
417
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
439
|
-
:
|
418
|
+
collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
|
440
419
|
|
441
|
-
assert_select 'form ul.items-list input[type=checkbox]', :
|
420
|
+
assert_select 'form ul.items-list input[type=checkbox]', count: 2
|
442
421
|
end
|
443
422
|
|
444
423
|
test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
|
445
424
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
446
|
-
:
|
425
|
+
collection_wrapper_class: "items-list"
|
447
426
|
|
448
|
-
assert_select 'form input[type=checkbox]', :
|
427
|
+
assert_select 'form input[type=checkbox]', count: 2
|
449
428
|
assert_no_select 'form ul'
|
450
429
|
assert_no_select '.items-list'
|
451
430
|
end
|
452
431
|
|
453
432
|
test "collection check boxes uses no class for collection wrapper tag by default" do
|
454
|
-
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :
|
433
|
+
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
|
455
434
|
|
456
435
|
assert_select 'form ul'
|
457
436
|
assert_no_select 'form ul[class]'
|
@@ -460,17 +439,17 @@ class BuilderTest < ActionView::TestCase
|
|
460
439
|
test "collection check boxes wrap items in a span tag by default" do
|
461
440
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
462
441
|
|
463
|
-
assert_select 'form span input[type=checkbox]', :
|
442
|
+
assert_select 'form span input[type=checkbox]', count: 2
|
464
443
|
end
|
465
444
|
|
466
445
|
test "collection check boxes wraps each item in the given item wrapper tag" do
|
467
|
-
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :
|
446
|
+
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
|
468
447
|
|
469
|
-
assert_select 'form li input[type=checkbox]', :
|
448
|
+
assert_select 'form li input[type=checkbox]', count: 2
|
470
449
|
end
|
471
450
|
|
472
451
|
test "collection check boxes does not wrap each item when given explicitly falsy value" do
|
473
|
-
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :
|
452
|
+
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
|
474
453
|
|
475
454
|
assert_select 'form input[type=checkbox]'
|
476
455
|
assert_no_select 'form span input[type=checkbox]'
|
@@ -478,25 +457,25 @@ class BuilderTest < ActionView::TestCase
|
|
478
457
|
|
479
458
|
test "collection check boxes uses the given class for item wrapper tag" do
|
480
459
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
481
|
-
:
|
460
|
+
item_wrapper_tag: :li, item_wrapper_class: "inline"
|
482
461
|
|
483
|
-
assert_select "form li.inline input[type=checkbox]", :
|
462
|
+
assert_select "form li.inline input[type=checkbox]", count: 2
|
484
463
|
end
|
485
464
|
|
486
465
|
test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
|
487
466
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
488
|
-
:
|
467
|
+
item_wrapper_tag: nil, item_wrapper_class: "inline"
|
489
468
|
|
490
|
-
assert_select 'form input[type=checkbox]', :
|
469
|
+
assert_select 'form input[type=checkbox]', count: 2
|
491
470
|
assert_no_select 'form li'
|
492
471
|
assert_no_select '.inline'
|
493
472
|
end
|
494
473
|
|
495
474
|
test "collection check boxes uses no class for item wrapper tag by default" do
|
496
475
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
497
|
-
:
|
476
|
+
item_wrapper_tag: :li
|
498
477
|
|
499
|
-
assert_select "form li", :
|
478
|
+
assert_select "form li", count: 2
|
500
479
|
assert_no_select "form li[class]"
|
501
480
|
end
|
502
481
|
|
@@ -527,7 +506,7 @@ class BuilderTest < ActionView::TestCase
|
|
527
506
|
|
528
507
|
test "collection check boxes with block helpers accept extra html options" do
|
529
508
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
530
|
-
b.label(:
|
509
|
+
b.label(class: "check_box") + b.check_box(class: "check_box")
|
531
510
|
end
|
532
511
|
|
533
512
|
assert_select 'label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]'
|
@@ -549,7 +528,7 @@ class BuilderTest < ActionView::TestCase
|
|
549
528
|
|
550
529
|
test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
|
551
530
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
552
|
-
b.label(:
|
531
|
+
b.label(class: b.object) { b.check_box + b.text }
|
553
532
|
end
|
554
533
|
|
555
534
|
assert_select 'label.true[for=user_active_true]', 'true' do
|
@@ -563,17 +542,17 @@ class BuilderTest < ActionView::TestCase
|
|
563
542
|
test "collection check boxes with block helpers does not leak the template" do
|
564
543
|
with_concat_form_for(@user) do |f|
|
565
544
|
collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
|
566
|
-
b.label(:
|
545
|
+
b.label(class: b.object) { b.check_box + b.text }
|
567
546
|
end
|
568
547
|
concat collection_input
|
569
548
|
|
570
549
|
concat f.hidden_field :name
|
571
550
|
end
|
572
551
|
|
573
|
-
assert_select 'label.true[for=user_active_true]', :
|
552
|
+
assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
|
574
553
|
assert_select 'input#user_active_true[type=checkbox]'
|
575
554
|
end
|
576
|
-
assert_select 'label.false[for=user_active_false]', :
|
555
|
+
assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
|
577
556
|
assert_select 'input#user_active_false[type=checkbox]'
|
578
557
|
end
|
579
558
|
end
|
@@ -608,7 +587,7 @@ class BuilderTest < ActionView::TestCase
|
|
608
587
|
|
609
588
|
test "fields for yields an instance of FormBuilder if it was set in options" do
|
610
589
|
with_custom_form_for(:user) do |f|
|
611
|
-
f.simple_fields_for(:company, :
|
590
|
+
f.simple_fields_for(:company, builder: SimpleForm::FormBuilder) do |company|
|
612
591
|
assert company.instance_of?(SimpleForm::FormBuilder)
|
613
592
|
end
|
614
593
|
end
|
@@ -616,7 +595,7 @@ class BuilderTest < ActionView::TestCase
|
|
616
595
|
|
617
596
|
test "fields inherites wrapper option from the parent form" do
|
618
597
|
swap_wrapper :another do
|
619
|
-
simple_form_for(:user, :
|
598
|
+
simple_form_for(:user, wrapper: :another) do |f|
|
620
599
|
f.simple_fields_for(:company) do |company|
|
621
600
|
assert_equal :another, company.options[:wrapper]
|
622
601
|
end
|
@@ -626,8 +605,8 @@ class BuilderTest < ActionView::TestCase
|
|
626
605
|
|
627
606
|
test "fields overrides wrapper option from the parent form" do
|
628
607
|
swap_wrapper :another do
|
629
|
-
simple_form_for(:user, :
|
630
|
-
f.simple_fields_for(:company, :
|
608
|
+
simple_form_for(:user, wrapper: :another) do |f|
|
609
|
+
f.simple_fields_for(:company, wrapper: false) do |company|
|
631
610
|
assert_equal false, company.options[:wrapper]
|
632
611
|
end
|
633
612
|
end
|
@@ -19,31 +19,31 @@ class FormHelperTest < ActionView::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
test 'SimpleForm should not use default browser validations if specified in the configuration options' do
|
22
|
-
swap SimpleForm, :
|
22
|
+
swap SimpleForm, browser_validations: false do
|
23
23
|
with_concat_form_for(:user)
|
24
24
|
assert_select 'form[novalidate="novalidate"]'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
test '
|
29
|
-
with_concat_form_for(:user, :
|
28
|
+
test 'disabled browser validations overrides default configuration' do
|
29
|
+
with_concat_form_for(:user, html: { novalidate: true })
|
30
30
|
assert_select 'form[novalidate="novalidate"]'
|
31
31
|
end
|
32
32
|
|
33
|
-
test '
|
34
|
-
swap SimpleForm, :
|
35
|
-
with_concat_form_for(:user, :
|
33
|
+
test 'enabled browser validations overrides disabled configuration' do
|
34
|
+
swap SimpleForm, browser_validations: false do
|
35
|
+
with_concat_form_for(:user, html: { novalidate: false })
|
36
36
|
assert_no_select 'form[novalidate]'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
test 'SimpleForm should add object name as css class to form when object is not present' do
|
41
|
-
with_concat_form_for(:user, :
|
41
|
+
with_concat_form_for(:user, html: { novalidate: true })
|
42
42
|
assert_select 'form.simple_form.user'
|
43
43
|
end
|
44
44
|
|
45
45
|
test 'SimpleForm should add :as option as css class to form when object is not present' do
|
46
|
-
with_concat_form_for(:user, :
|
46
|
+
with_concat_form_for(:user, as: 'superuser')
|
47
47
|
assert_select 'form.simple_form.superuser'
|
48
48
|
end
|
49
49
|
|
@@ -55,7 +55,7 @@ class FormHelperTest < ActionView::TestCase
|
|
55
55
|
|
56
56
|
test 'SimpleForm should add :as option with new prefix as css class to form if record is not persisted' do
|
57
57
|
@user.new_record!
|
58
|
-
with_concat_form_for(@user, :
|
58
|
+
with_concat_form_for(@user, as: 'superuser')
|
59
59
|
assert_select 'form.simple_form.new_superuser'
|
60
60
|
end
|
61
61
|
|
@@ -65,7 +65,7 @@ class FormHelperTest < ActionView::TestCase
|
|
65
65
|
end
|
66
66
|
|
67
67
|
test 'SimpleForm should add :as options with edit prefix as css class to form if record is persisted' do
|
68
|
-
with_concat_form_for(@user, :
|
68
|
+
with_concat_form_for(@user, as: 'superuser')
|
69
69
|
assert_select 'form.simple_form.edit_superuser'
|
70
70
|
end
|
71
71
|
|
@@ -75,28 +75,28 @@ class FormHelperTest < ActionView::TestCase
|
|
75
75
|
end
|
76
76
|
|
77
77
|
test 'SimpleForm should not add object class to form if css_class is specified' do
|
78
|
-
with_concat_form_for(:user, :
|
78
|
+
with_concat_form_for(:user, html: { class: nil })
|
79
79
|
assert_no_select 'form.user'
|
80
80
|
end
|
81
81
|
|
82
82
|
test 'SimpleForm should add custom class to form if css_class is specified' do
|
83
|
-
with_concat_form_for(:user, :
|
83
|
+
with_concat_form_for(:user, html: { class: 'my_class' })
|
84
84
|
assert_select 'form.my_class'
|
85
85
|
end
|
86
86
|
|
87
87
|
test 'pass options to SimpleForm' do
|
88
|
-
with_concat_form_for(:user, :
|
88
|
+
with_concat_form_for(:user, url: '/account', html: { id: 'my_form' })
|
89
89
|
assert_select 'form#my_form'
|
90
90
|
assert_select 'form[action=/account]'
|
91
91
|
end
|
92
92
|
|
93
|
-
test '
|
93
|
+
test 'form_for yields an instance of FormBuilder' do
|
94
94
|
with_concat_form_for(:user) do |f|
|
95
95
|
assert f.instance_of?(SimpleForm::FormBuilder)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
test '
|
99
|
+
test 'fields_for with a hash like model yields an instance of FormBuilder' do
|
100
100
|
with_concat_fields_for(:author, HashBackedAuthor.new) do |f|
|
101
101
|
assert f.instance_of?(SimpleForm::FormBuilder)
|
102
102
|
f.input :name
|
@@ -131,10 +131,19 @@ class FormHelperTest < ActionView::TestCase
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
+
test 'SimpleForm for swaps default action view field_error_proc' do
|
135
|
+
expected_error_proc = lambda {}
|
136
|
+
swap SimpleForm, field_error_proc: expected_error_proc do
|
137
|
+
simple_form_for :user do |f|
|
138
|
+
assert_equal expected_error_proc, ::ActionView::Base.field_error_proc
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
134
143
|
private
|
135
144
|
|
136
145
|
def swap_field_error_proc(expected_error_proc = lambda {})
|
137
|
-
swap ActionView::Base, :
|
146
|
+
swap ActionView::Base, field_error_proc: expected_error_proc do
|
138
147
|
yield
|
139
148
|
|
140
149
|
assert_equal expected_error_proc, ActionView::Base.field_error_proc
|