simple_form 2.1.0 → 3.0.0.rc

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.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +15 -32
  3. data/README.md +103 -71
  4. data/lib/generators/simple_form/install_generator.rb +3 -3
  5. data/lib/generators/simple_form/templates/README +1 -1
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +13 -13
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  9. data/lib/simple_form/action_view_extensions/builder.rb +1 -319
  10. data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
  11. data/lib/simple_form/components/html5.rb +5 -2
  12. data/lib/simple_form/components/labels.rb +3 -3
  13. data/lib/simple_form/components/maxlength.rb +1 -8
  14. data/lib/simple_form/components/pattern.rb +2 -2
  15. data/lib/simple_form/components.rb +1 -1
  16. data/lib/simple_form/error_notification.rb +2 -2
  17. data/lib/simple_form/form_builder.rb +147 -49
  18. data/lib/simple_form/helpers.rb +1 -1
  19. data/lib/simple_form/inputs/base.rb +2 -6
  20. data/lib/simple_form/inputs/block_input.rb +1 -1
  21. data/lib/simple_form/inputs/boolean_input.rb +5 -4
  22. data/lib/simple_form/inputs/collection_input.rb +6 -6
  23. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  24. data/lib/simple_form/inputs/password_input.rb +0 -1
  25. data/lib/simple_form/inputs/string_input.rb +0 -1
  26. data/lib/simple_form/railtie.rb +7 -0
  27. data/lib/simple_form/tags.rb +61 -0
  28. data/lib/simple_form/version.rb +1 -1
  29. data/lib/simple_form/wrappers/builder.rb +5 -29
  30. data/lib/simple_form/wrappers/many.rb +1 -1
  31. data/lib/simple_form/wrappers/root.rb +1 -1
  32. data/lib/simple_form/wrappers.rb +1 -1
  33. data/lib/simple_form.rb +39 -47
  34. data/test/action_view_extensions/builder_test.rb +75 -88
  35. data/test/action_view_extensions/form_helper_test.rb +25 -16
  36. data/test/components/label_test.rb +46 -46
  37. data/test/form_builder/association_test.rb +39 -29
  38. data/test/form_builder/button_test.rb +4 -4
  39. data/test/form_builder/error_notification_test.rb +8 -8
  40. data/test/form_builder/error_test.rb +12 -12
  41. data/test/form_builder/general_test.rb +58 -52
  42. data/test/form_builder/hint_test.rb +22 -22
  43. data/test/form_builder/input_field_test.rb +12 -12
  44. data/test/form_builder/label_test.rb +6 -6
  45. data/test/form_builder/wrapper_test.rb +21 -21
  46. data/test/inputs/boolean_input_test.rb +23 -23
  47. data/test/inputs/collection_check_boxes_input_test.rb +61 -55
  48. data/test/inputs/collection_radio_buttons_input_test.rb +76 -79
  49. data/test/inputs/collection_select_input_test.rb +70 -45
  50. data/test/inputs/datetime_input_test.rb +17 -11
  51. data/test/inputs/disabled_test.rb +10 -10
  52. data/test/inputs/discovery_test.rb +4 -4
  53. data/test/inputs/file_input_test.rb +1 -1
  54. data/test/inputs/general_test.rb +12 -12
  55. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  56. data/test/inputs/hidden_input_test.rb +3 -2
  57. data/test/inputs/numeric_input_test.rb +3 -3
  58. data/test/inputs/priority_input_test.rb +9 -3
  59. data/test/inputs/readonly_test.rb +12 -12
  60. data/test/inputs/required_test.rb +5 -5
  61. data/test/inputs/string_input_test.rb +15 -25
  62. data/test/inputs/text_input_test.rb +1 -1
  63. data/test/support/misc_helpers.rb +46 -24
  64. data/test/support/mock_controller.rb +6 -6
  65. data/test/support/models.rb +62 -61
  66. data/test/test_helper.rb +20 -24
  67. metadata +32 -33
  68. data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
  69. data/lib/simple_form/core_ext/hash.rb +0 -16
  70. data/lib/simple_form/form_builder.rb.orig +0 -486
  71. data/lib/simple_form/version.rb.orig +0 -7
