simple_form 2.1.3 → 3.0.0.beta1

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 (72) hide show
  1. data/CHANGELOG.md +6 -54
  2. data/README.md +129 -111
  3. data/lib/generators/simple_form/install_generator.rb +4 -4
  4. data/lib/generators/simple_form/templates/README +2 -2
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +8 -11
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  8. data/lib/simple_form.rb +31 -47
  9. data/lib/simple_form/action_view_extensions/builder.rb +0 -319
  10. data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
  12. data/lib/simple_form/components.rb +1 -1
  13. data/lib/simple_form/components/errors.rb +1 -7
  14. data/lib/simple_form/components/hints.rb +2 -7
  15. data/lib/simple_form/components/html5.rb +1 -1
  16. data/lib/simple_form/components/labels.rb +4 -4
  17. data/lib/simple_form/components/maxlength.rb +1 -8
  18. data/lib/simple_form/error_notification.rb +2 -2
  19. data/lib/simple_form/form_builder.rb +144 -46
  20. data/lib/simple_form/form_builder.rb.orig +486 -0
  21. data/lib/simple_form/helpers.rb +1 -1
  22. data/lib/simple_form/inputs/base.rb +3 -10
  23. data/lib/simple_form/inputs/block_input.rb +1 -1
  24. data/lib/simple_form/inputs/boolean_input.rb +6 -6
  25. data/lib/simple_form/inputs/collection_input.rb +7 -7
  26. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  27. data/lib/simple_form/inputs/password_input.rb +0 -1
  28. data/lib/simple_form/inputs/string_input.rb +0 -1
  29. data/lib/simple_form/railtie.rb +7 -0
  30. data/lib/simple_form/tags.rb +61 -0
  31. data/lib/simple_form/version.rb +1 -1
  32. data/lib/simple_form/version.rb.orig +7 -0
  33. data/lib/simple_form/wrappers.rb +1 -1
  34. data/lib/simple_form/wrappers/builder.rb +5 -29
  35. data/lib/simple_form/wrappers/many.rb +1 -1
  36. data/lib/simple_form/wrappers/root.rb +1 -1
  37. data/test/action_view_extensions/builder_test.rb +67 -87
  38. data/test/action_view_extensions/form_helper_test.rb +16 -16
  39. data/test/components/label_test.rb +46 -46
  40. data/test/form_builder/association_test.rb +23 -23
  41. data/test/form_builder/button_test.rb +4 -4
  42. data/test/form_builder/error_notification_test.rb +8 -8
  43. data/test/form_builder/error_test.rb +18 -65
  44. data/test/form_builder/general_test.rb +45 -65
  45. data/test/form_builder/hint_test.rb +23 -29
  46. data/test/form_builder/input_field_test.rb +12 -12
  47. data/test/form_builder/label_test.rb +6 -16
  48. data/test/form_builder/wrapper_test.rb +21 -21
  49. data/test/inputs/boolean_input_test.rb +23 -35
  50. data/test/inputs/collection_check_boxes_input_test.rb +55 -55
  51. data/test/inputs/collection_radio_buttons_input_test.rb +70 -79
  52. data/test/inputs/collection_select_input_test.rb +45 -51
  53. data/test/inputs/datetime_input_test.rb +11 -11
  54. data/test/inputs/disabled_test.rb +10 -10
  55. data/test/inputs/discovery_test.rb +4 -4
  56. data/test/inputs/file_input_test.rb +1 -1
  57. data/test/inputs/general_test.rb +12 -12
  58. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  59. data/test/inputs/hidden_input_test.rb +1 -1
  60. data/test/inputs/numeric_input_test.rb +3 -3
  61. data/test/inputs/priority_input_test.rb +3 -3
  62. data/test/inputs/readonly_test.rb +12 -12
  63. data/test/inputs/required_test.rb +5 -5
  64. data/test/inputs/string_input_test.rb +10 -25
  65. data/test/inputs/text_input_test.rb +1 -1
  66. data/test/support/misc_helpers.rb +24 -24
  67. data/test/support/mock_controller.rb +6 -6
  68. data/test/support/models.rb +37 -46
  69. data/test/test_helper.rb +20 -20
  70. metadata +49 -24
  71. checksums.yaml +0 -7
  72. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -19,31 +19,31 @@ class FormHelperTest < ActionView::TestCase
