simple_form 2.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +77 -33
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +387 -187
  5. data/lib/generators/simple_form/install_generator.rb +4 -4
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +45 -22
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +128 -24
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +87 -6
  10. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
  11. data/lib/simple_form/action_view_extensions/builder.rb +2 -319
  12. data/lib/simple_form/action_view_extensions/form_helper.rb +8 -11
  13. data/lib/simple_form/components/errors.rb +28 -2
  14. data/lib/simple_form/components/hints.rb +8 -3
  15. data/lib/simple_form/components/html5.rb +6 -3
  16. data/lib/simple_form/components/label_input.rb +20 -2
  17. data/lib/simple_form/components/labels.rb +14 -10
  18. data/lib/simple_form/components/maxlength.rb +2 -9
  19. data/lib/simple_form/components/min_max.rb +1 -1
  20. data/lib/simple_form/components/pattern.rb +3 -3
  21. data/lib/simple_form/components/placeholders.rb +2 -2
  22. data/lib/simple_form/components/readonly.rb +1 -1
  23. data/lib/simple_form/components.rb +1 -1
  24. data/lib/simple_form/error_notification.rb +2 -2
  25. data/lib/simple_form/form_builder.rb +262 -107
  26. data/lib/simple_form/helpers.rb +6 -6
  27. data/lib/simple_form/inputs/base.rb +37 -16
  28. data/lib/simple_form/inputs/block_input.rb +2 -2
  29. data/lib/simple_form/inputs/boolean_input.rb +33 -18
  30. data/lib/simple_form/inputs/collection_input.rb +34 -13
  31. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +7 -12
  32. data/lib/simple_form/inputs/collection_select_input.rb +4 -2
  33. data/lib/simple_form/inputs/date_time_input.rb +23 -9
  34. data/lib/simple_form/inputs/file_input.rb +4 -2
  35. data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
  36. data/lib/simple_form/inputs/hidden_input.rb +4 -2
  37. data/lib/simple_form/inputs/numeric_input.rb +3 -8
  38. data/lib/simple_form/inputs/password_input.rb +4 -3
  39. data/lib/simple_form/inputs/priority_input.rb +4 -2
  40. data/lib/simple_form/inputs/range_input.rb +1 -1
  41. data/lib/simple_form/inputs/string_input.rb +4 -3
  42. data/lib/simple_form/inputs/text_input.rb +4 -2
  43. data/lib/simple_form/railtie.rb +14 -0
  44. data/lib/simple_form/tags.rb +68 -0
  45. data/lib/simple_form/version.rb +1 -1
  46. data/lib/simple_form/wrappers/builder.rb +11 -35
  47. data/lib/simple_form/wrappers/leaf.rb +28 -0
  48. data/lib/simple_form/wrappers/many.rb +7 -7
  49. data/lib/simple_form/wrappers/root.rb +2 -2
  50. data/lib/simple_form/wrappers/single.rb +5 -3
  51. data/lib/simple_form/wrappers.rb +2 -1
  52. data/lib/simple_form.rb +99 -52
  53. data/test/action_view_extensions/builder_test.rb +113 -127
  54. data/test/action_view_extensions/form_helper_test.rb +58 -30
  55. data/test/components/label_test.rb +83 -83
  56. data/test/form_builder/association_test.rb +96 -61
  57. data/test/form_builder/button_test.rb +14 -14
  58. data/test/form_builder/error_notification_test.rb +9 -9
  59. data/test/form_builder/error_test.rb +159 -34
  60. data/test/form_builder/general_test.rb +176 -121
  61. data/test/form_builder/hint_test.rb +43 -37
  62. data/test/form_builder/input_field_test.rb +99 -52
  63. data/test/form_builder/label_test.rb +67 -15
  64. data/test/form_builder/wrapper_test.rb +157 -41
  65. data/test/generators/simple_form_generator_test.rb +4 -4
  66. data/test/inputs/boolean_input_test.rb +92 -24
  67. data/test/inputs/collection_check_boxes_input_test.rb +150 -71
  68. data/test/inputs/collection_radio_buttons_input_test.rb +213 -113
  69. data/test/inputs/collection_select_input_test.rb +221 -85
  70. data/test/inputs/datetime_input_test.rb +125 -47
  71. data/test/inputs/disabled_test.rb +25 -25
  72. data/test/inputs/discovery_test.rb +60 -10
  73. data/test/inputs/file_input_test.rb +3 -3
  74. data/test/inputs/general_test.rb +48 -32
  75. data/test/inputs/grouped_collection_select_input_test.rb +76 -27
  76. data/test/inputs/hidden_input_test.rb +6 -5
  77. data/test/inputs/numeric_input_test.rb +46 -46
  78. data/test/inputs/priority_input_test.rb +21 -15
  79. data/test/inputs/readonly_test.rb +31 -31
  80. data/test/inputs/required_test.rb +30 -18
  81. data/test/inputs/string_input_test.rb +53 -52
  82. data/test/inputs/text_input_test.rb +15 -8
  83. data/test/simple_form_test.rb +8 -0
  84. data/test/support/discovery_inputs.rb +32 -2
  85. data/test/support/misc_helpers.rb +130 -29
  86. data/test/support/mock_controller.rb +6 -6
  87. data/test/support/models.rb +125 -71
  88. data/test/test_helper.rb +28 -35
  89. metadata +17 -29
  90. data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
  91. data/lib/simple_form/core_ext/hash.rb +0 -16
  92. data/lib/simple_form/form_builder.rb.orig +0 -486
  93. data/lib/simple_form/version.rb.orig +0 -7
