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
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
@@ -6,246 +7,292 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
6
7
  SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
7
8
  end
8
9
 
9
- test 'input :as => :radio is deprecated in favor of :as => :radio_buttons' do
10
- assert_deprecated "[SIMPLE_FORM] Using `:as => :radio` as " \
11
- "input type is deprecated, please change it to `:as => :radio_buttons`." do
12
- with_input_for @user, :active, :radio
13
- end
14
-
15
- assert_select 'input[type=radio].radio_buttons', :count => 2
16
- end
17
-
18
- test 'input should generate boolean radio buttons by default for radio types' do
10
+ test 'input generates boolean radio buttons by default for radio types' do
19
11
  with_input_for @user, :active, :radio_buttons
20
12
  assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
21
13
  assert_select 'input[type=radio][value=false].radio_buttons#user_active_false'
22
14
  end
23
15
 
24
- test 'input as radio should generate internal labels by default' do
16
+ test 'input as radio generates internal labels by default' do
25
17
  with_input_for @user, :active, :radio_buttons
26
18
  assert_select 'label[for=user_active_true]', 'Yes'
27
19
  assert_select 'label[for=user_active_false]', 'No'
28
20
  end
29
21
 
30
- test 'input as radio should use i18n to translate internal labels' do
31
- store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
22
+ test 'input as radio generates internal labels with accurate `for` values with nested boolean style' do
23
+ swap SimpleForm, boolean_style: :nested do
24
+ with_input_for @user, :active, :radio_buttons
25
+ assert_select 'label[for=user_active_true]', 'Yes'
26
+ assert_select 'label[for=user_active_false]', 'No'
27
+ end
28
+ end
29
+
30
+ test 'nested label does not duplicate input id' do
31
+ swap SimpleForm, boolean_style: :nested do
32
+ with_input_for @user, :active, :radio_buttons, id: 'nested_id'
33
+ assert_select 'input#user_active_true'
34
+ assert_no_select 'label#user_active_true'
35
+ end
36
+ end
37
+
38
+ test 'input as radio uses i18n to translate internal labels' do
39
+ store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do
32
40
  with_input_for @user, :active, :radio_buttons
33
41
  assert_select 'label[for=user_active_true]', 'Sim'
34
42
  assert_select 'label[for=user_active_false]', 'Não'
35
43
  end
36
44
  end
37
45
 
38
- test 'input radio should not include for attribute by default' do
39
- with_input_for @user, :gender, :radio_buttons, :collection => [:male, :female]
46
+ test 'input radio does not include for attribute by default' do
47
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
40
48
  assert_select 'label'
41
49
  assert_no_select 'label[for=user_gender]'
42
50
  end
43
51
 
44
- test 'input radio should include for attribute when giving as html option' do
45
- with_input_for @user, :gender, :radio_buttons, :collection => [:male, :female], :label_html => { :for => 'gender' }
52
+ test 'input radio includes for attribute when giving as html option' do
53
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female], label_html: { for: 'gender' }
46
54
  assert_select 'label[for=gender]'
47
55
  end
48
56
 
49
- test 'input should mark the checked value when using boolean and radios' do
57
+ test 'input marks the checked value when using boolean and radios' do
50
58
  @user.active = false
51
59
  with_input_for @user, :active, :radio_buttons
52
60
  assert_no_select 'input[type=radio][value=true][checked]'
53
61
  assert_select 'input[type=radio][value=false][checked]'
54
62
  end
55
63
 
56
- test 'input should allow overriding collection for radio types' do
57
- with_input_for @user, :name, :radio_buttons, :collection => ['Jose', 'Carlos']
64
+ test 'input allows overriding collection for radio types' do
65
+ with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
58
66
  assert_select 'input[type=radio][value=Jose]'
59
67
  assert_select 'input[type=radio][value=Carlos]'
60
- assert_select 'label.collection_radio_buttons', 'Jose'
61
- assert_select 'label.collection_radio_buttons', 'Carlos'
68
+ assert_select 'label.collection_radio_buttons[for=user_name_jose]', 'Jose'
69
+ assert_select 'label.collection_radio_buttons[for=user_name_carlos]', 'Carlos'
62
70
  end
63
71
 