@@ -36,34 +36,34 @@ class ErrorTest < ActionView::TestCase
36
36
  end
37
37
 
38
38
  test 'error should generate messages for attribute with one error when using first' do
39
- swap SimpleForm, :error_method => :first do
39
+ swap SimpleForm, error_method: :first do
40
40
  with_error_for @user, :age
41
41
  assert_select 'span.error', 'is not a number'
42
42
  end
43
43
  end
44
44
 
45
45
  test 'error should generate messages for attribute with several errors when using to_sentence' do
46
- swap SimpleForm, :error_method => :to_sentence do
46
+ swap SimpleForm, error_method: :to_sentence do
47
47
  with_error_for @user, :age
48
48
  assert_select 'span.error', 'is not a number and must be greater than 18'
49
49
  end
50
50
  end
51
51
 
52
52
  test 'error should be able to pass html options' do
53
- with_error_for @user, :name, :id => 'error', :class => 'yay'
53
+ with_error_for @user, :name, id: 'error', class: 'yay'
54
54
  assert_select 'span#error.error.yay'
55
55
  end
56
56
 
57
57
  test 'error should not modify the options hash' do
58
- options = { :id => 'error', :class => 'yay' }
58
+ options = { id: 'error', class: 'yay' }
59
59
  with_error_for @user, :name, options
60
60
  assert_select 'span#error.error.yay'
61
- assert_equal({ :id => 'error', :class => 'yay' }, options)
61
+ assert_equal({ id: 'error', class: 'yay' }, options)
62
62
  end
63
63
 
64
64
  test 'error should find errors on attribute and association' do
65
- with_error_for @user, :company_id, :as => :select,
66
- :error_method => :to_sentence, :reflection => Association.new(Company, :company, {})
65
+ with_error_for @user, :company_id, as: :select,
66
+ error_method: :to_sentence, reflection: Association.new(Company, :company, {})
67
67
  assert_select 'span.error', 'must be valid and company must be present'
68
68
  end
69
69
 
@@ -73,7 +73,7 @@ class ErrorTest < ActionView::TestCase
73
73
  end
74
74
 
75
75
  test 'error should generate an error tag with a clean HTML when errors options are present' do
76
- with_error_for @user, :name, :error_tag => :p, :error_prefix => 'Name', :error_method => :first
76
+ with_error_for @user, :name, error_tag: :p, error_prefix: 'Name', error_method: :first
77
77
  assert_no_select 'p.error[error_html]'
78
78
  assert_no_select 'p.error[error_tag]'
79
79
  assert_no_select 'p.error[error_prefix]'
@@ -81,7 +81,7 @@ class ErrorTest < ActionView::TestCase
81
81
  end
82
82
 
83
83
  test 'error should generate an error message with raw HTML tags' do
84
- with_error_for @user, :name, :error_prefix => '<b>Name</b>'
84
+ with_error_for @user, :name, error_prefix: '<b>Name</b>'
85
85
  assert_select 'span.error', "Name can't be blank"
86
86
  assert_select 'span.error b', "Name"
87
87
  end
@@ -99,15 +99,15 @@ class ErrorTest < ActionView::TestCase
99
99
  end
100
100
 
101
101
  test 'full error should allow passing options to full error tag' do
102
- with_full_error_for @user, :name, :id => 'name_error', :error_prefix => "Your name"
102
+ with_full_error_for @user, :name, id: 'name_error', error_prefix: "Your name"
103
103
  assert_select 'span.error#name_error', "Your name can't be blank"
104
104
  end
105
105
 
106
106
  test 'full error should not modify the options hash' do
107
- options = { :id => 'name_error' }
107
+ options = { id: 'name_error' }
108
108
  with_full_error_for @user, :name, options
