simple_form 2.0.0 → 3.5.1

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 (103) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +97 -198
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +572 -296
  5. data/lib/generators/simple_form/install_generator.rb +17 -7
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/_form.html.erb +1 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +1 -0
  9. data/lib/generators/simple_form/templates/config/initializers/{simple_form.rb.tt → simple_form.rb} +57 -63
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +155 -0
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +111 -0
  12. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +14 -7
  13. data/lib/simple_form/action_view_extensions/builder.rb +5 -305
  14. data/lib/simple_form/action_view_extensions/form_helper.rb +18 -20
  15. data/lib/simple_form/components/errors.rb +30 -3
  16. data/lib/simple_form/components/hints.rb +10 -3
  17. data/lib/simple_form/components/html5.rb +17 -3
  18. data/lib/simple_form/components/label_input.rb +21 -2
  19. data/lib/simple_form/components/labels.rb +16 -11
  20. data/lib/simple_form/components/maxlength.rb +19 -12
  21. data/lib/simple_form/components/min_max.rb +4 -2
  22. data/lib/simple_form/components/minlength.rb +48 -0
  23. data/lib/simple_form/components/pattern.rb +5 -4
  24. data/lib/simple_form/components/placeholders.rb +3 -2
  25. data/lib/simple_form/components/readonly.rb +3 -2
  26. data/lib/simple_form/components.rb +15 -11
  27. data/lib/simple_form/error_notification.rb +4 -3
  28. data/lib/simple_form/form_builder.rb +283 -105
  29. data/lib/simple_form/helpers/autofocus.rb +1 -0
  30. data/lib/simple_form/helpers/disabled.rb +1 -0
  31. data/lib/simple_form/helpers/readonly.rb +1 -0
  32. data/lib/simple_form/helpers/required.rb +1 -0
  33. data/lib/simple_form/helpers/validators.rb +4 -3
  34. data/lib/simple_form/helpers.rb +7 -6
  35. data/lib/simple_form/i18n_cache.rb +1 -0
  36. data/lib/simple_form/inputs/base.rb +76 -23
  37. data/lib/simple_form/inputs/block_input.rb +3 -2
  38. data/lib/simple_form/inputs/boolean_input.rb +55 -16
  39. data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
  40. data/lib/simple_form/inputs/collection_input.rb +41 -18
  41. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +11 -19
  42. data/lib/simple_form/inputs/collection_select_input.rb +5 -2
  43. data/lib/simple_form/inputs/date_time_input.rb +23 -12
  44. data/lib/simple_form/inputs/file_input.rb +5 -2
  45. data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
  46. data/lib/simple_form/inputs/hidden_input.rb +5 -2
  47. data/lib/simple_form/inputs/numeric_input.rb +4 -8
  48. data/lib/simple_form/inputs/password_input.rb +6 -4
  49. data/lib/simple_form/inputs/priority_input.rb +5 -2
  50. data/lib/simple_form/inputs/range_input.rb +2 -1
  51. data/lib/simple_form/inputs/string_input.rb +6 -4
  52. data/lib/simple_form/inputs/text_input.rb +6 -3
  53. data/lib/simple_form/inputs.rb +20 -17
  54. data/lib/simple_form/map_type.rb +1 -0
  55. data/lib/simple_form/railtie.rb +15 -0
  56. data/lib/simple_form/tags.rb +69 -0
  57. data/lib/simple_form/version.rb +2 -1
  58. data/lib/simple_form/wrappers/builder.rb +12 -35
  59. data/lib/simple_form/wrappers/leaf.rb +29 -0
  60. data/lib/simple_form/wrappers/many.rb +12 -7
  61. data/lib/simple_form/wrappers/root.rb +7 -4
  62. data/lib/simple_form/wrappers/single.rb +12 -3
  63. data/lib/simple_form/wrappers.rb +3 -1
  64. data/lib/simple_form.rb +118 -63
  65. data/test/action_view_extensions/builder_test.rb +230 -164
  66. data/test/action_view_extensions/form_helper_test.rb +107 -39
  67. data/test/components/label_test.rb +105 -87
  68. data/test/form_builder/association_test.rb +131 -62
  69. data/test/form_builder/button_test.rb +15 -14
  70. data/test/form_builder/error_notification_test.rb +11 -10
  71. data/test/form_builder/error_test.rb +188 -34
  72. data/test/form_builder/general_test.rb +247 -102
  73. data/test/form_builder/hint_test.rb +59 -32
  74. data/test/form_builder/input_field_test.rb +138 -25
  75. data/test/form_builder/label_test.rb +84 -13
  76. data/test/form_builder/wrapper_test.rb +236 -33
  77. data/test/generators/simple_form_generator_test.rb +15 -4
  78. data/test/inputs/boolean_input_test.rb +147 -13
  79. data/test/inputs/collection_check_boxes_input_test.rb +166 -71
  80. data/test/inputs/collection_radio_buttons_input_test.rb +229 -113
  81. data/test/inputs/collection_select_input_test.rb +222 -85
  82. data/test/inputs/datetime_input_test.rb +134 -47
  83. data/test/inputs/disabled_test.rb +62 -21
  84. data/test/inputs/discovery_test.rb +70 -10
  85. data/test/inputs/file_input_test.rb +4 -3
  86. data/test/inputs/general_test.rb +90 -26
  87. data/test/inputs/grouped_collection_select_input_test.rb +88 -23
  88. data/test/inputs/hidden_input_test.rb +7 -5
  89. data/test/inputs/numeric_input_test.rb +56 -46
  90. data/test/inputs/priority_input_test.rb +31 -16
  91. data/test/inputs/readonly_test.rb +68 -27
  92. data/test/inputs/required_test.rb +63 -18
  93. data/test/inputs/string_input_test.rb +76 -51
  94. data/test/inputs/text_input_test.rb +21 -8
  95. data/test/simple_form_test.rb +9 -0
  96. data/test/support/discovery_inputs.rb +39 -2
  97. data/test/support/misc_helpers.rb +176 -20
  98. data/test/support/mock_controller.rb +13 -7
  99. data/test/support/models.rb +187 -71
  100. data/test/test_helper.rb +38 -39
  101. metadata +53 -39
  102. data/lib/simple_form/core_ext/hash.rb +0 -16
  103. data/test/support/mock_response.rb +0 -14
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class FormHelperTest < ActionView::TestCase
@@ -8,97 +9,164 @@ class FormHelperTest < ActionView::TestCase
8
9
  end