@@ -8,7 +8,7 @@ class FormBuilderTest < ActionView::TestCase
8
8
  end
9
9
  end
10
10
 
11
- test 'nested simple fields should yield an instance of FormBuilder' do
11
+ test 'nested simple fields yields an instance of FormBuilder' do
12
12
  simple_form_for :user do |f|
13
13
  f.simple_fields_for :posts do |posts_form|
14
14
  assert posts_form.instance_of?(SimpleForm::FormBuilder)
@@ -22,32 +22,51 @@ class FormBuilderTest < ActionView::TestCase
22
22
  end
23
23
  end
24
24
 
25
- test 'builder input should allow a block to configure input' do
25
+ test 'builder works without controller' do
26
+ stub_any_instance ActionView::TestCase, :controller, nil do
27
+ simple_form_for @user do |f|
28
+ assert f.input(:name)
29
+ end
30
+ end
31
+ end
32
+
33
+ test 'builder input allows a block to configure input' do
26
34
  with_form_for @user, :name do
27
- text_field_tag :foo, :bar, :id => :cool
35
+ text_field_tag :foo, :bar, id: :cool
28
36
  end
29
37
  assert_no_select 'input.string'
30
38
  assert_select 'input#cool'
31
39
  end
32
40
 
33
- test 'builder should allow adding custom input mappings for default input types' do
34
- swap SimpleForm, :input_mappings => { /count$/ => :integer } do
41
+ test 'builder allows adding custom input mappings for default input types' do
42
+ swap SimpleForm, input_mappings: { /count$/ => :integer } do
35
43
  with_form_for @user, :post_count
36
44
  assert_no_select 'form input#user_post_count.string'
37
45
  assert_select 'form input#user_post_count.numeric.integer'
38
46
  end
39
47
  end
40
48
 
41
- test 'builder should allow to skip input_type class' do
42
- swap SimpleForm, :generate_additional_classes_for => [:label, :wrapper] do
49
+ test 'builder does not override custom input mappings for custom collection' do
50
+ swap SimpleForm, input_mappings: { /gender$/ => :check_boxes } do
51
+ with_concat_form_for @user do |f|
52
+ f.input :gender, collection: [:male, :female]
53
+ end
54
+
55
+ assert_no_select 'select option', 'Male'
56
+ assert_select 'input[type=checkbox][value=male]'
57
+ end
58
+ end
59
+
60
+ test 'builder allows to skip input_type class' do
61
+ swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
43
62
  with_form_for @user, :post_count
