simple_form 2.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +77 -33
- data/MIT-LICENSE +1 -1
- data/README.md +387 -187
- data/lib/generators/simple_form/install_generator.rb +4 -4
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +45 -22
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +128 -24
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +87 -6
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +2 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +8 -11
- data/lib/simple_form/components/errors.rb +28 -2
- data/lib/simple_form/components/hints.rb +8 -3
- data/lib/simple_form/components/html5.rb +6 -3
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +14 -10
- data/lib/simple_form/components/maxlength.rb +2 -9
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +3 -3
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +262 -107
- data/lib/simple_form/helpers.rb +6 -6
- data/lib/simple_form/inputs/base.rb +37 -16
- data/lib/simple_form/inputs/block_input.rb +2 -2
- data/lib/simple_form/inputs/boolean_input.rb +33 -18
- data/lib/simple_form/inputs/collection_input.rb +34 -13
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +7 -12
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +23 -9
- data/lib/simple_form/inputs/file_input.rb +4 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
- data/lib/simple_form/inputs/hidden_input.rb +4 -2
- data/lib/simple_form/inputs/numeric_input.rb +3 -8
- data/lib/simple_form/inputs/password_input.rb +4 -3
- data/lib/simple_form/inputs/priority_input.rb +4 -2
- data/lib/simple_form/inputs/range_input.rb +1 -1
- data/lib/simple_form/inputs/string_input.rb +4 -3
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +14 -0
- data/lib/simple_form/tags.rb +68 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +11 -35
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +7 -7
- data/lib/simple_form/wrappers/root.rb +2 -2
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +2 -1
- data/lib/simple_form.rb +99 -52
- data/test/action_view_extensions/builder_test.rb +113 -127
- data/test/action_view_extensions/form_helper_test.rb +58 -30
- data/test/components/label_test.rb +83 -83
- data/test/form_builder/association_test.rb +96 -61
- data/test/form_builder/button_test.rb +14 -14
- data/test/form_builder/error_notification_test.rb +9 -9
- data/test/form_builder/error_test.rb +159 -34
- data/test/form_builder/general_test.rb +176 -121
- data/test/form_builder/hint_test.rb +43 -37
- data/test/form_builder/input_field_test.rb +99 -52
- data/test/form_builder/label_test.rb +67 -15
- data/test/form_builder/wrapper_test.rb +157 -41
- data/test/generators/simple_form_generator_test.rb +4 -4
- data/test/inputs/boolean_input_test.rb +92 -24
- data/test/inputs/collection_check_boxes_input_test.rb +150 -71
- data/test/inputs/collection_radio_buttons_input_test.rb +213 -113
- data/test/inputs/collection_select_input_test.rb +221 -85
- data/test/inputs/datetime_input_test.rb +125 -47
- data/test/inputs/disabled_test.rb +25 -25
- data/test/inputs/discovery_test.rb +60 -10
- data/test/inputs/file_input_test.rb +3 -3
- data/test/inputs/general_test.rb +48 -32
- data/test/inputs/grouped_collection_select_input_test.rb +76 -27
- data/test/inputs/hidden_input_test.rb +6 -5
- data/test/inputs/numeric_input_test.rb +46 -46
- data/test/inputs/priority_input_test.rb +21 -15
- data/test/inputs/readonly_test.rb +31 -31
- data/test/inputs/required_test.rb +30 -18
- data/test/inputs/string_input_test.rb +53 -52
- data/test/inputs/text_input_test.rb +15 -8
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +32 -2
- data/test/support/misc_helpers.rb +130 -29
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +125 -71
- data/test/test_helper.rb +28 -35
- metadata +17 -29
- data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
- data/lib/simple_form/core_ext/hash.rb +0 -16
- data/lib/simple_form/form_builder.rb.orig +0 -486
- data/lib/simple_form/version.rb.orig +0 -7
@@ -8,13 +8,13 @@ class BuilderTest < ActionView::TestCase
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def with_collection_radio_buttons(object, attribute, collection, value_method, text_method, options={}, html_options={}, &block)
|
11
|
+
def with_collection_radio_buttons(object, attribute, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
12
12
|
with_concat_form_for(object) do |f|
|
13
13
|
f.collection_radio_buttons attribute, collection, value_method, text_method, options, html_options, &block
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def with_collection_check_boxes(object, attribute, collection, value_method, text_method, options={}, html_options={}, &block)
|
17
|
+
def with_collection_check_boxes(object, attribute, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
18
18
|
with_concat_form_for(object) do |f|
|
19
19
|
f.collection_check_boxes attribute, collection, value_method, text_method, options, html_options, &block
|
20
20
|
end
|
@@ -42,15 +42,14 @@ class BuilderTest < ActionView::TestCase
|
|
42
42
|
assert_select 'form label.collection_radio_buttons[for=user_active_no]', 'No'
|
43
43
|
end
|
44
44
|
|
45
|
-
test "collection radio
|
45
|
+
test "collection radio sanitizes collection values for labels correctly" do
|
46
46
|
with_collection_radio_buttons @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
|
47
47
|
assert_select 'label.collection_radio_buttons[for=user_name_099]', '$0.99'
|
48
48
|
assert_select 'label.collection_radio_buttons[for=user_name_199]', '$1.99'
|
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,47 +244,34 @@ 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')]
|
278
264
|
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
279
265
|
|
280
|
-
assert_select 'form input#user_tag_ids_1[type=checkbox][value=1]'
|
281
|
-
assert_select 'form input#user_tag_ids_2[type=checkbox][value=2]'
|
266
|
+
assert_select 'form input#user_tag_ids_1[type=checkbox][value="1"]'
|
267
|
+
assert_select 'form input#user_tag_ids_2[type=checkbox][value="2"]'
|
282
268
|
end
|
283
269
|
|
284
270
|
test "collection check box generates only one hidden field for the entire collection, to ensure something will be sent back to the server when posting an empty collection" do
|
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=]", :
|
274
|
+
assert_select "form input[type=hidden][name='user[tag_ids][]'][value='']", count: 1
|
289
275
|
end
|
290
276
|
|
291
277
|
test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
|
@@ -303,93 +289,93 @@ class BuilderTest < ActionView::TestCase
|
|
303
289
|
assert_select 'form label.collection_check_boxes[for=user_active_no]', 'No'
|
304
290
|
end
|
305
291
|
|
306
|
-
test "collection check box
|
292
|
+
test "collection check box sanitizes collection values for labels correctly" do
|
307
293
|
with_collection_check_boxes @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
|
308
294
|
assert_select 'label.collection_check_boxes[for=user_name_099]', '$0.99'
|
309
295
|
assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99'
|
310
296
|
end
|
311
297
|
|
312
298
|
test "collection check box checks the correct value to local variables" do
|
313
|
-
user = User.
|
314
|
-
|
315
|
-
|
299
|
+
user = User.build(tag_ids: [1, 3])
|
300
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
301
|
+
|
316
302
|
with_collection_check_boxes user, :tag_ids, collection, :first, :last
|
317
303
|
|
318
|
-
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
319
|
-
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
320
|
-
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
304
|
+
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
|
305
|
+
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
|
306
|
+
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
|
321
307
|
end
|
322
308
|
|
323
309
|
test "collection check box accepts selected values as :checked option" do
|
324
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
325
|
-
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]
|
326
312
|
|
327
|
-
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
328
|
-
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
329
|
-
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
313
|
+
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
|
314
|
+
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
|
315
|
+
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
|
330
316
|
end
|
331
317
|
|
332
318
|
test "collection check boxes accepts selected string values as :checked option" do
|
333
|
-
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
334
|
-
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']
|
335
321
|
|
336
|
-
assert_select 'input[type=checkbox][value=1][checked=checked]'
|
337
|
-
assert_select 'input[type=checkbox][value=3][checked=checked]'
|
338
|
-
assert_no_select 'input[type=checkbox][value=2][checked=checked]'
|
322
|
+
assert_select 'input[type=checkbox][value="1"][checked=checked]'
|
323
|
+
assert_select 'input[type=checkbox][value="3"][checked=checked]'
|
324
|
+
assert_no_select 'input[type=checkbox][value="2"][checked=checked]'
|
339
325
|
end
|
340
326
|
|
341
327
|
test "collection check box accepts a single checked value" do
|
342
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
343
|
-
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
|
344
330
|
|
345
|
-
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
346
|
-
assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
|
347
|
-
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
331
|
+
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
|
332
|
+
assert_no_select 'form input[type=checkbox][value="1"][checked=checked]'
|
333
|
+
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
|
348
334
|
end
|
349
335
|
|
350
336
|
test "collection check box accepts selected values as :checked option and override the model values" do
|
351
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
337
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
352
338
|
@user.tag_ids = [2]
|
353
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :
|
339
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
|
354
340
|
|
355
|
-
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
356
|
-
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
357
|
-
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
341
|
+
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
|
342
|
+
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
|
343
|
+
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
|
358
344
|
end
|
359
345
|
|
360
346
|
test "collection check box accepts multiple disabled items" do
|
361
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
362
|
-
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]
|
363
349
|
|
364
|
-
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
365
|
-
assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
366
|
-
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
350
|
+
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
|
351
|
+
assert_select 'form input[type=checkbox][value="3"][disabled=disabled]'
|
352
|
+
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
|
367
353
|
end
|
368
354
|
|
369
355
|
test "collection check box accepts single disable item" do
|
370
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
371
|
-
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
|
372
358
|
|
373
|
-
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
374
|
-
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
375
|
-
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
359
|
+
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
|
360
|
+
assert_no_select 'form input[type=checkbox][value="3"][disabled=disabled]'
|
361
|
+
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
|
376
362
|
end
|
377
363
|
|
378
364
|
test "collection check box accepts a proc to disabled items" do
|
379
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
380
|
-
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 }
|
381
367
|
|
382
|
-
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
383
|
-
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
384
|
-
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
368
|
+
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
|
369
|
+
assert_no_select 'form input[type=checkbox][value="3"][disabled=disabled]'
|
370
|
+
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
|
385
371
|
end
|
386
372
|
|
387
373
|
test "collection check box accepts html options" do
|
388
374
|
collection = [[1, 'Tag 1'], [2, 'Tag 2']]
|
389
|
-
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, :
|
375
|
+
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, class: 'check'
|
390
376
|
|
391
|
-
assert_select 'form input.check[type=checkbox][value=1]'
|
392
|
-
assert_select 'form input.check[type=checkbox][value=2]'
|
377
|
+
assert_select 'form input.check[type=checkbox][value="1"]'
|
378
|
+
assert_select 'form input.check[type=checkbox][value="2"]'
|
393
379
|
end
|
394
380
|
|
395
381
|
test "collection check box with fields for" do
|
@@ -400,51 +386,51 @@ class BuilderTest < ActionView::TestCase
|
|
400
386
|
end
|
401
387
|
end
|
402
388
|
|
403
|
-
assert_select 'form input#user_post_tag_ids_1[type=checkbox][value=1]'
|
404
|
-
assert_select 'form input#user_post_tag_ids_2[type=checkbox][value=2]'
|
389
|
+
assert_select 'form input#user_post_tag_ids_1[type=checkbox][value="1"]'
|
390
|
+
assert_select 'form input#user_post_tag_ids_2[type=checkbox][value="2"]'
|
405
391
|
|
406
392
|
assert_select 'form label.collection_check_boxes[for=user_post_tag_ids_1]', 'Tag 1'
|
407
393
|
assert_select 'form label.collection_check_boxes[for=user_post_tag_ids_2]', 'Tag 2'
|
408
394
|
end
|
409
395
|
|
410
396
|
test "collection check boxes wraps the collection in the given collection wrapper tag" do
|
411
|
-
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
|
412
398
|
|
413
|
-
assert_select 'form ul input[type=checkbox]', :
|
399
|
+
assert_select 'form ul input[type=checkbox]', count: 2
|
414
400
|
end
|
415
401
|
|
416
402
|
test "collection check boxes does not render any wrapper tag by default" do
|
417
403
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
418
404
|
|
419
|
-
assert_select 'form input[type=checkbox]', :
|
405
|
+
assert_select 'form input[type=checkbox]', count: 2
|
420
406
|
assert_no_select 'form ul'
|
421
407
|
end
|
422
408
|
|
423
409
|
test "collection check boxes does not wrap the collection when given falsy values" do
|
424
|
-
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
|
425
411
|
|
426
|
-
assert_select 'form input[type=checkbox]', :
|
412
|
+
assert_select 'form input[type=checkbox]', count: 2
|
427
413
|
assert_no_select 'form ul'
|
428
414
|
end
|
429
415
|
|
430
416
|
test "collection check boxes uses the given class for collection wrapper tag" do
|
431
417
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
432
|
-
:
|
418
|
+
collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
|
433
419
|
|
434
|
-
assert_select 'form ul.items-list input[type=checkbox]', :
|
420
|
+
assert_select 'form ul.items-list input[type=checkbox]', count: 2
|
435
421
|
end
|
436
422
|
|
437
423
|
test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
|
438
424
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
439
|
-
:
|
425
|
+
collection_wrapper_class: "items-list"
|
440
426
|
|
441
|
-
assert_select 'form input[type=checkbox]', :
|
427
|
+
assert_select 'form input[type=checkbox]', count: 2
|
442
428
|
assert_no_select 'form ul'
|
443
429
|
assert_no_select '.items-list'
|
444
430
|
end
|
445
431
|
|
446
432
|
test "collection check boxes uses no class for collection wrapper tag by default" do
|
447
|
-
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
|
448
434
|
|
449
435
|
assert_select 'form ul'
|
450
436
|
assert_no_select 'form ul[class]'
|
@@ -453,17 +439,17 @@ class BuilderTest < ActionView::TestCase
|
|
453
439
|
test "collection check boxes wrap items in a span tag by default" do
|
454
440
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
455
441
|
|
456
|
-
assert_select 'form span input[type=checkbox]', :
|
442
|
+
assert_select 'form span input[type=checkbox]', count: 2
|
457
443
|
end
|
458
444
|
|
459
445
|
test "collection check boxes wraps each item in the given item wrapper tag" do
|
460
|
-
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
|
461
447
|
|
462
|
-
assert_select 'form li input[type=checkbox]', :
|
448
|
+
assert_select 'form li input[type=checkbox]', count: 2
|
463
449
|
end
|
464
450
|
|
465
451
|
test "collection check boxes does not wrap each item when given explicitly falsy value" do
|
466
|
-
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
|
467
453
|
|
468
454
|
assert_select 'form input[type=checkbox]'
|
469
455
|
assert_no_select 'form span input[type=checkbox]'
|
@@ -471,25 +457,25 @@ class BuilderTest < ActionView::TestCase
|
|
471
457
|
|
472
458
|
test "collection check boxes uses the given class for item wrapper tag" do
|
473
459
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
474
|
-
:
|
460
|
+
item_wrapper_tag: :li, item_wrapper_class: "inline"
|
475
461
|
|
476
|
-
assert_select "form li.inline input[type=checkbox]", :
|
462
|
+
assert_select "form li.inline input[type=checkbox]", count: 2
|
477
463
|
end
|
478
464
|
|
479
465
|
test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
|
480
466
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
481
|
-
:
|
467
|
+
item_wrapper_tag: nil, item_wrapper_class: "inline"
|
482
468
|
|
483
|
-
assert_select 'form input[type=checkbox]', :
|
469
|
+
assert_select 'form input[type=checkbox]', count: 2
|
484
470
|
assert_no_select 'form li'
|
485
471
|
assert_no_select '.inline'
|
486
472
|
end
|
487
473
|
|
488
474
|
test "collection check boxes uses no class for item wrapper tag by default" do
|
489
475
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
490
|
-
:
|
476
|
+
item_wrapper_tag: :li
|
491
477
|
|
492
|
-
assert_select "form li", :
|
478
|
+
assert_select "form li", count: 2
|
493
479
|
assert_no_select "form li[class]"
|
494
480
|
end
|
495
481
|
|
@@ -520,7 +506,7 @@ class BuilderTest < ActionView::TestCase
|
|
520
506
|
|
521
507
|
test "collection check boxes with block helpers accept extra html options" do
|
522
508
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
523
|
-
b.label(:
|
509
|
+
b.label(class: "check_box") + b.check_box(class: "check_box")
|
524
510
|
end
|
525
511
|
|
526
512
|
assert_select 'label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]'
|
@@ -542,7 +528,7 @@ class BuilderTest < ActionView::TestCase
|
|
542
528
|
|
543
529
|
test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
|
544
530
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
545
|
-
b.label(:
|
531
|
+
b.label(class: b.object) { b.check_box + b.text }
|
546
532
|
end
|
547
533
|
|
548
534
|
assert_select 'label.true[for=user_active_true]', 'true' do
|
@@ -556,17 +542,17 @@ class BuilderTest < ActionView::TestCase
|
|
556
542
|
test "collection check boxes with block helpers does not leak the template" do
|
557
543
|
with_concat_form_for(@user) do |f|
|
558
544
|
collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
|
559
|
-
b.label(:
|
545
|
+
b.label(class: b.object) { b.check_box + b.text }
|
560
546
|
end
|
561
547
|
concat collection_input
|
562
548
|
|
563
549
|
concat f.hidden_field :name
|
564
550
|
end
|
565
551
|
|
566
|
-
assert_select 'label.true[for=user_active_true]', :
|
552
|
+
assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
|
567
553
|
assert_select 'input#user_active_true[type=checkbox]'
|
568
554
|
end
|
569
|
-
assert_select 'label.false[for=user_active_false]', :
|
555
|
+
assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
|
570
556
|
assert_select 'input#user_active_false[type=checkbox]'
|
571
557
|
end
|
572
558
|
end
|
@@ -601,15 +587,15 @@ class BuilderTest < ActionView::TestCase
|
|
601
587
|
|
602
588
|
test "fields for yields an instance of FormBuilder if it was set in options" do
|
603
589
|
with_custom_form_for(:user) do |f|
|
604
|
-
f.simple_fields_for(:company, :
|
590
|
+
f.simple_fields_for(:company, builder: SimpleForm::FormBuilder) do |company|
|
605
591
|
assert company.instance_of?(SimpleForm::FormBuilder)
|
606
592
|
end
|
607
593
|
end
|
608
594
|
end
|
609
595
|
|
610
|
-
test "fields
|
596
|
+
test "fields inherits wrapper option from the parent form" do
|
611
597
|
swap_wrapper :another do
|
612
|
-
simple_form_for(:user, :
|
598
|
+
simple_form_for(:user, wrapper: :another) do |f|
|
613
599
|
f.simple_fields_for(:company) do |company|
|
614
600
|
assert_equal :another, company.options[:wrapper]
|
615
601
|
end
|
@@ -619,8 +605,8 @@ class BuilderTest < ActionView::TestCase
|
|
619
605
|
|
620
606
|
test "fields overrides wrapper option from the parent form" do
|
621
607
|
swap_wrapper :another do
|
622
|
-
simple_form_for(:user, :
|
623
|
-
f.simple_fields_for(:company, :
|
608
|
+
simple_form_for(:user, wrapper: :another) do |f|
|
609
|
+
f.simple_fields_for(:company, wrapper: false) do |company|
|
624
610
|
assert_equal false, company.options[:wrapper]
|
625
611
|
end
|
626
612
|
end
|