9
10
  end
10
11
 
11
- test 'SimpleForm should add default class to form' do
12
- concat(simple_form_for(:user) do |f| end)
12
+ test 'SimpleForm adds default class to form' do
13
+ with_concat_form_for(:user)
13
14
  assert_select 'form.simple_form'
14
15
  end
15
16
 
16
- test 'SimpleForm should use default browser validations by default' do
17
- concat(simple_form_for(:user) do |f| end)
17
+ test 'SimpleForm allows overriding default form class' do
18
+ swap SimpleForm, default_form_class: "my_custom_class" do
19
+ with_concat_form_for :user, html: { class: "override_class" }
20
+ assert_no_select 'form.my_custom_class'
21
+ assert_select 'form.override_class'
22
+ end
23
+ end
24
+
25
+ # Remove this test when SimpleForm.form_class is removed in 4.x
26
+ test 'SimpleForm allows overriding default form class, but not form class' do
27
+ ActiveSupport::Deprecation.silence do
28
+ swap SimpleForm, form_class: "fixed_class", default_form_class: "my_custom_class" do
29
+ with_concat_form_for :user, html: { class: "override_class" }
30
+ assert_no_select 'form.my_custom_class'
31
+ assert_select 'form.fixed_class.override_class'
32
+ end
33
+ end
34
+ end
35
+
36
+ test 'SimpleForm uses default browser validations by default' do
37
+ with_concat_form_for(:user)
18
38
  assert_no_select 'form[novalidate]'
19
39
  end
20
40
 
21
- test 'SimpleForm should not use default browser validations if specified in the configuration options' do
22
- swap SimpleForm, :browser_validations => false do
23
- concat(simple_form_for(:user) do |f| end)
41
+ test 'SimpleForm does not use default browser validations if specified in the configuration options' do
42
+ swap SimpleForm, browser_validations: false do
43
+ with_concat_form_for(:user)
24
44
  assert_select 'form[novalidate="novalidate"]'
