simple_form 3.1.0.rc2 → 3.2.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +76 -24
  5. data/lib/generators/simple_form/install_generator.rb +2 -2
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +4 -4
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +22 -2
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +85 -4
  9. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  10. data/lib/simple_form/action_view_extensions/form_helper.rb +5 -1
  11. data/lib/simple_form/components/errors.rb +3 -5
  12. data/lib/simple_form/components/html5.rb +4 -4
  13. data/lib/simple_form/components/labels.rb +1 -1
  14. data/lib/simple_form/form_builder.rb +9 -7
  15. data/lib/simple_form/inputs/base.rb +1 -5
  16. data/lib/simple_form/inputs/boolean_input.rb +1 -1
  17. data/lib/simple_form/inputs/collection_input.rb +2 -4
  18. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +1 -1
  19. data/lib/simple_form/inputs/date_time_input.rb +12 -8
  20. data/lib/simple_form/tags.rb +2 -4
  21. data/lib/simple_form/version.rb +1 -1
  22. data/lib/simple_form.rb +13 -2
  23. data/test/action_view_extensions/builder_test.rb +31 -31
  24. data/test/action_view_extensions/form_helper_test.rb +20 -1
  25. data/test/components/label_test.rb +1 -1
  26. data/test/form_builder/association_test.rb +37 -37
  27. data/test/form_builder/button_test.rb +5 -5
  28. data/test/form_builder/error_test.rb +75 -16
  29. data/test/form_builder/general_test.rb +42 -11
  30. data/test/form_builder/hint_test.rb +3 -3
  31. data/test/form_builder/input_field_test.rb +59 -53
  32. data/test/form_builder/label_test.rb +13 -3
  33. data/test/form_builder/wrapper_test.rb +29 -14
  34. data/test/generators/simple_form_generator_test.rb +2 -2
  35. data/test/inputs/boolean_input_test.rb +9 -1
  36. data/test/inputs/collection_check_boxes_input_test.rb +22 -0
  37. data/test/inputs/collection_radio_buttons_input_test.rb +25 -3
  38. data/test/inputs/collection_select_input_test.rb +17 -17
  39. data/test/inputs/datetime_input_test.rb +6 -1
  40. data/test/inputs/grouped_collection_select_input_test.rb +8 -8
  41. data/test/inputs/numeric_input_test.rb +19 -19
  42. data/test/inputs/priority_input_test.rb +6 -6
  43. data/test/inputs/required_test.rb +12 -0
  44. data/test/inputs/string_input_test.rb +10 -19
  45. data/test/inputs/text_input_test.rb +10 -3
  46. data/test/support/misc_helpers.rb +14 -1
  47. data/test/support/models.rb +11 -1
  48. data/test/test_helper.rb +9 -1
  49. metadata +17 -17
@@ -46,6 +46,17 @@ class FormBuilderTest < ActionView::TestCase
46
46
  end
47
47
  end
48
48
 
49
+ test 'builder does not override custom input mappings for custom collection' do
50
+ swap SimpleForm, input_mappings: { /gender$/ => :check_boxes } do
51
+ with_concat_form_for @user do |f|
52
+ f.input :gender, collection: [:male, :female]
53
+ end
54
+
55
+ assert_no_select 'select option', 'Male'
56
+ assert_select 'input[type=checkbox][value=male]'
57
+ end
58
+ end
59
+
49
60
  test 'builder allows to skip input_type class' do
50
61
  swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
51
62
  with_form_for @user, :post_count
@@ -217,10 +228,30 @@ class FormBuilderTest < ActionView::TestCase
217
228
  end
218
229
 
219
230
  # COMMON OPTIONS
231
+ # Remove this test when SimpleForm.form_class is removed in 4.x
220
232
  test 'builder adds chosen form class' do
221
- swap SimpleForm, form_class: :my_custom_class do
233
+ ActiveSupport::Deprecation.silence do
234
+ swap SimpleForm, form_class: :my_custom_class do
235
+ with_form_for @user, :name
236
+ assert_select 'form.my_custom_class'
237
+ end
238
+ end
239
+ end
240
+
241
+ # Remove this test when SimpleForm.form_class is removed in 4.x
242
+ test 'builder adds chosen form class and default form class' do
243
+ ActiveSupport::Deprecation.silence do
244
+ swap SimpleForm, form_class: "my_custom_class", default_form_class: "my_default_class" do
245
+ with_form_for @user, :name
246
+ assert_select 'form.my_custom_class.my_default_class'
247
+ end
248
+ end
249
+ end
250
+
251
+ test 'builder adds default form class' do
252
+ swap SimpleForm, default_form_class: "default_class" do
222
253
  with_form_for @user, :name