44
63
  assert_no_select "form input#user_post_count.integer"
45
64
  assert_select "form input#user_post_count"
46
65
  end
47
66
  end
48
67
 
49
- test 'builder should allow to add additional classes only for wrapper' do
50
- swap SimpleForm, :generate_additional_classes_for => [:wrapper] do
68
+ test 'builder allows to add additional classes only for wrapper' do
69
+ swap SimpleForm, generate_additional_classes_for: [:wrapper] do
51
70
  with_form_for @user, :post_count
52
71
  assert_no_select "form input#user_post_count.string"
53
72
  assert_no_select "form label#user_post_count.string"
@@ -55,8 +74,8 @@ class FormBuilderTest < ActionView::TestCase
55
74
  end
56
75
  end
57
76
 
58
- test 'builder should allow adding custom input mappings for integer input types' do
59
- swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
77
+ test 'builder allows adding custom input mappings for integer input types' do
78
+ swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
60
79
  with_form_for @user, :lock_version
61
80
  assert_no_select 'form input#user_lock_version.integer'
62
81
  assert_select 'form input#user_lock_version.hidden'
@@ -64,7 +83,7 @@ class FormBuilderTest < ActionView::TestCase
64
83
  end
65
84
 
66
85
  test 'builder uses the first matching custom input map when more than one matches' do
67
- swap SimpleForm, :input_mappings => { /count$/ => :integer, /^post_/ => :password } do
86
+ swap SimpleForm, input_mappings: { /count$/ => :integer, /^post_/ => :password } do
68
87
  with_form_for @user, :post_count
69
88
  assert_no_select 'form input#user_post_count.password'
70
89
  assert_select 'form input#user_post_count.numeric.integer'
@@ -72,265 +91,301 @@ class FormBuilderTest < ActionView::TestCase
72
91
  end
73
92
 
74
93
  test 'builder uses the custom map only for matched attributes' do
75
- swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
94
+ swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
76
95
  with_form_for @user, :post_count
77
96
  assert_no_select 'form input#user_post_count.hidden'
78
97
  assert_select 'form input#user_post_count.string'
79
98
  end
80
99
  end
81
100
 
101
+ test 'builder allow to use numbers in the model name' do
102
+ user = UserNumber1And2.build(tags: [Tag.new(nil, 'Tag1')])
103
+
104
+ with_concat_form_for(user, url: '/') do |f|
105
+ f.simple_fields_for(:tags) do |tags|
106
+ tags.input :name
107
+ end
108
+ end
109
+
110
+ assert_select 'form .user_number1_and2_tags_name'
111
+ assert_no_select 'form .user_number1_and2_tags_1_name'
112
+ end
113
+
82
114
  # INPUT TYPES
83
- test 'builder should generate text fields for string columns' do
115
+ test 'builder generates text fields for string columns' do
84
116
  with_form_for @user, :name
85
117
  assert_select 'form input#user_name.string'
86
118
  end
87
119
 
88
- test 'builder should generate text areas for text columns' do
120
+ test 'builder generates text areas for text columns' do
89
121
  with_form_for @user, :description
90
122
  assert_select 'form textarea#user_description.text'
91
123
  end
92
124
 
93
- test 'builder should generate a checkbox for boolean columns' do
125
+ test 'builder generates a checkbox for boolean columns' do
94
126
  with_form_for @user, :active
95
127
  assert_select 'form input[type=checkbox]#user_active.boolean'
96
128
  end
97
129
 
98
- test 'builder should use integer text field for integer columns' do
130
+ test 'builder uses integer text field for integer columns' do
99
131
  with_form_for @user, :age