25
45
  end
26
46
  end
27
47
 
28
- test 'a form specific disabled validation option should override the default enabled browser validation configuration option' do
29
- concat(simple_form_for(:user, :html => { :novalidate => true }) do |f| end)
48
+ test 'disabled browser validations overrides default configuration' do
49
+ with_concat_form_for(:user, html: { novalidate: true })
30
50
  assert_select 'form[novalidate="novalidate"]'
31
51
  end
32
52
 
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
- concat(simple_form_for(:user, :html => { :novalidate => false }) do |f| end)
53
+ test 'enabled browser validations overrides disabled configuration' do
54
+ swap SimpleForm, browser_validations: false do
55
+ with_concat_form_for(:user, html: { novalidate: false })
36
56
  assert_no_select 'form[novalidate]'
37
57
  end
38
58
  end
39
59
 
40
- test 'SimpleForm should add object name as css class to form when object is not present' do
41
- concat(simple_form_for(:user) do |f| end)
60
+ test 'SimpleForm adds object name as css class to form when object is not present' do
61
+ with_concat_form_for(:user, html: { novalidate: true })
42
62
  assert_select 'form.simple_form.user'
43
63
  end
44
64
 
45
- test 'SimpleForm should add :as option as css class to form when object is not present' do
46
- concat(simple_form_for(:user, :as => 'superuser') do |f| end)
65
+ test 'SimpleForm adds :as option as css class to form when object is not present' do
66
+ with_concat_form_for(:user, as: 'superuser')
47
67
  assert_select 'form.simple_form.superuser'
48
68
  end
49
69
 
50
- test 'SimpleForm should add object class name with new prefix as css class to form if record is not persisted' do
70
+ test 'SimpleForm adds object class name with new prefix as css class to form if record is not persisted' do
51
71
  @user.new_record!
52
- concat(simple_form_for(@user) do |f| end)
72
+ with_concat_form_for(@user)
53
73
  assert_select 'form.simple_form.new_user'
54
74
  end
55
75
 
56
- test 'SimpleForm should add :as option with new prefix as css class to form if record is not persisted' do
76
+ test 'SimpleForm adds :as option with new prefix as css class to form if record is not persisted' do
57
77
  @user.new_record!
58
- concat(simple_form_for(@user, :as => 'superuser') do |f| end)
78
+ with_concat_form_for(@user, as: 'superuser')
59
79
  assert_select 'form.simple_form.new_superuser'
60
80
  end
61
81
 
62
- test 'SimpleForm should add edit class prefix as css class to form if record is persisted' do
63
- concat(simple_form_for(@user) do |f| end)
82
+ test 'SimpleForm adds edit class prefix as css class to form if record is persisted' do
83
+ with_concat_form_for(@user)
64
84
  assert_select 'form.simple_form.edit_user'
65
85
  end
66
86
 
67
- test 'SimpleForm should add :as options with edit prefix as css class to form if record is persisted' do
68
- concat(simple_form_for(@user, :as => 'superuser') do |f| end)
87
+ test 'SimpleForm adds :as options with edit prefix as css class to form if record is persisted' do
88
+ with_concat_form_for(@user, as: 'superuser')
69
89
  assert_select 'form.simple_form.edit_superuser'
70
90
  end
71
91
 
72
- test 'SimpleForm should not add object class to form if css_class is specified' do
73
- concat(simple_form_for(:user, :html => {:class => nil}) do |f| end)
92
+ test 'SimpleForm adds last object name as css class to form when there is array of objects' do
93
+ with_concat_form_for([Company.new, @user])
94
+ assert_select 'form.simple_form.edit_user'
95
+ end
96
+
97
+ test 'SimpleForm does not add object class to form if css_class is specified' do
98
+ with_concat_form_for(:user, html: { class: nil })
74
99
  assert_no_select 'form.user'
75
100
  end
76
101
 