223
- assert_select 'form.my_custom_class'
254
+ assert_select 'form.default_class'
224
255
  end
225
256
  end
226
257
 
@@ -236,7 +267,7 @@ class FormBuilderTest < ActionView::TestCase
236
267
  end
237
268
 
238
269
  test 'builder does not propagate input options to wrapper with custom wrapper' do
239
- swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
270
+ swap_wrapper :default, custom_wrapper_with_wrapped_input do
240
271
  with_form_for @user, :name, input_html: { class: 'my_input' }
241
272
  assert_no_select 'form div.input.my_input'
242
273
  assert_select 'form input.my_input.string'
@@ -244,7 +275,7 @@ class FormBuilderTest < ActionView::TestCase
244
275
  end
245
276
 
246
277
  test 'builder does not propagate label options to wrapper with custom wrapper' do
247
- swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
278
+ swap_wrapper :default, custom_wrapper_with_wrapped_label do
248
279
  with_form_for @user, :name, label_html: { class: 'my_label' }
249
280
  assert_no_select 'form div.label.my_label'
250
281
  assert_select 'form label.my_label.string'
@@ -307,7 +338,7 @@ class FormBuilderTest < ActionView::TestCase
307
338
 
308
339
  test 'builder generates errors for attribute with errors' do
309
340
  with_form_for @user, :name
310
- assert_select 'span.error', "can't be blank"
341
+ assert_select 'span.error', "cannot be blank"
311
342
  end
312
343
 
313
344
  test 'builder is able to disable showing errors for an input' do
@@ -317,7 +348,7 @@ class FormBuilderTest < ActionView::TestCase
317
348
 
318
349
  test 'builder passes options to errors' do
319
350
  with_form_for @user, :name, error_html: { id: "cool" }
320
- assert_select 'span.error#cool', "can't be blank"
351
+ assert_select 'span.error#cool', "cannot be blank"
321
352
  end
322
353
 
323
354
  test 'placeholder does not be generated when set to false' do
@@ -333,15 +364,15 @@ class FormBuilderTest < ActionView::TestCase
333
364
  [:input, :input_field].each do |method|
334
365
  test "builder receives a default argument and pass it to the inputs when calling '#{method}'" do
335
366
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
336
- f.send(method, :name)
367
+ f.public_send(method, :name)
337
368
  end
338
369
  assert_select 'input.default_class'
339
370
  end
340
371
 
341
372
  test "builder receives a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
342
373
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
343
- concat(f.send(method, :name))
344
- concat(f.send(method, :credit_limit))
374
+ concat(f.public_send(method, :name))
375
+ concat(f.public_send(method, :credit_limit))
345
376
  end
346
377
 
347
378
  assert_select "input.string.default_class[name='user[name]']"
@@ -352,9 +383,9 @@ class FormBuilderTest < ActionView::TestCase
352
383
  @user.company = Company.new(1, 'Empresa')
353
384
 
354
385
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
355
- concat(f.send(method, :name))
386
+ concat(f.public_send(method, :name))
356
387
  concat(f.simple_fields_for(:company) do |company_form|
357
- concat(company_form.send(method, :name))
388
+ concat(company_form.public_send(method, :name))
358
389
  end)
359
390
  end
360
391
 
@@ -50,7 +50,7 @@ class HintTest < ActionView::TestCase
50
50
 
51
51
  test 'builder escapes hint text' do
52
52
  with_hint_for @user, :name, hint: '<script>alert(1337)</script>'
53
- assert_select 'span.hint', "&lt;script&gt;alert(1337)&lt;/script&gt;"
53
+ assert_no_select 'span.hint script'
54
54
  end
55
55
 
56
56
  # Without attribute name
@@ -137,8 +137,8 @@ class HintTest < ActionView::TestCase
137
137
 
138
138
  test 'hint with custom wrappers works' do