100
132
  assert_select 'form input#user_age.numeric.integer'
101
133
  end
102
134
 
103
- test 'builder should generate decimal text field for decimal columns' do
135
+ test 'builder generates decimal text field for decimal columns' do
104
136
  with_form_for @user, :credit_limit
105
137
  assert_select 'form input#user_credit_limit.numeric.decimal'
106
138
  end
107
139
 
108
- test 'builder should generate password fields for columns that matches password' do
140
+ test 'builder generates uuid fields for uuid columns' do
141
+ with_form_for @user, :uuid
142
+ assert_select 'form input#user_uuid.string.uuid'
143
+ end
144
+
145
+ test 'builder generates password fields for columns that matches password' do
109
146
  with_form_for @user, :password
110
147
  assert_select 'form input#user_password.password'
111
148
  end
112
149
 
113
- test 'builder should generate country fields for columns that matches country' do
150
+ test 'builder generates country fields for columns that matches country' do
114
151
  with_form_for @user, :residence_country
115
152
  assert_select 'form select#user_residence_country.country'
116
153
  end
117
154
 
118
- test 'builder should generate time_zone fields for columns that matches time_zone' do
155
+ test 'builder generates time_zone fields for columns that matches time_zone' do
119
156
  with_form_for @user, :time_zone
120
157
  assert_select 'form select#user_time_zone.time_zone'
121
158
  end
122
159
 
123
- test 'builder should generate email fields for columns that matches email' do
160
+ test 'builder generates email fields for columns that matches email' do
124
161
  with_form_for @user, :email
125
162
  assert_select 'form input#user_email.string.email'
126
163
  end
127
164
 
128
- test 'builder should generate tel fields for columns that matches phone' do
165
+ test 'builder generates tel fields for columns that matches phone' do
129
166
  with_form_for @user, :phone_number
130
167
  assert_select 'form input#user_phone_number.string.tel'
131
168
  end
132
169
 
133
- test 'builder should generate url fields for columns that matches url' do
170
+ test 'builder generates url fields for columns that matches url' do
134
171
  with_form_for @user, :url
135
172
  assert_select 'form input#user_url.string.url'
136
173
  end
137
174
 
138
- test 'builder should generate date select for date columns' do
175
+ test 'builder generates date select for date columns' do
139
176
  with_form_for @user, :born_at
140
177
  assert_select 'form select#user_born_at_1i.date'
141
178
  end
142
179
 
143
- test 'builder should generate time select for time columns' do
180
+ test 'builder generates time select for time columns' do
144
181
  with_form_for @user, :delivery_time
145
182
  assert_select 'form select#user_delivery_time_4i.time'
146
183
  end
147
184
 
148
- test 'builder should generate datetime select for datetime columns' do
185
+ test 'builder generates datetime select for datetime columns' do
149
186
  with_form_for @user, :created_at
150
187
  assert_select 'form select#user_created_at_1i.datetime'
151
188
  end
152
189
 
153
- test 'builder should generate datetime select for timestamp columns' do
190
+ test 'builder generates datetime select for timestamp columns' do
154
191
  with_form_for @user, :updated_at
155
192
  assert_select 'form select#user_updated_at_1i.datetime'
156
193
  end
157
194
 
158
- test 'builder should generate file for file columns' do
159
- @user.avatar = mock("file")
160
- @user.avatar.expects(:respond_to?).with(:mounted_as).returns(false)
161
- @user.avatar.expects(:respond_to?).with(:file?).returns(false)
162
- @user.avatar.expects(:respond_to?).with(:public_filename).returns(true)
195
+ test 'builder generates file for file columns' do
196
+ @user.avatar = MiniTest::Mock.new
197
+ @user.avatar.expect(:public_filename, true)
163
198
 
164
199
  with_form_for @user, :avatar
165
200
  assert_select 'form input#user_avatar.file'
166
201
  end