77
- test 'SimpleForm should add custom class to form if css_class is specified' do
78
- concat(simple_form_for(:user, :html => {:class => 'my_class'}) do |f| end)
102
+ test 'SimpleForm adds custom class to form if css_class is specified' do
103
+ with_concat_form_for(:user, html: { class: 'my_class' })
79
104
  assert_select 'form.my_class'
80
105
  end
81
106
 
82
- test 'pass options to SimpleForm' do
83
- concat(simple_form_for(:user, :url => '/account', :html => { :id => 'my_form' }) do |f| end)
107
+ test 'passes options to SimpleForm' do
108
+ with_concat_form_for(:user, url: '/account', html: { id: 'my_form' })
84
109
  assert_select 'form#my_form'
85
- assert_select 'form[action=/account]'
110
+ assert_select 'form[action="/account"]'
86
111
  end
87
112
 
88
- test 'fields for yields an instance of FormBuilder' do
89
- concat(simple_fields_for(:user) do |f|
113
+ test 'form_for yields an instance of FormBuilder' do
114
+ with_concat_form_for(:user) do |f|
90
115
  assert f.instance_of?(SimpleForm::FormBuilder)
91
- end)
116
+ end
92
117
  end
93
118
 
94
- test 'fields for with a hash like model yeilds an instance of FormBuilder' do
95
- @hash_backed_author = HashBackedAuthor.new
96
-
97
- concat(simple_fields_for(:author, @hash_backed_author) do |f|
119
+ test 'fields_for with a hash like model yields an instance of FormBuilder' do
120
+ with_concat_fields_for(:author, HashBackedAuthor.new) do |f|
98
121
  assert f.instance_of?(SimpleForm::FormBuilder)
99
122
  f.input :name
100
- end)
123
+ end
101
124
 
102
125
  assert_select "input[name='author[name]'][value='hash backed author']"
103
126
  end
127
+
128
+ test 'custom error proc is not destructive' do
129
+ swap_field_error_proc do
130
+ result = nil
131
+ simple_form_for :user do |f|
132
+ result = simple_fields_for 'address' do
133
+ 'hello'
134
+ end
135
+ end
136
+
137
+ assert_equal 'hello', result
138
+ end
139
+ end
140
+
141
+ test 'custom error proc survives an exception' do
142
+ swap_field_error_proc do
143
+ begin
144
+ simple_form_for :user do |f|
145
+ simple_fields_for 'address' do
146
+ raise 'an exception'
147
+ end
148
+ end
149
+ rescue StandardError
150
+ end
151
+ end
152
+ end
153
+
154
+ test 'SimpleForm for swaps default action view field_error_proc' do
155
+ expected_error_proc = -> {}
156
+ swap SimpleForm, field_error_proc: expected_error_proc do
157
+ simple_form_for :user do |f|
158
+ assert_equal expected_error_proc, ::ActionView::Base.field_error_proc
159
+ end
160
+ end
161
+ end
162
+
163
+ private
164
+
165
+ def swap_field_error_proc(expected_error_proc = -> {})
166
+ swap ActionView::Base, field_error_proc: expected_error_proc do
167
+ yield
168
+
169
+ assert_equal expected_error_proc, ActionView::Base.field_error_proc
170
+ end
171
+ end
104
172
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
@@ -7,54 +8,54 @@ class IsolatedLabelTest < ActionView::TestCase
7
8
  SimpleForm::Inputs::Base.reset_i18n_cache :translate_required_html
8
9
  end
9
10
 
10
- def with_label_for(object, attribute_name, type, options={})
11
+ def with_label_for(object, attribute_name, type, options = {})
11
12
  with_concat_form_for(object) do |f|
12
13
  options[:reflection] = Association.new(Company, :company, {}) if options.delete(:setup_association)
13
14
  SimpleForm::Inputs::Base.new(f, attribute_name, nil, type, options).label
14
15
  end
15
16
  end
16
17
 
17
- test 'label should generate a default humanized description' do
18
+ test 'label generates a default humanized description' do
18
19
  with_label_for @user, :name, :string
19
20
  assert_select 'label[for=user_name]', /Name/
20
21
  end
21
22
 
22
- test 'label should allow a customized description' do
23
- with_label_for @user, :name, :string, :label => 'My label!'
23
+ test 'label allows a customized description' do
24
+ with_label_for @user, :name, :string, label: 'My label!'
24
25
  assert_select 'label[for=user_name]', /My label!/