139
139
  swap_wrapper do
140
- with_hint_for @user, :name, hint: "can't be blank"
141
- assert_select 'div.omg_hint', "can&#39;t be blank"
140
+ with_hint_for @user, :name, hint: "cannot be blank"
141
+ assert_select 'div.omg_hint', "cannot be blank"
142
142
  end
143
143
  end
144
144
  end
@@ -2,10 +2,15 @@ require 'test_helper'
2
2
 
3
3
  # Tests for f.input_field
4
4
  class InputFieldTest < ActionView::TestCase
5
- test "builder input_field only renders the input tag, nothing else" do
6
- with_concat_form_for(@user) do |f|
7
- f.input_field :name
5
+ def with_input_field_for(object, *args)
6
+ with_concat_form_for(object) do |f|
7
+ f.input_field(*args)
8
8
  end
9
+ end
10
+
11
+ test "builder input_field only renders the input tag, nothing else" do
12
+ with_input_field_for @user, :name
13
+
9
14
  assert_select 'form > input.required.string'
10
15
  assert_no_select 'div.string'
11
16
  assert_no_select 'label'
@@ -13,45 +18,34 @@ class InputFieldTest < ActionView::TestCase
13
18
  end
14
19
 
15
20
  test 'builder input_field allows overriding default input type' do
16
- with_concat_form_for(@user) do |f|
17
- f.input_field :name, as: :text
18
- end
21
+ with_input_field_for @user, :name, as: :text
19
22
 
20
23
  assert_no_select 'input#user_name'
21
24
  assert_select 'textarea#user_name.text'
22
25
  end
23
26
 
24
27
  test 'builder input_field generates input type based on column type' do
25
- with_concat_form_for(@user) do |f|
26
- f.input_field :age
27
- end
28
+ with_input_field_for @user, :age
28
29
 
29
30
  assert_select 'input[type=number].integer#user_age'
30
31
  end
31
32
 
32
33
  test 'builder input_field is able to disable any component' do
33
- with_concat_form_for(@user) do |f|
34
- f.input_field :age, html5: false
35
- end
34
+ with_input_field_for @user, :age, html5: false
36
35
 
37
36
  assert_no_select 'input[html5=false]#user_age'
38
37
  assert_select 'input[type=text].integer#user_age'
39
38
  end
40
39
 
41
40
  test 'builder input_field allows passing options to input tag' do
42
- with_concat_form_for(@user) do |f|
43
- f.input_field :name, id: 'name_input', class: 'name'
44
- end
41
+ with_input_field_for @user, :name, id: 'name_input', class: 'name'
45
42
 
46
43
  assert_select 'input.string.name#name_input'
47
44
  end
48
45
 
49
46
  test 'builder input_field does not modify the options hash' do
50
47
  options = { id: 'name_input', class: 'name' }
51
-
52
- with_concat_form_for(@user) do |f|
53
- f.input_field :name, options
54
- end
48
+ with_input_field_for @user, :name, options
55
49
 
56
50
  assert_select 'input.string.name#name_input'
57
51
  assert_equal({ id: 'name_input', class: 'name' }, options)
@@ -59,9 +53,7 @@ class InputFieldTest < ActionView::TestCase
59
53
 
60
54
 
61
55
  test 'builder input_field generates an input tag with a clean HTML' do
62
- with_concat_form_for(@user) do |f|
63
- f.input_field :name, as: :integer, class: 'name'
64
- end
56
+ with_input_field_for @user, :name, as: :integer, class: 'name'
65
57
 
66
58
  assert_no_select 'input.integer[input_html]'
67
59
  assert_no_select 'input.integer[as]'
@@ -71,67 +63,51 @@ class InputFieldTest < ActionView::TestCase
71
63
  store_translations(:en, simple_form: { placeholders: { user: {
72
64
  name: 'Name goes here'
73
65
  } } }) do
66
+ with_input_field_for @user, :name
74
67
 
75
- with_concat_form_for(@user) do |f|
76
- f.input_field :name
77
- end
78
-
79
- assert_select 'input.string[placeholder=Name goes here]'
68
+ assert_select 'input.string[placeholder="Name goes here"]'
80
69
  end
81
70
  end
82
71
 
83
72
  test 'builder input_field uses min_max component' do