64
- test 'input should do automatic collection translation for radio types using defaults key' do
65
- store_translations(:en, :simple_form => { :options => { :defaults => {
66
- :gender => { :male => 'Male', :female => 'Female'}
72
+ test 'input does automatic collection translation for radio types using defaults key' do
73
+ store_translations(:en, simple_form: { options: { defaults: {
74
+ gender: { male: 'Male', female: 'Female' }
67
75
  } } } ) do
68
- with_input_for @user, :gender, :radio_buttons, :collection => [:male, :female]
76
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
69
77
  assert_select 'input[type=radio][value=male]'
70
78
  assert_select 'input[type=radio][value=female]'
71
- assert_select 'label.collection_radio_buttons', 'Male'
72
- assert_select 'label.collection_radio_buttons', 'Female'
79
+ assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
80
+ assert_select 'label.collection_radio_buttons[for=user_gender_female]', 'Female'
73
81
  end
74
82
  end
75
83
 
76
- test 'input should do automatic collection translation for radio types using specific object key' do
77
- store_translations(:en, :simple_form => { :options => { :user => {
78
- :gender => { :male => 'Male', :female => 'Female'}
84
+ test 'input does automatic collection translation for radio types using specific object key' do
85
+ store_translations(:en, simple_form: { options: { user: {
86
+ gender: { male: 'Male', female: 'Female' }
79
87
  } } } ) do
80
- with_input_for @user, :gender, :radio_buttons, :collection => [:male, :female]
88
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
81
89
  assert_select 'input[type=radio][value=male]'
82
90
  assert_select 'input[type=radio][value=female]'
83
- assert_select 'label.collection_radio_buttons', 'Male'
84
- assert_select 'label.collection_radio_buttons', 'Female'
91
+ assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
92
+ assert_select 'label.collection_radio_buttons[for=user_gender_female]', 'Female'
85
93
  end
86
94
  end
87
95
 
88
- test 'input should mark the current radio value by default' do
96
+ test 'input does automatic collection translation and preserve html markup' do
97
+ swap SimpleForm, boolean_style: :nested do
98
+ store_translations(:en, simple_form: { options: { user: {
99
+ gender: { male_html: '<strong>Male</strong>', female_html: '<strong>Female</strong>' }
100
+ } } } ) do
101
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
102
+ assert_select 'input[type=radio][value=male]'
103
+ assert_select 'input[type=radio][value=female]'
104
+ assert_select 'label[for=user_gender_male] strong', 'Male'
105
+ assert_select 'label[for=user_gender_female] strong', 'Female'
106
+ end
107
+ end
108
+ end
109
+
110
+ test 'input does automatic collection translation with keys prefixed with _html and a string value' do
111
+ swap SimpleForm, boolean_style: :nested do
112
+ store_translations(:en, simple_form: { options: { user: {
113
+ gender: { male_html: 'Male', female_html: 'Female' }
114
+ } } } ) do
115
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
116
+ assert_select 'input[type=radio][value=male]'
117
+ assert_select 'input[type=radio][value=female]'
118
+ assert_select 'label[for=user_gender_male]', 'Male'
119
+ assert_select 'label[for=user_gender_female]', 'Female'
120
+ end
121
+ end
122
+ end
123
+
124
+ test 'input marks the current radio value by default' do
89
125
  @user.name = "Carlos"
90
- with_input_for @user, :name, :radio_buttons, :collection => ['Jose', 'Carlos']
126
+ with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
91
127
  assert_select 'input[type=radio][value=Carlos][checked=checked]'
92
128
  end
93
129
 
94
- test 'input should allow using a collection with text/value arrays' do
95
- with_input_for @user, :name, :radio_buttons, :collection => [['Jose', 'jose'], ['Carlos', 'carlos']]
130
+ test 'input accepts html options as the last element of collection' do
131
+ with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose', class: 'foo']]
132
+ assert_select 'input.foo[type=radio][value=jose]'
133
+ end
134
+
135
+ test 'input allows using a collection with text/value arrays' do
136
+ with_input_for @user, :name, :radio_buttons, collection: [%w[Jose jose], %w[Carlos carlos]]
96
137
  assert_select 'input[type=radio][value=jose]'
97
138
  assert_select 'input[type=radio][value=carlos]'
98
139
  assert_select 'label.collection_radio_buttons', 'Jose'
99
140
  assert_select 'label.collection_radio_buttons', 'Carlos'
100
141
  end
101
142
 
102
- test 'input should allow using a collection with a Proc' do
103
- with_input_for @user, :name, :radio_buttons, :collection => Proc.new { ['Jose', 'Carlos' ] }
143
+ test 'input allows using a collection with a Proc' do
144
+ with_input_for @user, :name, :radio_buttons, collection: proc { %w[Jose Carlos] }
104
145
  assert_select 'label.collection_radio_buttons', 'Jose'
105
146
  assert_select 'label.collection_radio_buttons', 'Carlos'
106
147
  end
107
148
 
108
- test 'input should allow overriding only label method for collections' do
149
+ test 'input allows overriding only label method for collections' do
109
150
  with_input_for @user, :name, :radio_buttons,
110
- :collection => ['Jose' , 'Carlos'],
111
- :label_method => :upcase
151
+ collection: %w[Jose Carlos],
152
+ label_method: :upcase
112
153
  assert_select 'label.collection_radio_buttons', 'JOSE'
113
154
  assert_select 'label.collection_radio_buttons', 'CARLOS'
114
155
  end
115
156
 
116
- test 'input should allow overriding only value method for collections' do
157
+ test 'input allows overriding only value method for collections' do
117
158
  with_input_for @user, :name, :radio_buttons,
118
- :collection => ['Jose' , 'Carlos'],
119
- :value_method => :upcase
159
+ collection: %w[Jose Carlos],
160
+ value_method: :upcase
120
161
  assert_select 'input[type=radio][value=JOSE]'
121
162
  assert_select 'input[type=radio][value=CARLOS]'
122
163
  end
123
164
 
124
- test 'input should allow overriding label and value method for collections' do
165
+ test 'input allows overriding label and value method for collections' do
125
166
  with_input_for @user, :name, :radio_buttons,
126
- :collection => ['Jose' , 'Carlos'],
127
- :label_method => :upcase,
128
- :value_method => :downcase
167
+ collection: %w[Jose Carlos],
168
+ label_method: :upcase,
169
+ value_method: :downcase
129
170
  assert_select 'input[type=radio][value=jose]'
130
171
  assert_select 'input[type=radio][value=carlos]'
131
172
  assert_select 'label.collection_radio_buttons', 'JOSE'
132
173
  assert_select 'label.collection_radio_buttons', 'CARLOS'
133
174
  end
134
175
 
135
- test 'input should allow overriding label and value method using a lambda for collections' do
176
+ test 'input allows overriding label and value method using a lambda for collections' do
136
177
  with_input_for @user, :name, :radio_buttons,
137
- :collection => ['Jose' , 'Carlos'],
138
- :label_method => lambda { |i| i.upcase },
139
- :value_method => lambda { |i| i.downcase }
178
+ collection: %w[Jose Carlos],
179
+ label_method: ->(i) { i.upcase },
180
+ value_method: ->(i) { i.downcase }
140
181
  assert_select 'input[type=radio][value=jose]'
141
182
  assert_select 'input[type=radio][value=carlos]'
142
183
  assert_select 'label.collection_radio_buttons', 'JOSE'
143
184
  assert_select 'label.collection_radio_buttons', 'CARLOS'
144
185
  end
145
186
 
146
- test 'collection input with radio type should generate required html attribute' do
147
- with_input_for @user, :name, :radio_buttons, :collection => ['Jose' , 'Carlos']
187
+ test 'collection input with radio type generates required html attribute' do
188
+ with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
148
189
  assert_select 'input[type=radio].required'
149
190
  assert_select 'input[type=radio][required]'
150
191
  end
151
192
 
193
+ test 'collection input with radio type generates aria-required html attribute' do
194
+ with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
195
+ assert_select 'input[type=radio].required'
196
+ assert_select 'input[type=radio][aria-required=true]'
197
+ end
198
+
152
199
  test 'input radio does not wrap the collection by default' do
153
200
  with_input_for @user, :active, :radio_buttons
154
201
 
155
- assert_select 'form input[type=radio]', :count => 2
202
+ assert_select 'form input[type=radio]', count: 2
156
203
  assert_no_select 'form ul'
157
204
  end
158
205
 
159
206
  test 'input radio wraps the collection in the configured collection wrapper tag' do
160
- swap SimpleForm, :collection_wrapper_tag => :ul do
207
+ swap SimpleForm, collection_wrapper_tag: :ul do
161
208
  with_input_for @user, :active, :radio_buttons
162
209
 
163
- assert_select 'form ul input[type=radio]', :count => 2
210
+ assert_select 'form ul input[type=radio]', count: 2
164
211
  end
165
212
  end
166
213
 
167
214
  test 'input radio does not wrap the collection when configured with falsy values' do
168
- swap SimpleForm, :collection_wrapper_tag => false do
215
+ swap SimpleForm, collection_wrapper_tag: false do
169
216
  with_input_for @user, :active, :radio_buttons
170
217
 
171
- assert_select 'form input[type=radio]', :count => 2
218
+ assert_select 'form input[type=radio]', count: 2
172
219
  assert_no_select 'form ul'
173
220
  end
174
221
  end
175
222
 
176
223
  test 'input radio allows overriding the collection wrapper tag at input level' do
177
- swap SimpleForm, :collection_wrapper_tag => :ul do
178
- with_input_for @user, :active, :radio_buttons, :collection_wrapper_tag => :section
224
+ swap SimpleForm, collection_wrapper_tag: :ul do
225
+ with_input_for @user, :active, :radio_buttons, collection_wrapper_tag: :section
179
226
 
180
- assert_select 'form section input[type=radio]', :count => 2
227
+ assert_select 'form section input[type=radio]', count: 2
181
228
  assert_no_select 'form ul'
182
229
  end
183
230
  end
184
231
 
185
232
  test 'input radio allows disabling the collection wrapper tag at input level' do
186
- swap SimpleForm, :collection_wrapper_tag => :ul do
187
- with_input_for @user, :active, :radio_buttons, :collection_wrapper_tag => false
233
+ swap SimpleForm, collection_wrapper_tag: :ul do
234
+ with_input_for @user, :active, :radio_buttons, collection_wrapper_tag: false
188
235
 
189
- assert_select 'form input[type=radio]', :count => 2
236
+ assert_select 'form input[type=radio]', count: 2
190
237
  assert_no_select 'form ul'
191
238
  end
192
239
  end
193
240
 
194
241
  test 'input radio renders the wrapper tag with the configured wrapper class' do
195
- swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
242
+ swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
196
243
  with_input_for @user, :active, :radio_buttons
197
244
 
198
- assert_select 'form ul.inputs-list input[type=radio]', :count => 2
245
+ assert_select 'form ul.inputs-list input[type=radio]', count: 2
199
246
  end
200
247
  end
201
248
 
202
249
  test 'input radio allows giving wrapper class at input level only' do
203
- swap SimpleForm, :collection_wrapper_tag => :ul do
204
- with_input_for @user, :active, :radio_buttons, :collection_wrapper_class => 'items-list'
250
+ swap SimpleForm, collection_wrapper_tag: :ul do
251
+ with_input_for @user, :active, :radio_buttons, collection_wrapper_class: 'items-list'
205
252
 
206
- assert_select 'form ul.items-list input[type=radio]', :count => 2
253
+ assert_select 'form ul.items-list input[type=radio]', count: 2
207
254
  end
208
255
  end
209
256
 
210
257
  test 'input radio uses both configured and given wrapper classes for wrapper tag' do
211
- swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
212
- with_input_for @user, :active, :radio_buttons, :collection_wrapper_class => 'items-list'
258
+ swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
259
+ with_input_for @user, :active, :radio_buttons, collection_wrapper_class: 'items-list'
213
260
 
214
- assert_select 'form ul.inputs-list.items-list input[type=radio]', :count => 2
261
+ assert_select 'form ul.inputs-list.items-list input[type=radio]', count: 2
215
262
  end
216
263
  end
217
264
 
218
265
  test 'input radio wraps each item in the configured item wrapper tag' do
219
- swap SimpleForm, :item_wrapper_tag => :li do
266
+ swap SimpleForm, item_wrapper_tag: :li do
220
267
  with_input_for @user, :active, :radio_buttons
221
268
 
222
- assert_select 'form li input[type=radio]', :count => 2
269
+ assert_select 'form li input[type=radio]', count: 2
223
270
  end
224
271
  end
225
272
 
226
273
  test 'input radio does not wrap items when configured with falsy values' do
227
- swap SimpleForm, :item_wrapper_tag => false do
274
+ swap SimpleForm, item_wrapper_tag: false do
228
275
  with_input_for @user, :active, :radio_buttons
229
276
 
230
- assert_select 'form input[type=radio]', :count => 2
277
+ assert_select 'form input[type=radio]', count: 2
231
278
  assert_no_select 'form li'
232
279
  end
233
280
  end
234
281
 
235
282
  test 'input radio allows overriding the item wrapper tag at input level' do
236
- swap SimpleForm, :item_wrapper_tag => :li do
237
- with_input_for @user, :active, :radio_buttons, :item_wrapper_tag => :dl
283
+ swap SimpleForm, item_wrapper_tag: :li do
284
+ with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :dl
238
285
 
239
- assert_select 'form dl input[type=radio]', :count => 2
286
+ assert_select 'form dl input[type=radio]', count: 2
240
287
  assert_no_select 'form li'
241
288
  end
242
289
  end
243
290
 
244
291
  test 'input radio allows disabling the item wrapper tag at input level' do
245
- swap SimpleForm, :item_wrapper_tag => :ul do
246
- with_input_for @user, :active, :radio_buttons, :item_wrapper_tag => false
292
+ swap SimpleForm, item_wrapper_tag: :ul do
293
+ with_input_for @user, :active, :radio_buttons, item_wrapper_tag: false
247
294
 
248
- assert_select 'form input[type=radio]', :count => 2
295
+ assert_select 'form input[type=radio]', count: 2
249
296
  assert_no_select 'form li'
250
297
  end
251
298
  end
@@ -253,74 +300,143 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
253
300
  test 'input radio wraps items in a span tag by default' do
254
301
  with_input_for @user, :active, :radio_buttons
255
302
 
256
- assert_select 'form span input[type=radio]', :count => 2
303
+ assert_select 'form span input[type=radio]', count: 2
257
304
  end
258
305
 
259
306
  test 'input radio renders the item wrapper tag with a default class "radio"' do
260
- with_input_for @user, :active, :radio_buttons, :item_wrapper_tag => :li
307
+ with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :li
261
308
 
262
- assert_select 'form li.radio input[type=radio]', :count => 2
309
+ assert_select 'form li.radio input[type=radio]', count: 2
263
310
  end
264
311
 
265
312
  test 'input radio renders the item wrapper tag with the configured item wrapper class' do
266
- swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
313
+ swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
267
314
  with_input_for @user, :active, :radio_buttons
268
315
 
269
- assert_select 'form li.radio.item input[type=radio]', :count => 2
316
+ assert_select 'form li.radio.item input[type=radio]', count: 2
270
317
  end
271
318
  end
272
319
 
273
320
  test 'input radio allows giving item wrapper class at input level only' do
274
- swap SimpleForm, :item_wrapper_tag => :li do
275
- with_input_for @user, :active, :radio_buttons, :item_wrapper_class => 'item'
321
+ swap SimpleForm, item_wrapper_tag: :li do
322
+ with_input_for @user, :active, :radio_buttons, item_wrapper_class: 'item'
276
323
 
277
- assert_select 'form li.radio.item input[type=radio]', :count => 2
324
+ assert_select 'form li.radio.item input[type=radio]', count: 2
278
325
  end
279
326
  end
280
327
 
281
328
  test 'input radio uses both configured and given item wrapper classes for item wrapper tag' do
282
- swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
283
- with_input_for @user, :active, :radio_buttons, :item_wrapper_class => 'inline'
329
+ swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
330
+ with_input_for @user, :active, :radio_buttons, item_wrapper_class: 'inline'
284
331
 
285
- assert_select 'form li.radio.item.inline input[type=radio]', :count => 2
332
+ assert_select 'form li.radio.item.inline input[type=radio]', count: 2
286
333
  end
287
334
  end
288
335
 
289
336
  test 'input radio respects the nested boolean style config, generating nested label > input' do
290
- swap SimpleForm, :boolean_style => :nested do
337
+ swap SimpleForm, boolean_style: :nested do
291
338
  with_input_for @user, :active, :radio_buttons
292
339
 
293
- assert_select 'label.radio > input#user_active_true[type=radio]'
294
- assert_select 'label.radio', 'Yes'
295
- assert_select 'label.radio > input#user_active_false[type=radio]'
296
- assert_select 'label.radio', 'No'
340
+ assert_select 'span.radio > label > input#user_active_true[type=radio]'
341
+ assert_select 'span.radio > label', 'Yes'
342
+ assert_select 'span.radio > label > input#user_active_false[type=radio]'
343
+ assert_select 'span.radio > label', 'No'
297
344
  assert_no_select 'label.collection_radio_buttons'
298
345
  end
299
346
  end
300
347
 
301
- test 'input radio with nested style overrides configured item wrapper tag, forcing the :label' do
302
- swap SimpleForm, :boolean_style => :nested, :item_wrapper_tag => :li do
348
+ test 'input radio with nested style does not overrides configured item wrapper tag' do
349
+ swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
303
350
  with_input_for @user, :active, :radio_buttons
304
351
 
305
- assert_select 'label.radio > input'
306
- assert_no_select 'li'
352
+ assert_select 'li.radio > label > input'
307
353
  end
308
354
  end
309
355
 
310
- test 'input radio with nested style overrides given item wrapper tag, forcing the :label' do
311
- swap SimpleForm, :boolean_style => :nested do
312
- with_input_for @user, :active, :radio_buttons, :item_wrapper_tag => :li
356
+ test 'input radio with nested style does not overrides given item wrapper tag' do
357
+ swap SimpleForm, boolean_style: :nested do
358
+ with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :li
313
359
 
314
- assert_select 'label.radio > input'
315
- assert_no_select 'li'
360
+ assert_select 'li.radio > label > input'
316
361
  end
317
362
  end
318
363
 
319
364
  test 'input radio with nested style accepts giving extra wrapper classes' do
320
- swap SimpleForm, :boolean_style => :nested do
321
- with_input_for @user, :active, :radio_buttons, :item_wrapper_class => "inline"
365
+ swap SimpleForm, boolean_style: :nested do
366
+ with_input_for @user, :active, :radio_buttons, item_wrapper_class: "inline"
367
+
368
+ assert_select 'span.radio.inline > label > input'
369
+ end
370
+ end
371
+
372
+ test 'input radio with nested style renders item labels with specified class' do
373
+ swap SimpleForm, boolean_style: :nested do
374
+ with_input_for @user, :active, :radio_buttons, item_label_class: "test"
375
+
376
+ assert_select 'span.radio > label.test > input'
377
+ end
378
+ end
379
+
380
+ test 'input radio with nested style and falsey input wrapper renders item labels with specified class' do
381
+ swap SimpleForm, boolean_style: :nested, item_wrapper_tag: false do
382
+ with_input_for @user, :active, :radio_buttons, item_label_class: "radio-inline"
383
+
384
+ assert_select 'label.radio-inline > input'
385
+ assert_no_select 'span.radio'
386
+ end
387
+ end
388
+
389
+ test 'input radio wrapper class are not included when set to falsey' do
390
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
391
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
392
+
393
+ assert_no_select 'label.radio'
394
+ end
395
+ end
396
+
397
+ test 'input radio custom wrapper class is included when include input wrapper class is falsey' do
398
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
399
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female], item_wrapper_class: 'custom'
400
+
401
+ assert_no_select 'label.radio'
402
+ assert_select 'span.custom'
403
+ end
404
+ end
405
+
406
+ test 'input radio with nested style and namespace uses the right for attribute' do
407
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
408
+ with_concat_form_for @user, namespace: :foo do |f|
409
+ concat f.input :gender, as: :radio_buttons, collection: %i[male female]
410
+ end
411
+
412
+ assert_select 'label[for=foo_user_gender_male]'
413
+ assert_select 'label[for=foo_user_gender_female]'
414
+ end
415
+ end
416
+
417
+ test 'input radio with nested style and index uses the right for attribute' do
418
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
419
+ with_concat_form_for @user, index: 1 do |f|
420
+ concat f.input :gender, as: :radio_buttons, collection: %i[male female]
421
+ end
422
+
423
+ assert_select 'label[for=user_1_gender_male]'
424
+ assert_select 'label[for=user_1_gender_female]'
425
+ end
426
+ end
427
+
428
+ test 'input radio with nested style accetps non-string attribute as label' do
429
+ swap SimpleForm, boolean_style: :nested do
430
+ with_input_for @user, :amount,
431
+ :radio_buttons,
432
+ collection: { 100 => 'hundred', 200 => 'two_hundred' },
433
+ label_method: :first,
434
+ value_method: :second
322
435
 
323
- assert_select 'label.radio.inline > input'
436
+ assert_select 'input[type=radio][value=hundred]'
437
+ assert_select 'input[type=radio][value=two_hundred]'
438
+ assert_select 'span.radio > label', '100'
439
+ assert_select 'span.radio > label', '200'
324
440
  end
325
441
  end
326
442
  end