simple_form 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- data/CHANGELOG.md +7 -0
- data/lib/simple_form/version.rb +1 -1
- metadata +2 -4
- data/test/form_builder/general_test.rb.orig +0 -380
data/CHANGELOG.md
CHANGED
data/lib/simple_form/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-10-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activemodel
|
@@ -120,7 +120,6 @@ files:
|
|
120
120
|
- test/form_builder/error_notification_test.rb
|
121
121
|
- test/form_builder/error_test.rb
|
122
122
|
- test/form_builder/general_test.rb
|
123
|
-
- test/form_builder/general_test.rb.orig
|
124
123
|
- test/form_builder/hint_test.rb
|
125
124
|
- test/form_builder/input_field_test.rb
|
126
125
|
- test/form_builder/label_test.rb
|
@@ -182,7 +181,6 @@ test_files:
|
|
182
181
|
- test/form_builder/error_notification_test.rb
|
183
182
|
- test/form_builder/error_test.rb
|
184
183
|
- test/form_builder/general_test.rb
|
185
|
-
- test/form_builder/general_test.rb.orig
|
186
184
|
- test/form_builder/hint_test.rb
|
187
185
|
- test/form_builder/input_field_test.rb
|
188
186
|
- test/form_builder/label_test.rb
|
@@ -1,380 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class FormBuilderTest < ActionView::TestCase
|
5
|
-
def with_custom_form_for(object, *args, &block)
|
6
|
-
with_concat_custom_form_for(object) do |f|
|
7
|
-
f.input(*args, &block)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'nested simple fields should yield an instance of FormBuilder' do
|
12
|
-
simple_form_for :user do |f|
|
13
|
-
f.simple_fields_for :posts do |posts_form|
|
14
|
-
assert posts_form.instance_of?(SimpleForm::FormBuilder)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'builder input is html safe' do
|
20
|
-
simple_form_for @user do |f|
|
21
|
-
assert f.input(:name).html_safe?
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'builder input should allow a block to configure input' do
|
26
|
-
with_form_for @user, :name do
|
27
|
-
text_field_tag :foo, :bar, :id => :cool
|
28
|
-
end
|
29
|
-
assert_no_select 'input.string'
|
30
|
-
assert_select 'input#cool'
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'builder should allow adding custom input mappings for default input types' do
|
34
|
-
swap SimpleForm, :input_mappings => { /count$/ => :integer } do
|
35
|
-
with_form_for @user, :post_count
|
36
|
-
assert_no_select 'form input#user_post_count.string'
|
37
|
-
assert_select 'form input#user_post_count.numeric.integer'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'builder should allow to skip input_type class' do
|
42
|
-
swap SimpleForm, :generate_additional_classes_for => [:label, :wrapper] do
|
43
|
-
with_form_for @user, :post_count
|
44
|
-
assert_no_select "form input#user_post_count.integer"
|
45
|
-
assert_select "form input#user_post_count"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
test 'builder should allow adding custom input mappings for integer input types' do
|
50
|
-
swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
|
51
|
-
with_form_for @user, :lock_version
|
52
|
-
assert_no_select 'form input#user_lock_version.integer'
|
53
|
-
assert_select 'form input#user_lock_version.hidden'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'builder uses the first matching custom input map when more than one matches' do
|
58
|
-
swap SimpleForm, :input_mappings => { /count$/ => :integer, /^post_/ => :password } do
|
59
|
-
with_form_for @user, :post_count
|
60
|
-
assert_no_select 'form input#user_post_count.password'
|
61
|
-
assert_select 'form input#user_post_count.numeric.integer'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
test 'builder uses the custom map only for matched attributes' do
|
66
|
-
swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
|
67
|
-
with_form_for @user, :post_count
|
68
|
-
assert_no_select 'form input#user_post_count.hidden'
|
69
|
-
assert_select 'form input#user_post_count.string'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# INPUT TYPES
|
74
|
-
test 'builder should generate text fields for string columns' do
|
75
|
-
with_form_for @user, :name
|
76
|
-
assert_select 'form input#user_name.string'
|
77
|
-
end
|
78
|
-
|
79
|
-
test 'builder should generate text areas for text columns' do
|
80
|
-
with_form_for @user, :description
|
81
|
-
assert_select 'form textarea#user_description.text'
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'builder should generate a checkbox for boolean columns' do
|
85
|
-
with_form_for @user, :active
|
86
|
-
assert_select 'form input[type=checkbox]#user_active.boolean'
|
87
|
-
end
|
88
|
-
|
89
|
-
test 'builder should use integer text field for integer columns' do
|
90
|
-
with_form_for @user, :age
|
91
|
-
assert_select 'form input#user_age.numeric.integer'
|
92
|
-
end
|
93
|
-
|
94
|
-
test 'builder should generate decimal text field for decimal columns' do
|
95
|
-
with_form_for @user, :credit_limit
|
96
|
-
assert_select 'form input#user_credit_limit.numeric.decimal'
|
97
|
-
end
|
98
|
-
|
99
|
-
test 'builder should generate password fields for columns that matches password' do
|
100
|
-
with_form_for @user, :password
|
101
|
-
assert_select 'form input#user_password.password'
|
102
|
-
end
|
103
|
-
|
104
|
-
test 'builder should generate country fields for columns that matches country' do
|
105
|
-
with_form_for @user, :residence_country
|
106
|
-
assert_select 'form select#user_residence_country.country'
|
107
|
-
end
|
108
|
-
|
109
|
-
test 'builder should generate time_zone fields for columns that matches time_zone' do
|
110
|
-
with_form_for @user, :time_zone
|
111
|
-
assert_select 'form select#user_time_zone.time_zone'
|
112
|
-
end
|
113
|
-
|
114
|
-
test 'builder should generate email fields for columns that matches email' do
|
115
|
-
with_form_for @user, :email
|
116
|
-
assert_select 'form input#user_email.string.email'
|
117
|
-
end
|
118
|
-
|
119
|
-
test 'builder should generate tel fields for columns that matches phone' do
|
120
|
-
with_form_for @user, :phone_number
|
121
|
-
assert_select 'form input#user_phone_number.string.tel'
|
122
|
-
end
|
123
|
-
|
124
|
-
test 'builder should generate url fields for columns that matches url' do
|
125
|
-
with_form_for @user, :url
|
126
|
-
assert_select 'form input#user_url.string.url'
|
127
|
-
end
|
128
|
-
|
129
|
-
test 'builder should generate date select for date columns' do
|
130
|
-
with_form_for @user, :born_at
|
131
|
-
assert_select 'form select#user_born_at_1i.date'
|
132
|
-
end
|
133
|
-
|
134
|
-
test 'builder should generate time select for time columns' do
|
135
|
-
with_form_for @user, :delivery_time
|
136
|
-
assert_select 'form select#user_delivery_time_4i.time'
|
137
|
-
end
|
138
|
-
|
139
|
-
test 'builder should generate datetime select for datetime columns' do
|
140
|
-
with_form_for @user, :created_at
|
141
|
-
assert_select 'form select#user_created_at_1i.datetime'
|
142
|
-
end
|
143
|
-
|
144
|
-
test 'builder should generate datetime select for timestamp columns' do
|
145
|
-
with_form_for @user, :updated_at
|
146
|
-
assert_select 'form select#user_updated_at_1i.datetime'
|
147
|
-
end
|
148
|
-
|
149
|
-
test 'builder should generate file for file columns' do
|
150
|
-
@user.avatar = mock("file")
|
151
|
-
@user.avatar.expects(:respond_to?).with(:mounted_as).returns(false)
|
152
|
-
@user.avatar.expects(:respond_to?).with(:file?).returns(false)
|
153
|
-
@user.avatar.expects(:respond_to?).with(:public_filename).returns(true)
|
154
|
-
|
155
|
-
with_form_for @user, :avatar
|
156
|
-
assert_select 'form input#user_avatar.file'
|
157
|
-
end
|
158
|
-
|
159
|
-
test 'builder should generate file for attributes that are real db columns but have file methods' do
|
160
|
-
@user.home_picture = mock("file")
|
161
|
-
@user.home_picture.expects(:respond_to?).with(:mounted_as).returns(true)
|
162
|
-
|
163
|
-
with_form_for @user, :home_picture
|
164
|
-
assert_select 'form input#user_home_picture.file'
|
165
|
-
end
|
166
|
-
|
167
|
-
test 'build should generate select if a collection is given' do
|
168
|
-
with_form_for @user, :age, :collection => 1..60
|
169
|
-
assert_select 'form select#user_age.select'
|
170
|
-
end
|
171
|
-
|
172
|
-
test 'builder should allow overriding default input type for text' do
|
173
|
-
with_form_for @user, :name, :as => :text
|
174
|
-
assert_no_select 'form input#user_name'
|
175
|
-
assert_select 'form textarea#user_name.text'
|
176
|
-
|
177
|
-
with_form_for @user, :active, :as => :radio_buttons
|
178
|
-
assert_no_select 'form input[type=checkbox]'
|
179
|
-
assert_select 'form input.radio_buttons[type=radio]', :count => 2
|
180
|
-
|
181
|
-
with_form_for @user, :born_at, :as => :string
|
182
|
-
assert_no_select 'form select'
|
183
|
-
assert_select 'form input#user_born_at.string'
|
184
|
-
end
|
185
|
-
|
186
|
-
# COMMON OPTIONS
|
187
|
-
test 'builder should add chosen form class' do
|
188
|
-
swap SimpleForm, :form_class => :my_custom_class do
|
189
|
-
with_form_for @user, :name
|
190
|
-
assert_select 'form.my_custom_class'
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
test 'builder should allow passing options to input' do
|
195
|
-
with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
|
196
|
-
assert_select 'form input#my_input.my_input.string'
|
197
|
-
end
|
198
|
-
|
199
|
-
test 'builder should not propagate input options to wrapper' do
|
200
|
-
with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
|
201
|
-
assert_no_select 'form div.input.my_input.string'
|
202
|
-
assert_select 'form input#my_input.my_input.string'
|
203
|
-
end
|
204
|
-
|
205
|
-
test 'builder should generate a input with label' do
|
206
|
-
with_form_for @user, :name
|
207
|
-
assert_select 'form label.string[for=user_name]', /Name/
|
208
|
-
end
|
209
|
-
|
210
|
-
test 'builder should be able to disable the label for a input' do
|
211
|
-
with_form_for @user, :name, :label => false
|
212
|
-
assert_no_select 'form label'
|
213
|
-
end
|
214
|
-
|
215
|
-
test 'builder should use custom label' do
|
216
|
-
with_form_for @user, :name, :label => 'Yay!'
|
217
|
-
assert_select 'form label', /Yay!/
|
218
|
-
end
|
219
|
-
|
220
|
-
test 'builder should pass options to label' do
|
221
|
-
with_form_for @user, :name, :label_html => { :id => "cool" }
|
222
|
-
assert_select 'form label#cool', /Name/
|
223
|
-
end
|
224
|
-
|
225
|
-
test 'builder should not generate hints for a input' do
|
226
|
-
with_form_for @user, :name
|
227
|
-
assert_no_select 'span.hint'
|
228
|
-
end
|
229
|
-
|
230
|
-
test 'builder should be able to add a hint for a input' do
|
231
|
-
with_form_for @user, :name, :hint => 'test'
|
232
|
-
assert_select 'span.hint', 'test'
|
233
|
-
end
|
234
|
-
|
235
|
-
test 'builder should be able to disable a hint even if it exists in i18n' do
|
236
|
-
store_translations(:en, :simple_form => { :hints => { :name => 'Hint test' } }) do
|
237
|
-
with_form_for @user, :name, :hint => false
|
238
|
-
assert_no_select 'span.hint'
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
test 'builder should pass options to hint' do
|
243
|
-
with_form_for @user, :name, :hint => 'test', :hint_html => { :id => "cool" }
|
244
|
-
assert_select 'span.hint#cool', 'test'
|
245
|
-
end
|
246
|
-
|
247
|
-
test 'builder should generate errors for attribute without errors' do
|
248
|
-
with_form_for @user, :credit_limit
|
249
|
-
assert_no_select 'span.errors'
|
250
|
-
end
|
251
|
-
|
252
|
-
test 'builder should generate errors for attribute with errors' do
|
253
|
-
with_form_for @user, :name
|
254
|
-
assert_select 'span.error', "can't be blank"
|
255
|
-
end
|
256
|
-
|
257
|
-
test 'builder should be able to disable showing errors for a input' do
|
258
|
-
with_form_for @user, :name, :error => false
|
259
|
-
assert_no_select 'span.error'
|
260
|
-
end
|
261
|
-
|
262
|
-
test 'builder should pass options to errors' do
|
263
|
-
with_form_for @user, :name, :error_html => { :id => "cool" }
|
264
|
-
assert_select 'span.error#cool', "can't be blank"
|
265
|
-
end
|
266
|
-
|
267
|
-
test 'placeholder should not be generated when set to false' do
|
268
|
-
store_translations(:en, :simple_form => { :placeholders => { :user => {
|
269
|
-
:name => 'Name goes here'
|
270
|
-
} } }) do
|
271
|
-
with_form_for @user, :name, :placeholder => false
|
272
|
-
assert_no_select 'input[placeholder]'
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
# DEFAULT OPTIONS
|
277
|
-
test 'builder should receive a default argument and pass it to the inputs' do
|
278
|
-
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
279
|
-
f.input :name
|
280
|
-
end
|
281
|
-
assert_select 'input.default_class'
|
282
|
-
end
|
283
|
-
|
284
|
-
test 'builder should receive a default argument and pass it to the inputs, respecting the specific options' do
|
285
|
-
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
286
|
-
f.input :name, :input_html => { :id => 'specific_id' }
|
287
|
-
end
|
288
|
-
assert_select 'input.default_class#specific_id'
|
289
|
-
end
|
290
|
-
|
291
|
-
test 'builder should receive a default argument and pass it to the inputs, overwriting the defaults with specific options' do
|
292
|
-
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
|
293
|
-
f.input :name, :input_html => { :id => 'specific_id' }
|
294
|
-
end
|
295
|
-
assert_select 'input.default_class#specific_id'
|
296
|
-
end
|
297
|
-
|
298
|
-
test 'builder should receive a default argument and pass it to the inputs without changing the defaults' do
|
299
|
-
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
|
300
|
-
concat(f.input :name)
|
301
|
-
concat(f.input :credit_limit)
|
302
|
-
end
|
303
|
-
|
304
|
-
assert_select "input.string.default_class[name='user[name]']"
|
305
|
-
assert_no_select "input.string[name='user[credit_limit]']"
|
306
|
-
end
|
307
|
-
|
308
|
-
<<<<<<< HEAD
|
309
|
-
test 'builder should receive a default argument and pass it to the inputs and nested form' do
|
310
|
-
@user.company = Company.new(1, 'Empresa')
|
311
|
-
|
312
|
-
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
313
|
-
concat(f.input :name)
|
314
|
-
concat(f.simple_fields_for(:company) do |company_form|
|
315
|
-
concat(company_form.input :name)
|
316
|
-
end)
|
317
|
-
end
|
318
|
-
|
319
|
-
assert_select "input.string.default_class[name='user[name]']"
|
320
|
-
assert_select "input.string.default_class[name='user[company_attributes][name]']"
|
321
|
-
=======
|
322
|
-
test 'input size and maxlength should be the column limit plus one to make room for decimal point if the user uses text instead of number for field type' do
|
323
|
-
with_concat_form_for @user do |f|
|
324
|
-
concat(f.input(:credit_limit, :as => :string))
|
325
|
-
end
|
326
|
-
|
327
|
-
assert_select "input[type=text][name='user[credit_limit]'][maxlength=16][size=16]"
|
328
|
-
assert_no_select "input[type=text][name='user[credit_limit]'][maxlength=15][size=15]"
|
329
|
-
>>>>>>> shwoodard-limit_with_decimal_point
|
330
|
-
end
|
331
|
-
|
332
|
-
# WITHOUT OBJECT
|
333
|
-
test 'builder should generate properly when object is not present' do
|
334
|
-
with_form_for :project, :name
|
335
|
-
assert_select 'form input.string#project_name'
|
336
|
-
end
|
337
|
-
|
338
|
-
test 'builder should generate password fields based on attribute name when object is not present' do
|
339
|
-
with_form_for :project, :password_confirmation
|
340
|
-
assert_select 'form input[type=password].password#project_password_confirmation'
|
341
|
-
end
|
342
|
-
|
343
|
-
test 'builder should generate text fields by default for all attributes when object is not present' do
|
344
|
-
with_form_for :project, :created_at
|
345
|
-
assert_select 'form input.string#project_created_at'
|
346
|
-
with_form_for :project, :budget
|
347
|
-
assert_select 'form input.string#project_budget'
|
348
|
-
end
|
349
|
-
|
350
|
-
test 'builder should allow overriding input type when object is not present' do
|
351
|
-
with_form_for :project, :created_at, :as => :datetime
|
352
|
-
assert_select 'form select.datetime#project_created_at_1i'
|
353
|
-
with_form_for :project, :budget, :as => :decimal
|
354
|
-
assert_select 'form input.decimal#project_budget'
|
355
|
-
end
|
356
|
-
|
357
|
-
# CUSTOM FORM BUILDER
|
358
|
-
test 'custom builder should inherit mappings' do
|
359
|
-
with_custom_form_for @user, :email
|
360
|
-
assert_select 'form input[type=email]#user_email.custom'
|
361
|
-
end
|
362
|
-
|
363
|
-
test 'form with CustomMapTypeFormBuilder should use custom map type builder' do
|
364
|
-
with_concat_custom_mapping_form_for(:user) do |user|
|
365
|
-
assert user.instance_of?(CustomMapTypeFormBuilder)
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
test 'form with CustomMapTypeFormBuilder should use custom mapping' do
|
370
|
-
with_concat_custom_mapping_form_for(:user) do |user|
|
371
|
-
assert_equal SimpleForm::Inputs::StringInput, user.class.mappings[:custom_type]
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
test 'form without CustomMapTypeFormBuilder should not use custom mapping' do
|
376
|
-
with_concat_form_for(:user) do |user|
|
377
|
-
assert_nil user.class.mappings[:custom_type]
|
378
|
-
end
|
379
|
-
end
|
380
|
-
end
|