simple_form 2.0.0 → 2.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.
- data/CHANGELOG.md +34 -231
- data/MIT-LICENSE +1 -1
- data/README.md +221 -159
- data/lib/generators/simple_form/install_generator.rb +14 -5
- data/lib/generators/simple_form/templates/config/initializers/{simple_form.rb.tt → simple_form.rb} +8 -42
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +26 -0
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -5
- data/lib/simple_form/action_view_extensions/builder.rb +46 -30
- data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +7 -9
- data/lib/simple_form/components/hints.rb +3 -2
- data/lib/simple_form/components/label_input.rb +1 -1
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +2 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/components.rb +12 -10
- data/lib/simple_form/error_notification.rb +1 -1
- data/lib/simple_form/form_builder.rb +18 -8
- data/lib/simple_form/form_builder.rb.orig +486 -0
- data/lib/simple_form/helpers/validators.rb +2 -2
- data/lib/simple_form/inputs/base.rb +33 -8
- data/lib/simple_form/inputs/boolean_input.rb +19 -5
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -6
- data/lib/simple_form/inputs/date_time_input.rb +0 -4
- data/lib/simple_form/inputs.rb +19 -17
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/version.rb.orig +7 -0
- data/lib/simple_form/wrappers/many.rb +5 -1
- data/lib/simple_form/wrappers/root.rb +4 -2
- data/lib/simple_form/wrappers/single.rb +6 -0
- data/lib/simple_form.rb +17 -8
- data/test/action_view_extensions/builder_test.rb +145 -66
- data/test/action_view_extensions/form_helper_test.rb +59 -20
- data/test/components/label_test.rb +34 -17
- data/test/form_builder/association_test.rb +19 -10
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/general_test.rb +74 -12
- data/test/form_builder/hint_test.rb +15 -0
- data/test/form_builder/input_field_test.rb +45 -0
- data/test/form_builder/label_test.rb +6 -0
- data/test/form_builder/wrapper_test.rb +58 -4
- data/test/generators/simple_form_generator_test.rb +11 -1
- data/test/inputs/boolean_input_test.rb +39 -0
- data/test/inputs/datetime_input_test.rb +2 -2
- data/test/inputs/disabled_test.rb +51 -11
- data/test/inputs/discovery_test.rb +9 -1
- data/test/inputs/general_test.rb +58 -11
- data/test/inputs/grouped_collection_select_input_test.rb +15 -0
- data/test/inputs/numeric_input_test.rb +6 -0
- data/test/inputs/readonly_test.rb +51 -11
- data/test/inputs/string_input_test.rb +6 -0
- data/test/support/discovery_inputs.rb +6 -0
- data/test/support/misc_helpers.rb +41 -1
- data/test/support/models.rb +8 -4
- data/test/test_helper.rb +8 -6
- metadata +26 -13
- data/test/support/mock_response.rb +0 -14
|
@@ -21,41 +21,56 @@ class BuilderTest < ActionView::TestCase
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# COLLECTION RADIO
|
|
24
|
-
test
|
|
24
|
+
test "collection radio accepts a collection and generate inputs from value method" do
|
|
25
25
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
|
26
26
|
|
|
27
27
|
assert_select 'form input[type=radio][value=true]#user_active_true'
|
|
28
28
|
assert_select 'form input[type=radio][value=false]#user_active_false'
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
test
|
|
31
|
+
test "collection radio accepts a collection and generate inputs from label method" do
|
|
32
32
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
|
33
33
|
|
|
34
34
|
assert_select 'form label.collection_radio_buttons[for=user_active_true]', 'true'
|
|
35
35
|
assert_select 'form label.collection_radio_buttons[for=user_active_false]', 'false'
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
test
|
|
38
|
+
test "collection radio handles camelized collection values for labels correctly" do
|
|
39
39
|
with_collection_radio_buttons @user, :active, ['Yes', 'No'], :to_s, :to_s
|
|
40
40
|
|
|
41
41
|
assert_select 'form label.collection_radio_buttons[for=user_active_yes]', 'Yes'
|
|
42
42
|
assert_select 'form label.collection_radio_buttons[for=user_active_no]', 'No'
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
test
|
|
45
|
+
test "collection radio should sanitize 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
|
-
test
|
|
51
|
+
test "collection radio checks the correct value to local variables" do
|
|
52
|
+
user = User.new
|
|
53
|
+
user.active = false
|
|
54
|
+
with_collection_radio_buttons user, :active, [true, false], :to_s, :to_s
|
|
55
|
+
|
|
56
|
+
assert_select 'form input[type=radio][value=true]'
|
|
57
|
+
assert_select 'form input[type=radio][value=false][checked=checked]'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
test "collection radio accepts checked item" do
|
|
52
61
|
with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => true
|
|
53
62
|
|
|
54
63
|
assert_select 'form input[type=radio][value=true][checked=checked]'
|
|
55
64
|
assert_no_select 'form input[type=radio][value=false][checked=checked]'
|
|
56
65
|
end
|
|
57
66
|
|
|
58
|
-
test
|
|
67
|
+
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, :checked => false
|
|
69
|
+
assert_no_select 'form input[type=radio][value=true][checked=checked]'
|
|
70
|
+
assert_select 'form input[type=radio][value=false][checked=checked]'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test "collection radio accepts multiple disabled items" do
|
|
59
74
|
collection = [[1, true], [0, false], [2, 'other']]
|
|
60
75
|
with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => [true, false]
|
|
61
76
|
|
|
@@ -64,7 +79,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
64
79
|
assert_no_select 'form input[type=radio][value=other][disabled=disabled]'
|
|
65
80
|
end
|
|
66
81
|
|
|
67
|
-
test
|
|
82
|
+
test "collection radio accepts single disable item" do
|
|
68
83
|
collection = [[1, true], [0, false]]
|
|
69
84
|
with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => true
|
|
70
85
|
|
|
@@ -72,7 +87,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
72
87
|
assert_no_select 'form input[type=radio][value=false][disabled=disabled]'
|
|
73
88
|
end
|
|
74
89
|
|
|
75
|
-
test
|
|
90
|
+
test "collection radio accepts html options as input" do
|
|
76
91
|
collection = [[1, true], [0, false]]
|
|
77
92
|
with_collection_radio_buttons @user, :active, collection, :last, :first, {}, :class => 'special-radio'
|
|
78
93
|
|
|
@@ -80,34 +95,34 @@ class BuilderTest < ActionView::TestCase
|
|
|
80
95
|
assert_select 'form input[type=radio][value=false].special-radio#user_active_false'
|
|
81
96
|
end
|
|
82
97
|
|
|
83
|
-
test
|
|
98
|
+
test "collection radio wraps the collection in the given collection wrapper tag" do
|
|
84
99
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
|
|
85
100
|
|
|
86
101
|
assert_select 'form ul input[type=radio]', :count => 2
|
|
87
102
|
end
|
|
88
103
|
|
|
89
|
-
test
|
|
104
|
+
test "collection radio does not render any wrapper tag by default" do
|
|
90
105
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
|
91
106
|
|
|
92
107
|
assert_select 'form input[type=radio]', :count => 2
|
|
93
108
|
assert_no_select 'form ul'
|
|
94
109
|
end
|
|
95
110
|
|
|
96
|
-
test
|
|
111
|
+
test "collection radio does not wrap the collection when given falsy values" do
|
|
97
112
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
|
|
98
113
|
|
|
99
114
|
assert_select 'form input[type=radio]', :count => 2
|
|
100
115
|
assert_no_select 'form ul'
|
|
101
116
|
end
|
|
102
117
|
|
|
103
|
-
test
|
|
118
|
+
test "collection radio uses the given class for collection wrapper tag" do
|
|
104
119
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
|
105
120
|
:collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
|
|
106
121
|
|
|
107
122
|
assert_select 'form ul.items-list input[type=radio]', :count => 2
|
|
108
123
|
end
|
|
109
124
|
|
|
110
|
-
test
|
|
125
|
+
test "collection radio uses no class for collection wrapper tag when no wrapper tag is given" do
|
|
111
126
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
|
112
127
|
:collection_wrapper_class => "items-list"
|
|
113
128
|
|
|
@@ -116,41 +131,41 @@ class BuilderTest < ActionView::TestCase
|
|
|
116
131
|
assert_no_select '.items-list'
|
|
117
132
|
end
|
|
118
133
|
|
|
119
|
-
test
|
|
134
|
+
test "collection radio uses no class for collection wrapper tag by default" do
|
|
120
135
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
|
|
121
136
|
|
|
122
137
|
assert_select 'form ul'
|
|
123
138
|
assert_no_select 'form ul[class]'
|
|
124
139
|
end
|
|
125
140
|
|
|
126
|
-
test
|
|
141
|
+
test "collection radio wrap items in a span tag by default" do
|
|
127
142
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
|
128
143
|
|
|
129
144
|
assert_select 'form span input[type=radio][value=true]#user_active_true + label'
|
|
130
145
|
assert_select 'form span input[type=radio][value=false]#user_active_false + label'
|
|
131
146
|
end
|
|
132
147
|
|
|
133
|
-
test
|
|
148
|
+
test "collection radio wraps each item in the given item wrapper tag" do
|
|
134
149
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
|
|
135
150
|
|
|
136
151
|
assert_select 'form li input[type=radio]', :count => 2
|
|
137
152
|
end
|
|
138
153
|
|
|
139
|
-
test
|
|
154
|
+
test "collection radio does not wrap each item when given explicitly falsy value" do
|
|
140
155
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
|
|
141
156
|
|
|
142
157
|
assert_select 'form input[type=radio]'
|
|
143
158
|
assert_no_select 'form span input[type=radio]'
|
|
144
159
|
end
|
|
145
160
|
|
|
146
|
-
test
|
|
161
|
+
test "collection radio uses the given class for item wrapper tag" do
|
|
147
162
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
|
148
163
|
:item_wrapper_tag => :li, :item_wrapper_class => "inline"
|
|
149
164
|
|
|
150
165
|
assert_select "form li.inline input[type=radio]", :count => 2
|
|
151
166
|
end
|
|
152
167
|
|
|
153
|
-
test
|
|
168
|
+
test "collection radio uses no class for item wrapper tag when no wrapper tag is given" do
|
|
154
169
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
|
155
170
|
:item_wrapper_tag => nil, :item_wrapper_class => "inline"
|
|
156
171
|
|
|
@@ -159,7 +174,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
159
174
|
assert_no_select '.inline'
|
|
160
175
|
end
|
|
161
176
|
|
|
162
|
-
test
|
|
177
|
+
test "collection radio uses no class for item wrapper tag by default" do
|
|
163
178
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
|
164
179
|
:item_wrapper_tag => :li
|
|
165
180
|
|
|
@@ -167,14 +182,14 @@ class BuilderTest < ActionView::TestCase
|
|
|
167
182
|
assert_no_select "form li[class]"
|
|
168
183
|
end
|
|
169
184
|
|
|
170
|
-
test
|
|
185
|
+
test "collection radio does not wrap input inside the label" do
|
|
171
186
|
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
|
172
187
|
|
|
173
188
|
assert_select 'form input[type=radio] + label'
|
|
174
189
|
assert_no_select 'form label input'
|
|
175
190
|
end
|
|
176
191
|
|
|
177
|
-
test
|
|
192
|
+
test "collection radio accepts a block to render the label as radio button wrapper" do
|
|
178
193
|
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
|
179
194
|
b.label { b.radio_button }
|
|
180
195
|
end
|
|
@@ -183,7 +198,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
183
198
|
assert_select 'label[for=user_active_false] > input#user_active_false[type=radio]'
|
|
184
199
|
end
|
|
185
200
|
|
|
186
|
-
test
|
|
201
|
+
test "collection radio accepts a block to change the order of label and radio button" do
|
|
187
202
|
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
|
188
203
|
b.label + b.radio_button
|
|
189
204
|
end
|
|
@@ -192,7 +207,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
192
207
|
assert_select 'label[for=user_active_false] + input#user_active_false[type=radio]'
|
|
193
208
|
end
|
|
194
209
|
|
|
195
|
-
test
|
|
210
|
+
test "collection radio with block helpers accept extra html options" do
|
|
196
211
|
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
|
197
212
|
b.label(:class => "radio_button") + b.radio_button(:class => "radio_button")
|
|
198
213
|
end
|
|
@@ -201,7 +216,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
201
216
|
assert_select 'label.radio_button[for=user_active_false] + input#user_active_false.radio_button[type=radio]'
|
|
202
217
|
end
|
|
203
218
|
|
|
204
|
-
test
|
|
219
|
+
test "collection radio with block helpers allows access to current text and value" do
|
|
205
220
|
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
|
206
221
|
b.label(:"data-value" => b.value) { b.radio_button + b.text }
|
|
207
222
|
end
|
|
@@ -214,7 +229,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
214
229
|
end
|
|
215
230
|
end
|
|
216
231
|
|
|
217
|
-
test
|
|
232
|
+
test "collection radio with block helpers allows access to the current object item in the collection to access extra properties" do
|
|
218
233
|
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
|
219
234
|
b.label(:class => b.object) { b.radio_button + b.text }
|
|
220
235
|
end
|
|
@@ -227,7 +242,25 @@ class BuilderTest < ActionView::TestCase
|
|
|
227
242
|
end
|
|
228
243
|
end
|
|
229
244
|
|
|
230
|
-
test
|
|
245
|
+
test "collection radio with block helpers does not leak the template" do
|
|
246
|
+
with_concat_form_for(@user) do |f|
|
|
247
|
+
collection_input = f.collection_radio_buttons :active, [true, false], :to_s, :to_s do |b|
|
|
248
|
+
b.label(:class => b.object) { b.radio_button + b.text }
|
|
249
|
+
end
|
|
250
|
+
concat collection_input
|
|
251
|
+
|
|
252
|
+
concat f.hidden_field :name
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
assert_select 'label.true[for=user_active_true]', :text => 'true', :count => 1 do
|
|
256
|
+
assert_select 'input#user_active_true[type=radio]'
|
|
257
|
+
end
|
|
258
|
+
assert_select 'label.false[for=user_active_false]', :text => 'false', :count => 1 do
|
|
259
|
+
assert_select 'input#user_active_false[type=radio]'
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
test "collection_radio helper is deprecated in favor of collection_radio_buttons" do
|
|
231
264
|
assert_deprecated "[SIMPLE_FORM] The `collection_radio` helper is deprecated, " \
|
|
232
265
|
"please use `collection_radio_buttons` instead" do
|
|
233
266
|
with_concat_form_for(@user) do |f|
|
|
@@ -240,7 +273,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
240
273
|
end
|
|
241
274
|
|
|
242
275
|
# COLLECTION CHECK BOX
|
|
243
|
-
test
|
|
276
|
+
test "collection check box accepts a collection and generate a serie of checkboxes for value method" do
|
|
244
277
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
|
245
278
|
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
|
246
279
|
|
|
@@ -248,14 +281,14 @@ class BuilderTest < ActionView::TestCase
|
|
|
248
281
|
assert_select 'form input#user_tag_ids_2[type=checkbox][value=2]'
|
|
249
282
|
end
|
|
250
283
|
|
|
251
|
-
test
|
|
284
|
+
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
|
|
252
285
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
|
253
286
|
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
|
254
287
|
|
|
255
288
|
assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", :count => 1
|
|
256
289
|
end
|
|
257
290
|
|
|
258
|
-
test
|
|
291
|
+
test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
|
|
259
292
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
|
260
293
|
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
|
261
294
|
|
|
@@ -263,20 +296,31 @@ class BuilderTest < ActionView::TestCase
|
|
|
263
296
|
assert_select 'form label.collection_check_boxes[for=user_tag_ids_2]', 'Tag 2'
|
|
264
297
|
end
|
|
265
298
|
|
|
266
|
-
test
|
|
299
|
+
test "collection check box handles camelized collection values for labels correctly" do
|
|
267
300
|
with_collection_check_boxes @user, :active, ['Yes', 'No'], :to_s, :to_s
|
|
268
301
|
|
|
269
302
|
assert_select 'form label.collection_check_boxes[for=user_active_yes]', 'Yes'
|
|
270
303
|
assert_select 'form label.collection_check_boxes[for=user_active_no]', 'No'
|
|
271
304
|
end
|
|
272
305
|
|
|
273
|
-
test
|
|
306
|
+
test "collection check box should sanitize collection values for labels correctly" do
|
|
274
307
|
with_collection_check_boxes @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
|
|
275
308
|
assert_select 'label.collection_check_boxes[for=user_name_099]', '$0.99'
|
|
276
309
|
assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99'
|
|
277
310
|
end
|
|
278
311
|
|
|
279
|
-
test
|
|
312
|
+
test "collection check box checks the correct value to local variables" do
|
|
313
|
+
user = User.new
|
|
314
|
+
user.tag_ids = [1, 3]
|
|
315
|
+
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
|
316
|
+
with_collection_check_boxes user, :tag_ids, collection, :first, :last
|
|
317
|
+
|
|
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]'
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
test "collection check box accepts selected values as :checked option" do
|
|
280
324
|
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
|
281
325
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
|
|
282
326
|
|
|
@@ -285,7 +329,16 @@ class BuilderTest < ActionView::TestCase
|
|
|
285
329
|
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
|
286
330
|
end
|
|
287
331
|
|
|
288
|
-
test
|
|
332
|
+
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, :checked => ['1', '3']
|
|
335
|
+
|
|
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]'
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
test "collection check box accepts a single checked value" do
|
|
289
342
|
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
|
290
343
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => 3
|
|
291
344
|
|
|
@@ -294,7 +347,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
294
347
|
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
|
295
348
|
end
|
|
296
349
|
|
|
297
|
-
test
|
|
350
|
+
test "collection check box accepts selected values as :checked option and override the model values" do
|
|
298
351
|
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
|
299
352
|
@user.tag_ids = [2]
|
|
300
353
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
|
|
@@ -304,7 +357,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
304
357
|
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
|
305
358
|
end
|
|
306
359
|
|
|
307
|
-
test
|
|
360
|
+
test "collection check box accepts multiple disabled items" do
|
|
308
361
|
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
|
309
362
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => [1, 3]
|
|
310
363
|
|
|
@@ -313,7 +366,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
313
366
|
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
|
314
367
|
end
|
|
315
368
|
|
|
316
|
-
test
|
|
369
|
+
test "collection check box accepts single disable item" do
|
|
317
370
|
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
|
318
371
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => 1
|
|
319
372
|
|
|
@@ -322,7 +375,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
322
375
|
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
|
323
376
|
end
|
|
324
377
|
|
|
325
|
-
test
|
|
378
|
+
test "collection check box accepts a proc to disabled items" do
|
|
326
379
|
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
|
327
380
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
|
|
328
381
|
|
|
@@ -331,7 +384,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
331
384
|
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
|
332
385
|
end
|
|
333
386
|
|
|
334
|
-
test
|
|
387
|
+
test "collection check box accepts html options" do
|
|
335
388
|
collection = [[1, 'Tag 1'], [2, 'Tag 2']]
|
|
336
389
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, :class => 'check'
|
|
337
390
|
|
|
@@ -339,7 +392,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
339
392
|
assert_select 'form input.check[type=checkbox][value=2]'
|
|
340
393
|
end
|
|
341
394
|
|
|
342
|
-
test
|
|
395
|
+
test "collection check box with fields for" do
|
|
343
396
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
|
344
397
|
with_concat_form_for(@user) do |f|
|
|
345
398
|
f.fields_for(:post) do |p|
|
|
@@ -354,34 +407,34 @@ class BuilderTest < ActionView::TestCase
|
|
|
354
407
|
assert_select 'form label.collection_check_boxes[for=user_post_tag_ids_2]', 'Tag 2'
|
|
355
408
|
end
|
|
356
409
|
|
|
357
|
-
test
|
|
410
|
+
test "collection check boxes wraps the collection in the given collection wrapper tag" do
|
|
358
411
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
|
|
359
412
|
|
|
360
413
|
assert_select 'form ul input[type=checkbox]', :count => 2
|
|
361
414
|
end
|
|
362
415
|
|
|
363
|
-
test
|
|
416
|
+
test "collection check boxes does not render any wrapper tag by default" do
|
|
364
417
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
|
365
418
|
|
|
366
419
|
assert_select 'form input[type=checkbox]', :count => 2
|
|
367
420
|
assert_no_select 'form ul'
|
|
368
421
|
end
|
|
369
422
|
|
|
370
|
-
test
|
|
423
|
+
test "collection check boxes does not wrap the collection when given falsy values" do
|
|
371
424
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
|
|
372
425
|
|
|
373
426
|
assert_select 'form input[type=checkbox]', :count => 2
|
|
374
427
|
assert_no_select 'form ul'
|
|
375
428
|
end
|
|
376
429
|
|
|
377
|
-
test
|
|
430
|
+
test "collection check boxes uses the given class for collection wrapper tag" do
|
|
378
431
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
|
379
432
|
:collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
|
|
380
433
|
|
|
381
434
|
assert_select 'form ul.items-list input[type=checkbox]', :count => 2
|
|
382
435
|
end
|
|
383
436
|
|
|
384
|
-
test
|
|
437
|
+
test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
|
|
385
438
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
|
386
439
|
:collection_wrapper_class => "items-list"
|
|
387
440
|
|
|
@@ -390,40 +443,40 @@ class BuilderTest < ActionView::TestCase
|
|
|
390
443
|
assert_no_select '.items-list'
|
|
391
444
|
end
|
|
392
445
|
|
|
393
|
-
test
|
|
446
|
+
test "collection check boxes uses no class for collection wrapper tag by default" do
|
|
394
447
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
|
|
395
448
|
|
|
396
449
|
assert_select 'form ul'
|
|
397
450
|
assert_no_select 'form ul[class]'
|
|
398
451
|
end
|
|
399
452
|
|
|
400
|
-
test
|
|
453
|
+
test "collection check boxes wrap items in a span tag by default" do
|
|
401
454
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
|
402
455
|
|
|
403
456
|
assert_select 'form span input[type=checkbox]', :count => 2
|
|
404
457
|
end
|
|
405
458
|
|
|
406
|
-
test
|
|
459
|
+
test "collection check boxes wraps each item in the given item wrapper tag" do
|
|
407
460
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
|
|
408
461
|
|
|
409
462
|
assert_select 'form li input[type=checkbox]', :count => 2
|
|
410
463
|
end
|
|
411
464
|
|
|
412
|
-
test
|
|
465
|
+
test "collection check boxes does not wrap each item when given explicitly falsy value" do
|
|
413
466
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
|
|
414
467
|
|
|
415
468
|
assert_select 'form input[type=checkbox]'
|
|
416
469
|
assert_no_select 'form span input[type=checkbox]'
|
|
417
470
|
end
|
|
418
471
|
|
|
419
|
-
test
|
|
472
|
+
test "collection check boxes uses the given class for item wrapper tag" do
|
|
420
473
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
|
421
474
|
:item_wrapper_tag => :li, :item_wrapper_class => "inline"
|
|
422
475
|
|
|
423
476
|
assert_select "form li.inline input[type=checkbox]", :count => 2
|
|
424
477
|
end
|
|
425
478
|
|
|
426
|
-
test
|
|
479
|
+
test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
|
|
427
480
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
|
428
481
|
:item_wrapper_tag => nil, :item_wrapper_class => "inline"
|
|
429
482
|
|
|
@@ -432,7 +485,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
432
485
|
assert_no_select '.inline'
|
|
433
486
|
end
|
|
434
487
|
|
|
435
|
-
test
|
|
488
|
+
test "collection check boxes uses no class for item wrapper tag by default" do
|
|
436
489
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
|
437
490
|
:item_wrapper_tag => :li
|
|
438
491
|
|
|
@@ -440,14 +493,14 @@ class BuilderTest < ActionView::TestCase
|
|
|
440
493
|
assert_no_select "form li[class]"
|
|
441
494
|
end
|
|
442
495
|
|
|
443
|
-
test
|
|
496
|
+
test "collection check box does not wrap input inside the label" do
|
|
444
497
|
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
|
445
498
|
|
|
446
499
|
assert_select 'form input[type=checkbox] + label'
|
|
447
500
|
assert_no_select 'form label input'
|
|
448
501
|
end
|
|
449
502
|
|
|
450
|
-
test
|
|
503
|
+
test "collection check boxes accepts a block to render the label as check box wrapper" do
|
|
451
504
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
|
452
505
|
b.label { b.check_box }
|
|
453
506
|
end
|
|
@@ -456,7 +509,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
456
509
|
assert_select 'label[for=user_active_false] > input#user_active_false[type=checkbox]'
|
|
457
510
|
end
|
|
458
511
|
|
|
459
|
-
test
|
|
512
|
+
test "collection check boxes accepts a block to change the order of label and check box" do
|
|
460
513
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
|
461
514
|
b.label + b.check_box
|
|
462
515
|
end
|
|
@@ -465,7 +518,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
465
518
|
assert_select 'label[for=user_active_false] + input#user_active_false[type=checkbox]'
|
|
466
519
|
end
|
|
467
520
|
|
|
468
|
-
test
|
|
521
|
+
test "collection check boxes with block helpers accept extra html options" do
|
|
469
522
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
|
470
523
|
b.label(:class => "check_box") + b.check_box(:class => "check_box")
|
|
471
524
|
end
|
|
@@ -474,7 +527,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
474
527
|
assert_select 'label.check_box[for=user_active_false] + input#user_active_false.check_box[type=checkbox]'
|
|
475
528
|
end
|
|
476
529
|
|
|
477
|
-
test
|
|
530
|
+
test "collection check boxes with block helpers allows access to current text and value" do
|
|
478
531
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
|
479
532
|
b.label(:"data-value" => b.value) { b.check_box + b.text }
|
|
480
533
|
end
|
|
@@ -487,7 +540,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
487
540
|
end
|
|
488
541
|
end
|
|
489
542
|
|
|
490
|
-
test
|
|
543
|
+
test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
|
|
491
544
|
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
|
492
545
|
b.label(:class => b.object) { b.check_box + b.text }
|
|
493
546
|
end
|
|
@@ -500,8 +553,26 @@ class BuilderTest < ActionView::TestCase
|
|
|
500
553
|
end
|
|
501
554
|
end
|
|
502
555
|
|
|
556
|
+
test "collection check boxes with block helpers does not leak the template" do
|
|
557
|
+
with_concat_form_for(@user) do |f|
|
|
558
|
+
collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
|
|
559
|
+
b.label(:class => b.object) { b.check_box + b.text }
|
|
560
|
+
end
|
|
561
|
+
concat collection_input
|
|
562
|
+
|
|
563
|
+
concat f.hidden_field :name
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
assert_select 'label.true[for=user_active_true]', :text => 'true', :count => 1 do
|
|
567
|
+
assert_select 'input#user_active_true[type=checkbox]'
|
|
568
|
+
end
|
|
569
|
+
assert_select 'label.false[for=user_active_false]', :text => 'false', :count => 1 do
|
|
570
|
+
assert_select 'input#user_active_false[type=checkbox]'
|
|
571
|
+
end
|
|
572
|
+
end
|
|
573
|
+
|
|
503
574
|
# SIMPLE FIELDS
|
|
504
|
-
test
|
|
575
|
+
test "simple fields for is available and yields an instance of FormBuilder" do
|
|
505
576
|
with_concat_form_for(@user) do |f|
|
|
506
577
|
f.simple_fields_for(:posts) do |posts_form|
|
|
507
578
|
assert posts_form.instance_of?(SimpleForm::FormBuilder)
|
|
@@ -509,11 +580,9 @@ class BuilderTest < ActionView::TestCase
|
|
|
509
580
|
end
|
|
510
581
|
end
|
|
511
582
|
|
|
512
|
-
test
|
|
513
|
-
@hash_backed_author = HashBackedAuthor.new
|
|
514
|
-
|
|
583
|
+
test "fields for with a hash like model yeilds an instance of FormBuilder" do
|
|
515
584
|
with_concat_form_for(:user) do |f|
|
|
516
|
-
f.simple_fields_for(:author,
|
|
585
|
+
f.simple_fields_for(:author, HashBackedAuthor.new) do |author|
|
|
517
586
|
assert author.instance_of?(SimpleForm::FormBuilder)
|
|
518
587
|
author.input :name
|
|
519
588
|
end
|
|
@@ -522,7 +591,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
522
591
|
assert_select "input[name='user[author][name]'][value='hash backed author']"
|
|
523
592
|
end
|
|
524
593
|
|
|
525
|
-
test
|
|
594
|
+
test "fields for yields an instance of CustomBuilder if main builder is a CustomBuilder" do
|
|
526
595
|
with_custom_form_for(:user) do |f|
|
|
527
596
|
f.simple_fields_for(:company) do |company|
|
|
528
597
|
assert company.instance_of?(CustomFormBuilder)
|
|
@@ -530,7 +599,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
530
599
|
end
|
|
531
600
|
end
|
|
532
601
|
|
|
533
|
-
test
|
|
602
|
+
test "fields for yields an instance of FormBuilder if it was set in options" do
|
|
534
603
|
with_custom_form_for(:user) do |f|
|
|
535
604
|
f.simple_fields_for(:company, :builder => SimpleForm::FormBuilder) do |company|
|
|
536
605
|
assert company.instance_of?(SimpleForm::FormBuilder)
|
|
@@ -538,7 +607,7 @@ class BuilderTest < ActionView::TestCase
|
|
|
538
607
|
end
|
|
539
608
|
end
|
|
540
609
|
|
|
541
|
-
test
|
|
610
|
+
test "fields inherites wrapper option from the parent form" do
|
|
542
611
|
swap_wrapper :another do
|
|
543
612
|
simple_form_for(:user, :wrapper => :another) do |f|
|
|
544
613
|
f.simple_fields_for(:company) do |company|
|
|
@@ -547,4 +616,14 @@ class BuilderTest < ActionView::TestCase
|
|
|
547
616
|
end
|
|
548
617
|
end
|
|
549
618
|
end
|
|
619
|
+
|
|
620
|
+
test "fields overrides wrapper option from the parent form" do
|
|
621
|
+
swap_wrapper :another do
|
|
622
|
+
simple_form_for(:user, :wrapper => :another) do |f|
|
|
623
|
+
f.simple_fields_for(:company, :wrapper => false) do |company|
|
|
624
|
+
assert_equal false, company.options[:wrapper]
|
|
625
|
+
end
|
|
626
|
+
end
|
|
627
|
+
end
|
|
628
|
+
end
|
|
550
629
|
end
|