84
- with_concat_form_for(@other_validating_user) do |f|
85
- f.input_field :age, as: :integer
86
- end
73
+ with_input_field_for @other_validating_user, :age, as: :integer
87
74
 
88
- assert_select 'input[min=18]'
75
+ assert_select 'input[min="18"]'
89
76
  end
90
77
 
91
78
  test 'builder input_field does not use pattern component by default' do
92
- with_concat_form_for(@other_validating_user) do |f|
93
- f.input_field :country, as: :string
94
- end
79
+ with_input_field_for @other_validating_user, :country, as: :string
95
80
 
96
81
  assert_no_select 'input[pattern="\w+"]'
97
82
  end
98
83
 
99
84
  test 'builder input_field infers pattern from attributes' do
100
- with_concat_form_for(@other_validating_user) do |f|
101
- f.input_field :country, as: :string, pattern: true
102
- end
85
+ with_input_field_for @other_validating_user, :country, as: :string, pattern: true
103
86
 
104
87
  assert_select 'input[pattern="\w+"]'
105
88
  end
106
89
 
107
90
  test 'builder input_field accepts custom patter' do
108
- with_concat_form_for(@other_validating_user) do |f|
109
- f.input_field :country, as: :string, pattern: '\d+'
110
- end
91
+ with_input_field_for @other_validating_user, :country, as: :string, pattern: '\d+'
111
92
 
112
93
  assert_select 'input[pattern="\d+"]'
113
94
  end
114
95
 
115
96
  test 'builder input_field uses readonly component' do
116
- with_concat_form_for(@other_validating_user) do |f|
117
- f.input_field :age, as: :integer, readonly: true
118
- end
97
+ with_input_field_for @other_validating_user, :age, as: :integer, readonly: true
119
98
 
120
99
  assert_select 'input.integer.readonly[readonly]'
121
100
  end
122
101
 
123
102
  test 'builder input_field uses maxlength component' do
124
- with_concat_form_for(@validating_user) do |f|
125
- f.input_field :name, as: :string
126
- end
103
+ with_input_field_for @validating_user, :name, as: :string
127
104
 
128
- assert_select 'input.string[maxlength=25]'
105
+ assert_select 'input.string[maxlength="25"]'
129
106
  end
130
107
 
131
108
  test 'builder collection input_field generates input tag with a clean HTML' do
132
- with_concat_form_for(@user) do |f|
133
- f.input_field :status, collection: ['Open', 'Closed'], class: 'status', label_method: :to_s, value_method: :to_s
134
- end
109
+ with_input_field_for @user, :status, collection: ['Open', 'Closed'],
110
+ class: 'status', label_method: :to_s, value_method: :to_s
135
111
 
136
112
  assert_no_select 'select.status[input_html]'
137
113
  assert_no_select 'select.status[collection]'
@@ -140,10 +116,40 @@ class InputFieldTest < ActionView::TestCase
140
116
  end
141
117
 
142
118
  test 'build input_field does not treat "boolean_style" as a HTML attribute' do
143
- with_concat_form_for(@user) do |f|
144
- f.input_field :active, boolean_style: :nested
145
- end
119
+ with_input_field_for @user, :active, boolean_style: :nested
146
120
 
147
121
  assert_no_select 'input.boolean[boolean_style]'
148
122
  end
123
+
124
+ test 'build input_field without pattern component use the pattern string' do
125
+ swap_wrapper :default, custom_wrapper_with_html5_components do
126
+ with_input_field_for @user, :name, pattern: '\w+'
127
+
128
+ assert_select 'input[pattern="\w+"]'
129
+ end
130
+ end
131
+
132
+ test 'build input_field without placeholder component use the placeholder string' do
133
+ swap_wrapper :default, custom_wrapper_with_html5_components do
134
+ with_input_field_for @user, :name, placeholder: 'Placeholder'
135
+
136
+ assert_select 'input[placeholder="Placeholder"]'
137
+ end
138
+ end
139
+
140
+ test 'build input_field without maxlength component use the maxlength string' do
141
+ swap_wrapper :default, custom_wrapper_with_html5_components do
142
+ with_input_field_for @user, :name, maxlength: 5
143
+
144
+ assert_select 'input[maxlength="5"]'
145
+ end
146
+ end
147
+
148
+ test 'build input_field without readonly component use the readonly string' do
149
+ swap_wrapper :default, custom_wrapper_with_html5_components do
150
+ with_input_field_for @user, :name, readonly: true
151
+
152
+ assert_select 'input[readonly="readonly"]'
153
+ end
154
+ end
149
155
  end