19
19
  end
20
20
 
21
21
  test 'SimpleForm should not use default browser validations if specified in the configuration options' do
22
- swap SimpleForm, :browser_validations => false do
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
- test 'a form specific disabled validation option should override the default enabled browser validation configuration option' do
29
- with_concat_form_for(:user, :html => { :novalidate => true })
28
+ test 'disabled browser validations overrides default configuration' do
29
+ with_concat_form_for(:user, html: { novalidate: true })
30
30
  assert_select 'form[novalidate="novalidate"]'
31
31
  end
32
32
 
33
- test 'a form specific enabled validation option should override the disabled browser validation configuration option' do
34
- swap SimpleForm, :browser_validations => false do
35
- with_concat_form_for(:user, :html => { :novalidate => false })
33
+ test 'enabled browser validations overrides disabled configuration' do
34
+ swap SimpleForm, browser_validations: false do
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
- with_concat_form_for(:user, :html => { :novalidate => true })
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
- with_concat_form_for(:user, :as => 'superuser')
46
+ with_concat_form_for(:user, as: 'superuser')
47
47
  assert_select 'form.simple_form.superuser'
48
48
  end
49
49
 
@@ -55,7 +55,7 @@ class FormHelperTest < ActionView::TestCase
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
- with_concat_form_for(@user, :as => 'superuser')
58
+ with_concat_form_for(@user, as: 'superuser')
59
59
  assert_select 'form.simple_form.new_superuser'
60
60
  end
61
61
 
@@ -65,7 +65,7 @@ class FormHelperTest < ActionView::TestCase
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
- with_concat_form_for(@user, :as => 'superuser')
68
+ with_concat_form_for(@user, as: 'superuser')
69
69
  assert_select 'form.simple_form.edit_superuser'
70
70
  end
71
71
 
@@ -75,28 +75,28 @@ class FormHelperTest < ActionView::TestCase
75
75
  end
76
76
 
77
77
  test 'SimpleForm should not add object class to form if css_class is specified' do
78
- with_concat_form_for(:user, :html => {:class => nil})
78
+ with_concat_form_for(:user, html: { class: nil })
79
79
  assert_no_select 'form.user'
80
80
  end
81
81
 
82
82
  test 'SimpleForm should add custom class to form if css_class is specified' do
83
- with_concat_form_for(:user, :html => {:class => 'my_class'})
83
+ with_concat_form_for(:user, html: { class: 'my_class' })
84
84
  assert_select 'form.my_class'
85
85
  end
86
86
 
87
87
  test 'pass options to SimpleForm' do
88
- with_concat_form_for(:user, :url => '/account', :html => { :id => 'my_form' })
88
+ with_concat_form_for(:user, url: '/account', html: { id: 'my_form' })
89
89
  assert_select 'form#my_form'
90
90
  assert_select 'form[action=/account]'
91
91
  end
92
92
 
93
- test 'fields for yields an instance of FormBuilder' do
93
+ test 'form_for yields an instance of FormBuilder' do
94
94
  with_concat_form_for(:user) do |f|
95
95
  assert f.instance_of?(SimpleForm::FormBuilder)
96
96
  end
97
97
  end
98
98
 
99
- test 'fields for with a hash like model yeilds an instance of FormBuilder' do
99
+ test 'fields_for with a hash like model yields an instance of FormBuilder' do
100
100
  with_concat_fields_for(:author, HashBackedAuthor.new) do |f|
101
101
  assert f.instance_of?(SimpleForm::FormBuilder)
102
102
  f.input :name
@@ -134,7 +134,7 @@ class FormHelperTest < ActionView::TestCase
134
134
  private
135
135
 
136
136
  def swap_field_error_proc(expected_error_proc = lambda {})
137
- swap ActionView::Base, :field_error_proc => expected_error_proc do
137
+ swap ActionView::Base, field_error_proc: expected_error_proc do
138
138
  yield
139
139
 
140
140
  assert_equal expected_error_proc, ActionView::Base.field_error_proc
@@ -20,7 +20,7 @@ class IsolatedLabelTest < ActionView::TestCase
20
20
  end
21
21
 
22
22
  test 'label should allow a customized description' do