109
109
  assert_select 'span.error#name_error', "Super User Name! can't be blank"
110
- assert_equal({ :id => 'name_error' }, options)
110
+ assert_equal({ id: 'name_error' }, options)
111
111
  end
112
112
 
113
113
  # CUSTOM WRAPPERS
@@ -22,16 +22,24 @@ class FormBuilderTest < ActionView::TestCase
22
22
  end
23
23
  end
24
24
 
25
+ test 'builder should work 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
+
25
33
  test 'builder input should allow 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
41
  test 'builder should allow adding custom input mappings for default input types' do
34
- swap SimpleForm, :input_mappings => { /count$/ => :integer } 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'
@@ -39,7 +47,7 @@ class FormBuilderTest < ActionView::TestCase
39
47
  end
40
48
 
41
49
  test 'builder should allow to skip input_type class' do
42
- swap SimpleForm, :generate_additional_classes_for => [:label, :wrapper] do
50
+ swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
43
51
  with_form_for @user, :post_count
44
52
  assert_no_select "form input#user_post_count.integer"
45
53
  assert_select "form input#user_post_count"
@@ -47,7 +55,7 @@ class FormBuilderTest < ActionView::TestCase
47
55
  end
48
56
 
49
57
  test 'builder should allow to add additional classes only for wrapper' do
50
- swap SimpleForm, :generate_additional_classes_for => [:wrapper] do
58
+ swap SimpleForm, generate_additional_classes_for: [:wrapper] do
51
59
  with_form_for @user, :post_count
52
60
  assert_no_select "form input#user_post_count.string"
53
61
  assert_no_select "form label#user_post_count.string"
@@ -56,7 +64,7 @@ class FormBuilderTest < ActionView::TestCase
56
64
  end
57
65
 
58
66
  test 'builder should allow adding custom input mappings for integer input types' do
59
- swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
67
+ swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
60
68
  with_form_for @user, :lock_version
61
69
  assert_no_select 'form input#user_lock_version.integer'
62
70
  assert_select 'form input#user_lock_version.hidden'
@@ -64,7 +72,7 @@ class FormBuilderTest < ActionView::TestCase
64
72
  end
65
73
 
66
74
  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
75
+ swap SimpleForm, input_mappings: { /count$/ => :integer, /^post_/ => :password } do
68
76
  with_form_for @user, :post_count
69
77
  assert_no_select 'form input#user_post_count.password'
70
78
  assert_select 'form input#user_post_count.numeric.integer'
@@ -72,7 +80,7 @@ class FormBuilderTest < ActionView::TestCase
72
80
  end
73
81
 
74
82
  test 'builder uses the custom map only for matched attributes' do
75
- swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
83
+ swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
76
84
  with_form_for @user, :post_count
77
85
  assert_no_select 'form input#user_post_count.hidden'
78
86
  assert_select 'form input#user_post_count.string'
@@ -156,64 +164,62 @@ class FormBuilderTest < ActionView::TestCase
156
164
  end
157
165
 
158
166
  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)
167
+ @user.avatar = MiniTest::Mock.new
168
+ @user.avatar.expect(:public_filename, true)
163
169
 
164
170
  with_form_for @user, :avatar
165
171
  assert_select 'form input#user_avatar.file'
166
172
  end
167
173
 
168
174
  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)
175
+ @user.home_picture = MiniTest::Mock.new
176
+ @user.home_picture.expect(:mounted_as, true)
171
177
 
172
178
  with_form_for @user, :home_picture
173
179
  assert_select 'form input#user_home_picture.file'
174
180
  end
175
181
 
176
182
  test 'build should generate select if a collection is given' do
177
- with_form_for @user, :age, :collection => 1..60
183
+ with_form_for @user, :age, collection: 1..60
178
184
  assert_select 'form select#user_age.select'
179
185
  end
180
186
 
181
187
  test 'builder should allow overriding default input type for text' do
