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