simple_form 1.5.2 → 2.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- data/CHANGELOG.md +224 -0
- data/MIT-LICENSE +1 -1
- data/README.md +817 -0
- data/lib/generators/simple_form/install_generator.rb +15 -1
- data/lib/generators/simple_form/templates/README +12 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +173 -0
- data/lib/simple_form.rb +109 -43
- data/lib/simple_form/action_view_extensions/builder.rb +158 -53
- data/lib/simple_form/action_view_extensions/form_helper.rb +29 -22
- data/lib/simple_form/components.rb +11 -1
- data/lib/simple_form/components/errors.rb +6 -24
- data/lib/simple_form/components/hints.rb +7 -21
- data/lib/simple_form/components/html5.rb +26 -0
- data/lib/simple_form/components/labels.rb +15 -13
- data/lib/simple_form/components/maxlength.rb +41 -0
- data/lib/simple_form/components/min_max.rb +49 -0
- data/lib/simple_form/components/pattern.rb +34 -0
- data/lib/simple_form/components/placeholders.rb +5 -17
- data/lib/simple_form/components/readonly.rb +22 -0
- data/lib/simple_form/core_ext/hash.rb +16 -0
- data/lib/simple_form/error_notification.rb +8 -1
- data/lib/simple_form/form_builder.rb +86 -22
- data/lib/simple_form/helpers.rb +7 -4
- data/lib/simple_form/helpers/autofocus.rb +11 -0
- data/lib/simple_form/helpers/disabled.rb +15 -0
- data/lib/simple_form/helpers/readonly.rb +15 -0
- data/lib/simple_form/helpers/required.rb +7 -10
- data/lib/simple_form/helpers/validators.rb +4 -4
- data/lib/simple_form/inputs.rb +17 -13
- data/lib/simple_form/inputs/base.rb +50 -81
- data/lib/simple_form/inputs/boolean_input.rb +43 -4
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
- data/lib/simple_form/inputs/collection_input.rb +27 -13
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +69 -0
- data/lib/simple_form/inputs/collection_select_input.rb +14 -0
- data/lib/simple_form/inputs/date_time_input.rb +2 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
- data/lib/simple_form/inputs/hidden_input.rb +3 -6
- data/lib/simple_form/inputs/numeric_input.rb +3 -51
- data/lib/simple_form/inputs/password_input.rb +1 -2
- data/lib/simple_form/inputs/priority_input.rb +2 -2
- data/lib/simple_form/inputs/range_input.rb +1 -3
- data/lib/simple_form/inputs/string_input.rb +6 -8
- data/lib/simple_form/inputs/text_input.rb +1 -2
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers.rb +8 -0
- data/lib/simple_form/wrappers/builder.rb +75 -0
- data/lib/simple_form/wrappers/many.rb +68 -0
- data/lib/simple_form/wrappers/root.rb +34 -0
- data/lib/simple_form/wrappers/single.rb +18 -0
- data/test/action_view_extensions/builder_test.rb +195 -100
- data/test/action_view_extensions/form_helper_test.rb +24 -2
- data/test/components/label_test.rb +20 -5
- data/test/form_builder/association_test.rb +167 -0
- data/test/form_builder/button_test.rb +28 -0
- data/test/{error_notification_test.rb → form_builder/error_notification_test.rb} +2 -1
- data/test/form_builder/error_test.rb +101 -0
- data/test/form_builder/general_test.rb +348 -0
- data/test/form_builder/hint_test.rb +115 -0
- data/test/form_builder/input_field_test.rb +51 -0
- data/test/form_builder/label_test.rb +51 -0
- data/test/form_builder/wrapper_test.rb +140 -0
- data/test/generators/simple_form_generator_test.rb +32 -0
- data/test/inputs/boolean_input_test.rb +91 -0
- data/test/inputs/collection_check_boxes_input_test.rb +224 -0
- data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
- data/test/inputs/collection_select_input_test.rb +241 -0
- data/test/inputs/datetime_input_test.rb +85 -0
- data/test/inputs/disabled_test.rb +38 -0
- data/test/inputs/discovery_test.rb +61 -0
- data/test/inputs/file_input_test.rb +16 -0
- data/test/inputs/general_test.rb +69 -0
- data/test/inputs/grouped_collection_select_input_test.rb +109 -0
- data/test/inputs/hidden_input_test.rb +30 -0
- data/test/inputs/numeric_input_test.rb +167 -0
- data/test/inputs/priority_input_test.rb +43 -0
- data/test/inputs/readonly_test.rb +61 -0
- data/test/inputs/required_test.rb +113 -0
- data/test/inputs/string_input_test.rb +140 -0
- data/test/inputs/text_input_test.rb +24 -0
- data/test/{discovery_inputs.rb → support/discovery_inputs.rb} +0 -0
- data/test/support/misc_helpers.rb +48 -6
- data/test/support/mock_controller.rb +2 -2
- data/test/support/models.rb +20 -5
- data/test/test_helper.rb +5 -8
- metadata +123 -98
- data/.gitignore +0 -3
- data/.gitmodules +0 -3
- data/.travis.yml +0 -15
- data/CHANGELOG.rdoc +0 -159
- data/Gemfile +0 -9
- data/README.rdoc +0 -466
- data/Rakefile +0 -27
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +0 -93
- data/lib/simple_form/components/wrapper.rb +0 -38
- data/lib/simple_form/helpers/has_errors.rb +0 -15
- data/lib/simple_form/helpers/maxlength.rb +0 -24
- data/lib/simple_form/helpers/pattern.rb +0 -28
- data/simple_form.gemspec +0 -25
- data/test/components/error_test.rb +0 -56
- data/test/components/hint_test.rb +0 -74
- data/test/components/wrapper_test.rb +0 -63
- data/test/custom_components.rb +0 -7
- data/test/form_builder_test.rb +0 -930
- data/test/inputs_test.rb +0 -995
data/test/inputs_test.rb
DELETED
@@ -1,995 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class InputTest < ActionView::TestCase
|
5
|
-
|
6
|
-
setup do
|
7
|
-
SimpleForm::Inputs::CollectionInput.reset_i18n_cache :boolean_collection
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_input_for(object, attribute_name, type, options={})
|
11
|
-
with_concat_form_for(object) do |f|
|
12
|
-
f.input(attribute_name, options.merge(:as => type))
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# ALL
|
17
|
-
test 'input should generate css class based on default input type' do
|
18
|
-
with_input_for @user, :name, :string
|
19
|
-
assert_select 'input.string'
|
20
|
-
with_input_for @user, :description, :text
|
21
|
-
assert_select 'textarea.text'
|
22
|
-
with_input_for @user, :age, :integer
|
23
|
-
assert_select 'input.integer'
|
24
|
-
with_input_for @user, :born_at, :date
|
25
|
-
assert_select 'select.date'
|
26
|
-
with_input_for @user, :created_at, :datetime
|
27
|
-
assert_select 'select.datetime'
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'input should generate disabled elements based on the disabled option' do
|
31
|
-
with_input_for @user, :name, :string, :disabled => true
|
32
|
-
assert_select 'input.string[disabled]'
|
33
|
-
with_input_for @user, :description, :text, :disabled => true
|
34
|
-
assert_select 'textarea.text[disabled]'
|
35
|
-
with_input_for @user, :age, :integer, :disabled => true
|
36
|
-
assert_select 'input.integer[disabled]'
|
37
|
-
with_input_for @user, :born_at, :date, :disabled => true
|
38
|
-
assert_select 'select.date[disabled]'
|
39
|
-
with_input_for @user, :created_at, :datetime, :disabled => true
|
40
|
-
assert_select 'select.datetime[disabled]'
|
41
|
-
|
42
|
-
with_input_for @user, :name, :string, :disabled => false
|
43
|
-
assert_select 'input.string:not([disabled])'
|
44
|
-
with_input_for @user, :description, :text, :disabled => false
|
45
|
-
assert_select 'textarea.text:not([disabled])'
|
46
|
-
with_input_for @user, :age, :integer, :disabled => false
|
47
|
-
assert_select 'input.integer:not([disabled])'
|
48
|
-
with_input_for @user, :born_at, :date, :disabled => false
|
49
|
-
assert_select 'select.date:not([disabled])'
|
50
|
-
with_input_for @user, :created_at, :datetime, :disabled => false
|
51
|
-
assert_select 'select.datetime:not([disabled])'
|
52
|
-
|
53
|
-
with_input_for @user, :name, :string
|
54
|
-
assert_select 'input.string:not([disabled])'
|
55
|
-
with_input_for @user, :description, :text
|
56
|
-
assert_select 'textarea.text:not([disabled])'
|
57
|
-
with_input_for @user, :age, :integer
|
58
|
-
assert_select 'input.integer:not([disabled])'
|
59
|
-
with_input_for @user, :born_at, :date
|
60
|
-
assert_select 'select.date:not([disabled])'
|
61
|
-
with_input_for @user, :created_at, :datetime
|
62
|
-
assert_select 'select.datetime:not([disabled])'
|
63
|
-
end
|
64
|
-
|
65
|
-
test 'input should generate autofocus attribute based on the autofocus option' do
|
66
|
-
with_input_for @user, :name, :string, :autofocus => true
|
67
|
-
assert_select 'input.string[autofocus]'
|
68
|
-
with_input_for @user, :description, :text, :autofocus => true
|
69
|
-
assert_select 'textarea.text[autofocus]'
|
70
|
-
with_input_for @user, :age, :integer, :autofocus => true
|
71
|
-
assert_select 'input.integer[autofocus]'
|
72
|
-
with_input_for @user, :born_at, :date, :autofocus => true
|
73
|
-
assert_select 'select.date[autofocus]'
|
74
|
-
with_input_for @user, :created_at, :datetime, :autofocus => true
|
75
|
-
assert_select 'select.datetime[autofocus]'
|
76
|
-
|
77
|
-
with_input_for @user, :name, :string, :autofocus => false
|
78
|
-
assert_select 'input.string:not([autofocus])'
|
79
|
-
with_input_for @user, :description, :text, :autofocus => false
|
80
|
-
assert_select 'textarea.text:not([autofocus])'
|
81
|
-
with_input_for @user, :age, :integer, :autofocus => false
|
82
|
-
assert_select 'input.integer:not([autofocus])'
|
83
|
-
with_input_for @user, :born_at, :date, :autofocus => false
|
84
|
-
assert_select 'select.date:not([autofocus])'
|
85
|
-
with_input_for @user, :created_at, :datetime, :autofocus => false
|
86
|
-
assert_select 'select.datetime:not([autofocus])'
|
87
|
-
|
88
|
-
with_input_for @user, :name, :string
|
89
|
-
assert_select 'input.string:not([autofocus])'
|
90
|
-
with_input_for @user, :description, :text
|
91
|
-
assert_select 'textarea.text:not([autofocus])'
|
92
|
-
with_input_for @user, :age, :integer
|
93
|
-
assert_select 'input.integer:not([autofocus])'
|
94
|
-
with_input_for @user, :born_at, :date
|
95
|
-
assert_select 'select.date:not([autofocus])'
|
96
|
-
with_input_for @user, :created_at, :datetime
|
97
|
-
assert_select 'select.datetime:not([autofocus])'
|
98
|
-
end
|
99
|
-
|
100
|
-
test "when not using HTML5, it does not generate autofocus attribute" do
|
101
|
-
swap SimpleForm, :html5 => false do
|
102
|
-
with_input_for @user, :name, :string, :autofocus => true
|
103
|
-
assert_no_select 'input.string[autofocus]'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'components option is deprecated' do
|
108
|
-
assert_deprecated(/The option :components of f\.input is deprecated/) do
|
109
|
-
with_input_for @user, :name, :string, :components => [:input]
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
test 'input should render components according to an optional :components option' do
|
114
|
-
ActiveSupport::Deprecation.silence do
|
115
|
-
with_input_for @user, :name, :string, :components => [:input, :label]
|
116
|
-
assert_select 'input + label'
|
117
|
-
|
118
|
-
with_input_for @user, :age, :integer, :components => [:input, :label]
|
119
|
-
assert_select 'input + label'
|
120
|
-
|
121
|
-
with_input_for @user, :active, :boolean, :components => [:label, :input]
|
122
|
-
assert_select 'label + input'
|
123
|
-
|
124
|
-
with_input_for @user, :description, :text, :components => [:input, :label]
|
125
|
-
assert_select 'textarea + label'
|
126
|
-
|
127
|
-
with_input_for @user, :password, :password, :components => [:input, :label]
|
128
|
-
assert_select 'input + label'
|
129
|
-
|
130
|
-
with_input_for @user, :name, :file, :components => [:input, :label]
|
131
|
-
assert_select 'input + label'
|
132
|
-
|
133
|
-
with_input_for @user, :country, :country, :components => [:input, :label]
|
134
|
-
assert_select 'select + label'
|
135
|
-
|
136
|
-
with_input_for @user, :time_zone, :time_zone, :components => [:input, :label]
|
137
|
-
assert_select 'select + label'
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# StringInput
|
142
|
-
test 'input should map text field to string attribute' do
|
143
|
-
with_input_for @user, :name, :string
|
144
|
-
assert_select "input#user_name[type=text][name='user[name]'][value=New in Simple Form!]"
|
145
|
-
end
|
146
|
-
|
147
|
-
test 'input should generate a password field for password attributes' do
|
148
|
-
with_input_for @user, :password, :password
|
149
|
-
assert_select "input#user_password.password[type=password][name='user[password]']"
|
150
|
-
end
|
151
|
-
|
152
|
-
test 'input should not use size attribute for decimal attributes' do
|
153
|
-
with_input_for @user, :credit_limit, :decimal
|
154
|
-
assert_no_select 'input.decimal[size]'
|
155
|
-
end
|
156
|
-
|
157
|
-
test 'input should get maxlength from column definition for string attributes' do
|
158
|
-
with_input_for @user, :name, :string
|
159
|
-
assert_select 'input.string[maxlength=100]'
|
160
|
-
end
|
161
|
-
|
162
|
-
test 'input should not get maxlength from column without size definition for string attributes' do
|
163
|
-
with_input_for @user, :action, :string
|
164
|
-
assert_no_select 'input.string[maxlength]'
|
165
|
-
end
|
166
|
-
|
167
|
-
test 'input should get size from column definition for string attributes respecting maximum value' do
|
168
|
-
with_input_for @user, :name, :string
|
169
|
-
assert_select 'input.string[size=50]'
|
170
|
-
end
|
171
|
-
|
172
|
-
test 'input should use default text size for password attributes' do
|
173
|
-
with_input_for @user, :password, :password
|
174
|
-
assert_select 'input.password[type=password][size=50]'
|
175
|
-
end
|
176
|
-
|
177
|
-
test 'input should get maxlength from column definition for password attributes' do
|
178
|
-
with_input_for @user, :password, :password
|
179
|
-
assert_select 'input.password[type=password][maxlength=100]'
|
180
|
-
end
|
181
|
-
|
182
|
-
test 'input should infer maxlength column definition from validation when present' do
|
183
|
-
with_input_for @validating_user, :name, :string
|
184
|
-
assert_select 'input.string[maxlength=25]'
|
185
|
-
end
|
186
|
-
|
187
|
-
test 'when not using HTML5, does not show maxlength attribute' do
|
188
|
-
swap SimpleForm, :html5 => false do
|
189
|
-
with_input_for @user, :password, :password
|
190
|
-
assert_no_select 'input[type=password][maxlength]'
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
test 'when not using HTML5, does not show maxlength attribute with validating lenght attribute' do
|
195
|
-
swap SimpleForm, :html5 => false do
|
196
|
-
with_input_for @validating_user, :name, :string
|
197
|
-
assert_no_select 'input.string[maxlength]'
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
test 'input should not generate placeholder by default' do
|
202
|
-
with_input_for @user, :name, :string
|
203
|
-
assert_no_select 'input[placeholder]'
|
204
|
-
end
|
205
|
-
|
206
|
-
test 'input should accept the placeholder option' do
|
207
|
-
with_input_for @user, :name, :string, :placeholder => 'Put in some text'
|
208
|
-
assert_select 'input.string[placeholder=Put in some text]'
|
209
|
-
end
|
210
|
-
|
211
|
-
test 'input should generate a password field for password attributes that accept placeholder' do
|
212
|
-
with_input_for @user, :password, :password, :placeholder => 'Password Confirmation'
|
213
|
-
assert_select 'input[type=password].password[placeholder=Password Confirmation]#user_password'
|
214
|
-
end
|
215
|
-
|
216
|
-
test 'input should use i18n to translate placeholder text' do
|
217
|
-
store_translations(:en, :simple_form => { :placeholders => { :user => {
|
218
|
-
:name => 'Name goes here'
|
219
|
-
} } }) do
|
220
|
-
with_input_for @user, :name, :string
|
221
|
-
assert_select 'input.string[placeholder=Name goes here]'
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
[:email, :url, :search, :tel].each do |type|
|
226
|
-
test "input should allow type #{type}" do
|
227
|
-
with_input_for @user, :name, type
|
228
|
-
assert_select "input.string.#{type}"
|
229
|
-
assert_select "input[type=#{type}]"
|
230
|
-
end
|
231
|
-
|
232
|
-
test "input should not allow type #{type} if HTML5 compatibility is disabled" do
|
233
|
-
swap SimpleForm, :html5 => false do
|
234
|
-
with_input_for @user, :name, type
|
235
|
-
assert_no_select "input[type=#{type}]"
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
test 'input should infer pattern from attributes when pattern is true' do
|
241
|
-
with_input_for @other_validating_user, :country, :string, :pattern => true
|
242
|
-
assert_select 'input[pattern="\w+"]'
|
243
|
-
end
|
244
|
-
|
245
|
-
test 'input should use given pattern from attributes' do
|
246
|
-
with_input_for @other_validating_user, :country, :string, :pattern => "\\d+"
|
247
|
-
assert_select 'input[pattern="\d+"]'
|
248
|
-
end
|
249
|
-
|
250
|
-
test 'input should fail if pattern is true but no pattern exists' do
|
251
|
-
assert_raise RuntimeError do
|
252
|
-
with_input_for @other_validating_user, :name, :string, :pattern => true
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
# NumericInput
|
257
|
-
test 'input should generate an integer text field for integer attributes ' do
|
258
|
-
with_input_for @user, :age, :integer
|
259
|
-
assert_select 'input[type=number].integer#user_age'
|
260
|
-
end
|
261
|
-
|
262
|
-
test 'input should generate a float text field for float attributes ' do
|
263
|
-
with_input_for @user, :age, :float
|
264
|
-
assert_select 'input[type=number].float#user_age'
|
265
|
-
end
|
266
|
-
|
267
|
-
test 'input should generate a decimal text field for decimal attributes ' do
|
268
|
-
with_input_for @user, :age, :decimal
|
269
|
-
assert_select 'input[type=number].decimal#user_age'
|
270
|
-
end
|
271
|
-
|
272
|
-
test 'input should not generate min attribute by default' do
|
273
|
-
with_input_for @user, :age, :integer
|
274
|
-
assert_no_select 'input[min]'
|
275
|
-
end
|
276
|
-
|
277
|
-
test 'input should not generate max attribute by default' do
|
278
|
-
with_input_for @user, :age, :integer
|
279
|
-
assert_no_select 'input[max]'
|
280
|
-
end
|
281
|
-
|
282
|
-
test 'input should infer min value from integer attributes with greater than validation' do
|
283
|
-
with_input_for @other_validating_user, :age, :float
|
284
|
-
assert_no_select 'input[min]'
|
285
|
-
|
286
|
-
with_input_for @other_validating_user, :age, :integer
|
287
|
-
assert_select 'input[min=18]'
|
288
|
-
end
|
289
|
-
|
290
|
-
test 'input should infer min value from integer attributes with greater than validation using symbol' do
|
291
|
-
with_input_for @validating_user, :amount, :float
|
292
|
-
assert_no_select 'input[min]'
|
293
|
-
|
294
|
-
with_input_for @validating_user, :amount, :integer
|
295
|
-
assert_select 'input[min=11]'
|
296
|
-
end
|
297
|
-
|
298
|
-
test 'input should infer min value from integer attributes with greater than or equal to validation using symbol' do
|
299
|
-
with_input_for @validating_user, :attempts, :float
|
300
|
-
assert_select 'input[min=1]'
|
301
|
-
|
302
|
-
with_input_for @validating_user, :attempts, :integer
|
303
|
-
assert_select 'input[min=1]'
|
304
|
-
end
|
305
|
-
|
306
|
-
test 'input should infer min value from integer attributes with greater than validation using proc' do
|
307
|
-
with_input_for @other_validating_user, :amount, :float
|
308
|
-
assert_no_select 'input[min]'
|
309
|
-
|
310
|
-
with_input_for @other_validating_user, :amount, :integer
|
311
|
-
assert_select 'input[min=20]'
|
312
|
-
end
|
313
|
-
|
314
|
-
test 'input should infer min value from integer attributes with greater than or equal to validation using proc' do
|
315
|
-
with_input_for @other_validating_user, :attempts, :float
|
316
|
-
assert_select 'input[min=19]'
|
317
|
-
|
318
|
-
with_input_for @other_validating_user, :attempts, :integer
|
319
|
-
assert_select 'input[min=19]'
|
320
|
-
end
|
321
|
-
|
322
|
-
test 'input should infer max value from attributes with less than validation' do
|
323
|
-
with_input_for @other_validating_user, :age, :float
|
324
|
-
assert_no_select 'input[max]'
|
325
|
-
|
326
|
-
with_input_for @other_validating_user, :age, :integer
|
327
|
-
assert_select 'input[max=99]'
|
328
|
-
end
|
329
|
-
|
330
|
-
test 'input should infer max value from attributes with less than validation using symbol' do
|
331
|
-
with_input_for @validating_user, :amount, :float
|
332
|
-
assert_no_select 'input[max]'
|
333
|
-
|
334
|
-
with_input_for @validating_user, :amount, :integer
|
335
|
-
assert_select 'input[max=99]'
|
336
|
-
end
|
337
|
-
|
338
|
-
test 'input should infer max value from attributes with less than or equal to validation using symbol' do
|
339
|
-
with_input_for @validating_user, :attempts, :float
|
340
|
-
assert_select 'input[max=100]'
|
341
|
-
|
342
|
-
with_input_for @validating_user, :attempts, :integer
|
343
|
-
assert_select 'input[max=100]'
|
344
|
-
end
|
345
|
-
|
346
|
-
test 'input should infer max value from attributes with less than validation using proc' do
|
347
|
-
with_input_for @other_validating_user, :amount, :float
|
348
|
-
assert_no_select 'input[max]'
|
349
|
-
|
350
|
-
with_input_for @other_validating_user, :amount, :integer
|
351
|
-
assert_select 'input[max=118]'
|
352
|
-
end
|
353
|
-
|
354
|
-
test 'input should infer max value from attributes with less than or equal to validation using proc' do
|
355
|
-
with_input_for @other_validating_user, :attempts, :float
|
356
|
-
assert_select 'input[max=119]'
|
357
|
-
|
358
|
-
with_input_for @other_validating_user, :attempts, :integer
|
359
|
-
assert_select 'input[max=119]'
|
360
|
-
end
|
361
|
-
|
362
|
-
test 'input should have step value of any except for integer attribute' do
|
363
|
-
with_input_for @validating_user, :age, :float
|
364
|
-
assert_select 'input[step="any"]'
|
365
|
-
|
366
|
-
with_input_for @validating_user, :age, :integer
|
367
|
-
assert_select 'input[step=1]'
|
368
|
-
end
|
369
|
-
|
370
|
-
test 'numeric input should not generate placeholder by default' do
|
371
|
-
with_input_for @user, :age, :integer
|
372
|
-
assert_no_select 'input[placeholder]'
|
373
|
-
end
|
374
|
-
|
375
|
-
test 'numeric input should accept the placeholder option' do
|
376
|
-
with_input_for @user, :age, :integer, :placeholder => 'Put in your age'
|
377
|
-
assert_select 'input.integer[placeholder=Put in your age]'
|
378
|
-
end
|
379
|
-
|
380
|
-
test 'numeric input should use i18n to translate placeholder text' do
|
381
|
-
store_translations(:en, :simple_form => { :placeholders => { :user => {
|
382
|
-
:age => 'Age goes here'
|
383
|
-
} } }) do
|
384
|
-
with_input_for @user, :age, :integer
|
385
|
-
assert_select 'input.integer[placeholder=Age goes here]'
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
[:integer, :float, :decimal].each do |type|
|
390
|
-
test "#{type} input should infer min value from attributes with greater than or equal validation" do
|
391
|
-
with_input_for @validating_user, :age, type
|
392
|
-
assert_select 'input[min=18]'
|
393
|
-
end
|
394
|
-
|
395
|
-
test "#{type} input should infer the max value from attributes with less than or equal to validation" do
|
396
|
-
with_input_for @validating_user, :age, type
|
397
|
-
assert_select 'input[max=99]'
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
# Numeric input but HTML5 disabled
|
402
|
-
test 'when not using HTML5 input should not generate field with type number and use text instead' do
|
403
|
-
swap SimpleForm, :html5 => false do
|
404
|
-
with_input_for @user, :age, :integer
|
405
|
-
assert_no_select "input[type=number]"
|
406
|
-
assert_select "input#user_age[type=text]"
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
|
-
test 'when not using HTML5 input should not use min or max or step attributes for numeric type' do
|
411
|
-
swap SimpleForm, :html5 => false do
|
412
|
-
with_input_for @validating_user, :age, :integer
|
413
|
-
assert_no_select "input[min]"
|
414
|
-
assert_no_select "input[max]"
|
415
|
-
assert_no_select "input[step]"
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
# RangeInput
|
420
|
-
test 'range input generates a input type range, based on numeric input' do
|
421
|
-
with_input_for @user, :age, :range
|
422
|
-
assert_select "input#user_age.range[type=range]"
|
423
|
-
end
|
424
|
-
|
425
|
-
test 'range input does not generate placeholder' do
|
426
|
-
with_input_for @user, :age, :range, :placeholder => "Select your age"
|
427
|
-
assert_select "input[type=range]"
|
428
|
-
assert_no_select "input[placeholder]"
|
429
|
-
end
|
430
|
-
|
431
|
-
test 'range input allows givin min and max attributes' do
|
432
|
-
with_input_for @user, :age, :range, :input_html => { :min => 10, :max => 50 }
|
433
|
-
assert_select "input[type=range][min=10][max=50]"
|
434
|
-
end
|
435
|
-
|
436
|
-
test 'range input infers min and max attributes from validations' do
|
437
|
-
with_input_for @validating_user, :age, :range
|
438
|
-
assert_select "input[type=range][min=18][max=99]"
|
439
|
-
end
|
440
|
-
|
441
|
-
test 'range input add default step attribute' do
|
442
|
-
with_input_for @validating_user, :age, :range
|
443
|
-
assert_select "input[type=range][step=1]"
|
444
|
-
end
|
445
|
-
|
446
|
-
test 'range input allows givin a step through input html options' do
|
447
|
-
with_input_for @validating_user, :age, :range, :input_html => { :step => 2 }
|
448
|
-
assert_select "input[type=range][step=2]"
|
449
|
-
end
|
450
|
-
|
451
|
-
test 'range input should not generate min attribute by default' do
|
452
|
-
with_input_for @user, :age, :range
|
453
|
-
assert_no_select 'input[min]'
|
454
|
-
end
|
455
|
-
|
456
|
-
test 'range input should not generate max attribute by default' do
|
457
|
-
with_input_for @user, :age, :range
|
458
|
-
assert_no_select 'input[max]'
|
459
|
-
end
|
460
|
-
|
461
|
-
# RangeInput iwth HTML5 disabled
|
462
|
-
test 'when not using HTML5, range input does not generate field with range type, and use text instead' do
|
463
|
-
swap SimpleForm, :html5 => false do
|
464
|
-
with_input_for @user, :age, :range
|
465
|
-
assert_no_select "input[type=number]"
|
466
|
-
assert_select "input[type=text]"
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
test 'when not using HTML5, range input should not use min or max or step attributes' do
|
471
|
-
swap SimpleForm, :html5 => false do
|
472
|
-
with_input_for @validating_user, :age, :range
|
473
|
-
assert_no_select "input[min]"
|
474
|
-
assert_no_select "input[max]"
|
475
|
-
assert_no_select "input[step]"
|
476
|
-
end
|
477
|
-
end
|
478
|
-
|
479
|
-
# BooleanInput
|
480
|
-
test 'input should generate a checkbox by default for boolean attributes' do
|
481
|
-
with_input_for @user, :active, :boolean
|
482
|
-
assert_select 'input[type=checkbox].boolean#user_active'
|
483
|
-
assert_select 'input.boolean + label.boolean.optional'
|
484
|
-
end
|
485
|
-
|
486
|
-
# MappingInput
|
487
|
-
test 'input should generate a text area for text attributes' do
|
488
|
-
with_input_for @user, :description, :text
|
489
|
-
assert_select 'textarea.text#user_description'
|
490
|
-
end
|
491
|
-
|
492
|
-
test 'input should generate a text area for text attributes that accept placeholder' do
|
493
|
-
with_input_for @user, :description, :text, :placeholder => 'Put in some text'
|
494
|
-
assert_select 'textarea.text[placeholder=Put in some text]'
|
495
|
-
end
|
496
|
-
|
497
|
-
test 'input should get maxlength from column definition for text attributes' do
|
498
|
-
with_input_for @user, :description, :text
|
499
|
-
assert_select 'textarea.text[maxlength=200]'
|
500
|
-
end
|
501
|
-
|
502
|
-
test 'input should infer maxlength column definition from validation when present for text attributes' do
|
503
|
-
with_input_for @validating_user, :description, :text
|
504
|
-
assert_select 'textarea.text[maxlength=50]'
|
505
|
-
end
|
506
|
-
|
507
|
-
test 'when not using HTML5, does not show maxlength attribute for text attributes' do
|
508
|
-
swap SimpleForm, :html5 => false do
|
509
|
-
with_input_for @user, :description, :text
|
510
|
-
assert_no_select 'textarea.text[maxlength]'
|
511
|
-
end
|
512
|
-
end
|
513
|
-
|
514
|
-
test 'when not using HTML5, does not show maxlength attribute with validating lenght text attribute' do
|
515
|
-
swap SimpleForm, :html5 => false do
|
516
|
-
with_input_for @validating_user, :name, :string
|
517
|
-
assert_no_select 'input.string[maxlength]'
|
518
|
-
end
|
519
|
-
end
|
520
|
-
|
521
|
-
test 'input should generate a file field' do
|
522
|
-
with_input_for @user, :name, :file
|
523
|
-
assert_select 'input#user_name[type=file]'
|
524
|
-
end
|
525
|
-
|
526
|
-
test "input should generate a file field that doesn't accept placeholder" do
|
527
|
-
with_input_for @user, :name, :file, :placeholder => 'Put in some text'
|
528
|
-
assert_no_select 'input[placeholder]'
|
529
|
-
end
|
530
|
-
|
531
|
-
# HiddenInput
|
532
|
-
test 'input should generate a hidden field' do
|
533
|
-
with_input_for @user, :name, :hidden
|
534
|
-
assert_no_select 'input[type=text]'
|
535
|
-
assert_select 'input#user_name[type=hidden]'
|
536
|
-
end
|
537
|
-
|
538
|
-
test 'hint should not be generated for hidden fields' do
|
539
|
-
with_input_for @user, :name, :hidden, :hint => 'Use with care...'
|
540
|
-
assert_no_select 'span.hint'
|
541
|
-
end
|
542
|
-
|
543
|
-
test 'label should not be generated for hidden inputs' do
|
544
|
-
with_input_for @user, :name, :hidden
|
545
|
-
assert_no_select 'label'
|
546
|
-
end
|
547
|
-
|
548
|
-
test 'required/optional options should not be generated for hidden inputs' do
|
549
|
-
with_input_for @user, :name, :hidden
|
550
|
-
assert_no_select 'input.required'
|
551
|
-
assert_no_select 'input[required]'
|
552
|
-
assert_no_select 'input.optional'
|
553
|
-
assert_select 'input.hidden#user_name'
|
554
|
-
end
|
555
|
-
|
556
|
-
# PriorityInput
|
557
|
-
test 'input should generate a country select field' do
|
558
|
-
with_input_for @user, :country, :country
|
559
|
-
assert_select 'select#user_country'
|
560
|
-
assert_select 'select option[value=Brazil]', 'Brazil'
|
561
|
-
assert_no_select 'select option[value=][disabled=disabled]'
|
562
|
-
end
|
563
|
-
|
564
|
-
test 'input should generate a country select with simple form default' do
|
565
|
-
swap SimpleForm, :country_priority => [ 'Brazil' ] do
|
566
|
-
with_input_for @user, :country, :country
|
567
|
-
assert_select 'select option[value=][disabled=disabled]'
|
568
|
-
end
|
569
|
-
end
|
570
|
-
|
571
|
-
test 'input should generate a time zone select field' do
|
572
|
-
with_input_for @user, :time_zone, :time_zone
|
573
|
-
assert_select 'select#user_time_zone'
|
574
|
-
assert_select 'select option[value=Brasilia]', '(GMT-03:00) Brasilia'
|
575
|
-
assert_no_select 'select option[value=][disabled=disabled]'
|
576
|
-
end
|
577
|
-
|
578
|
-
test 'input should generate a time zone select field with default' do
|
579
|
-
with_input_for @user, :time_zone, :time_zone, :default => 'Brasilia'
|
580
|
-
assert_select 'select option[value=Brasilia][selected=selected]'
|
581
|
-
assert_no_select 'select option[value=]'
|
582
|
-
end
|
583
|
-
|
584
|
-
test 'input should generate a time zone select using options priority' do
|
585
|
-
with_input_for @user, :time_zone, :time_zone, :priority => /Brasilia/
|
586
|
-
assert_select 'select option[value=][disabled=disabled]'
|
587
|
-
assert_no_select 'select option[value=]', /^$/
|
588
|
-
end
|
589
|
-
|
590
|
-
test 'priority input should not generate invalid required html attribute' do
|
591
|
-
with_input_for @user, :country, :country
|
592
|
-
assert_select 'select.required'
|
593
|
-
assert_no_select 'select[required]'
|
594
|
-
end
|
595
|
-
|
596
|
-
# DateTime input
|
597
|
-
test 'input should generate a datetime select by default for datetime attributes' do
|
598
|
-
with_input_for @user, :created_at, :datetime
|
599
|
-
1.upto(5) do |i|
|
600
|
-
assert_select "form select.datetime#user_created_at_#{i}i"
|
601
|
-
end
|
602
|
-
end
|
603
|
-
|
604
|
-
test 'input should be able to pass options to datetime select' do
|
605
|
-
with_input_for @user, :created_at, :datetime,
|
606
|
-
:disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
|
607
|
-
|
608
|
-
assert_select 'select.datetime[disabled=disabled]'
|
609
|
-
assert_select 'select.datetime option', 'ano'
|
610
|
-
assert_select 'select.datetime option', 'mês'
|
611
|
-
assert_select 'select.datetime option', 'dia'
|
612
|
-
end
|
613
|
-
|
614
|
-
test 'input should generate a date select for date attributes' do
|
615
|
-
with_input_for @user, :born_at, :date
|
616
|
-
assert_select 'select.date#user_born_at_1i'
|
617
|
-
assert_select 'select.date#user_born_at_2i'
|
618
|
-
assert_select 'select.date#user_born_at_3i'
|
619
|
-
assert_no_select 'select.date#user_born_at_4i'
|
620
|
-
end
|
621
|
-
|
622
|
-
test 'input should be able to pass options to date select' do
|
623
|
-
with_input_for @user, :born_at, :date, :as => :date,
|
624
|
-
:disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
|
625
|
-
|
626
|
-
assert_select 'select.date[disabled=disabled]'
|
627
|
-
assert_select 'select.date option', 'ano'
|
628
|
-
assert_select 'select.date option', 'mês'
|
629
|
-
assert_select 'select.date option', 'dia'
|
630
|
-
end
|
631
|
-
|
632
|
-
test 'input should be able to pass :default to date select' do
|
633
|
-
with_input_for @user, :born_at, :date, :default => Date.today
|
634
|
-
assert_select "select.date option[value=#{Date.today.year}][selected=selected]"
|
635
|
-
end
|
636
|
-
|
637
|
-
test 'input should generate a time select for time attributes' do
|
638
|
-
with_input_for @user, :delivery_time, :time
|
639
|
-
assert_select 'input[type=hidden]#user_delivery_time_1i'
|
640
|
-
assert_select 'input[type=hidden]#user_delivery_time_2i'
|
641
|
-
assert_select 'input[type=hidden]#user_delivery_time_3i'
|
642
|
-
assert_select 'select.time#user_delivery_time_4i'
|
643
|
-
assert_select 'select.time#user_delivery_time_5i'
|
644
|
-
end
|
645
|
-
|
646
|
-
test 'input should be able to pass options to time select' do
|
647
|
-
with_input_for @user, :delivery_time, :time, :required => true,
|
648
|
-
:disabled => true, :prompt => { :hour => 'hora', :minute => 'minuto' }
|
649
|
-
|
650
|
-
assert_select 'select.time[disabled=disabled]'
|
651
|
-
assert_select 'select.time option', 'hora'
|
652
|
-
assert_select 'select.time option', 'minuto'
|
653
|
-
end
|
654
|
-
|
655
|
-
test 'label should point to first option when date input type' do
|
656
|
-
with_input_for :project, :created_at, :date
|
657
|
-
assert_select 'label[for=project_created_at_1i]'
|
658
|
-
end
|
659
|
-
|
660
|
-
test 'label should point to first option when datetime input type' do
|
661
|
-
with_input_for :project, :created_at, :datetime
|
662
|
-
assert_select 'label[for=project_created_at_1i]'
|
663
|
-
end
|
664
|
-
|
665
|
-
test 'label should point to first option when time input type' do
|
666
|
-
with_input_for :project, :created_at, :time
|
667
|
-
assert_select 'label[for=project_created_at_4i]'
|
668
|
-
end
|
669
|
-
|
670
|
-
test 'date time input should not generate invalid required html attribute' do
|
671
|
-
with_input_for @user, :delivery_time, :time, :required => true
|
672
|
-
assert_select 'select.required'
|
673
|
-
assert_no_select 'select[required]'
|
674
|
-
end
|
675
|
-
|
676
|
-
# CollectionInput
|
677
|
-
test 'input should generate boolean radio buttons by default for radio types' do
|
678
|
-
with_input_for @user, :active, :radio
|
679
|
-
assert_select 'input[type=radio][value=true].radio#user_active_true'
|
680
|
-
assert_select 'input[type=radio][value=false].radio#user_active_false'
|
681
|
-
end
|
682
|
-
|
683
|
-
test 'input as radio should generate internal labels by default' do
|
684
|
-
with_input_for @user, :active, :radio
|
685
|
-
assert_select 'label[for=user_active_true]', 'Yes'
|
686
|
-
assert_select 'label[for=user_active_false]', 'No'
|
687
|
-
end
|
688
|
-
|
689
|
-
test 'input as radio should use i18n to translate internal labels' do
|
690
|
-
store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
|
691
|
-
with_input_for @user, :active, :radio
|
692
|
-
assert_select 'label[for=user_active_true]', 'Sim'
|
693
|
-
assert_select 'label[for=user_active_false]', 'Não'
|
694
|
-
end
|
695
|
-
end
|
696
|
-
|
697
|
-
test 'input should mark the checked value when using boolean and radios' do
|
698
|
-
@user.active = false
|
699
|
-
with_input_for @user, :active, :radio
|
700
|
-
assert_no_select 'input[type=radio][value=true][checked]'
|
701
|
-
assert_select 'input[type=radio][value=false][checked]'
|
702
|
-
end
|
703
|
-
|
704
|
-
test 'input should generate a boolean select with options by default for select types' do
|
705
|
-
with_input_for @user, :active, :select
|
706
|
-
assert_select 'select.select#user_active'
|
707
|
-
assert_select 'select option[value=true]', 'Yes'
|
708
|
-
assert_select 'select option[value=false]', 'No'
|
709
|
-
end
|
710
|
-
|
711
|
-
test 'input as select should use i18n to translate select boolean options' do
|
712
|
-
store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
|
713
|
-
with_input_for @user, :active, :select
|
714
|
-
assert_select 'select option[value=true]', 'Sim'
|
715
|
-
assert_select 'select option[value=false]', 'Não'
|
716
|
-
end
|
717
|
-
end
|
718
|
-
|
719
|
-
test 'input should allow overriding collection for select types' do
|
720
|
-
with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
|
721
|
-
assert_select 'select.select#user_name'
|
722
|
-
assert_select 'select option', 'Jose'
|
723
|
-
assert_select 'select option', 'Carlos'
|
724
|
-
end
|
725
|
-
|
726
|
-
test 'input should mark the selected value by default' do
|
727
|
-
@user.name = "Carlos"
|
728
|
-
with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
|
729
|
-
assert_select 'select option[selected=selected]', 'Carlos'
|
730
|
-
end
|
731
|
-
|
732
|
-
test 'input should mark the selected value also when using integers' do
|
733
|
-
@user.age = 18
|
734
|
-
with_input_for @user, :age, :select, :collection => 18..60
|
735
|
-
assert_select 'select option[selected=selected]', '18'
|
736
|
-
end
|
737
|
-
|
738
|
-
test 'input should mark the selected value when using booleans and select' do
|
739
|
-
@user.active = false
|
740
|
-
with_input_for @user, :active, :select
|
741
|
-
assert_no_select 'select option[selected][value=true]', 'Yes'
|
742
|
-
assert_select 'select option[selected][value=false]', 'No'
|
743
|
-
end
|
744
|
-
|
745
|
-
test 'input should set the correct value when using a collection that includes floats' do
|
746
|
-
with_input_for @user, :age, :select, :collection => [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
|
747
|
-
assert_select 'select option[value="2.0"]'
|
748
|
-
assert_select 'select option[value="2.5"]'
|
749
|
-
end
|
750
|
-
|
751
|
-
test 'input should set the correct values when using a collection that uses mixed values' do
|
752
|
-
with_input_for @user, :age, :select, :collection => ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
|
753
|
-
assert_select 'select option[value="Hello Kitty"]'
|
754
|
-
assert_select 'select option[value="2"]'
|
755
|
-
assert_select 'select option[value="4.5"]'
|
756
|
-
assert_select 'select option[value="johnny"]'
|
757
|
-
assert_select 'select option[value=""]'
|
758
|
-
assert_select 'select option[value="true"]'
|
759
|
-
assert_select 'select option[value="false"]'
|
760
|
-
end
|
761
|
-
|
762
|
-
test 'input should include a blank option even if :include_blank is set to false if the collection includes a nil value' do
|
763
|
-
with_input_for @user, :age, :select, :collection => [nil], :include_blank => false
|
764
|
-
assert_select 'select option[value=""]'
|
765
|
-
end
|
766
|
-
|
767
|
-
test 'input should automatically set include blank' do
|
768
|
-
with_input_for @user, :age, :select, :collection => 18..30
|
769
|
-
assert_select 'select option[value=]', ''
|
770
|
-
end
|
771
|
-
|
772
|
-
test 'input should not set include blank if otherwise is told' do
|
773
|
-
with_input_for @user, :age, :select, :collection => 18..30, :include_blank => false
|
774
|
-
assert_no_select 'select option[value=]', ''
|
775
|
-
end
|
776
|
-
|
777
|
-
test 'input should not set include blank if prompt is given' do
|
778
|
-
with_input_for @user, :age, :select, :collection => 18..30, :prompt => "Please select foo"
|
779
|
-
assert_no_select 'select option[value=]', ''
|
780
|
-
end
|
781
|
-
|
782
|
-
test 'input should not set include blank if multiple is given' do
|
783
|
-
with_input_for @user, :age, :select, :collection => 18..30, :input_html => { :multiple => true }
|
784
|
-
assert_no_select 'select option[value=]', ''
|
785
|
-
end
|
786
|
-
|
787
|
-
test 'input should detect label and value on collections' do
|
788
|
-
users = [ setup_new_user(:id => 1, :name => "Jose"), setup_new_user(:id => 2, :name => "Carlos") ]
|
789
|
-
with_input_for @user, :description, :select, :collection => users
|
790
|
-
assert_select 'select option[value=1]', 'Jose'
|
791
|
-
assert_select 'select option[value=2]', 'Carlos'
|
792
|
-
end
|
793
|
-
|
794
|
-
test 'input should disable the anothers components when the option is a object' do
|
795
|
-
with_input_for @user, :description, :select, :collection => ["Jose", "Carlos"], :disabled => true
|
796
|
-
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
797
|
-
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
798
|
-
assert_select 'select[disabled=disabled]'
|
799
|
-
assert_select 'div.disabled'
|
800
|
-
end
|
801
|
-
|
802
|
-
test 'input should not disable the anothers components when the option is a object' do
|
803
|
-
with_input_for @user, :description, :select, :collection => ["Jose", "Carlos"], :disabled => 'Jose'
|
804
|
-
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
805
|
-
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
806
|
-
assert_no_select 'select[disabled=disabled]'
|
807
|
-
assert_no_select 'div.disabled'
|
808
|
-
end
|
809
|
-
|
810
|
-
test 'input should allow disabled options with a lambda for collection select' do
|
811
|
-
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
812
|
-
:disabled => lambda { |x| x == "Carlos" }
|
813
|
-
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
814
|
-
assert_select 'select option[value=Antonio]', 'Antonio'
|
815
|
-
assert_no_select 'select option[value=Antonio][disabled]'
|
816
|
-
end
|
817
|
-
|
818
|
-
test 'input should allow disabled and label method with lambdas for collection select' do
|
819
|
-
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
820
|
-
:disabled => lambda { |x| x == "Carlos" }, :label_method => lambda { |x| x.upcase }
|
821
|
-
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
822
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
823
|
-
assert_no_select 'select option[value=Antonio][disabled]'
|
824
|
-
end
|
825
|
-
|
826
|
-
test 'input should allow a non lambda disabled option with lambda label method for collections' do
|
827
|
-
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
828
|
-
:disabled => "Carlos", :label_method => lambda { |x| x.upcase }
|
829
|
-
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
830
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
831
|
-
assert_no_select 'select option[value=Antonio][disabled]'
|
832
|
-
end
|
833
|
-
|
834
|
-
test 'input should allow selected and label method with lambdas for collection select' do
|
835
|
-
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
836
|
-
:selected => lambda { |x| x == "Carlos" }, :label_method => lambda { |x| x.upcase }
|
837
|
-
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
838
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
839
|
-
assert_no_select 'select option[value=Antonio][selected]'
|
840
|
-
end
|
841
|
-
|
842
|
-
test 'input should allow a non lambda selected option with lambda label method for collection select' do
|
843
|
-
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
844
|
-
:selected => "Carlos", :label_method => lambda { |x| x.upcase }
|
845
|
-
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
846
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
847
|
-
assert_no_select 'select option[value=Antonio][selected]'
|
848
|
-
end
|
849
|
-
|
850
|
-
test 'input should not override default selection through attribute value with label method as lambda for collection select' do
|
851
|
-
@user.name = "Carlos"
|
852
|
-
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
853
|
-
:label_method => lambda { |x| x.upcase }
|
854
|
-
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
855
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
856
|
-
assert_no_select 'select option[value=Antonio][selected]'
|
857
|
-
end
|
858
|
-
|
859
|
-
test 'input should allow overriding collection for radio types' do
|
860
|
-
with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos']
|
861
|
-
assert_select 'input[type=radio][value=Jose]'
|
862
|
-
assert_select 'input[type=radio][value=Carlos]'
|
863
|
-
assert_select 'label.collection_radio', 'Jose'
|
864
|
-
assert_select 'label.collection_radio', 'Carlos'
|
865
|
-
end
|
866
|
-
|
867
|
-
test 'input should mark the current radio value by default' do
|
868
|
-
@user.name = "Carlos"
|
869
|
-
with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos']
|
870
|
-
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
871
|
-
end
|
872
|
-
|
873
|
-
test 'input should allow using a collection with text/value arrays' do
|
874
|
-
with_input_for @user, :name, :radio, :collection => [['Jose', 'jose'], ['Carlos', 'carlos']]
|
875
|
-
assert_select 'input[type=radio][value=jose]'
|
876
|
-
assert_select 'input[type=radio][value=carlos]'
|
877
|
-
assert_select 'label.collection_radio', 'Jose'
|
878
|
-
assert_select 'label.collection_radio', 'Carlos'
|
879
|
-
end
|
880
|
-
|
881
|
-
test 'input should allow overriding only label method for collections' do
|
882
|
-
with_input_for @user, :name, :radio,
|
883
|
-
:collection => ['Jose' , 'Carlos'],
|
884
|
-
:label_method => :upcase
|
885
|
-
assert_select 'label.collection_radio', 'JOSE'
|
886
|
-
assert_select 'label.collection_radio', 'CARLOS'
|
887
|
-
end
|
888
|
-
|
889
|
-
test 'input should allow overriding only value method for collections' do
|
890
|
-
with_input_for @user, :name, :radio,
|
891
|
-
:collection => ['Jose' , 'Carlos'],
|
892
|
-
:value_method => :upcase
|
893
|
-
assert_select 'input[type=radio][value=JOSE]'
|
894
|
-
assert_select 'input[type=radio][value=CARLOS]'
|
895
|
-
end
|
896
|
-
|
897
|
-
test 'input should allow overriding label and value method for collections' do
|
898
|
-
with_input_for @user, :name, :radio,
|
899
|
-
:collection => ['Jose' , 'Carlos'],
|
900
|
-
:label_method => :upcase,
|
901
|
-
:value_method => :downcase
|
902
|
-
assert_select 'input[type=radio][value=jose]'
|
903
|
-
assert_select 'input[type=radio][value=carlos]'
|
904
|
-
assert_select 'label.collection_radio', 'JOSE'
|
905
|
-
assert_select 'label.collection_radio', 'CARLOS'
|
906
|
-
end
|
907
|
-
|
908
|
-
test 'input should allow overriding label and value method using a lambda for collections' do
|
909
|
-
with_input_for @user, :name, :radio,
|
910
|
-
:collection => ['Jose' , 'Carlos'],
|
911
|
-
:label_method => lambda { |i| i.upcase },
|
912
|
-
:value_method => lambda { |i| i.downcase }
|
913
|
-
assert_select 'input[type=radio][value=jose]'
|
914
|
-
assert_select 'input[type=radio][value=carlos]'
|
915
|
-
assert_select 'label.collection_radio', 'JOSE'
|
916
|
-
assert_select 'label.collection_radio', 'CARLOS'
|
917
|
-
end
|
918
|
-
|
919
|
-
test 'input should allow overriding label and value method using a lambda for collection selects' do
|
920
|
-
with_input_for @user, :name, :select,
|
921
|
-
:collection => ['Jose' , 'Carlos'],
|
922
|
-
:label_method => lambda { |i| i.upcase },
|
923
|
-
:value_method => lambda { |i| i.downcase }
|
924
|
-
assert_select 'select option[value=jose]', "JOSE"
|
925
|
-
assert_select 'select option[value=carlos]', "CARLOS"
|
926
|
-
end
|
927
|
-
|
928
|
-
test 'input should allow overriding only label but not value method using a lambda for collection select' do
|
929
|
-
with_input_for @user, :name, :select,
|
930
|
-
:collection => ['Jose' , 'Carlos'],
|
931
|
-
:label_method => lambda { |i| i.upcase }
|
932
|
-
assert_select 'select option[value=Jose]', "JOSE"
|
933
|
-
assert_select 'select option[value=Carlos]', "CARLOS"
|
934
|
-
end
|
935
|
-
|
936
|
-
test 'input should allow overriding only value but not label method using a lambda for collection select' do
|
937
|
-
with_input_for @user, :name, :select,
|
938
|
-
:collection => ['Jose' , 'Carlos'],
|
939
|
-
:value_method => lambda { |i| i.downcase }
|
940
|
-
assert_select 'select option[value=jose]', "Jose"
|
941
|
-
assert_select 'select option[value=carlos]', "Carlos"
|
942
|
-
end
|
943
|
-
|
944
|
-
test 'input should allow symbols for collections' do
|
945
|
-
with_input_for @user, :name, :select, :collection => [:jose, :carlos]
|
946
|
-
assert_select 'select.select#user_name'
|
947
|
-
assert_select 'select option[value=jose]', 'jose'
|
948
|
-
assert_select 'select option[value=carlos]', 'carlos'
|
949
|
-
end
|
950
|
-
|
951
|
-
test 'collection input with radio type should generate required html attribute' do
|
952
|
-
with_input_for @user, :name, :radio, :collection => ['Jose' , 'Carlos']
|
953
|
-
assert_select 'input[type=radio].required'
|
954
|
-
assert_select 'input[type=radio][required]'
|
955
|
-
end
|
956
|
-
|
957
|
-
test 'when not using HTML5, collection input with radio type should not generate required html attribute' do
|
958
|
-
swap SimpleForm, :html5 => false do
|
959
|
-
with_input_for @user, :name, :radio, :collection => ['Jose' , 'Carlos']
|
960
|
-
assert_select 'input[type=radio].required'
|
961
|
-
assert_no_select 'input[type=radio][required]'
|
962
|
-
end
|
963
|
-
end
|
964
|
-
|
965
|
-
test 'when not using browser validations, input should not generate required html attribute' do
|
966
|
-
swap SimpleForm, :browser_validations => false do
|
967
|
-
with_input_for @user, :name, :string
|
968
|
-
assert_select 'input[type=text].required'
|
969
|
-
assert_no_select 'input[type=text][required]'
|
970
|
-
end
|
971
|
-
end
|
972
|
-
|
973
|
-
test 'collection input with select type should not generate invalid required html attribute' do
|
974
|
-
with_input_for @user, :name, :select, :collection => ['Jose' , 'Carlos']
|
975
|
-
assert_select 'select.required'
|
976
|
-
assert_no_select 'select[required]'
|
977
|
-
end
|
978
|
-
|
979
|
-
# With no object
|
980
|
-
test 'input should be generated properly when object is not present' do
|
981
|
-
with_input_for :project, :name, :string
|
982
|
-
assert_select 'input.string.required#project_name'
|
983
|
-
end
|
984
|
-
|
985
|
-
test 'input as radio should be generated properly when object is not present ' do
|
986
|
-
with_input_for :project, :name, :radio
|
987
|
-
assert_select 'input.radio#project_name_true'
|
988
|
-
assert_select 'input.radio#project_name_false'
|
989
|
-
end
|
990
|
-
|
991
|
-
test 'input as select with collection should be generated properly when object is not present' do
|
992
|
-
with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
|
993
|
-
assert_select 'select.select#project_name'
|
994
|
-
end
|
995
|
-
end
|