@@ -29,9 +29,19 @@ class LabelTest < ActionView::TestCase
29
29
  assert_select 'label.string.required[for=validating_user_name]', /Name/
30
30
  end
31
31
 
32
+ test 'builder adds a disabled class to label if the attribute is disabled' do
33
+ with_label_for @validating_user, :name, disabled: true
34
+ assert_select 'label.string.disabled[for=validating_user_name]', /Name/
35
+ end
36
+
37
+ test 'builder does not add a disabled class to label if the attribute is not disabled' do
38
+ with_label_for @validating_user, :name, disabled: false
39
+ assert_no_select 'label.string.disabled[for=validating_user_name]', /Name/
40
+ end
41
+
32
42
  test 'builder escapes label text' do
33
43
  with_label_for @user, :name, label: '<script>alert(1337)</script>', required: false
34
- assert_select 'label.string', "&lt;script&gt;alert(1337)&lt;/script&gt;"
44
+ assert_no_select 'label.string script'
35
45
  end
36
46
 
37
47
  test 'builder does not escape label text if it is safe' do
@@ -80,7 +90,7 @@ class LabelTest < ActionView::TestCase
80
90
  end
81
91
 
82
92
  test 'configuration allow set label text for wrappers' do
83
- swap_wrapper :default, self.custom_wrapper_with_label_text do
93
+ swap_wrapper :default, custom_wrapper_with_label_text do
84
94
  with_concat_form_for(@user) do |f|
85
95
  concat f.input :age
86
96
  end
@@ -89,7 +99,7 @@ class LabelTest < ActionView::TestCase
89
99
  end
90
100
 
91
101
  test 'configuration allow set rewrited label tag for wrappers' do
92
- swap_wrapper :default, self.custom_wrapper_with_custom_label_component do
102
+ swap_wrapper :default, custom_wrapper_with_custom_label_component do
93
103
  with_concat_form_for(@user) do |f|
94
104
  concat f.input :age
95
105
  end
@@ -129,7 +129,7 @@ class WrapperTest < ActionView::TestCase
129
129
  end
130
130
 
131
131
  test 'custom wrappers can have additional attributes' do
132
- swap_wrapper :default, self.custom_wrapper_with_additional_attributes do
132
+ swap_wrapper :default, custom_wrapper_with_additional_attributes do
133
133
  with_form_for @user, :name
134
134
 
135
135
  assert_select "div.custom_wrapper[title='some title'][data-wrapper='test']"
@@ -137,9 +137,9 @@ class WrapperTest < ActionView::TestCase
137
137
  end
138
138
 
139
139
  test 'custom wrappers can have full error message on attributes' do
140
- swap_wrapper :default, self.custom_wrapper_with_full_error do
140
+ swap_wrapper :default, custom_wrapper_with_full_error do
141
141
  with_form_for @user, :name
142
- assert_select 'span.error', "Name can't be blank"
142
+ assert_select 'span.error', "Name cannot be blank"
143
143
  end
144
144
  end
145
145
 
@@ -188,7 +188,7 @@ class WrapperTest < ActionView::TestCase
188
188
  end
189
189
 
190
190
  test 'does not duplicate label classes for different inputs' do
191
- swap_wrapper :default, self.custom_wrapper_with_label_html_option do
191
+ swap_wrapper :default, custom_wrapper_with_label_html_option do
192
192
  with_concat_form_for(@user) do |f|
193
193
  concat f.input :name, required: false
194
194
  concat f.input :email, as: :email, required: true
@@ -227,8 +227,23 @@ class WrapperTest < ActionView::TestCase
227
227
  assert_select "section.custom_wrapper div.another_wrapper input.string"
228
228
  end
229
229
 
