simple_form 2.1.0 → 3.0.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 (69) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +22 -32
  3. data/README.md +161 -119
  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 +16 -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 +155 -51
  18. data/lib/simple_form/helpers.rb +1 -1
  19. data/lib/simple_form/inputs/base.rb +6 -6
  20. data/lib/simple_form/inputs/block_input.rb +1 -1
  21. data/lib/simple_form/inputs/boolean_input.rb +6 -4
  22. data/lib/simple_form/inputs/collection_input.rb +6 -6
  23. data/lib/simple_form/inputs/date_time_input.rb +1 -1
  24. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  25. data/lib/simple_form/inputs/password_input.rb +0 -1
  26. data/lib/simple_form/inputs/string_input.rb +0 -1
  27. data/lib/simple_form/railtie.rb +7 -0
  28. data/lib/simple_form/tags.rb +62 -0
  29. data/lib/simple_form/version.rb +1 -1
  30. data/lib/simple_form/wrappers/builder.rb +5 -29
  31. data/lib/simple_form/wrappers/many.rb +1 -1
  32. data/lib/simple_form/wrappers/root.rb +1 -1
  33. data/lib/simple_form/wrappers.rb +1 -1
  34. data/lib/simple_form.rb +43 -47
  35. data/test/action_view_extensions/builder_test.rb +78 -92
  36. data/test/action_view_extensions/form_helper_test.rb +25 -16
  37. data/test/components/label_test.rb +46 -46
  38. data/test/form_builder/association_test.rb +47 -29
  39. data/test/form_builder/button_test.rb +4 -4
  40. data/test/form_builder/error_notification_test.rb +8 -8
  41. data/test/form_builder/error_test.rb +12 -12
  42. data/test/form_builder/general_test.rb +71 -52
  43. data/test/form_builder/hint_test.rb +22 -22
  44. data/test/form_builder/input_field_test.rb +29 -12
  45. data/test/form_builder/label_test.rb +7 -7
  46. data/test/form_builder/wrapper_test.rb +21 -21
  47. data/test/inputs/boolean_input_test.rb +35 -23
  48. data/test/inputs/collection_check_boxes_input_test.rb +66 -55
  49. data/test/inputs/collection_radio_buttons_input_test.rb +81 -79
  50. data/test/inputs/collection_select_input_test.rb +76 -45
  51. data/test/inputs/datetime_input_test.rb +17 -11
  52. data/test/inputs/disabled_test.rb +10 -10
  53. data/test/inputs/discovery_test.rb +4 -4
  54. data/test/inputs/file_input_test.rb +1 -1
  55. data/test/inputs/general_test.rb +28 -12
  56. data/test/inputs/grouped_collection_select_input_test.rb +33 -20
  57. data/test/inputs/hidden_input_test.rb +3 -2
  58. data/test/inputs/numeric_input_test.rb +3 -3
  59. data/test/inputs/priority_input_test.rb +9 -3
  60. data/test/inputs/readonly_test.rb +12 -12
  61. data/test/inputs/required_test.rb +5 -5
  62. data/test/inputs/string_input_test.rb +15 -25
  63. data/test/inputs/text_input_test.rb +1 -1
  64. data/test/support/misc_helpers.rb +46 -24
  65. data/test/support/mock_controller.rb +6 -6
  66. data/test/support/models.rb +80 -62
  67. data/test/test_helper.rb +17 -34
  68. metadata +31 -29
  69. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -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,43 +34,53 @@ 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
42
42
 
43
43
  test 'builder preloads collection association' do
44
- value = @user.tags = Object.new
45
- value.expects(:to_a).returns(value)
44
+ value = @user.tags = MiniTest::Mock.new
45
+ value.expect(:to_a, value)
46
46
 
47
47
  with_association_for @user, :tags
48
48
  assert_select 'form select.select#user_tag_ids'
49
49
  assert_select 'form select option[value=1]', 'Tag 1'