182
- with_form_for @user, :name, :as => :text
188
+ with_form_for @user, :name, as: :text
183
189
  assert_no_select 'form input#user_name'
184
190
  assert_select 'form textarea#user_name.text'
185
191
 
186
- with_form_for @user, :active, :as => :radio_buttons
192
+ with_form_for @user, :active, as: :radio_buttons
187
193
  assert_no_select 'form input[type=checkbox]'
188
- assert_select 'form input.radio_buttons[type=radio]', :count => 2
194
+ assert_select 'form input.radio_buttons[type=radio]', count: 2
189
195
 
190
- with_form_for @user, :born_at, :as => :string
196
+ with_form_for @user, :born_at, as: :string
191
197
  assert_no_select 'form select'
192
198
  assert_select 'form input#user_born_at.string'
193
199
  end
194
200
 
195
201
  # COMMON OPTIONS
196
202
  test 'builder should add chosen form class' do
197
- swap SimpleForm, :form_class => :my_custom_class do
203
+ swap SimpleForm, form_class: :my_custom_class do
198
204
  with_form_for @user, :name
199
205
  assert_select 'form.my_custom_class'
200
206
  end
201
207
  end
202
208
 
203
209
  test 'builder should allow passing options to input' do
204
- with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
210
+ with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
205
211
  assert_select 'form input#my_input.my_input.string'
206
212
  end
207
213
 
208
214
  test 'builder should not propagate input options to wrapper' do
209
- with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
215
+ with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
210
216
  assert_no_select 'form div.input.my_input.string'
211
217
  assert_select 'form input#my_input.my_input.string'
212
218
  end
213
219
 
214
220
  test 'builder should not propagate input options to wrapper with custom wrapper' do
215
221
  swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
216
- with_form_for @user, :name, :input_html => { :class => 'my_input' }
222
+ with_form_for @user, :name, input_html: { class: 'my_input' }
217
223
  assert_no_select 'form div.input.my_input'
218
224
  assert_select 'form input.my_input.string'
219
225
  end
@@ -221,7 +227,7 @@ class FormBuilderTest < ActionView::TestCase
221
227
 
222
228
  test 'builder should not propagate label options to wrapper with custom wrapper' do
223
229
  swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
224
- with_form_for @user, :name, :label_html => { :class => 'my_label' }
230
+ with_form_for @user, :name, label_html: { class: 'my_label' }
225
231
  assert_no_select 'form div.label.my_label'
226
232
  assert_select 'form label.my_label.string'
227
233
  end
@@ -233,22 +239,22 @@ class FormBuilderTest < ActionView::TestCase
233
239
  end
234
240
 
235
241
  test 'builder should be able to disable the label for a input' do
236
- with_form_for @user, :name, :label => false
242
+ with_form_for @user, :name, label: false
237
243
  assert_no_select 'form label'
238
244
  end
239
245
 
240
246
  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
247
+ with_form_for @user, :name, label: false, wrapper: custom_wrapper_with_wrapped_label_input
242
248
  assert_select 'form input#user_name'
243
249
  end
244
250
 
245
251
  test 'builder should use custom label' do
246
- with_form_for @user, :name, :label => 'Yay!'
252
+ with_form_for @user, :name, label: 'Yay!'
247
253
  assert_select 'form label', /Yay!/
248
254
  end
249
255
 
250
256
  test 'builder should pass options to label' do
251
- with_form_for @user, :name, :label_html => { :id => "cool" }
257
+ with_form_for @user, :name, label_html: { id: "cool" }
252
258
  assert_select 'form label#cool', /Name/
253
259
  end
254
260
 
@@ -258,21 +264,21 @@ class FormBuilderTest < ActionView::TestCase
258
264
  end
259
265
 
260
266
  test 'builder should be able to add a hint for a input' do
261
- with_form_for @user, :name, :hint => 'test'
267
+ with_form_for @user, :name, hint: 'test'
262
268
  assert_select 'span.hint', 'test'
