simple_form 1.5.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. data/CHANGELOG.md +234 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +816 -0
  4. data/lib/generators/simple_form/install_generator.rb +15 -1
  5. data/lib/generators/simple_form/templates/README +12 -0
  6. data/lib/generators/simple_form/templates/_form.html.erb +2 -2
  7. data/lib/generators/simple_form/templates/_form.html.haml +2 -2
  8. data/lib/generators/simple_form/templates/_form.html.slim +4 -4
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +176 -0
  10. data/lib/simple_form/action_view_extensions/builder.rb +206 -59
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +30 -23
  12. data/lib/simple_form/components/errors.rb +6 -24
  13. data/lib/simple_form/components/hints.rb +7 -21
  14. data/lib/simple_form/components/html5.rb +26 -0
  15. data/lib/simple_form/components/labels.rb +22 -14
  16. data/lib/simple_form/components/maxlength.rb +41 -0
  17. data/lib/simple_form/components/min_max.rb +49 -0
  18. data/lib/simple_form/components/pattern.rb +34 -0
  19. data/lib/simple_form/components/placeholders.rb +5 -17
  20. data/lib/simple_form/components/readonly.rb +22 -0
  21. data/lib/simple_form/components.rb +11 -1
  22. data/lib/simple_form/core_ext/hash.rb +16 -0
  23. data/lib/simple_form/error_notification.rb +9 -3
  24. data/lib/simple_form/form_builder.rb +105 -28
  25. data/lib/simple_form/helpers/autofocus.rb +11 -0
  26. data/lib/simple_form/helpers/disabled.rb +15 -0
  27. data/lib/simple_form/helpers/readonly.rb +15 -0
  28. data/lib/simple_form/helpers/required.rb +10 -11
  29. data/lib/simple_form/helpers/validators.rb +4 -4
  30. data/lib/simple_form/helpers.rb +7 -4
  31. data/lib/simple_form/inputs/base.rb +53 -81
  32. data/lib/simple_form/inputs/boolean_input.rb +46 -4
  33. data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
  34. data/lib/simple_form/inputs/collection_input.rb +27 -13
  35. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +67 -0
  36. data/lib/simple_form/inputs/collection_select_input.rb +14 -0
  37. data/lib/simple_form/inputs/date_time_input.rb +10 -6
  38. data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
  39. data/lib/simple_form/inputs/hidden_input.rb +3 -6
  40. data/lib/simple_form/inputs/numeric_input.rb +3 -51
  41. data/lib/simple_form/inputs/password_input.rb +1 -2
  42. data/lib/simple_form/inputs/priority_input.rb +2 -2
  43. data/lib/simple_form/inputs/range_input.rb +1 -3
  44. data/lib/simple_form/inputs/string_input.rb +6 -8
  45. data/lib/simple_form/inputs/text_input.rb +1 -2
  46. data/lib/simple_form/inputs.rb +17 -13
  47. data/lib/simple_form/version.rb +1 -1
  48. data/lib/simple_form/wrappers/builder.rb +103 -0
  49. data/lib/simple_form/wrappers/many.rb +69 -0
  50. data/lib/simple_form/wrappers/root.rb +34 -0
  51. data/lib/simple_form/wrappers/single.rb +18 -0
  52. data/lib/simple_form/wrappers.rb +8 -0
  53. data/lib/simple_form.rb +118 -48
  54. data/test/action_view_extensions/builder_test.rb +285 -102
  55. data/test/action_view_extensions/form_helper_test.rb +32 -10
  56. data/test/components/label_test.rb +44 -5
  57. data/test/form_builder/association_test.rb +177 -0
  58. data/test/form_builder/button_test.rb +47 -0
  59. data/test/{error_notification_test.rb → form_builder/error_notification_test.rb} +18 -1
  60. data/test/form_builder/error_test.rb +121 -0
  61. data/test/form_builder/general_test.rb +356 -0
  62. data/test/form_builder/hint_test.rb +123 -0
  63. data/test/form_builder/input_field_test.rb +63 -0
  64. data/test/form_builder/label_test.rb +65 -0
  65. data/test/form_builder/wrapper_test.rb +149 -0
  66. data/test/generators/simple_form_generator_test.rb +32 -0
  67. data/test/inputs/boolean_input_test.rb +101 -0
  68. data/test/inputs/collection_check_boxes_input_test.rb +224 -0
  69. data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
  70. data/test/inputs/collection_select_input_test.rb +241 -0
  71. data/test/inputs/datetime_input_test.rb +99 -0
  72. data/test/inputs/disabled_test.rb +38 -0
  73. data/test/inputs/discovery_test.rb +61 -0
  74. data/test/inputs/file_input_test.rb +16 -0
  75. data/test/inputs/general_test.rb +69 -0
  76. data/test/inputs/grouped_collection_select_input_test.rb +118 -0
  77. data/test/inputs/hidden_input_test.rb +30 -0
  78. data/test/inputs/numeric_input_test.rb +167 -0
  79. data/test/inputs/priority_input_test.rb +43 -0
  80. data/test/inputs/readonly_test.rb +61 -0
  81. data/test/inputs/required_test.rb +113 -0
  82. data/test/inputs/string_input_test.rb +140 -0
  83. data/test/inputs/text_input_test.rb +24 -0
  84. data/test/support/misc_helpers.rb +53 -12
  85. data/test/support/mock_controller.rb +2 -2
  86. data/test/support/models.rb +20 -5
  87. data/test/test_helper.rb +11 -12
  88. metadata +124 -96
  89. data/.gitignore +0 -3
  90. data/.gitmodules +0 -3
  91. data/.travis.yml +0 -15
  92. data/CHANGELOG.rdoc +0 -159
  93. data/Gemfile +0 -9
  94. data/README.rdoc +0 -466
  95. data/Rakefile +0 -27
  96. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +0 -93
  97. data/lib/simple_form/components/wrapper.rb +0 -38
  98. data/lib/simple_form/helpers/has_errors.rb +0 -15
  99. data/lib/simple_form/helpers/maxlength.rb +0 -24
  100. data/lib/simple_form/helpers/pattern.rb +0 -28
  101. data/simple_form.gemspec +0 -25
  102. data/test/components/error_test.rb +0 -56
  103. data/test/components/hint_test.rb +0 -74
  104. data/test/components/wrapper_test.rb +0 -63
  105. data/test/custom_components.rb +0 -7
  106. data/test/form_builder_test.rb +0 -930
  107. data/test/inputs_test.rb +0 -995
  108. /data/test/{discovery_inputs.rb → support/discovery_inputs.rb} +0 -0