50
50
  assert_select 'form select option[value=2]', 'Tag 2'
51
51
  assert_select 'form select option[value=3]', 'Tag 3'
52
+
53
+ value.verify
52
54
  end
53
55
 
54
56
  test 'builder does not preload collection association if preload is false' do
55
- value = @user.tags = Object.new
56
- value.expects(:to_a).never
57
+ value = @user.tags = MiniTest::Mock.new
58
+ value.expect(:to_a, nil)
57
59
 
58
- with_association_for @user, :tags, :preload => false
60
+ with_association_for @user, :tags, preload: false
59
61
  assert_select 'form select.select#user_tag_ids'
60
62
  assert_select 'form select option[value=1]', 'Tag 1'
61
63
  assert_select 'form select option[value=2]', 'Tag 2'
62
64
  assert_select 'form select option[value=3]', 'Tag 3'
65
+
66
+ assert_raises MockExpectationError do
67
+ value.verify
68
+ end
63
69
  end
64
70
 
65
71
  test 'builder does not preload non-collection association' do
66
- value = @user.company = Object.new
67
- value.expects(:to_a).never
72
+ value = @user.company = MiniTest::Mock.new
73
+ value.expect(:to_a, nil)
68
74
 
69
75
  with_association_for @user, :company
70
76
  assert_select 'form select.select#user_company_id'
71
77
  assert_select 'form select option[value=1]', 'Company 1'
72
78
  assert_select 'form select option[value=2]', 'Company 2'
73
79
  assert_select 'form select option[value=3]', 'Company 3'
80
+
81
+ assert_raises MockExpectationError do
82
+ value.verify
83
+ end
74
84
  end
75
85
 
76
86
  # ASSOCIATIONS - BELONGS TO
@@ -83,21 +93,29 @@ class AssociationTest < ActionView::TestCase
83
93
  end
84
94
 
85
95
  test 'builder creates blank select if collection is nil' do
86
- with_association_for @user, :company, :collection => nil
96
+ with_association_for @user, :company, collection: nil
87
97
  assert_select 'form select.select#user_company_id'
88
98
  assert_no_select 'form select option[value=1]', 'Company 1'
89
99
  end
90
100
 
91
101
  test 'builder allows collection radio for belongs_to associations' do
92
- with_association_for @user, :company, :as => :radio_buttons
102
+ with_association_for @user, :company, as: :radio_buttons
93
103
  assert_select 'form input.radio_buttons#user_company_id_1'
94
104
  assert_select 'form input.radio_buttons#user_company_id_2'
95
105
  assert_select 'form input.radio_buttons#user_company_id_3'
96
106
  end
97
107
 
108
+ test 'builder allows collection to have a proc as a condition' do
109
+ with_association_for @user, :extra_special_company
110
+ assert_select 'form select.select#user_extra_special_company_id'
111
+ assert_select 'form select option[value=1]'
112
+ assert_no_select 'form select option[value=2]'
113
+ assert_no_select 'form select option[value=3]'
114
+ end
115
+
98
116
  test 'builder marks the record which already belongs to the user' do
99
117
  @user.company_id = 2
100
- with_association_for @user, :company, :as => :radio_buttons
118
+ with_association_for @user, :company, as: :radio_buttons
101
119
  assert_no_select 'form input.radio_buttons#user_company_id_1[checked=checked]'
102
120
  assert_select 'form input.radio_buttons#user_company_id_2[checked=checked]'
103
121
  assert_no_select 'form input.radio_buttons#user_company_id_3[checked=checked]'
@@ -113,32 +131,32 @@ class AssociationTest < ActionView::TestCase
113
131
  end
114
132
 
115
133
  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')]
134
+ with_association_for @user, :company, include_blank: false,
135
+ collection: [Company.new(999, 'Teste')]
118
136
  assert_select 'form select.select#user_company_id'
119
137
  assert_no_select 'form select option[value=1]'