23
- with_label_for @user, :name, :string, :label => 'My label!'
23
+ with_label_for @user, :name, :string, label: 'My label!'
24
24
  assert_select 'label[for=user_name]', /My label!/
25
25
  end
26
26
 
@@ -30,14 +30,14 @@ class IsolatedLabelTest < ActionView::TestCase
30
30
  end
31
31
 
32
32
  test 'label should use human attribute name based on association name' do
33
- with_label_for @user, :company_id, :string, :setup_association => true
33
+ with_label_for @user, :company_id, :string, setup_association: true
34
34
  assert_select 'label', /Company Human Name!/
35
35
  end
36
36
 
37
37
  test 'label should use i18n based on model, action, and attribute to lookup translation' do
38
38
  @controller.action_name = "new"
39
- store_translations(:en, :simple_form => { :labels => { :user => {
40
- :new => { :description => 'Nova descrição' }
39
+ store_translations(:en, simple_form: { labels: { user: {
40
+ new: { description: 'Nova descrição' }
41
41
  } } }) do
42
42
  with_label_for @user, :description, :text
43
43
  assert_select 'label[for=user_description]', /Nova descrição/
@@ -46,8 +46,8 @@ class IsolatedLabelTest < ActionView::TestCase
46
46
 
47
47
  test 'label should fallback to new when action is create' do
48
48
  @controller.action_name = "create"
49
- store_translations(:en, :simple_form => { :labels => { :user => {
50
- :new => { :description => 'Nova descrição' }
49
+ store_translations(:en, simple_form: { labels: { user: {
50
+ new: { description: 'Nova descrição' }
51
51
  } } }) do
52
52
  with_label_for @user, :description, :text
53
53
  assert_select 'label[for=user_description]', /Nova descrição/
@@ -64,8 +64,8 @@ class IsolatedLabelTest < ActionView::TestCase
64
64
  end
65
65
 
66
66
  test 'label should use i18n based on model and attribute to lookup translation' do
67
- store_translations(:en, :simple_form => { :labels => { :user => {
68
- :description => 'Descrição'
67
+ store_translations(:en, simple_form: { labels: { user: {
68
+ description: 'Descrição'
69
69
  } } }) do
70
70
  with_label_for @user, :description, :text
71
71
  assert_select 'label[for=user_description]', /Descrição/
@@ -73,15 +73,15 @@ class IsolatedLabelTest < ActionView::TestCase
73
73
  end
74
74
 
75
75
  test 'label should use i18n under defaults to lookup translation' do
76
- store_translations(:en, :simple_form => { :labels => { :defaults => { :age => 'Idade' } } }) do
76
+ store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
77
77
  with_label_for @user, :age, :integer
78
78
  assert_select 'label[for=user_age]', /Idade/
79
79
  end
80
80
  end
81
81
 
82
82
  test 'label should not use i18n label if translate is false' do
83
- swap SimpleForm, :translate_labels => false do
84
- store_translations(:en, :simple_form => { :labels => { :defaults => { :age => 'Idade' } } }) do
83
+ swap SimpleForm, translate_labels: false do
84
+ store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
85
85
  with_label_for @user, :age, :integer
86
86
  assert_select 'label[for=user_age]', /Age/
87
87
  end
@@ -89,19 +89,19 @@ class IsolatedLabelTest < ActionView::TestCase
89
89
  end
90
90
 
91
91
  test 'label uses i18n with lookup for association name' do
92
- store_translations(:en, :simple_form => { :labels => {
93
- :user => { :company => 'My company!' }
92
+ store_translations(:en, simple_form: { labels: {
93
+ user: { company: 'My company!' }
94
94
  } }) do
95
- with_label_for @user, :company_id, :string, :setup_association => true
95
+ with_label_for @user, :company_id, :string, setup_association: true
96
96
  assert_select 'label[for=user_company_id]', /My company!/
97
97
  end
98
98
  end
99
99
 
100
100
  test 'label uses i18n under defaults namespace to lookup for association name' do
101
- store_translations(:en, :simple_form => { :labels => {
102
- :defaults => { :company => 'Plataformatec' }
101
+ store_translations(:en, simple_form: { labels: {
102
+ defaults: { company: 'Plataformatec' }
103
103
  } }) do
104
- with_label_for @user, :company, :string, :setup_association => true
104
+ with_label_for @user, :company, :string, setup_association: true
105
105
 
106
106
  assert_select 'form label', /Plataformatec/
107
107
  end
@@ -110,8 +110,8 @@ class IsolatedLabelTest < ActionView::TestCase
110
110
  test 'label should do correct i18n lookup for nested models with nested translation' do
111
111
  @user.company = Company.new(1, 'Empresa')
112
112
 
113
- store_translations(:en, :simple_form => { :labels => {
114
- :user => { :name => 'Usuario', :company => { :name => 'Nome da empresa' } }
113
+ store_translations(:en, simple_form: { labels: {
114
+ user: { name: 'Usuario', company: { name: 'Nome da empresa' } }
115
115
  } }) do
116
116
  with_concat_form_for @user do |f|
117
117
  concat f.input :name
@@ -128,9 +128,9 @@ class IsolatedLabelTest < ActionView::TestCase
128
128
  test 'label should do correct i18n lookup for nested models with no nested translation' do
129
129
  @user.company = Company.new(1, 'Empresa')
130
130
 
131
- store_translations(:en, :simple_form => { :labels => {
132
- :user => { :name => 'Usuario' },
133
- :company => { :name => 'Nome da empresa' }
131
+ store_translations(:en, simple_form: { labels: {
132
+ user: { name: 'Usuario' },
133
+ company: { name: 'Nome da empresa' }
134
134
  } }) do
135
135
  with_concat_form_for @user do |f|
136
136
  concat f.input :name
@@ -147,13 +147,13 @@ class IsolatedLabelTest < ActionView::TestCase
147
147
  test 'label should do correct i18n lookup for nested has_many models with no nested translation' do
148
148
  @user.tags = [Tag.new(1, 'Empresa')]
149
149
 
150
- store_translations(:en, :simple_form => { :labels => {
151
- :user => { :name => 'Usuario' },
152
- :tags => { :name => 'Nome da empresa' }
150
+ store_translations(:en, simple_form: { labels: {
151
+ user: { name: 'Usuario' },
152
+ tags: { name: 'Nome da empresa' }
153
153
  } }) do
154
154
  with_concat_form_for @user do |f|
155
155
  concat f.input :name
156
- concat(f.simple_fields_for(:tags, :child_index => "new_index") do |tags_form|
156
+ concat(f.simple_fields_for(:tags, child_index: "new_index") do |tags_form|
157
157
  concat(tags_form.input :name)
158
158
  end)
159
159
  end
@@ -177,7 +177,7 @@ class IsolatedLabelTest < ActionView::TestCase
177
177
  end
178
178
 
179
179
  test 'label should not have css class from type when generate_additional_classes_for does not include :label' do
180
- swap SimpleForm, :generate_additional_classes_for => [:wrapper, :input] do
180
+ swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
181
181
  with_label_for @user, :name, :string
182
182
  assert_no_select 'label.string'
183
183
  with_label_for @user, :description, :text
@@ -192,7 +192,7 @@ class IsolatedLabelTest < ActionView::TestCase
192
192
  end
193
193
 
194
194
  test 'label should not generate empty css class' do
195
- swap SimpleForm, :generate_additional_classes_for => [:wrapper, :input] do
195
+ swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
196
196
  with_label_for @user, :name, :string
197
197
  assert_no_select 'label[class]'
198
198
  end
@@ -206,7 +206,7 @@ class IsolatedLabelTest < ActionView::TestCase
206
206
  end
207
207
 
208
208
  test 'label should not obtain required from ActiveModel::Validations when generate_additional_classes_for does not include :label' do
209
- swap SimpleForm, :generate_additional_classes_for => [:wrapper, :input] do
209
+ swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
210
210
  with_label_for @validating_user, :name, :string
211
211
  assert_no_select 'label.required'
212
212
  with_label_for @validating_user, :status, :string
@@ -215,9 +215,9 @@ class IsolatedLabelTest < ActionView::TestCase
215
215
  end
216
216
 
217
217
  test 'label should allow overriding required when ActiveModel::Validations is included' do
218
- with_label_for @validating_user, :name, :string, :required => false
218
+ with_label_for @validating_user, :name, :string, required: false
219
219
  assert_select 'label.optional'
220
- with_label_for @validating_user, :status, :string, :required => true
220
+ with_label_for @validating_user, :status, :string, required: true
221
221
  assert_select 'label.required'
222
222
  end
223
223
 
@@ -227,7 +227,7 @@ class IsolatedLabelTest < ActionView::TestCase
227
227
  end
228
228
 
229
229
  test 'label should be able to disable required when ActiveModel::Validations is not included' do
230
- with_label_for @user, :name, :string, :required => false
230
+ with_label_for @user, :name, :string, required: false
231
231
  assert_no_select 'label.required'
232
232
  end
233
233
 
@@ -237,26 +237,26 @@ class IsolatedLabelTest < ActionView::TestCase
237
237
  end
238
238
 
239
239
  test 'label should not have required text in no required inputs' do
240
- with_label_for @user, :name, :string, :required => false
240
+ with_label_for @user, :name, :string, required: false
241
241
  assert_no_select 'form label abbr'
242
242
  end
243
243
 
244
244
  test 'label should use i18n to find required text' do
245
- store_translations(:en, :simple_form => { :required => { :text => 'campo requerido' } }) do
245
+ store_translations(:en, simple_form: { required: { text: 'campo requerido' } }) do
246
246
  with_label_for @user, :name, :string
247
247
  assert_select 'form label abbr[title=campo requerido]', '*'
248
248
  end
249
249
  end
250
250
 
251
251
  test 'label should use i18n to find required mark' do
252
- store_translations(:en, :simple_form => { :required => { :mark => '*-*' } }) do
252
+ store_translations(:en, simple_form: { required: { mark: '*-*' } }) do
253
253
  with_label_for @user, :name, :string
254
254
  assert_select 'form label abbr', '*-*'
255
255
  end
256
256
  end
257
257
 
258
258
  test 'label should use i18n to find required string tag' do
259
- store_translations(:en, :simple_form => { :required => { :html => '<span class="required" title="requerido">*</span>' } }) do
259
+ store_translations(:en, simple_form: { required: { html: '<span class="required" title="requerido">*</span>' } }) do
260
260
  with_label_for @user, :name, :string
261
261
  assert_no_select 'form label abbr'
262
262
  assert_select 'form label span.required[title=requerido]', '*'
@@ -264,22 +264,22 @@ class IsolatedLabelTest < ActionView::TestCase
264
264
  end
265
265
 
266
266
  test 'label should allow overwriting input id' do
267
- with_label_for @user, :name, :string, :input_html => { :id => 'my_new_id' }
267
+ with_label_for @user, :name, :string, input_html: { id: 'my_new_id' }
268
268
  assert_select 'label[for=my_new_id]'
269
269
  end
270
270
 
271
271
  test 'label should allow overwriting of for attribute' do
272
- with_label_for @user, :name, :string, :label_html => { :for => 'my_new_id' }
272
+ with_label_for @user, :name, :string, label_html: { for: 'my_new_id' }
273
273
  assert_select 'label[for=my_new_id]'
274
274
  end
275
275
 
276
276
  test 'label should allow overwriting of for attribute with input_html not containing id' do
277
- with_label_for @user, :name, :string, :label_html => { :for => 'my_new_id' }, :input_html => { :class => 'foo' }
277
+ with_label_for @user, :name, :string, label_html: { for: 'my_new_id' }, input_html: { class: 'foo' }
278
278
  assert_select 'label[for=my_new_id]'
279
279
  end
280
280
 
281
281
  test 'label should use default input id when it was not overridden' do
282
- with_label_for @user, :name, :string, :input_html => { :class => 'my_new_id' }
282
+ with_label_for @user, :name, :string, input_html: { class: 'my_new_id' }
283
283
  assert_select 'label[for=user_name]'
284
284
  end
285
285
 
@@ -289,13 +289,13 @@ class IsolatedLabelTest < ActionView::TestCase
289
289
  end
290
290
 
291
291
  test 'label should include for attribute for select collection' do
292
- with_label_for @user, :sex, :select, :collection => [:male, :female]
292
+ with_label_for @user, :sex, :select, collection: [:male, :female]
293
293
  assert_select 'label[for=user_sex]'
294
294
  end
295
295
 
296
296
  test 'label should use i18n properly when object is not present' do
297
- store_translations(:en, :simple_form => { :labels => {
298
- :project => { :name => 'Nome' }
297
+ store_translations(:en, simple_form: { labels: {
298
+ project: { name: 'Nome' }
299
299
  } }) do
300
300
  with_label_for :project, :name, :string
301
301
  assert_select 'label[for=project_name]', /Nome/
@@ -305,19 +305,19 @@ class IsolatedLabelTest < ActionView::TestCase
305
305
  test 'label should add required by default when object is not present' do
306
306
  with_label_for :project, :name, :string
307
307
  assert_select 'label.required[for=project_name]'
308
- with_label_for :project, :description, :string, :required => false
308
+ with_label_for :project, :description, :string, required: false
309
309
  assert_no_select 'label.required[for=project_description]'
310
310
  end
311
311
 
312
312
  test 'label should add chosen label class' do
313
- swap SimpleForm, :label_class => :my_custom_class do
313
+ swap SimpleForm, label_class: :my_custom_class do
314
314
  with_label_for @user, :name, :string
315
315
  assert_select 'label.my_custom_class'
316
316
  end
317
317
  end
318
318
 
319
319
  test 'label strips extra classes even when label_class is nil' do
320
- swap SimpleForm, :label_class => nil do
320
+ swap SimpleForm, label_class: nil do
321
321
  with_label_for @user, :name, :string
322
322
  assert_select "label[class='string required']"
323
323
  assert_no_select "label[class='string required ']"
@@ -25,7 +25,7 @@ class AssociationTest < ActionView::TestCase
25
25
  test 'builder association forwards collection to simple_fields_for' do
26
26
  calls = 0
27
27
  simple_form_for @user do |f|
28
- f.association :company, :collection => Company.all do |c|
28
+ f.association :company, collection: Company.all do |c|
29
29
  calls += 1
30
30
  end
31
31
  end
@@ -34,8 +34,8 @@ class AssociationTest < ActionView::TestCase
34
34
  end
35
35
 
36
36
  test 'builder association marks input as required based on both association and attribute' do
37
- swap SimpleForm, :required_by_default => false do
38
- with_association_for @validating_user, :company, :collection => []
37
+ swap SimpleForm, required_by_default: false do
38
+ with_association_for @validating_user, :company, collection: []
39
39
  assert_select 'label.required'
40
40
  end
41
41
  end
@@ -55,7 +55,7 @@ class AssociationTest < ActionView::TestCase
55
55
  value = @user.tags = Object.new
56
56
  value.expects(:to_a).never
57
57
 
58
- with_association_for @user, :tags, :preload => false
58
+ with_association_for @user, :tags, preload: false
59
59
  assert_select 'form select.select#user_tag_ids'
60
60
  assert_select 'form select option[value=1]', 'Tag 1'
61
61
  assert_select 'form select option[value=2]', 'Tag 2'
@@ -83,13 +83,13 @@ class AssociationTest < ActionView::TestCase
83
83
  end
84
84
 
85
85
  test 'builder creates blank select if collection is nil' do
86
- with_association_for @user, :company, :collection => nil
86
+ with_association_for @user, :company, collection: nil
87
87
  assert_select 'form select.select#user_company_id'
88
88
  assert_no_select 'form select option[value=1]', 'Company 1'
89
89
  end
90
90
 
91
91
  test 'builder allows collection radio for belongs_to associations' do
92
- with_association_for @user, :company, :as => :radio_buttons
92
+ with_association_for @user, :company, as: :radio_buttons
93
93
  assert_select 'form input.radio_buttons#user_company_id_1'
94
94
  assert_select 'form input.radio_buttons#user_company_id_2'
95
95
  assert_select 'form input.radio_buttons#user_company_id_3'
@@ -97,7 +97,7 @@ class AssociationTest < ActionView::TestCase
97
97
 
98
98
  test 'builder marks the record which already belongs to the user' do
99
99
  @user.company_id = 2
100
- with_association_for @user, :company, :as => :radio_buttons
100
+ with_association_for @user, :company, as: :radio_buttons
101
101
  assert_no_select 'form input.radio_buttons#user_company_id_1[checked=checked]'
102
102
  assert_select 'form input.radio_buttons#user_company_id_2[checked=checked]'
103
103
  assert_no_select 'form input.radio_buttons#user_company_id_3[checked=checked]'
@@ -113,32 +113,32 @@ class AssociationTest < ActionView::TestCase
113
113
  end
114
114
 
115
115
  test 'builder should allow overriding collection to association input' do
116
- with_association_for @user, :company, :include_blank => false,
117
- :collection => [Company.new(999, 'Teste')]
116
+ with_association_for @user, :company, include_blank: false,
117
+ collection: [Company.new(999, 'Teste')]
118
118
  assert_select 'form select.select#user_company_id'
119
119
  assert_no_select 'form select option[value=1]'
120
120
  assert_select 'form select option[value=999]', 'Teste'
121
- assert_select 'form select option', :count => 1
121
+ assert_select 'form select option', count: 1
122
122
  end
123
123
 
124
124
  # ASSOCIATIONS - has_*
125
125
  test 'builder does not allow has_one associations' do
126
126
  assert_raise ArgumentError do
127
- with_association_for @user, :first_company, :as => :radio_buttons
127
+ with_association_for @user, :first_company, as: :radio_buttons
128
128
  end
129
129
  end
130
130
 
131
131
  test 'builder creates a select with multiple options for collection associations' do
132
132
  with_association_for @user, :tags
133
133
  assert_select 'form select.select#user_tag_ids'
134
- assert_select 'form select[multiple=multiple][size=5]'
134
+ assert_select 'form select[multiple=multiple]'
135
135
  assert_select 'form select option[value=1]', 'Tag 1'
136
136
  assert_select 'form select option[value=2]', 'Tag 2'
137
137
  assert_select 'form select option[value=3]', 'Tag 3'
138
138
  end
139
139
 
140
140
  test 'builder allows size to be overwritten for collection associations' do
141
- with_association_for @user, :tags, :input_html => { :size => 10 }
141
+ with_association_for @user, :tags, input_html: { size: 10 }
142
142
  assert_select 'form select[multiple=multiple][size=10]'
143
143
  end
144
144
 
@@ -152,7 +152,7 @@ class AssociationTest < ActionView::TestCase
152
152
 
153
153
  test 'builder allows a collection of check boxes for collection associations' do
154
154
  @user.tag_ids = [1, 2]
155
- with_association_for @user, :tags, :as => :check_boxes
155
+ with_association_for @user, :tags, as: :check_boxes
156
156
  assert_select 'form input#user_tag_ids_1[type=checkbox]'
157
157
  assert_select 'form input#user_tag_ids_2[type=checkbox]'
158
158
  assert_select 'form input#user_tag_ids_3[type=checkbox]'
@@ -160,27 +160,27 @@ class AssociationTest < ActionView::TestCase
160
160
 
161
161
  test 'builder marks all selected records for collection boxes' do
162
162
  @user.tag_ids = [1, 2]
163
- with_association_for @user, :tags, :as => :check_boxes
163
+ with_association_for @user, :tags, as: :check_boxes
164
164
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
165
165
  assert_select 'form input[type=checkbox][value=2][checked=checked]'
166
166
  assert_no_select 'form input[type=checkbox][value=3][checked=checked]'
167
167
  end
168
168
 
169
169
  test 'builder with collection support giving collection and item wrapper tags' do
170
- with_association_for @user, :tags, :as => :check_boxes,
171
- :collection_wrapper_tag => :ul, :item_wrapper_tag => :li
170
+ with_association_for @user, :tags, as: :check_boxes,
171
+ collection_wrapper_tag: :ul, item_wrapper_tag: :li
172
172
 
173
- assert_select 'form ul', :count => 1
174
- assert_select 'form ul li', :count => 3
173
+ assert_select 'form ul', count: 1
174
+ assert_select 'form ul li', count: 3
175
175
  end
176
176
 
177
177
  test 'builder with collection support should not change the options hash' do
178
- options = { :as => :check_boxes, :collection_wrapper_tag => :ul, :item_wrapper_tag => :li}
178
+ options = { as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li}
179
179
  with_association_for @user, :tags, options
180
180
 
181
- assert_select 'form ul', :count => 1
182
- assert_select 'form ul li', :count => 3
183
- assert_equal({ :as => :check_boxes, :collection_wrapper_tag => :ul, :item_wrapper_tag => :li},
181
+ assert_select 'form ul', count: 1
182
+ assert_select 'form ul li', count: 3
183
+ assert_equal({ as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li},
184
184
  options)
185
185
  end
186
186
  end