263
269
  end
264
270
 
265
271
  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'
272
+ store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
273
+ stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
274
+ with_form_for @user, :name, hint: false
275
+ assert_no_select 'span.hint'
276
+ end
271
277
  end
272
278
  end
273
279
 
274
280
  test 'builder should pass options to hint' do
275
- with_form_for @user, :name, :hint => 'test', :hint_html => { :id => "cool" }
281
+ with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }
276
282
  assert_select 'span.hint#cool', 'test'
277
283
  end
278
284
 
@@ -287,20 +293,20 @@ class FormBuilderTest < ActionView::TestCase
287
293
  end
288
294
 
289
295
  test 'builder should be able to disable showing errors for a input' do
290
- with_form_for @user, :name, :error => false
296
+ with_form_for @user, :name, error: false
291
297
  assert_no_select 'span.error'
292
298
  end
293
299
 
294
300
  test 'builder should pass options to errors' do
295
- with_form_for @user, :name, :error_html => { :id => "cool" }
301
+ with_form_for @user, :name, error_html: { id: "cool" }
296
302
  assert_select 'span.error#cool', "can't be blank"
297
303
  end
298
304
 
299
305
  test 'placeholder should not be generated when set to false' do
300
- store_translations(:en, :simple_form => { :placeholders => { :user => {
301
- :name => 'Name goes here'
306
+ store_translations(:en, simple_form: { placeholders: { user: {
307
+ name: 'Name goes here'
302
308
  } } }) do
303
- with_form_for @user, :name, :placeholder => false
309
+ with_form_for @user, :name, placeholder: false
304
310
  assert_no_select 'input[placeholder]'
305
311
  end
306
312
  end
@@ -308,14 +314,14 @@ class FormBuilderTest < ActionView::TestCase
308
314
  # DEFAULT OPTIONS
309
315
  [:input, :input_field].each do |method|
310
316
  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|
317
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
312
318
  f.send(method, :name)
313
319
  end
314
320
  assert_select 'input.default_class'
315
321
  end
316
322
 
317
323
  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|
324
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
319
325
  concat(f.send(method, :name))
320
326
  concat(f.send(method, :credit_limit))
321
327
  end
@@ -327,7 +333,7 @@ class FormBuilderTest < ActionView::TestCase
327
333
  test "builder should receive a default argument and pass it to the inputs and nested form when calling '#{method}'" do
328
334
  @user.company = Company.new(1, 'Empresa')
329
335
 
330
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
336
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
331
337
  concat(f.send(method, :name))
332
338
  concat(f.simple_fields_for(:company) do |company_form|
333
339
  concat(company_form.send(method, :name))
@@ -340,29 +346,29 @@ class FormBuilderTest < ActionView::TestCase
340
346
  end
341
347
 
342
348
  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' }
349
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
350
+ f.input :name, input_html: { id: 'specific_id' }
345
351
  end
346
352
  assert_select 'input.default_class#specific_id'
347
353
  end
348
354
 
349
355
  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'
356
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
357
+ f.input_field :name, id: 'specific_id'
352
358
  end
353
359
  assert_select 'input.default_class#specific_id'
354
360
  end
355
361
 
356
362
  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' }
363
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
364
+ f.input :name, input_html: { id: 'specific_id' }
359
365
  end
360
366
  assert_select 'input.default_class#specific_id'
361
367
  end
362
368
 
363
369
  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'
370
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
371
+ f.input_field :name, id: 'specific_id'
366
372
  end
367
373
  assert_select 'input.default_class#specific_id'
368
374
  end
@@ -386,9 +392,9 @@ class FormBuilderTest < ActionView::TestCase
386
392
  end
387
393
 
388
394
  test 'builder should allow overriding input type when object is not present' do
389
- with_form_for :project, :created_at, :as => :datetime
395
+ with_form_for :project, :created_at, as: :datetime
390
396
  assert_select 'form select.datetime#project_created_at_1i'
391
- with_form_for :project, :budget, :as => :decimal
397
+ with_form_for :project, :budget, as: :decimal
392
398
  assert_select 'form input.decimal#project_budget'
393
399
  end
394
400
 
@@ -14,36 +14,36 @@ class HintTest < ActionView::TestCase
14
14
  end
15
15
 
16
16
  test 'hint should be generated with optional text' do
17
- with_hint_for @user, :name, :hint => 'Use with care...'
17
+ with_hint_for @user, :name, hint: 'Use with care...'
18
18
  assert_select 'span.hint', 'Use with care...'
19
19
  end
20
20
 
21
21
  test 'hint should not modify the options hash' do
22
- options = { :hint => 'Use with care...' }
22
+ options = { hint: 'Use with care...' }
23
23
  with_hint_for @user, :name, options
24
24
  assert_select 'span.hint', 'Use with care...'
25
- assert_equal({ :hint => 'Use with care...' }, options)
25
+ assert_equal({ hint: 'Use with care...' }, options)
26
26
  end
27
27
 
28
28
  test 'hint should be generated cleanly with optional text' do
29
- with_hint_for @user, :name, :hint => 'Use with care...', :hint_tag => :span
29
+ with_hint_for @user, :name, hint: 'Use with care...', hint_tag: :span
30
30
  assert_no_select 'span.hint[hint]'
31
31
  assert_no_select 'span.hint[hint_tag]'
32
32
  assert_no_select 'span.hint[hint_html]'
33
33
  end
34
34
 
35
35
  test 'hint uses the current component tag set' do
36
- with_hint_for @user, :name, :hint => 'Use with care...', :hint_tag => :p
36
+ with_hint_for @user, :name, hint: 'Use with care...', hint_tag: :p
37
37
  assert_select 'p.hint', 'Use with care...'
38
38
  end
39
39
 
40
40
  test 'hint should be able to pass html options' do
41
- with_hint_for @user, :name, :hint => 'Yay!', :id => 'hint', :class => 'yay'
41
+ with_hint_for @user, :name, hint: 'Yay!', id: 'hint', class: 'yay'
42
42
  assert_select 'span#hint.hint.yay'
43
43
  end
44
44
 
45
45
  test 'hint should be output as html_safe' do
46
- with_hint_for @user, :name, :hint => '<b>Bold</b> and not...'
46
+ with_hint_for @user, :name, hint: '<b>Bold</b> and not...'
47
47
  assert_select 'span.hint', 'Bold and not...'
48
48
  end
49
49
 
@@ -61,22 +61,22 @@ class HintTest < ActionView::TestCase
61
61
  end
62
62
 
63
63
  test 'hint without attribute name uses the current component tag set' do
64
- with_hint_for @user, 'Hello World!', :hint_tag => :p
64
+ with_hint_for @user, 'Hello World!', hint_tag: :p
65
65
  assert_no_select 'p.hint[hint]'
66
66
  assert_no_select 'p.hint[hint_html]'
67
67
  assert_no_select 'p.hint[hint_tag]'
68
68
  end
69
69
 
70
70
  test 'hint without attribute name should be able to pass html options' do
71
- with_hint_for @user, 'Yay', :id => 'hint', :class => 'yay'
71
+ with_hint_for @user, 'Yay', id: 'hint', class: 'yay'
72
72
  assert_select 'span#hint.hint.yay', 'Yay'
73
73
  end
74
74
 
75
75
  # I18n
76
76
 
77
77
  test 'hint should use i18n based on model, action, and attribute to lookup translation' do
78
- store_translations(:en, :simple_form => { :hints => { :user => {
79
- :edit => { :name => 'Content of this input will be truncated...' }
78
+ store_translations(:en, simple_form: { hints: { user: {
79
+ edit: { name: 'Content of this input will be truncated...' }
80
80
  } } }) do
81
81
  with_hint_for @user, :name
82
82
  assert_select 'span.hint', 'Content of this input will be truncated...'
@@ -84,8 +84,8 @@ class HintTest < ActionView::TestCase
84
84
  end
85
85
 
86
86
  test 'hint should use i18n with model and attribute to lookup translation' do
87
- store_translations(:en, :simple_form => { :hints => { :user => {
88
- :name => 'Content of this input will be capitalized...'
87
+ store_translations(:en, simple_form: { hints: { user: {
88
+ name: 'Content of this input will be capitalized...'
89
89
  } } }) do
90
90
  with_hint_for @user, :name
91
91
  assert_select 'span.hint', 'Content of this input will be capitalized...'
@@ -93,8 +93,8 @@ class HintTest < ActionView::TestCase
93
93
  end
94
94
 
95
95
  test 'hint should use i18n under defaults namespace to lookup translation' do
96
- store_translations(:en, :simple_form => {
97
- :hints => {:defaults => {:name => 'Content of this input will be downcased...' } }
96
+ store_translations(:en, simple_form: {
97
+ hints: { defaults: { name: 'Content of this input will be downcased...' } }
98
98
  }) do
99
99
  with_hint_for @user, :name
100
100
  assert_select 'span.hint', 'Content of this input will be downcased...'
@@ -102,17 +102,17 @@ class HintTest < ActionView::TestCase
102
102
  end
103
103
 
104
104
  test 'hint should use i18n with lookup for association name' do
105
- store_translations(:en, :simple_form => { :hints => {
106
- :user => { :company => 'My company!' }
105
+ store_translations(:en, simple_form: { hints: {
106
+ user: { company: 'My company!' }
107
107
  } } ) do
108
- with_hint_for @user, :company_id, :as => :string, :reflection => Association.new(Company, :company, {})
108
+ with_hint_for @user, :company_id, as: :string, reflection: Association.new(Company, :company, {})
109
109
  assert_select 'span.hint', /My company!/
110
110
  end
111
111
  end
112
112
 
113
113
  test 'hint should output translations as html_safe' do
114
- store_translations(:en, :simple_form => { :hints => { :user => {
115
- :edit => { :name => '<b>This is bold</b> and this is not...' }
114
+ store_translations(:en, simple_form: { hints: { user: {
115
+ edit: { name: '<b>This is bold</b> and this is not...' }
116
116
  } } }) do
117
117
  with_hint_for @user, :name
118
118
  assert_select 'span.hint', 'This is bold and this is not...'
@@ -123,7 +123,7 @@ class HintTest < ActionView::TestCase
123
123
  # No object
124
124
 
125
125
  test 'hint should generate properly when object is not present' do
126
- with_hint_for :project, :name, :hint => 'Test without object'
126
+ with_hint_for :project, :name, hint: 'Test without object'
127
127
  assert_select 'span.hint', 'Test without object'
128
128
  end
129
129
 
@@ -131,7 +131,7 @@ class HintTest < ActionView::TestCase
131
131
 
132
132
  test 'hint with custom wrappers works' do
133
133
  swap_wrapper do
134
- with_hint_for @user, :name, :hint => "can't be blank"
134
+ with_hint_for @user, :name, hint: "can't be blank"
135
135
  assert_select 'div.omg_hint', "can't be blank"
136
136
  end
137
137
  end
@@ -14,7 +14,7 @@ class InputFieldTest < ActionView::TestCase
14
14
 
15
15
  test 'builder input_field should allow overriding default input type' do
16
16
  with_concat_form_for(@user) do |f|
17
- f.input_field :name, :as => :text
17
+ f.input_field :name, as: :text
18
18
  end
19
19
 
20
20
  assert_no_select 'input#user_name'
@@ -23,27 +23,27 @@ class InputFieldTest < ActionView::TestCase
23
23
 
24
24
  test 'builder input_field should allow passing options to input tag' do
25
25
  with_concat_form_for(@user) do |f|
26
- f.input_field :name, :id => 'name_input', :class => 'name'
26
+ f.input_field :name, id: 'name_input', class: 'name'
27
27
  end
28
28
 
29
29
  assert_select 'input.string.name#name_input'
30
30
  end
31
31
 
32
32
  test 'builder input_field should not modify the options hash' do
33
- options = { :id => 'name_input', :class => 'name' }
33
+ options = { id: 'name_input', class: 'name' }
34
34
 
35
35
  with_concat_form_for(@user) do |f|
36
36
  f.input_field :name, options
37
37
  end
38
38
 
39
39
  assert_select 'input.string.name#name_input'
40
- assert_equal({ :id => 'name_input', :class => 'name' }, options)
40
+ assert_equal({ id: 'name_input', class: 'name' }, options)
41
41
  end
42
42
 
43
43
 
44
44
  test 'builder input_field should generate an input tag with a clean HTML' do
45
45
  with_concat_form_for(@user) do |f|
46
- f.input_field :name, :as => :integer, :class => 'name'
46
+ f.input_field :name, as: :integer, class: 'name'
47
47
  end
48
48
 
49
49
  assert_no_select 'input.integer[input_html]'
@@ -51,8 +51,8 @@ class InputFieldTest < ActionView::TestCase
51
51
  end
52
52
 
53
53
  test 'builder input_field should use i18n to translate placeholder text' do
54
- store_translations(:en, :simple_form => { :placeholders => { :user => {
55
- :name => 'Name goes here'
54
+ store_translations(:en, simple_form: { placeholders: { user: {
55
+ name: 'Name goes here'
56
56
  } } }) do
57
57
 
58
58
  with_concat_form_for(@user) do |f|
@@ -65,7 +65,7 @@ class InputFieldTest < ActionView::TestCase
65
65
 
66
66
  test 'builder input_field should use min_max component' do
67
67
  with_concat_form_for(@other_validating_user) do |f|
68
- f.input_field :age, :as => :integer
68
+ f.input_field :age, as: :integer
69
69
  end
70
70
 
71
71
  assert_select 'input[min=18]'
@@ -73,7 +73,7 @@ class InputFieldTest < ActionView::TestCase
73
73
 
74
74
  test 'builder input_field should use pattern component' do
75
75
  with_concat_form_for(@other_validating_user) do |f|
76
- f.input_field :country, :as => :string
76
+ f.input_field :country, as: :string
77
77
  end
78
78
 
79
79
  assert_select 'input[pattern="\w+"]'
@@ -81,7 +81,7 @@ class InputFieldTest < ActionView::TestCase
81
81
 
82
82
  test 'builder input_field should use readonly component' do
83
83
  with_concat_form_for(@other_validating_user) do |f|
84
- f.input_field :age, :as => :integer, :readonly => true
84
+ f.input_field :age, as: :integer, readonly: true
85
85
  end
86
86
 
87
87
  assert_select 'input.integer.readonly[readonly]'
@@ -89,7 +89,7 @@ class InputFieldTest < ActionView::TestCase
89
89
 
90
90
  test 'builder input_field should use maxlength component' do
91
91
  with_concat_form_for(@validating_user) do |f|
92
- f.input_field :name, :as => :string
92
+ f.input_field :name, as: :string
93
93
  end
94
94
 
95
95
  assert_select 'input.string[maxlength=25]'
@@ -97,7 +97,7 @@ class InputFieldTest < ActionView::TestCase
97
97
 
98
98
  test 'builder collection input_field should generate input tag with a clean HTML' do
99
99
  with_concat_form_for(@user) do |f|
100
- f.input_field :status, :collection => ['Open', 'Closed'], :class => 'status', :label_method => :to_s, :value_method => :to_s
100
+ f.input_field :status, collection: ['Open', 'Closed'], class: 'status', label_method: :to_s, value_method: :to_s
101
101
  end
102
102
 
103
103
  assert_no_select 'select.status[input_html]'