230
+ test 'simple_fields_form reuses custom wrapper mapping per form basis' do
231
+ @user.company = Company.new(1, 'Empresa')
232
+
233
+ swap_wrapper :another do
234
+ with_concat_form_for @user, wrapper_mappings: { string: :another } do |f|
235
+ concat(f.simple_fields_for(:company) do |company_form|
236
+ concat(company_form.input(:name))
237
+ end)
238
+ end
239
+ end
240
+
241
+ assert_select "section.custom_wrapper div.another_wrapper label"
242
+ assert_select "section.custom_wrapper div.another_wrapper input.string"
243
+ end
244
+
230
245
  test 'input accepts attributes in the DSL' do
231
- swap_wrapper :default, self.custom_wrapper_with_input_class do
246
+ swap_wrapper :default, custom_wrapper_with_input_class do
232
247
  with_concat_form_for @user do |f|
233
248
  concat f.input :name
234
249
  end
@@ -238,7 +253,7 @@ class WrapperTest < ActionView::TestCase
238
253
  end
239
254
 
240
255
  test 'label accepts attributes in the DSL' do
241
- swap_wrapper :default, self.custom_wrapper_with_label_class do
256
+ swap_wrapper :default, custom_wrapper_with_label_class do
242
257
  with_concat_form_for @user do |f|
243
258
  concat f.input :name
244
259
  end
@@ -248,7 +263,7 @@ class WrapperTest < ActionView::TestCase
248
263
  end
249
264
 
250
265
  test 'label_input accepts attributes in the DSL' do
251
- swap_wrapper :default, self.custom_wrapper_with_label_input_class do
266
+ swap_wrapper :default, custom_wrapper_with_label_input_class do
252
267
  with_concat_form_for @user do |f|
253
268
  concat f.input :name
254
269
  end
@@ -259,7 +274,7 @@ class WrapperTest < ActionView::TestCase
259
274
  end
260
275
 
261
276
  test 'input accepts data attributes in the DSL' do
262
- swap_wrapper :default, self.custom_wrapper_with_input_attributes do
277
+ swap_wrapper :default, custom_wrapper_with_input_attributes do
263
278
  with_concat_form_for @user do |f|
264
279
  concat f.input :name
265
280
  end
@@ -269,15 +284,15 @@ class WrapperTest < ActionView::TestCase
269
284
  end
270
285
 
271
286
  test 'inline wrapper displays when there is content' do
272
- swap_wrapper :default, self.custom_wrapper_with_wrapped_optional_component do
273
- with_form_for @user, :name, hint: "can't be blank"
274
- assert_select 'section.custom_wrapper div.no_output_wrapper p.omg_hint', "can&#39;t be blank"
287
+ swap_wrapper :default, custom_wrapper_with_wrapped_optional_component do
288
+ with_form_for @user, :name, hint: "cannot be blank"
289
+ assert_select 'section.custom_wrapper div.no_output_wrapper p.omg_hint', "cannot be blank"
275
290
  assert_select 'p.omg_hint'
276
291
  end
277
292
  end
278
293
 
279
294
  test 'inline wrapper does not display when there is no content' do
280
- swap_wrapper :default, self.custom_wrapper_with_wrapped_optional_component do
295
+ swap_wrapper :default, custom_wrapper_with_wrapped_optional_component do
281
296
  with_form_for @user, :name
282
297
  assert_select 'section.custom_wrapper div.no_output_wrapper'
283
298
  assert_no_select 'p.omg_hint'
@@ -285,7 +300,7 @@ class WrapperTest < ActionView::TestCase
285
300
  end
286
301
 
287
302
  test 'optional wrapper does not display when there is content' do
288
- swap_wrapper :default, self.custom_wrapper_with_unless_blank do
303
+ swap_wrapper :default, custom_wrapper_with_unless_blank do
289
304
  with_form_for @user, :name, hint: "can't be blank"
290
305
  assert_select 'section.custom_wrapper div.no_output_wrapper'
291
306
  assert_select 'div.no_output_wrapper'
@@ -294,7 +309,7 @@ class WrapperTest < ActionView::TestCase
294
309
  end
295
310
 
296
311
  test 'optional wrapper does not display when there is no content' do
297
- swap_wrapper :default, self.custom_wrapper_with_unless_blank do
312
+ swap_wrapper :default, custom_wrapper_with_unless_blank do
298
313
  with_form_for @user, :name
299
314
  assert_no_select 'section.custom_wrapper div.no_output_wrapper'