25
26
  end
26
27
 
27
- test 'label should use human attribute name from object when available' do
28
+ test 'label uses human attribute name from object when available' do
28
29
  with_label_for @user, :description, :text
29
30
  assert_select 'label[for=user_description]', /User Description!/
30
31
  end
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
+ test 'label uses human attribute name based on association name' do
34
+ with_label_for @user, :company_id, :string, setup_association: true
34
35
  assert_select 'label', /Company Human Name!/
35
36
  end
36
37
 
37
- test 'label should use i18n based on model, action, and attribute to lookup translation' do
38
+ test 'label uses i18n based on model, action, and attribute to lookup translation' do
38
39
  @controller.action_name = "new"
39
- store_translations(:en, :simple_form => { :labels => { :user => {
40
- :new => { :description => 'Nova descrição' }
41
- } } } ) do
40
+ store_translations(:en, simple_form: { labels: { user: {
41
+ new: { description: 'Nova descrição' }
42
+ } } }) do
42
43
  with_label_for @user, :description, :text
43
44
  assert_select 'label[for=user_description]', /Nova descrição/
44
45
  end
45
46
  end
46
47
 
47
- test 'label should fallback to new when action is create' do
48
+ test 'label fallbacks to new when action is create' do
48
49
  @controller.action_name = "create"
49
- store_translations(:en, :simple_form => { :labels => { :user => {
50
- :new => { :description => 'Nova descrição' }
51
- } } } ) do
50
+ store_translations(:en, simple_form: { labels: { user: {
51
+ new: { description: 'Nova descrição' }
52
+ } } }) do
52
53
  with_label_for @user, :description, :text
53
54
  assert_select 'label[for=user_description]', /Nova descrição/
54
55
  end
55
56
  end
56
57
 
57
- test 'label should not explode while looking for i18n translation when action is not set' do
58
+ test 'label does not explode while looking for i18n translation when action is not set' do
58
59
  def @controller.action_name; nil; end
59
60
 
60
61
  assert_nothing_raised do
@@ -63,46 +64,56 @@ class IsolatedLabelTest < ActionView::TestCase
63
64
  assert_select 'label[for=user_description]'
64
65
  end
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'
69
- } } } ) do
67
+ test 'label uses i18n based on model and attribute to lookup translation' do
68
+ store_translations(:en, simple_form: { labels: { user: {
69
+ description: 'Descrição'
70
+ } } }) do
70
71
  with_label_for @user, :description, :text
71
72
  assert_select 'label[for=user_description]', /Descrição/
72
73
  end
73
74
  end
74
75
 
75
- test 'input should use i18n under defaults to lookup translation' do
76
- store_translations(:en, :simple_form => { :labels => { :defaults => {:age => 'Idade'} } } ) do
76
+ test 'label uses i18n under defaults to lookup translation' do
77
+ store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
77
78
  with_label_for @user, :age, :integer
78
79
  assert_select 'label[for=user_age]', /Idade/
79
80
  end
80
81
  end
81
82
 
82
- test 'input 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
+ test 'label does not use i18n label if translate is false' do
84
+ swap SimpleForm, translate_labels: false do
85
+ store_translations(:en, simple_form: { labels: { defaults: { age: 'Idade' } } }) do
85
86
  with_label_for @user, :age, :integer
86
87
  assert_select 'label[for=user_age]', /Age/
87
88
  end
88
89
  end
89
90
  end
90
91
 
91
- test 'label should use i18n with lookup for association name' do
92
- store_translations(:en, :simple_form => { :labels => {
93
- :user => { :company => 'My company!' }
94
- } } ) do
95
- with_label_for @user, :company_id, :string, :setup_association => true
92
+ test 'label uses i18n with lookup for association name' do
93
+ store_translations(:en, simple_form: { labels: {
94
+ user: { company: 'My company!' }
95
+ } }) do
96
+ with_label_for @user, :company_id, :string, setup_association: true
96
97
  assert_select 'label[for=user_company_id]', /My company!/
97
98
  end
98
99
  end