120
138
  assert_select 'form select option[value=999]', 'Teste'
121
- assert_select 'form select option', :count => 1
139
+ assert_select 'form select option', count: 1
122
140
  end
123
141
 
124
142
  # ASSOCIATIONS - has_*
125
143
  test 'builder does not allow has_one associations' do
126
144
  assert_raise ArgumentError do
127
- with_association_for @user, :first_company, :as => :radio_buttons
145
+ with_association_for @user, :first_company, as: :radio_buttons
128
146
  end
129
147
  end
130
148
 
131
149
  test 'builder creates a select with multiple options for collection associations' do
132
150
  with_association_for @user, :tags
133
151
  assert_select 'form select.select#user_tag_ids'
134
- assert_select 'form select[multiple=multiple][size=5]'
152
+ assert_select 'form select[multiple=multiple]'
135
153
  assert_select 'form select option[value=1]', 'Tag 1'
136
154
  assert_select 'form select option[value=2]', 'Tag 2'
137
155
  assert_select 'form select option[value=3]', 'Tag 3'
138
156
  end
139
157
 
140
158
  test 'builder allows size to be overwritten for collection associations' do
141
- with_association_for @user, :tags, :input_html => { :size => 10 }
159
+ with_association_for @user, :tags, input_html: { size: 10 }
142
160
  assert_select 'form select[multiple=multiple][size=10]'
143
161
  end
144
162
 
@@ -152,7 +170,7 @@ class AssociationTest < ActionView::TestCase
152
170
 
153
171
  test 'builder allows a collection of check boxes for collection associations' do
154
172
  @user.tag_ids = [1, 2]
155
- with_association_for @user, :tags, :as => :check_boxes
173
+ with_association_for @user, :tags, as: :check_boxes
156
174
  assert_select 'form input#user_tag_ids_1[type=checkbox]'
157
175
  assert_select 'form input#user_tag_ids_2[type=checkbox]'
158
176
  assert_select 'form input#user_tag_ids_3[type=checkbox]'
@@ -160,27 +178,27 @@ class AssociationTest < ActionView::TestCase
160
178
 
161
179
  test 'builder marks all selected records for collection boxes' do
162
180
  @user.tag_ids = [1, 2]
163
- with_association_for @user, :tags, :as => :check_boxes
181
+ with_association_for @user, :tags, as: :check_boxes
164
182
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
165
183
  assert_select 'form input[type=checkbox][value=2][checked=checked]'
166
184
  assert_no_select 'form input[type=checkbox][value=3][checked=checked]'
167
185
  end
168
186
 
169
187
  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
188
+ with_association_for @user, :tags, as: :check_boxes,
189
+ collection_wrapper_tag: :ul, item_wrapper_tag: :li
172
190
 
173
- assert_select 'form ul', :count => 1
174
- assert_select 'form ul li', :count => 3
191
+ assert_select 'form ul', count: 1
192
+ assert_select 'form ul li', count: 3
175
193
  end
176
194
 
177
195
  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}
196
+ options = { as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li}
179
197
  with_association_for @user, :tags, options
180
198
 
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},
199
+ assert_select 'form ul', count: 1
200
+ assert_select 'form ul li', count: 3
201
+ assert_equal({ as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li},
184
202
  options)
185
203
  end
186
204
  end
@@ -14,15 +14,15 @@ class ButtonTest < ActionView::TestCase
14
14
  end
15
15
 
16
16
  test 'builder should create buttons with options' do
17
- with_button_for :post, :submit, :class => 'my_button'
17
+ with_button_for :post, :submit, class: 'my_button'
18
18
  assert_select 'form input.button.my_button[type=submit][value=Save Post]'
19
19
  end
20
20
 
21
21
  test 'builder should not modify the options hash' do
22
- options = { :class => 'my_button' }
22
+ options = { class: 'my_button' }
23
23
  with_button_for :post, :submit, options