@@ -0,0 +1,149 @@
1
+ require 'test_helper'
2
+
3
+ class WrapperTest < ActionView::TestCase
4
+ test 'wrapper should not have error class for attribute without errors' do
5
+ with_form_for @user, :active
6
+ assert_no_select 'div.field_with_errors'
7
+ end
8
+
9
+ test 'wrapper should not have error class when object is not present' do
10
+ with_form_for :project, :name
11
+ assert_no_select 'div.field_with_errors'
12
+ end
13
+
14
+ test 'wrapper should add error class for attribute with errors' do
15
+ with_form_for @user, :name
16
+ assert_select 'div.field_with_errors'
17
+ end
18
+
19
+ test 'wrapper should add hint class for attribute with a hint' do
20
+ with_form_for @user, :name, :hint => 'hint'
21
+ assert_select 'div.field_with_hint'
22
+ end
23
+
24
+ test 'wrapper should not have disabled class by default' do
25
+ with_form_for @user, :active
26
+ assert_no_select 'div.disabled'
27
+ end
28
+
29
+ test 'wrapper should have disabled class when input is disabled' do
30
+ with_form_for @user, :active, :disabled => true
31
+ assert_select 'div.disabled'
32
+ end
33
+
34
+ test 'wrapper should support no wrapping when wrapper is false' do
35
+ with_form_for @user, :name, :wrapper => false
36
+ assert_select 'form > label[for=user_name]'
37
+ assert_select 'form > input#user_name.string'
38
+ end
39
+
40
+ test 'wrapper should support no wrapping when wrapper tag is false' do
41
+ with_form_for @user, :name, :wrapper => custom_wrapper_without_top_level
42
+ assert_select 'form > label[for=user_name]'
43
+ assert_select 'form > input#user_name.string'
44
+ end
45
+
46
+ test 'wrapper should wrapping tag adds required/optional css classes' do
47
+ with_form_for @user, :name
48
+ assert_select 'form div.input.required.string'
49
+
50
+ with_form_for @user, :age, :required => false
51
+ assert_select 'form div.input.optional.integer'
52
+ end
53
+
54
+ test 'wrapper should allow custom options to be given' do
55
+ with_form_for @user, :name, :wrapper_html => { :id => "super_cool", :class => 'yay' }
56
+ assert_select 'form #super_cool.required.string.yay'
57
+ end
58
+
59
+ test 'wrapper should allow tag to be given on demand' do
60
+ with_form_for @user, :name, :wrapper_tag => :b
61
+ assert_select 'form b.required.string'
62
+ end
63
+
64
+ test 'wrapper should allow wrapper class to be given on demand' do
65
+ with_form_for @user, :name, :wrapper_class => :wrapper
66
+ assert_select 'form div.wrapper.required.string'
67
+ end
68
+
69
+ test 'wrapper should skip additional classes when configured' do
70
+ swap SimpleForm, :generate_additional_classes_for => [:input, :label] do
71
+ with_form_for @user, :name, :wrapper_class => :wrapper
72
+ assert_select 'form div.wrapper'
73
+ assert_no_select 'div.required'
74
+ assert_no_select 'div.string'
75
+ end
76
+ end
77
+
78
+ # Custom wrapper test
79
+
80
+ test 'custom wrappers works' do
81
+ swap_wrapper do
82
+ with_form_for @user, :name, :hint => "cool"
83
+ assert_select "section.custom_wrapper div.another_wrapper label"
84
+ assert_select "section.custom_wrapper div.another_wrapper input.string"
85
+ assert_no_select "section.custom_wrapper div.another_wrapper span.omg_error"
86
+ assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
87
+ assert_select "section.custom_wrapper > div.omg_hint", "cool"
88
+ end
89
+ end
90
+
91
+ test 'custom wrappers can be turned off' do
92
+ swap_wrapper do
93
+ with_form_for @user, :name, :another => false
94
+ assert_no_select "section.custom_wrapper div.another_wrapper label"
95
+ assert_no_select "section.custom_wrapper div.another_wrapper input.string"
96
+ assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
97
+ end
98
+ end
99
+
100
+ test 'custom wrappers on a form basis' do
101
+ swap_wrapper :another do
102
+ concat simple_form_for(@user) { |f|
103
+ f.input :name
104
+ }
105
+
106
+ assert_no_select "section.custom_wrapper div.another_wrapper label"
107
+ assert_no_select "section.custom_wrapper div.another_wrapper input.string"
108
+
109
+ concat simple_form_for(@user, :wrapper => :another) { |f|
110
+ f.input :name
111
+ }
112
+
113
+ assert_select "section.custom_wrapper div.another_wrapper label"
114
+ assert_select "section.custom_wrapper div.another_wrapper input.string"
115
+ end
116
+ end
117
+
118
+ test 'custom wrappers on input basis' do
119
+ swap_wrapper :another do
120
+ with_form_for @user, :name
121
+ assert_no_select "section.custom_wrapper div.another_wrapper label"
122
+ assert_no_select "section.custom_wrapper div.another_wrapper input.string"
123
+ output_buffer.replace ""
124
+
125
+ with_form_for @user, :name, :wrapper => :another
126
+ assert_select "section.custom_wrapper div.another_wrapper label"
127
+ assert_select "section.custom_wrapper div.another_wrapper input.string"
128
+ output_buffer.replace ""
129
+ end
130
+
131
+ with_form_for @user, :name, :wrapper => custom_wrapper
132
+ assert_select "section.custom_wrapper div.another_wrapper label"
133
+ assert_select "section.custom_wrapper div.another_wrapper input.string"
134
+ end
135
+
136
+ test 'access wrappers with indifferent access' do
137
+ swap_wrapper :another do
138
+ with_form_for @user, :name, :wrapper => "another"
139
+ assert_select "section.custom_wrapper div.another_wrapper label"
140
+ assert_select "section.custom_wrapper div.another_wrapper input.string"
141
+ end
142
+ end
143
+
144
+ test 'raise error when wrapper not found' do
145
+ assert_raise SimpleForm::WrapperNotFound do
146
+ with_form_for @user, :name, :wrapper => :not_found
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class SimpleFormGeneratorTest < Rails::Generators::TestCase
4
+ tests SimpleForm::Generators::InstallGenerator
5
+ destination File.expand_path('../../tmp', __FILE__)
6
+ setup :prepare_destination
7
+ teardown { rm_rf(destination_root) }
8
+
9
+ test 'generates example locale file' do
10
+ run_generator
11
+ assert_file 'config/locales/simple_form.en.yml'
12
+ end
13
+
14
+ test 'generates the simple_form initializer' do
15
+ run_generator
16
+ assert_file 'config/initializers/simple_form.rb',
17
+ /config\.default_wrapper = :default/, /config\.boolean_style = :nested/
18
+ end
19
+
20
+ test 'generates the simple_form initializer with the bootstrap wrappers' do
21
+ run_generator %w(--bootstrap)
22
+ assert_file 'config/initializers/simple_form.rb', /config\.wrappers :bootstrap/,
23
+ /config\.default_wrapper = :bootstrap/
24
+ end
25
+
26
+ %W(erb haml slim).each do |engine|
27
+ test "generates the scaffold template when using #{engine}" do
28
+ run_generator ['-e', engine]
29
+ assert_file "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,101 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class BooleanInputTest < ActionView::TestCase
5
+ test 'input should generate a checkbox by default for boolean attributes' do
6
+ with_input_for @user, :active, :boolean
7
+ assert_select 'input[type=checkbox].boolean#user_active'
8
+ assert_select 'label.boolean.optional', 'Active'
9
+ end
10
+
11
+ test 'input does not generate the label with the checkbox when label option is false' do
12
+ with_input_for @user, :active, :boolean, :label => false
13
+ assert_select 'input[type=checkbox].boolean#user_active'
14
+ assert_no_select 'label'
15
+ end
16
+
17
+ test 'input uses inline boolean style by default' do
18
+ with_input_for @user, :active, :boolean
19
+ assert_select 'input.boolean + label.boolean.optional'
20
+ assert_no_select 'label > input'
21
+ end
22
+
23
+ test 'input allows changing default boolean style config to nested, generating a default label and a manual hidden field for checkbox' do
24
+ swap SimpleForm, :boolean_style => :nested do
25
+ with_input_for @user, :active, :boolean
26
+ assert_select 'label[for=user_active]', 'Active'
27
+ assert_select 'label.boolean > input.boolean'
28
+ assert_no_select 'input[type=checkbox] + label'
29
+ end
30
+ end
31
+
32
+ test 'input boolean with nested generates a manual hidden field for checkbox outside the label, to recreate Rails functionality with valid html5' do
33
+ swap SimpleForm, :boolean_style => :nested do
34
+ with_input_for @user, :active, :boolean
35
+
36
+ assert_select "input[type=hidden][name='user[active]'] + label.boolean > input.boolean"
37
+ assert_no_select 'input[type=checkbox] + label'
38
+ end
39
+ end
40
+
41
+ test 'input boolean with nested generates a disabled hidden field for checkbox outside the label, if the field is disabled' do
42
+ swap SimpleForm, :boolean_style => :nested do
43
+ with_input_for @user, :active, :boolean, :disabled => true
44
+
45
+ assert_select "input[type=hidden][name='user[active]'][disabled] + label.boolean > input.boolean[disabled]"
46
+ end
47
+ end
48
+
49
+ test 'input accepts changing boolean style to nested through given options' do
50
+ with_input_for @user, :active, :boolean, :boolean_style => :nested
51
+ assert_select 'label[for=user_active]', 'Active'
52
+ assert_select 'label.boolean > input.boolean'
53
+ assert_no_select 'input[type=checkbox] + label'
54
+ end
55
+
56
+ test 'input accepts changing boolean style to inline through given options, when default is nested' do
57
+ swap SimpleForm, :boolean_style => :nested do
58
+ with_input_for @user, :active, :boolean, :boolean_style => :inline
59
+ assert_select 'label[for=user_active]', 'Active'
60
+ assert_select 'input.boolean + label.boolean'
61
+ assert_no_select 'label > input'
62
+ end
63
+ end
64
+
65
+ test 'input with nested style allows disabling label' do
66
+ swap SimpleForm, :boolean_style => :nested do
67
+ with_input_for @user, :active, :boolean, :label => false
68
+ assert_select 'input.boolean'
69
+ assert_no_select 'label.boolean'
70
+ end
71
+ end
72
+
73
+ test 'input boolean works using :input only in wrapper config (no label_input)' do
74
+ swap_wrapper do
75
+ with_input_for @user, :active, :boolean
76
+
77
+ assert_select 'label.boolean + input[type=hidden] + input.boolean'
78
+ assert_no_select 'label.checkbox'
79
+ end
80
+ end
81
+
82
+ test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra "checkbox" label wrapper' do
83
+ swap_wrapper do
84
+ swap SimpleForm, :boolean_style => :nested do
85
+ with_input_for @user, :active, :boolean
86
+
87
+ assert_select 'label.boolean + input[type=hidden] + label.checkbox > input.boolean'
88
+ end
89
+ end
90
+ end
91
+
92
+ test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
93
+ swap_wrapper :default, self.custom_wrapper_without_top_level do
94
+ swap SimpleForm, :boolean_style => :nested do
95
+ with_input_for @user, :active, :boolean
96
+
97
+ assert_select 'input[type=hidden] + label.boolean.checkbox > input.boolean'
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,224 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class CollectionCheckBoxesInputTest < ActionView::TestCase
5
+ setup do
6
+ SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
7
+ end
8
+
9
+ test 'input check boxes should not include for attribute by default' do
10
+ with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
11
+ assert_select 'label'
12
+ assert_no_select 'label[for=user_gender]'
13
+ end
14
+
15
+ test 'input check boxes should include for attribute when giving as html option' do
16
+ with_input_for @user, :gender, :check_boxes, :collection => [:male, :female], :label_html => { :for => 'gender' }
17
+ assert_select 'label[for=gender]'
18
+ end
19
+
20
+ test 'collection input with check_boxes type should not generate required html attribute' do
21
+ with_input_for @user, :name, :check_boxes, :collection => ['Jose' , 'Carlos']
22
+ assert_select 'input.required'
23
+ assert_no_select 'input[required]'
24
+ end
25
+
26
+ test 'input should do automatic collection translation for check_box types using defaults key' do
27
+ store_translations(:en, :simple_form => { :options => { :defaults => {
28
+ :gender => { :male => 'Male', :female => 'Female'}
29
+ } } } ) do
30
+ with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
31
+ assert_select 'input[type=checkbox][value=male]'
32
+ assert_select 'input[type=checkbox][value=female]'
33
+ assert_select 'label.collection_check_boxes', 'Male'
34
+ assert_select 'label.collection_check_boxes', 'Female'
35
+ end
36
+ end
37
+
38
+ test 'input should do automatic collection translation for check_box types using specific object key' do
39
+ store_translations(:en, :simple_form => { :options => { :user => {
40
+ :gender => { :male => 'Male', :female => 'Female'}
41
+ } } } ) do
42
+ with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
43
+ assert_select 'input[type=checkbox][value=male]'
44
+ assert_select 'input[type=checkbox][value=female]'
45
+ assert_select 'label.collection_check_boxes', 'Male'
46
+ assert_select 'label.collection_check_boxes', 'Female'
47
+ end
48
+ end
49
+
50
+ test 'input check boxes does not wrap the collection by default' do
51
+ with_input_for @user, :active, :check_boxes
52
+
53
+ assert_select 'form input[type=checkbox]', :count => 2
54
+ assert_no_select 'form ul'
55
+ end
56
+
57
+ test 'input check boxes wraps the collection in the configured collection wrapper tag' do
58
+ swap SimpleForm, :collection_wrapper_tag => :ul do
59
+ with_input_for @user, :active, :check_boxes
60
+
61
+ assert_select 'form ul input[type=checkbox]', :count => 2
62
+ end
63
+ end
64
+
65
+ test 'input check boxes does not wrap the collection when configured with falsy values' do
66
+ swap SimpleForm, :collection_wrapper_tag => false do
67
+ with_input_for @user, :active, :check_boxes
68
+
69
+ assert_select 'form input[type=checkbox]', :count => 2
70
+ assert_no_select 'form ul'
71
+ end
72
+ end
73
+
74
+ test 'input check boxes allows overriding the collection wrapper tag at input level' do
75
+ swap SimpleForm, :collection_wrapper_tag => :ul do
76
+ with_input_for @user, :active, :check_boxes, :collection_wrapper_tag => :section
77
+
78
+ assert_select 'form section input[type=checkbox]', :count => 2
79
+ assert_no_select 'form ul'
80
+ end
81
+ end
82
+
83
+ test 'input check boxes allows disabling the collection wrapper tag at input level' do
84
+ swap SimpleForm, :collection_wrapper_tag => :ul do
85
+ with_input_for @user, :active, :check_boxes, :collection_wrapper_tag => false
86
+
87
+ assert_select 'form input[type=checkbox]', :count => 2
88
+ assert_no_select 'form ul'
89
+ end
90
+ end
91
+
92
+ test 'input check boxes renders the wrapper tag with the configured wrapper class' do
93
+ swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
94
+ with_input_for @user, :active, :check_boxes
95
+
96
+ assert_select 'form ul.inputs-list input[type=checkbox]', :count => 2
97
+ end
98
+ end
99
+
100
+ test 'input check boxes allows giving wrapper class at input level only' do
101
+ swap SimpleForm, :collection_wrapper_tag => :ul do
102
+ with_input_for @user, :active, :check_boxes, :collection_wrapper_class => 'items-list'
103
+
104
+ assert_select 'form ul.items-list input[type=checkbox]', :count => 2
105
+ end
106
+ end
107
+
108
+ test 'input check boxes uses both configured and given wrapper classes for wrapper tag' do
109
+ swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => 'inputs-list' do
110
+ with_input_for @user, :active, :check_boxes, :collection_wrapper_class => 'items-list'
111
+
112
+ assert_select 'form ul.inputs-list.items-list input[type=checkbox]', :count => 2
113
+ end
114
+ end
115
+
116
+ test 'input check boxes wraps each item in the configured item wrapper tag' do
117
+ swap SimpleForm, :item_wrapper_tag => :li do
118
+ with_input_for @user, :active, :check_boxes
119
+
120
+ assert_select 'form li input[type=checkbox]', :count => 2
121
+ end
122
+ end
123
+
124
+ test 'input check boxes does not wrap items when configured with falsy values' do
125
+ swap SimpleForm, :item_wrapper_tag => false do
126
+ with_input_for @user, :active, :check_boxes
127
+
128
+ assert_select 'form input[type=checkbox]', :count => 2
129
+ assert_no_select 'form li'
130
+ end
131
+ end
132
+
133
+ test 'input check boxes allows overriding the item wrapper tag at input level' do
134
+ swap SimpleForm, :item_wrapper_tag => :li do
135
+ with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :dl
136
+
137
+ assert_select 'form dl input[type=checkbox]', :count => 2
138
+ assert_no_select 'form li'
139
+ end
140
+ end
141
+
142
+ test 'input check boxes allows disabling the item wrapper tag at input level' do
143
+ swap SimpleForm, :item_wrapper_tag => :ul do
144
+ with_input_for @user, :active, :check_boxes, :item_wrapper_tag => false
145
+
146
+ assert_select 'form input[type=checkbox]', :count => 2
147
+ assert_no_select 'form li'
148
+ end
149
+ end
150
+
151
+ test 'input check boxes wraps items in a span tag by default' do
152
+ with_input_for @user, :active, :check_boxes
153
+
154
+ assert_select 'form span input[type=checkbox]', :count => 2
155
+ end
156
+
157
+ test 'input check boxes renders the item wrapper tag with a default class "checkbox"' do
158
+ with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :li
159
+
160
+ assert_select 'form li.checkbox input[type=checkbox]', :count => 2
161
+ end
162
+
163
+ test 'input check boxes renders the item wrapper tag with the configured item wrapper class' do
164
+ swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
165
+ with_input_for @user, :active, :check_boxes
166
+
167
+ assert_select 'form li.checkbox.item input[type=checkbox]', :count => 2
168
+ end
169
+ end
170
+
171
+ test 'input check boxes allows giving item wrapper class at input level only' do
172
+ swap SimpleForm, :item_wrapper_tag => :li do
173
+ with_input_for @user, :active, :check_boxes, :item_wrapper_class => 'item'
174
+
175
+ assert_select 'form li.checkbox.item input[type=checkbox]', :count => 2
176
+ end
177
+ end
178
+
179
+ test 'input check boxes uses both configured and given item wrapper classes for item wrapper tag' do
180
+ swap SimpleForm, :item_wrapper_tag => :li, :item_wrapper_class => 'item' do
181
+ with_input_for @user, :active, :check_boxes, :item_wrapper_class => 'inline'
182
+
183
+ assert_select 'form li.checkbox.item.inline input[type=checkbox]', :count => 2
184
+ end
185
+ end
186
+
187
+ test 'input check boxes respects the nested boolean style config, generating nested label > input' do
188
+ swap SimpleForm, :boolean_style => :nested do
189
+ with_input_for @user, :active, :check_boxes
190
+
191
+ assert_select 'label.checkbox > input#user_active_true[type=checkbox]'
192
+ assert_select 'label.checkbox', 'Yes'
193
+ assert_select 'label.checkbox > input#user_active_false[type=checkbox]'
194
+ assert_select 'label.checkbox', 'No'
195
+ assert_no_select 'label.collection_radio_buttons'
196
+ end
197
+ end
198
+
199
+ test 'input check boxes with nested style overrides configured item wrapper tag, forcing the :label' do
200
+ swap SimpleForm, :boolean_style => :nested, :item_wrapper_tag => :li do
201
+ with_input_for @user, :active, :check_boxes
202
+
203
+ assert_select 'label.checkbox > input'
204
+ assert_no_select 'li'
205
+ end
206
+ end
207
+
208
+ test 'input check boxes with nested style overrides given item wrapper tag, forcing the :label' do
209
+ swap SimpleForm, :boolean_style => :nested do
210
+ with_input_for @user, :active, :check_boxes, :item_wrapper_tag => :li
211
+
212
+ assert_select 'label.checkbox > input'
213
+ assert_no_select 'li'
214
+ end
215
+ end
216
+
217
+ test 'input check boxes with nested style accepts giving extra wrapper classes' do
218
+ swap SimpleForm, :boolean_style => :nested do
219
+ with_input_for @user, :active, :check_boxes, :item_wrapper_class => "inline"
220
+
221
+ assert_select 'label.checkbox.inline > input'
222
+ end
223
+ end
224
+ end