300
315
  assert_no_select 'div.no_output_wrapper'
@@ -29,8 +29,8 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
29
29
  run_generator %w(--foundation)
30
30
  assert_file 'config/initializers/simple_form.rb',
31
31
  /config\.default_wrapper = :default/, /config\.boolean_style = :nested/
32
- assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :foundation/,
33
- /config\.default_wrapper = :foundation/
32
+ assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :vertical_form/,
33
+ /config\.default_wrapper = :vertical_form/, /config\.item_wrapper_tag = :div/
34
34
  end
35
35
 
36
36
  %W(erb haml slim).each do |engine|
@@ -57,7 +57,7 @@ class BooleanInputTest < ActionView::TestCase
57
57
  test 'input boolean with nested escapes :inline_label with HTML' do
58
58
  swap SimpleForm, boolean_style: :nested do
59
59
  with_input_for @user, :active, :boolean, inline_label: '<b>I am so inline.</b>'
60
- assert_select 'label.checkbox', text: ' &lt;b&gt;I am so inline.&lt;/b&gt;'
60
+ assert_no_select 'label.checkbox b'
61
61
  end
62
62
  end
63
63
 
@@ -197,4 +197,12 @@ class BooleanInputTest < ActionView::TestCase
197
197
  end
198
198
  end
199
199
  end
200
+
201
+ test 'input boolean works with wrapper config defining a class for the input' do
202
+ swap_wrapper :default, self.custom_wrapper_with_input_class do
203
+ with_input_for @user, :active, :boolean
204
+
205
+ assert_select 'input.boolean.inline-class'
206
+ end
207
+ end
200
208
  end
@@ -278,4 +278,26 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
278
278
  assert_select 'span.custom'
279
279
  end
280
280
  end
281
+
282
+ test 'input check boxes with nested style and namespace uses the right for attribute' do
283
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
284
+ with_concat_form_for @user, namespace: :foo do |f|
285
+ concat f.input :gender, as: :check_boxes, collection: [:male, :female]
286
+ end
287
+
288
+ assert_select 'label[for=foo_user_gender_male]'
289
+ assert_select 'label[for=foo_user_gender_female]'
290
+ end
291
+ end
292
+
293
+ test 'input check boxes with nested style and index uses the right for attribute' do
294
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
295
+ with_concat_form_for @user, index: 1 do |f|
296
+ concat f.input :gender, as: :check_boxes, collection: [:male, :female]
297
+ end
298
+
299
+ assert_select 'label[for=user_1_gender_male]'
300
+ assert_select 'label[for=user_1_gender_female]'
301
+ end
302
+ end
281
303
  end
@@ -100,8 +100,8 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
100
100
  with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
101
101
  assert_select 'input[type=radio][value=male]'
102
102
  assert_select 'input[type=radio][value=female]'
103
- assert_select 'label[for=user_gender_male]', 'Male'
104
- assert_select 'label[for=user_gender_female]', 'Female'
103
+ assert_select 'label[for=user_gender_male] strong', 'Male'
104
+ assert_select 'label[for=user_gender_female] strong', 'Female'
105
105
  end
106
106
  end
107
107
  end
@@ -393,7 +393,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
393
393
  end
394
394
  end
395
395
 
396
- test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
396
+ test 'input radio custom wrapper class is included when include input wrapper class is falsey' do
397
397
  swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
398
398
  with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], item_wrapper_class: 'custom'
399
399
 
@@ -401,4 +401,26 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
401
401
  assert_select 'span.custom'
402
402
  end
403
403
  end
404
+
405
+ test 'input radio with nested style and namespace uses the right for attribute' do
406
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
407
+ with_concat_form_for @user, namespace: :foo do |f|
408
+ concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
409
+ end
410
+
411
+ assert_select 'label[for=foo_user_gender_male]'
412
+ assert_select 'label[for=foo_user_gender_female]'
413
+ end
414
+ end
415
+
416
+ test 'input radio with nested style and index uses the right for attribute' do
417
+ swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
418
+ with_concat_form_for @user, index: 1 do |f|
419
+ concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
420
+ end
421
+
422
+ assert_select 'label[for=user_1_gender_male]'
423
+ assert_select 'label[for=user_1_gender_female]'
424
+ end
425
+ end
404
426
  end