24
24
  assert_select 'form input.button.my_button[type=submit][value=Save Post]'
25
- assert_equal({ :class => 'my_button' }, options)
25
+ assert_equal({ class: 'my_button' }, options)
26
26
  end
27
27
 
28
28
  test 'builder should create buttons for records' do
@@ -32,7 +32,7 @@ class ButtonTest < ActionView::TestCase
32
32
  end
33
33
 
34
34
  test "builder should use the default class from the configuration" do
35
- swap SimpleForm, :button_class => 'btn' do
35
+ swap SimpleForm, button_class: 'btn' do
36
36
  with_button_for :post, :submit
37
37
  assert_select 'form input.btn[type=submit][value=Save Post]'
38
38
  end
@@ -27,7 +27,7 @@ class ErrorNotificationTest < ActionView::TestCase
27
27
  end
28
28
 
29
29
  test 'error notification uses I18n based on model to generate the notification message' do
30
- store_translations(:en, :simple_form => { :error_notification => { :user =>
30
+ store_translations(:en, simple_form: { error_notification: { user:
31
31
  'Alguns erros foram encontrados para o usuário:'
32
32
  } }) do
33
33
  with_error_notification_for @user
@@ -36,8 +36,8 @@ class ErrorNotificationTest < ActionView::TestCase
36
36
  end
37
37
 
38
38
  test 'error notification uses I18n fallbacking to default message' do
39
- store_translations(:en, :simple_form => { :error_notification => {
40
- :default_message => 'Opa! Alguns erros foram encontrados, poderia verificar?'
39
+ store_translations(:en, simple_form: { error_notification: {
40
+ default_message: 'Opa! Alguns erros foram encontrados, poderia verificar?'
41
41
  } }) do
42
42
  with_error_notification_for @user
43
43
  assert_select 'p.error_notification', 'Opa! Alguns erros foram encontrados, poderia verificar?'
@@ -45,30 +45,30 @@ class ErrorNotificationTest < ActionView::TestCase
45
45
  end
46
46
 
47
47
  test 'error notification allows passing the notification message' do
48
- with_error_notification_for @user, :message => 'Erro encontrado ao criar usuario'
48
+ with_error_notification_for @user, message: 'Erro encontrado ao criar usuario'
49
49
  assert_select 'p.error_notification', 'Erro encontrado ao criar usuario'
50
50
  end
51
51
 
52
52
  test 'error notification accepts other html options' do
53
- with_error_notification_for @user, :id => 'user_error_message', :class => 'form_error'
53
+ with_error_notification_for @user, id: 'user_error_message', class: 'form_error'
54
54
  assert_select 'p#user_error_message.form_error.error_notification'
55
55
  end
56
56
 
57
57
  test 'error notification allows configuring the wrapper element' do
58
- swap SimpleForm, :error_notification_tag => :div do
58
+ swap SimpleForm, error_notification_tag: :div do
59
59
  with_error_notification_for @user
60
60
  assert_select 'div.error_notification'
61
61
  end
62
62
  end
63
63
 
64
64
  test 'error notification can contain HTML tags' do
65
- with_error_notification_for @user, :message => 'Erro encontrado ao criar <b>usuário</b>'
65
+ with_error_notification_for @user, message: 'Erro encontrado ao criar <b>usuário</b>'
66
66
  assert_select 'p.error_notification', 'Erro encontrado ao criar usuário'
67
67
  assert_select 'p.error_notification b', 'usuário'
68
68
  end
69
69
 
70
70
  test 'error notification uses I18n based on model to generate the notification message and accepts HTML' do
71
- store_translations(:en, :simple_form => { :error_notification => { :user =>
71
+ store_translations(:en, simple_form: { error_notification: { user:
72
72
  'Alguns erros foram encontrados para o <b>usuário</b>:'
73
73
  } }) do
74
74
  with_error_notification_for @user
@@ -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