simple_form 2.0.1 → 2.0.2
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 +21 -0
- data/MIT-LICENSE +1 -1
- data/README.md +149 -147
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +3 -1
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -5
- data/lib/simple_form/action_view_extensions/builder.rb +4 -2
- data/lib/simple_form/components/hints.rb +2 -1
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/components/min_max.rb +1 -0
- data/lib/simple_form/error_notification.rb +1 -1
- data/lib/simple_form/form_builder.rb +1 -1
- data/lib/simple_form/inputs/base.rb +19 -2
- data/lib/simple_form/inputs/boolean_input.rb +6 -1
- data/lib/simple_form/version.rb +1 -1
- data/test/action_view_extensions/builder_test.rb +6 -0
- data/test/action_view_extensions/form_helper_test.rb +18 -18
- data/test/form_builder/association_test.rb +3 -3
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/general_test.rb +14 -0
- data/test/form_builder/general_test.rb.orig +380 -0
- data/test/form_builder/hint_test.rb +16 -0
- data/test/form_builder/wrapper_test.rb +17 -4
- data/test/inputs/boolean_input_test.rb +14 -0
- data/test/inputs/discovery_test.rb +9 -1
- data/test/inputs/numeric_input_test.rb +6 -0
- data/test/inputs/string_input_test.rb +6 -0
- data/test/support/discovery_inputs.rb +6 -0
- data/test/support/misc_helpers.rb +11 -1
- data/test/support/models.rb +7 -3
- data/test/test_helper.rb +2 -5
- metadata +20 -10
- data/test/support/mock_response.rb +0 -14
@@ -9,95 +9,95 @@ class FormHelperTest < ActionView::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test 'SimpleForm should add default class to form' do
|
12
|
-
|
12
|
+
with_concat_form_for(:user)
|
13
13
|
assert_select 'form.simple_form'
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'SimpleForm should use default browser validations by default' do
|
17
|
-
|
17
|
+
with_concat_form_for(:user)
|
18
18
|
assert_no_select 'form[novalidate]'
|
19
19
|
end
|
20
20
|
|
21
21
|
test 'SimpleForm should not use default browser validations if specified in the configuration options' do
|
22
22
|
swap SimpleForm, :browser_validations => false do
|
23
|
-
|
23
|
+
with_concat_form_for(:user)
|
24
24
|
assert_select 'form[novalidate="novalidate"]'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
test 'a form specific disabled validation option should override the default enabled browser validation configuration option' do
|
29
|
-
|
29
|
+
with_concat_form_for(:user, :html => { :novalidate => true })
|
30
30
|
assert_select 'form[novalidate="novalidate"]'
|
31
31
|
end
|
32
32
|
|
33
33
|
test 'a form specific enabled validation option should override the disabled browser validation configuration option' do
|
34
34
|
swap SimpleForm, :browser_validations => false do
|
35
|
-
|
35
|
+
with_concat_form_for(:user, :html => { :novalidate => false })
|
36
36
|
assert_no_select 'form[novalidate]'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
test 'SimpleForm should add object name as css class to form when object is not present' do
|
41
|
-
|
41
|
+
with_concat_form_for(:user, :html => { :novalidate => true })
|
42
42
|
assert_select 'form.simple_form.user'
|
43
43
|
end
|
44
44
|
|
45
45
|
test 'SimpleForm should add :as option as css class to form when object is not present' do
|
46
|
-
|
46
|
+
with_concat_form_for(:user, :as => 'superuser')
|
47
47
|
assert_select 'form.simple_form.superuser'
|
48
48
|
end
|
49
49
|
|
50
50
|
test 'SimpleForm should add object class name with new prefix as css class to form if record is not persisted' do
|
51
51
|
@user.new_record!
|
52
|
-
|
52
|
+
with_concat_form_for(@user)
|
53
53
|
assert_select 'form.simple_form.new_user'
|
54
54
|
end
|
55
55
|
|
56
56
|
test 'SimpleForm should add :as option with new prefix as css class to form if record is not persisted' do
|
57
57
|
@user.new_record!
|
58
|
-
|
58
|
+
with_concat_form_for(@user, :as => 'superuser')
|
59
59
|
assert_select 'form.simple_form.new_superuser'
|
60
60
|
end
|
61
61
|
|
62
62
|
test 'SimpleForm should add edit class prefix as css class to form if record is persisted' do
|
63
|
-
|
63
|
+
with_concat_form_for(@user)
|
64
64
|
assert_select 'form.simple_form.edit_user'
|
65
65
|
end
|
66
66
|
|
67
67
|
test 'SimpleForm should add :as options with edit prefix as css class to form if record is persisted' do
|
68
|
-
|
68
|
+
with_concat_form_for(@user, :as => 'superuser')
|
69
69
|
assert_select 'form.simple_form.edit_superuser'
|
70
70
|
end
|
71
71
|
|
72
72
|
test 'SimpleForm should not add object class to form if css_class is specified' do
|
73
|
-
|
73
|
+
with_concat_form_for(:user, :html => {:class => nil})
|
74
74
|
assert_no_select 'form.user'
|
75
75
|
end
|
76
76
|
|
77
77
|
test 'SimpleForm should add custom class to form if css_class is specified' do
|
78
|
-
|
78
|
+
with_concat_form_for(:user, :html => {:class => 'my_class'})
|
79
79
|
assert_select 'form.my_class'
|
80
80
|
end
|
81
81
|
|
82
82
|
test 'pass options to SimpleForm' do
|
83
|
-
|
83
|
+
with_concat_form_for(:user, :url => '/account', :html => { :id => 'my_form' })
|
84
84
|
assert_select 'form#my_form'
|
85
85
|
assert_select 'form[action=/account]'
|
86
86
|
end
|
87
87
|
|
88
88
|
test 'fields for yields an instance of FormBuilder' do
|
89
|
-
|
89
|
+
with_concat_form_for(:user) do |f|
|
90
90
|
assert f.instance_of?(SimpleForm::FormBuilder)
|
91
|
-
end
|
91
|
+
end
|
92
92
|
end
|
93
93
|
|
94
94
|
test 'fields for with a hash like model yeilds an instance of FormBuilder' do
|
95
95
|
@hash_backed_author = HashBackedAuthor.new
|
96
96
|
|
97
|
-
|
97
|
+
with_concat_fields_for(:author, @hash_backed_author) do |f|
|
98
98
|
assert f.instance_of?(SimpleForm::FormBuilder)
|
99
99
|
f.input :name
|
100
|
-
end
|
100
|
+
end
|
101
101
|
|
102
102
|
assert_select "input[name='author[name]'][value='hash backed author']"
|
103
103
|
end
|
@@ -41,7 +41,7 @@ class AssociationTest < ActionView::TestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
test 'builder preloads collection association' do
|
44
|
-
value = @user.tags
|
44
|
+
value = @user.tags = Object.new
|
45
45
|
value.expects(:to_a).returns(value)
|
46
46
|
with_association_for @user, :tags
|
47
47
|
assert_select 'form select.select#user_tag_ids'
|
@@ -51,7 +51,7 @@ class AssociationTest < ActionView::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
test 'builder does not preload collection association if preload is false' do
|
54
|
-
value = @user.company
|
54
|
+
value = @user.company = Object.new
|
55
55
|
value.expects(:to_a).never
|
56
56
|
with_association_for @user, :company, :preload => false
|
57
57
|
assert_select 'form select.select#user_company_id'
|
@@ -61,7 +61,7 @@ class AssociationTest < ActionView::TestCase
|
|
61
61
|
end
|
62
62
|
|
63
63
|
test 'builder does not preload non-collection association' do
|
64
|
-
value = @user.company
|
64
|
+
value = @user.company = Object.new
|
65
65
|
value.expects(:to_a).never
|
66
66
|
with_association_for @user, :company, :preload => false
|
67
67
|
assert_select 'form select.select#user_company_id'
|
@@ -23,7 +23,7 @@ class ErrorNotificationTest < ActionView::TestCase
|
|
23
23
|
|
24
24
|
test 'error notification is generated when the object has some error' do
|
25
25
|
with_error_notification_for @user
|
26
|
-
assert_select 'p.error_notification', '
|
26
|
+
assert_select 'p.error_notification', 'Please review the problems below:'
|
27
27
|
end
|
28
28
|
|
29
29
|
test 'error notification uses I18n based on model to generate the notification message' do
|
@@ -305,6 +305,20 @@ class FormBuilderTest < ActionView::TestCase
|
|
305
305
|
assert_no_select "input.string[name='user[credit_limit]']"
|
306
306
|
end
|
307
307
|
|
308
|
+
test 'builder should receive a default argument and pass it to the inputs and nested form' do
|
309
|
+
@user.company = Company.new(1, 'Empresa')
|
310
|
+
|
311
|
+
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
312
|
+
concat(f.input :name)
|
313
|
+
concat(f.simple_fields_for(:company) do |company_form|
|
314
|
+
concat(company_form.input :name)
|
315
|
+
end)
|
316
|
+
end
|
317
|
+
|
318
|
+
assert_select "input.string.default_class[name='user[name]']"
|
319
|
+
assert_select "input.string.default_class[name='user[company_attributes][name]']"
|
320
|
+
end
|
321
|
+
|
308
322
|
# WITHOUT OBJECT
|
309
323
|
test 'builder should generate properly when object is not present' do
|
310
324
|
with_form_for :project, :name
|
@@ -0,0 +1,380 @@
|
|
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
|
@@ -41,6 +41,12 @@ class HintTest < ActionView::TestCase
|
|
41
41
|
with_hint_for @user, :name, :hint => 'Yay!', :id => 'hint', :class => 'yay'
|
42
42
|
assert_select 'span#hint.hint.yay'
|
43
43
|
end
|
44
|
+
|
45
|
+
test 'hint should be output as html_safe' do
|
46
|
+
with_hint_for @user, :name, :hint => '<b>Bold</b> and not...'
|
47
|
+
assert_select 'span.hint', 'Bold and not...'
|
48
|
+
end
|
49
|
+
|
44
50
|
|
45
51
|
# Without attribute name
|
46
52
|
|
@@ -104,6 +110,16 @@ class HintTest < ActionView::TestCase
|
|
104
110
|
assert_select 'span.hint', /My company!/
|
105
111
|
end
|
106
112
|
end
|
113
|
+
|
114
|
+
test 'hint should output translations as html_safe' do
|
115
|
+
store_translations(:en, :simple_form => { :hints => { :user => {
|
116
|
+
:edit => { :name => '<b>This is bold</b> and this is not...' }
|
117
|
+
} } }) do
|
118
|
+
with_hint_for @user, :name
|
119
|
+
assert_select 'span.hint', 'This is bold and this is not...'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
107
123
|
|
108
124
|
# No object
|
109
125
|
|
@@ -99,16 +99,16 @@ class WrapperTest < ActionView::TestCase
|
|
99
99
|
|
100
100
|
test 'custom wrappers on a form basis' do
|
101
101
|
swap_wrapper :another do
|
102
|
-
|
102
|
+
with_concat_form_for(@user) do |f|
|
103
103
|
f.input :name
|
104
|
-
|
104
|
+
end
|
105
105
|
|
106
106
|
assert_no_select "section.custom_wrapper div.another_wrapper label"
|
107
107
|
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
108
108
|
|
109
|
-
|
109
|
+
with_concat_form_for(@user, :wrapper => :another) do |f|
|
110
110
|
f.input :name
|
111
|
-
|
111
|
+
end
|
112
112
|
|
113
113
|
assert_select "section.custom_wrapper div.another_wrapper label"
|
114
114
|
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
@@ -141,6 +141,19 @@ class WrapperTest < ActionView::TestCase
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
+
test 'do not duplicate label classes for different inputs' do
|
145
|
+
swap_wrapper :default, self.custom_wrapper_with_label_html_option do
|
146
|
+
with_concat_form_for(@user) do |f|
|
147
|
+
concat f.input :name, :required => false
|
148
|
+
concat f.input :email, :as => :email, :required => true
|
149
|
+
end
|
150
|
+
|
151
|
+
assert_select "label.string.optional.extra-label-class[for='user_name']"
|
152
|
+
assert_select "label.email.required.extra-label-class[for='user_email']"
|
153
|
+
assert_no_select "label.string.optional.extra-label-class[for='user_email']"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
144
157
|
test 'raise error when wrapper not found' do
|
145
158
|
assert_raise SimpleForm::WrapperNotFound do
|
146
159
|
with_form_for @user, :name, :wrapper => :not_found
|
@@ -29,6 +29,20 @@ class BooleanInputTest < ActionView::TestCase
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
test 'input boolean with nested allows :inline_label' do
|
33
|
+
swap SimpleForm, :boolean_style => :nested do
|
34
|
+
with_input_for @user, :active, :boolean, :label => false, :inline_label => 'I am so inline.'
|
35
|
+
assert_select 'label.checkbox', :text => 'I am so inline.'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'input boolean with nested style creates an inline label using the default label text when inline_label option set to true' do
|
40
|
+
swap SimpleForm, :boolean_style => :nested do
|
41
|
+
with_input_for @user, :active, :boolean, :label => false, :inline_label => true
|
42
|
+
assert_select 'label.checkbox', :text => 'Active'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
32
46
|
test 'input boolean with nested generates a manual hidden field for checkbox outside the label, to recreate Rails functionality with valid html5' do
|
33
47
|
swap SimpleForm, :boolean_style => :nested do
|
34
48
|
with_input_for @user, :active, :boolean
|
@@ -12,6 +12,7 @@ class DiscoveryTest < ActionView::TestCase
|
|
12
12
|
Object.send :remove_const, :StringInput
|
13
13
|
Object.send :remove_const, :NumericInput
|
14
14
|
Object.send :remove_const, :CustomizedInput
|
15
|
+
Object.send :remove_const, :CollectionSelectInput
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -58,4 +59,11 @@ class DiscoveryTest < ActionView::TestCase
|
|
58
59
|
assert_select 'form section input#user_age.numeric.integer'
|
59
60
|
end
|
60
61
|
end
|
61
|
-
|
62
|
+
|
63
|
+
test 'new inputs can override the input_html_options' do
|
64
|
+
discovery do
|
65
|
+
with_form_for @user, :active, :as => :select
|
66
|
+
assert_select 'form select#user_active.select.chosen'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -164,4 +164,10 @@ class NumericInputTest < ActionView::TestCase
|
|
164
164
|
assert_select 'input[max=99]'
|
165
165
|
end
|
166
166
|
end
|
167
|
+
|
168
|
+
test 'min_max should not emit max value as bare string' do
|
169
|
+
with_input_for @other_validating_user, :age, :integer
|
170
|
+
assert_select 'input[max]'
|
171
|
+
assert_no_select 'div', %r{^99}
|
172
|
+
end
|
167
173
|
end
|