167
202
 
168
- test 'builder should generate file for attributes that are real db columns but have file methods' do
169
- @user.home_picture = mock("file")
170
- @user.home_picture.expects(:respond_to?).with(:mounted_as).returns(true)
203
+ test 'builder generates file for attributes that are real db columns but have file methods' do
204
+ @user.home_picture = MiniTest::Mock.new
205
+ @user.home_picture.expect(:mounted_as, true)
171
206
 
172
207
  with_form_for @user, :home_picture
173
208
  assert_select 'form input#user_home_picture.file'
174
209
  end
175
210
 
176
- test 'build should generate select if a collection is given' do
177
- with_form_for @user, :age, :collection => 1..60
211
+ test 'build generates select if a collection is given' do
212
+ with_form_for @user, :age, collection: 1..60
178
213
  assert_select 'form select#user_age.select'
179
214
  end
180
215
 
181
- test 'builder should allow overriding default input type for text' do
182
- with_form_for @user, :name, :as => :text
216
+ test 'builder allows overriding default input type for text' do
217
+ with_form_for @user, :name, as: :text
183
218
  assert_no_select 'form input#user_name'
184
219
  assert_select 'form textarea#user_name.text'
185
220
 
186
- with_form_for @user, :active, :as => :radio_buttons
221
+ with_form_for @user, :active, as: :radio_buttons
187
222
  assert_no_select 'form input[type=checkbox]'
188
- assert_select 'form input.radio_buttons[type=radio]', :count => 2
223
+ assert_select 'form input.radio_buttons[type=radio]', count: 2
189
224
 
190
- with_form_for @user, :born_at, :as => :string
225
+ with_form_for @user, :born_at, as: :string
191
226
  assert_no_select 'form select'
192
227
  assert_select 'form input#user_born_at.string'
193
228
  end
194
229
 
195
230
  # COMMON OPTIONS
196
- test 'builder should add chosen form class' do
197
- swap SimpleForm, :form_class => :my_custom_class do
231
+ # Remove this test when SimpleForm.form_class is removed in 4.x
232
+ test 'builder adds chosen form class' do
233
+ ActiveSupport::Deprecation.silence do
234
+ swap SimpleForm, form_class: :my_custom_class do
235
+ with_form_for @user, :name
236
+ assert_select 'form.my_custom_class'
237
+ end
238
+ end
239
+ end
240
+
241
+ # Remove this test when SimpleForm.form_class is removed in 4.x
242
+ test 'builder adds chosen form class and default form class' do
243
+ ActiveSupport::Deprecation.silence do
244
+ swap SimpleForm, form_class: "my_custom_class", default_form_class: "my_default_class" do
245
+ with_form_for @user, :name
246
+ assert_select 'form.my_custom_class.my_default_class'
247
+ end
248
+ end
249
+ end
250
+
251
+ test 'builder adds default form class' do
252
+ swap SimpleForm, default_form_class: "default_class" do
198
253
  with_form_for @user, :name
199
- assert_select 'form.my_custom_class'
254
+ assert_select 'form.default_class'
200
255
  end
201
256
  end
202
257
 
203
- test 'builder should allow passing options to input' do
204
- with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
258
+ test 'builder allows passing options to input' do
259
+ with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
205
260
  assert_select 'form input#my_input.my_input.string'
206
261
  end
207
262
 
208
- test 'builder should not propagate input options to wrapper' do
209
- with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
263
+ test 'builder does not propagate input options to wrapper' do
264
+ with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
210
265
  assert_no_select 'form div.input.my_input.string'
211
266
  assert_select 'form input#my_input.my_input.string'
212
267
  end
213
268
 
214
- test 'builder should not propagate input options to wrapper with custom wrapper' do
215
- swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
216
- with_form_for @user, :name, :input_html => { :class => 'my_input' }
269
+ test 'builder does not propagate input options to wrapper with custom wrapper' do
270
+ swap_wrapper :default, custom_wrapper_with_wrapped_input do
271
+ with_form_for @user, :name, input_html: { class: 'my_input' }
217
272
  assert_no_select 'form div.input.my_input'
