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