99
100
 
100
- test 'label should do correct i18n lookup for nested models with nested translation' do
101
+ test 'label uses i18n under defaults namespace to lookup for association name' do
102
+ store_translations(:en, simple_form: { labels: {
103
+ defaults: { company: 'Plataformatec' }
104
+ } }) do
105
+ with_label_for @user, :company, :string, setup_association: true
106
+
107
+ assert_select 'form label', /Plataformatec/
108
+ end
109
+ end
110
+
111
+ test 'label does correct i18n lookup for nested models with nested translation' do
101
112
  @user.company = Company.new(1, 'Empresa')
102
113
 
103
- store_translations(:en, :simple_form => { :labels => {
104
- :user => { :name => 'Usuario', :company => { :name => 'Nome da empresa' } }
105
- } } ) do
114
+ store_translations(:en, simple_form: { labels: {
115
+ user: { name: 'Usuario', company: { name: 'Nome da empresa' } }
116
+ } }) do
106
117
  with_concat_form_for @user do |f|
107
118
  concat f.input :name
108
119
  concat(f.simple_fields_for(:company) do |company_form|
@@ -115,13 +126,13 @@ class IsolatedLabelTest < ActionView::TestCase
115
126
  end
116
127
  end
117
128
 
118
- test 'label should do correct i18n lookup for nested models with no nested translation' do
129
+ test 'label does correct i18n lookup for nested models with no nested translation' do
119
130
  @user.company = Company.new(1, 'Empresa')
120
131
 
121
- store_translations(:en, :simple_form => { :labels => {
122
- :user => { :name => 'Usuario' },
123
- :company => { :name => 'Nome da empresa' }
124
- } } ) do
132
+ store_translations(:en, simple_form: { labels: {
133
+ user: { name: 'Usuario' },
134
+ company: { name: 'Nome da empresa' }
135
+ } }) do
125
136
  with_concat_form_for @user do |f|
126
137
  concat f.input :name
127
138
  concat(f.simple_fields_for(:company) do |company_form|
@@ -134,16 +145,16 @@ class IsolatedLabelTest < ActionView::TestCase
134
145
  end
135
146
  end
136
147
 
137
- test 'label should do correct i18n lookup for nested has_many models with no nested translation' do
148
+ test 'label does correct i18n lookup for nested has_many models with no nested translation' do
138
149
  @user.tags = [Tag.new(1, 'Empresa')]
139
150
 
140
- store_translations(:en, :simple_form => { :labels => {
141
- :user => { :name => 'Usuario' },
142
- :tags => { :name => 'Nome da empresa' }
143
- } } ) do
151
+ store_translations(:en, simple_form: { labels: {
152
+ user: { name: 'Usuario' },
153
+ tags: { name: 'Nome da empresa' }
154
+ } }) do
144
155
  with_concat_form_for @user do |f|
145
156
  concat f.input :name
146
- concat(f.simple_fields_for(:tags, :child_index => "new_index") do |tags_form|
157
+ concat(f.simple_fields_for(:tags, child_index: "new_index") do |tags_form|
147
158
  concat(tags_form.input :name)
148
159
  end)
149
160
  end
@@ -153,7 +164,7 @@ class IsolatedLabelTest < ActionView::TestCase
153
164
  end
154
165
  end
155
166
 
156
- test 'label should have css class from type' do
167
+ test 'label has css class from type' do
157
168
  with_label_for @user, :name, :string
158
169
  assert_select 'label.string'
159
170
  with_label_for @user, :description, :text
@@ -166,8 +177,8 @@ class IsolatedLabelTest < ActionView::TestCase
166
177
  assert_select 'label.datetime'
167
178
  end
168
179
 
169
- test 'label should not have css class from type when generate_additional_classes_for does not include :label' do
170
- swap SimpleForm, :generate_additional_classes_for => [:wrapper, :input] do
180
+ test 'label does not have css class from type when generate_additional_classes_for does not include :label' do
181
+ swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
171
182
  with_label_for @user, :name, :string
172
183
  assert_no_select 'label.string'
173
184
  with_label_for @user, :description, :text
@@ -181,15 +192,22 @@ class IsolatedLabelTest < ActionView::TestCase
181
192
  end
182
193
  end
183
194
 
184
- test 'label should obtain required from ActiveModel::Validations when it is included' do
195
+ test 'label does not generate empty css class' do
196
+ swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
197
+ with_label_for @user, :name, :string
198
+ assert_no_select 'label[class]'
199
+ end
200
+ end
201
+
202
+ test 'label obtains required from ActiveModel::Validations when it is included' do
185
203
  with_label_for @validating_user, :name, :string
186
204
  assert_select 'label.required'
187
205
  with_label_for @validating_user, :status, :string
188
206
  assert_select 'label.optional'
189
207
  end
190
208
 
191
- test 'label should not obtain required from ActiveModel::Validations when generate_additional_classes_for does not include :label' do
192
- swap SimpleForm, :generate_additional_classes_for => [:wrapper, :input] do
209
+ test 'label does not obtain required from ActiveModel::Validations when generate_additional_classes_for does not include :label' do
210
+ swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
193
211
  with_label_for @validating_user, :name, :string
194
212
  assert_no_select 'label.required'
195
213
  with_label_for @validating_user, :status, :string
@@ -197,110 +215,110 @@ class IsolatedLabelTest < ActionView::TestCase
197
215
  end
198
216
  end
199
217
 
200
- test 'label should allow overriding required when ActiveModel::Validations is included' do
201
- with_label_for @validating_user, :name, :string, :required => false
218
+ test 'label allows overriding required when ActiveModel::Validations is included' do
219
+ with_label_for @validating_user, :name, :string, required: false
202
220
  assert_select 'label.optional'
203
- with_label_for @validating_user, :status, :string, :required => true
221
+ with_label_for @validating_user, :status, :string, required: true
204
222
  assert_select 'label.required'
205
223
  end
206
224
 
207
- test 'label should be required by default when ActiveModel::Validations is not included' do
225
+ test 'label is required by default when ActiveModel::Validations is not included' do
208
226
  with_label_for @user, :name, :string
209
227
  assert_select 'label.required'
210
228
  end
211
229
 
212
- test 'label should be able to disable required when ActiveModel::Validations is not included' do
213
- with_label_for @user, :name, :string, :required => false
230
+ test 'label is able to disable required when ActiveModel::Validations is not included' do
231
+ with_label_for @user, :name, :string, required: false
214
232
  assert_no_select 'label.required'
215
233
  end
216
234
 
217
- test 'label should add required text when required' do
235
+ test 'label adds required text when required' do
218
236
  with_label_for @user, :name, :string
219
237
  assert_select 'label.required abbr[title=required]', '*'
220
238
  end
221
239
 
222
- test 'label should not have required text in no required inputs' do
223
- with_label_for @user, :name, :string, :required => false
240
+ test 'label does not have required text in no required inputs' do
241
+ with_label_for @user, :name, :string, required: false
224
242
  assert_no_select 'form label abbr'
225
243
  end
226
244
 
227
- test 'label should use i18n to find required text' do
228
- store_translations(:en, :simple_form => { :required => { :text => 'campo requerido' }}) do
245
+ test 'label uses i18n to find required text' do
246
+ store_translations(:en, simple_form: { required: { text: 'campo requerido' } }) do
229
247
  with_label_for @user, :name, :string
230
- assert_select 'form label abbr[title=campo requerido]', '*'
248
+ assert_select 'form label abbr[title="campo requerido"]', '*'
231
249
  end
232
250
  end
233
251
 
234
- test 'label should use i18n to find required mark' do
235
- store_translations(:en, :simple_form => { :required => { :mark => '*-*' }}) do
252
+ test 'label uses i18n to find required mark' do
253
+ store_translations(:en, simple_form: { required: { mark: '*-*' } }) do
236
254
  with_label_for @user, :name, :string
237
255
  assert_select 'form label abbr', '*-*'
238
256
  end
239
257
  end
240
258
 
241
- test 'label should use i18n to find required string tag' do
242
- store_translations(:en, :simple_form => { :required => { :html => '<span class="required" title="requerido">*</span>' }}) do
259
+ test 'label uses i18n to find required string tag' do
260
+ store_translations(:en, simple_form: { required: { html: '<span class="required" title="requerido">*</span>' } }) do
243
261
  with_label_for @user, :name, :string
244
262
  assert_no_select 'form label abbr'
245
263
  assert_select 'form label span.required[title=requerido]', '*'
246
264
  end
247
265
  end
248
266
 
249
- test 'label should allow overwriting input id' do
250
- with_label_for @user, :name, :string, :input_html => { :id => 'my_new_id' }
267
+ test 'label allows overwriting input id' do
268
+ with_label_for @user, :name, :string, input_html: { id: 'my_new_id' }
251
269
  assert_select 'label[for=my_new_id]'
252
270
  end
253
271
 
254
- test 'label should allow overwriting of for attribute' do
255
- with_label_for @user, :name, :string, :label_html => { :for => 'my_new_id' }
272
+ test 'label allows overwriting of for attribute' do
273
+ with_label_for @user, :name, :string, label_html: { for: 'my_new_id' }
256
274
  assert_select 'label[for=my_new_id]'
257
275
  end
258
276
 
259
- test 'label should allow overwriting of for attribute with input_html not containing id' do
260
- with_label_for @user, :name, :string, :label_html => { :for => 'my_new_id' }, :input_html => {:class => 'foo'}
277
+ test 'label allows overwriting of for attribute with input_html not containing id' do
278
+ with_label_for @user, :name, :string, label_html: { for: 'my_new_id' }, input_html: { class: 'foo' }
261
279
  assert_select 'label[for=my_new_id]'
262
280
  end
263
281
 
264
- test 'label should use default input id when it was not overridden' do
265
- with_label_for @user, :name, :string, :input_html => { :class => 'my_new_id' }
282
+ test 'label uses default input id when it was not overridden' do
283
+ with_label_for @user, :name, :string, input_html: { class: 'my_new_id' }
266
284
  assert_select 'label[for=user_name]'
267
285
  end
268
286
 
269
- test 'label should be generated properly when object is not present' do
287
+ test 'label is generated properly when object is not present' do
270
288
  with_label_for :project, :name, :string
271
289
  assert_select 'label[for=project_name]', /Name/
272
290
  end
273
291
 
274
- test 'label should include for attribute for select collection' do
275
- with_label_for @user, :sex, :select, :collection => [:male, :female]
292
+ test 'label includes for attribute for select collection' do
293
+ with_label_for @user, :sex, :select, collection: %i[male female]
276
294
  assert_select 'label[for=user_sex]'
277
295
  end
278
296
 
279
- test 'label should use i18n properly when object is not present' do
280
- store_translations(:en, :simple_form => { :labels => {
281
- :project => { :name => 'Nome' }
282
- } } ) do
297
+ test 'label uses i18n properly when object is not present' do
298
+ store_translations(:en, simple_form: { labels: {
299
+ project: { name: 'Nome' }
300
+ } }) do
283
301
  with_label_for :project, :name, :string
284
302
  assert_select 'label[for=project_name]', /Nome/
285
303
  end
286
304
  end
287
305
 
288
- test 'label should add required by default when object is not present' do
306
+ test 'label adds required by default when object is not present' do
289
307
  with_label_for :project, :name, :string
290
308
  assert_select 'label.required[for=project_name]'
291
- with_label_for :project, :description, :string, :required => false
309
+ with_label_for :project, :description, :string, required: false
292
310
  assert_no_select 'label.required[for=project_description]'
293
311
  end
294
312
 
295
- test 'label should add chosen label class' do
296
- swap SimpleForm, :label_class => :my_custom_class do
313
+ test 'label adds chosen label class' do
314
+ swap SimpleForm, label_class: :my_custom_class do
297
315
  with_label_for @user, :name, :string
298
316
  assert_select 'label.my_custom_class'
299
317
  end
300
318
  end
301
319
 
302
320
  test 'label strips extra classes even when label_class is nil' do
303
- swap SimpleForm, :label_class => nil do
321
+ swap SimpleForm, label_class: nil do
304
322
  with_label_for @user, :name, :string
305
323
  assert_select "label[class='string required']"
306
324
  assert_no_select "label[class='string required ']"