218
273
  assert_select 'form input.my_input.string'
219
274
  end
220
275
  end
221
276
 
222
- test 'builder should not propagate label options to wrapper with custom wrapper' do
223
- swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
224
- with_form_for @user, :name, :label_html => { :class => 'my_label' }
277
+ test 'builder does not propagate label options to wrapper with custom wrapper' do
278
+ swap_wrapper :default, custom_wrapper_with_wrapped_label do
279
+ with_form_for @user, :name, label_html: { class: 'my_label' }
225
280
  assert_no_select 'form div.label.my_label'
226
281
  assert_select 'form label.my_label.string'
227
282
  end
228
283
  end
229
284
 
230
- test 'builder should generate a input with label' do
285
+ test 'builder generates an input with label' do
231
286
  with_form_for @user, :name
232
287
  assert_select 'form label.string[for=user_name]', /Name/
233
288
  end
234
289
 
235
- test 'builder should be able to disable the label for a input' do
236
- with_form_for @user, :name, :label => false
290
+ test 'builder is able to disable the label for an input' do
291
+ with_form_for @user, :name, label: false
237
292
  assert_no_select 'form label'
238
293
  end
239
294
 
240
- test 'builder should be able to disable the label for an input and return a html safe string' do
241
- with_form_for @user, :name, :label => false, :wrapper => custom_wrapper_with_wrapped_label_input
295
+ test 'builder is able to disable the label for an input and return a html safe string' do
296
+ with_form_for @user, :name, label: false, wrapper: custom_wrapper_with_wrapped_label_input
242
297
  assert_select 'form input#user_name'
243
298
  end
244
299
 
245
- test 'builder should use custom label' do
246
- with_form_for @user, :name, :label => 'Yay!'
300
+ test 'builder uses custom label' do
301
+ with_form_for @user, :name, label: 'Yay!'
247
302
  assert_select 'form label', /Yay!/
248
303
  end
249
304
 
250
- test 'builder should pass options to label' do
251
- with_form_for @user, :name, :label_html => { :id => "cool" }
305
+ test 'builder passes options to label' do
306
+ with_form_for @user, :name, label_html: { id: "cool" }
252
307
  assert_select 'form label#cool', /Name/
253
308
  end
254
309
 
255
- test 'builder should not generate hints for a input' do
310
+ test 'builder does not generate hints for an input' do
256
311
  with_form_for @user, :name
257
312
  assert_no_select 'span.hint'
258
313
  end
259
314
 
260
- test 'builder should be able to add a hint for a input' do
261
- with_form_for @user, :name, :hint => 'test'
315
+ test 'builder is able to add a hint for an input' do
316
+ with_form_for @user, :name, hint: 'test'
262
317
  assert_select 'span.hint', 'test'
263
318
  end
264
319
 
265
- test 'builder should be able to disable a hint even if it exists in i18n' do
266
- store_translations(:en, :simple_form => { :hints => { :name => 'Hint test' } }) do
267
- SimpleForm::Inputs::Base.any_instance.expects(:hint).never
268
-
269
- with_form_for @user, :name, :hint => false
270
- assert_no_select 'span.hint'
320
+ test 'builder is able to disable a hint even if it exists in i18n' do
321
+ store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
322
+ stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
323
+ with_form_for @user, :name, hint: false
324
+ assert_no_select 'span.hint'
325
+ end
271
326
  end
272
327
  end
273
328
 
274
- test 'builder should pass options to hint' do
275
- with_form_for @user, :name, :hint => 'test', :hint_html => { :id => "cool" }
329
+ test 'builder passes options to hint' do
330
+ with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }
276
331
  assert_select 'span.hint#cool', 'test'
277
332
  end
278
333
 
279
- test 'builder should generate errors for attribute without errors' do
334
+ test 'builder generates errors for attribute without errors' do
280
335
  with_form_for @user, :credit_limit
281
336
  assert_no_select 'span.errors'
282
337
  end
283
338
 
284
- test 'builder should generate errors for attribute with errors' do
339
+ test 'builder generates errors for attribute with errors' do
285
340
  with_form_for @user, :name
286
- assert_select 'span.error', "can't be blank"
341
+ assert_select 'span.error', "cannot be blank"
287
342
  end
288
343
 
289
- test 'builder should be able to disable showing errors for a input' do
290
- with_form_for @user, :name, :error => false
344
+ test 'builder is able to disable showing errors for an input' do
345
+ with_form_for @user, :name, error: false
291
346
  assert_no_select 'span.error'
292
347
  end
293
348
 
294
- test 'builder should pass options to errors' do
295
- with_form_for @user, :name, :error_html => { :id => "cool" }
296
- assert_select 'span.error#cool', "can't be blank"
349
+ test 'builder passes options to errors' do
350
+ with_form_for @user, :name, error_html: { id: "cool" }
351
+ assert_select 'span.error#cool', "cannot be blank"
297
352
  end
298
353
 
299
- test 'placeholder should not be generated when set to false' do
300
- store_translations(:en, :simple_form => { :placeholders => { :user => {
301
- :name => 'Name goes here'
354
+ test 'placeholder does not be generated when set to false' do
355
+ store_translations(:en, simple_form: { placeholders: { user: {
356
+ name: 'Name goes here'
302
357
  } } }) do
303
- with_form_for @user, :name, :placeholder => false
358
+ with_form_for @user, :name, placeholder: false
304
359
  assert_no_select 'input[placeholder]'
305
360
  end
306
361
  end
307
362
 
308
363
  # DEFAULT OPTIONS
309
364
  [:input, :input_field].each do |method|
310
- test "builder should receive a default argument and pass it to the inputs when calling '#{method}'" do
311
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
312
- f.send(method, :name)
365
+ test "builder receives a default argument and pass it to the inputs when calling '#{method}'" do
366
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
367
+ f.public_send(method, :name)
313
368
  end
314
369
  assert_select 'input.default_class'
315
370
  end
316
371
 
317
- test "builder should receive a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
318
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
319
- concat(f.send(method, :name))
320
- concat(f.send(method, :credit_limit))
372
+ test "builder receives a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
373
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
374
+ concat(f.public_send(method, :name))
375
+ concat(f.public_send(method, :credit_limit))
321
376
  end
322
377
 
323
378
  assert_select "input.string.default_class[name='user[name]']"
324
379
  assert_no_select "input.string[name='user[credit_limit]']"
325
380
  end
326
381
 
327
- test "builder should receive a default argument and pass it to the inputs and nested form when calling '#{method}'" do
382
+ test "builder receives a default argument and pass it to the inputs and nested form when calling '#{method}'" do
328
383
  @user.company = Company.new(1, 'Empresa')
329
384
 
330
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
331
- concat(f.send(method, :name))
385
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
386
+ concat(f.public_send(method, :name))
332
387
  concat(f.simple_fields_for(:company) do |company_form|
333
- concat(company_form.send(method, :name))
388
+ concat(company_form.public_send(method, :name))
334
389
  end)
335
390
  end
336
391
 
@@ -339,78 +394,78 @@ class FormBuilderTest < ActionView::TestCase
339
394
  end
340
395
  end
341
396
 
342
- test "builder should receive a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
343
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
344
- f.input :name, :input_html => { :id => 'specific_id' }
397
+ test "builder receives a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
398
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
399
+ f.input :name, input_html: { id: 'specific_id' }
345
400
  end
346
401
  assert_select 'input.default_class#specific_id'
347
402
  end
348
403
 
349
- test "builder should receive a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
350
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
351
- f.input_field :name, :id => 'specific_id'
404
+ test "builder receives a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
405
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
406
+ f.input_field :name, id: 'specific_id'
352
407
  end
353
408
  assert_select 'input.default_class#specific_id'
354
409
  end
355
410
 
356
- test "builder should receive a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
357
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
358
- f.input :name, :input_html => { :id => 'specific_id' }
411
+ test "builder receives a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
412
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
413
+ f.input :name, input_html: { id: 'specific_id' }
359
414
  end
360
415
  assert_select 'input.default_class#specific_id'
361
416
  end
362
417
 
363
- test "builder should receive a default argument and pass it to the inputs when calling 'input_field', overwriting the defaults with specific options" do
364
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
365
- f.input_field :name, :id => 'specific_id'
418
+ test "builder receives a default argument and pass it to the inputs when calling 'input_field', overwriting the defaults with specific options" do
419
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
420
+ f.input_field :name, id: 'specific_id'
366
421
  end
367
422
  assert_select 'input.default_class#specific_id'
368
423
  end
369
424
 
370
425
  # WITHOUT OBJECT
371
- test 'builder should generate properly when object is not present' do
426
+ test 'builder generates properly when object is not present' do
372
427
  with_form_for :project, :name
373
428
  assert_select 'form input.string#project_name'
374
429
  end
375
430
 
376
- test 'builder should generate password fields based on attribute name when object is not present' do
431
+ test 'builder generates password fields based on attribute name when object is not present' do
377
432
  with_form_for :project, :password_confirmation
378
433
  assert_select 'form input[type=password].password#project_password_confirmation'
379
434
  end
380
435
 
381
- test 'builder should generate text fields by default for all attributes when object is not present' do
436
+ test 'builder generates text fields by default for all attributes when object is not present' do
382
437
  with_form_for :project, :created_at
383
438
  assert_select 'form input.string#project_created_at'
384
439
  with_form_for :project, :budget
385
440
  assert_select 'form input.string#project_budget'
386
441
  end
387
442
 
388
- test 'builder should allow overriding input type when object is not present' do
389
- with_form_for :project, :created_at, :as => :datetime
443
+ test 'builder allows overriding input type when object is not present' do
444
+ with_form_for :project, :created_at, as: :datetime
390
445
  assert_select 'form select.datetime#project_created_at_1i'
391
- with_form_for :project, :budget, :as => :decimal
446
+ with_form_for :project, :budget, as: :decimal
392
447
  assert_select 'form input.decimal#project_budget'
393
448
  end
394
449
 
395
450
  # CUSTOM FORM BUILDER
396
- test 'custom builder should inherit mappings' do
451
+ test 'custom builder inherits mappings' do
397
452
  with_custom_form_for @user, :email
398
453
  assert_select 'form input[type=email]#user_email.custom'
399
454
  end
400
455
 
401
- test 'form with CustomMapTypeFormBuilder should use custom map type builder' do
456
+ test 'form with CustomMapTypeFormBuilder uses custom map type builder' do
402
457
  with_concat_custom_mapping_form_for(:user) do |user|
403
458
  assert user.instance_of?(CustomMapTypeFormBuilder)
404
459
  end
405
460
  end
406
461
 
407
- test 'form with CustomMapTypeFormBuilder should use custom mapping' do
462
+ test 'form with CustomMapTypeFormBuilder uses custom mapping' do
408
463
  with_concat_custom_mapping_form_for(:user) do |user|
409
464
  assert_equal SimpleForm::Inputs::StringInput, user.class.mappings[:custom_type]
410
465
  end
411
466
  end
412
467
 
413
- test 'form without CustomMapTypeFormBuilder should not use custom mapping' do
468
+ test 'form without CustomMapTypeFormBuilder does not use custom mapping' do
414
469
  with_concat_form_for(:user) do |user|
415
470
  assert_nil user.class.mappings[:custom_type]
416
471
  end