simple_form 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -32
- data/README.md +161 -119
- data/lib/generators/simple_form/install_generator.rb +3 -3
- data/lib/generators/simple_form/templates/README +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +16 -13
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
- data/lib/simple_form/components/html5.rb +5 -2
- data/lib/simple_form/components/labels.rb +3 -3
- data/lib/simple_form/components/maxlength.rb +1 -8
- data/lib/simple_form/components/pattern.rb +2 -2
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +155 -51
- data/lib/simple_form/helpers.rb +1 -1
- data/lib/simple_form/inputs/base.rb +6 -6
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +6 -4
- data/lib/simple_form/inputs/collection_input.rb +6 -6
- data/lib/simple_form/inputs/date_time_input.rb +1 -1
- data/lib/simple_form/inputs/numeric_input.rb +0 -6
- data/lib/simple_form/inputs/password_input.rb +0 -1
- data/lib/simple_form/inputs/string_input.rb +0 -1
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +62 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +5 -29
- data/lib/simple_form/wrappers/many.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -1
- data/lib/simple_form.rb +43 -47
- data/test/action_view_extensions/builder_test.rb +78 -92
- data/test/action_view_extensions/form_helper_test.rb +25 -16
- data/test/components/label_test.rb +46 -46
- data/test/form_builder/association_test.rb +47 -29
- data/test/form_builder/button_test.rb +4 -4
- data/test/form_builder/error_notification_test.rb +8 -8
- data/test/form_builder/error_test.rb +12 -12
- data/test/form_builder/general_test.rb +71 -52
- data/test/form_builder/hint_test.rb +22 -22
- data/test/form_builder/input_field_test.rb +29 -12
- data/test/form_builder/label_test.rb +7 -7
- data/test/form_builder/wrapper_test.rb +21 -21
- data/test/inputs/boolean_input_test.rb +35 -23
- data/test/inputs/collection_check_boxes_input_test.rb +66 -55
- data/test/inputs/collection_radio_buttons_input_test.rb +81 -79
- data/test/inputs/collection_select_input_test.rb +76 -45
- data/test/inputs/datetime_input_test.rb +17 -11
- data/test/inputs/disabled_test.rb +10 -10
- data/test/inputs/discovery_test.rb +4 -4
- data/test/inputs/file_input_test.rb +1 -1
- data/test/inputs/general_test.rb +28 -12
- data/test/inputs/grouped_collection_select_input_test.rb +33 -20
- data/test/inputs/hidden_input_test.rb +3 -2
- data/test/inputs/numeric_input_test.rb +3 -3
- data/test/inputs/priority_input_test.rb +9 -3
- data/test/inputs/readonly_test.rb +12 -12
- data/test/inputs/required_test.rb +5 -5
- data/test/inputs/string_input_test.rb +15 -25
- data/test/inputs/text_input_test.rb +1 -1
- data/test/support/misc_helpers.rb +46 -24
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +80 -62
- data/test/test_helper.rb +17 -34
- metadata +31 -29
- data/lib/simple_form/core_ext/hash.rb +0 -16
| @@ -38,7 +38,7 @@ class WrapperTest < ActionView::TestCase | |
| 38 38 | 
             
              end
         | 
| 39 39 |  | 
| 40 40 | 
             
              test 'wrapper should add hint class for attribute with a hint' do
         | 
| 41 | 
            -
                with_form_for @user, :name, : | 
| 41 | 
            +
                with_form_for @user, :name, hint: 'hint'
         | 
| 42 42 | 
             
                assert_select 'div.field_with_hint'
         | 
| 43 43 | 
             
              end
         | 
| 44 44 |  | 
| @@ -48,18 +48,18 @@ class WrapperTest < ActionView::TestCase | |
| 48 48 | 
             
              end
         | 
| 49 49 |  | 
| 50 50 | 
             
              test 'wrapper should have disabled class when input is disabled' do
         | 
| 51 | 
            -
                with_form_for @user, :active, : | 
| 51 | 
            +
                with_form_for @user, :active, disabled: true
         | 
| 52 52 | 
             
                assert_select 'div.disabled'
         | 
| 53 53 | 
             
              end
         | 
| 54 54 |  | 
| 55 55 | 
             
              test 'wrapper should support no wrapping when wrapper is false' do
         | 
| 56 | 
            -
                with_form_for @user, :name, : | 
| 56 | 
            +
                with_form_for @user, :name, wrapper: false
         | 
| 57 57 | 
             
                assert_select 'form > label[for=user_name]'
         | 
| 58 58 | 
             
                assert_select 'form > input#user_name.string'
         | 
| 59 59 | 
             
              end
         | 
| 60 60 |  | 
| 61 61 | 
             
              test 'wrapper should support no wrapping when wrapper tag is false' do
         | 
| 62 | 
            -
                with_form_for @user, :name, : | 
| 62 | 
            +
                with_form_for @user, :name, wrapper: custom_wrapper_without_top_level
         | 
| 63 63 | 
             
                assert_select 'form > label[for=user_name]'
         | 
| 64 64 | 
             
                assert_select 'form > input#user_name.string'
         | 
| 65 65 | 
             
              end
         | 
| @@ -68,28 +68,28 @@ class WrapperTest < ActionView::TestCase | |
| 68 68 | 
             
                with_form_for @user, :name
         | 
| 69 69 | 
             
                assert_select 'form div.input.required.string'
         | 
| 70 70 |  | 
| 71 | 
            -
                with_form_for @user, :age, : | 
| 71 | 
            +
                with_form_for @user, :age, required: false
         | 
| 72 72 | 
             
                assert_select 'form div.input.optional.integer'
         | 
| 73 73 | 
             
              end
         | 
| 74 74 |  | 
| 75 75 | 
             
              test 'wrapper should allow custom options to be given' do
         | 
| 76 | 
            -
                with_form_for @user, :name, : | 
| 76 | 
            +
                with_form_for @user, :name, wrapper_html: { id: "super_cool", class: 'yay' }
         | 
| 77 77 | 
             
                assert_select 'form #super_cool.required.string.yay'
         | 
| 78 78 | 
             
              end
         | 
| 79 79 |  | 
| 80 80 | 
             
              test 'wrapper should allow tag to be given on demand' do
         | 
| 81 | 
            -
                with_form_for @user, :name, : | 
| 81 | 
            +
                with_form_for @user, :name, wrapper_tag: :b
         | 
| 82 82 | 
             
                assert_select 'form b.required.string'
         | 
| 83 83 | 
             
              end
         | 
| 84 84 |  | 
| 85 85 | 
             
              test 'wrapper should allow wrapper class to be given on demand' do
         | 
| 86 | 
            -
                with_form_for @user, :name, : | 
| 86 | 
            +
                with_form_for @user, :name, wrapper_class: :wrapper
         | 
| 87 87 | 
             
                assert_select 'form div.wrapper.required.string'
         | 
| 88 88 | 
             
              end
         | 
| 89 89 |  | 
| 90 90 | 
             
              test 'wrapper should skip additional classes when configured' do
         | 
| 91 | 
            -
                swap SimpleForm, : | 
| 92 | 
            -
                  with_form_for @user, :name, : | 
| 91 | 
            +
                swap SimpleForm, generate_additional_classes_for: [:input, :label] do
         | 
| 92 | 
            +
                  with_form_for @user, :name, wrapper_class: :wrapper
         | 
| 93 93 | 
             
                  assert_select 'form div.wrapper'
         | 
| 94 94 | 
             
                  assert_no_select 'div.required'
         | 
| 95 95 | 
             
                  assert_no_select 'div.string'
         | 
| @@ -98,7 +98,7 @@ class WrapperTest < ActionView::TestCase | |
| 98 98 | 
             
              end
         | 
| 99 99 |  | 
| 100 100 | 
             
              test 'wrapper should not generate empty css class' do
         | 
| 101 | 
            -
                swap SimpleForm, : | 
| 101 | 
            +
                swap SimpleForm, generate_additional_classes_for: [:input, :label] do
         | 
| 102 102 | 
             
                  swap_wrapper :default, custom_wrapper_without_class do
         | 
| 103 103 | 
             
                    with_form_for @user, :name
         | 
| 104 104 | 
             
                    assert_no_select 'div#custom_wrapper_without_class[class]'
         | 
| @@ -110,7 +110,7 @@ class WrapperTest < ActionView::TestCase | |
| 110 110 |  | 
| 111 111 | 
             
              test 'custom wrappers works' do
         | 
| 112 112 | 
             
                swap_wrapper do
         | 
| 113 | 
            -
                  with_form_for @user, :name, : | 
| 113 | 
            +
                  with_form_for @user, :name, hint: "cool"
         | 
| 114 114 | 
             
                  assert_select "section.custom_wrapper div.another_wrapper label"
         | 
| 115 115 | 
             
                  assert_select "section.custom_wrapper div.another_wrapper input.string"
         | 
| 116 116 | 
             
                  assert_no_select "section.custom_wrapper div.another_wrapper span.omg_error"
         | 
| @@ -121,7 +121,7 @@ class WrapperTest < ActionView::TestCase | |
| 121 121 |  | 
| 122 122 | 
             
              test 'custom wrappers can be turned off' do
         | 
| 123 123 | 
             
                swap_wrapper do
         | 
| 124 | 
            -
                  with_form_for @user, :name, : | 
| 124 | 
            +
                  with_form_for @user, :name, another: false
         | 
| 125 125 | 
             
                  assert_no_select "section.custom_wrapper div.another_wrapper label"
         | 
| 126 126 | 
             
                  assert_no_select "section.custom_wrapper div.another_wrapper input.string"
         | 
| 127 127 | 
             
                  assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
         | 
| @@ -137,7 +137,7 @@ class WrapperTest < ActionView::TestCase | |
| 137 137 | 
             
                  assert_no_select "section.custom_wrapper div.another_wrapper label"
         | 
| 138 138 | 
             
                  assert_no_select "section.custom_wrapper div.another_wrapper input.string"
         | 
| 139 139 |  | 
| 140 | 
            -
                  with_concat_form_for(@user, : | 
| 140 | 
            +
                  with_concat_form_for(@user, wrapper: :another) do |f|
         | 
| 141 141 | 
             
                    f.input :name
         | 
| 142 142 | 
             
                  end
         | 
| 143 143 |  | 
| @@ -153,20 +153,20 @@ class WrapperTest < ActionView::TestCase | |
| 153 153 | 
             
                  assert_no_select "section.custom_wrapper div.another_wrapper input.string"
         | 
| 154 154 | 
             
                  output_buffer.replace ""
         | 
| 155 155 |  | 
| 156 | 
            -
                  with_form_for @user, :name, : | 
| 156 | 
            +
                  with_form_for @user, :name, wrapper: :another
         | 
| 157 157 | 
             
                  assert_select "section.custom_wrapper div.another_wrapper label"
         | 
| 158 158 | 
             
                  assert_select "section.custom_wrapper div.another_wrapper input.string"
         | 
| 159 159 | 
             
                  output_buffer.replace ""
         | 
| 160 160 | 
             
                end
         | 
| 161 161 |  | 
| 162 | 
            -
                with_form_for @user, :name, : | 
| 162 | 
            +
                with_form_for @user, :name, wrapper: custom_wrapper
         | 
| 163 163 | 
             
                assert_select "section.custom_wrapper div.another_wrapper label"
         | 
| 164 164 | 
             
                assert_select "section.custom_wrapper div.another_wrapper input.string"
         | 
| 165 165 | 
             
              end
         | 
| 166 166 |  | 
| 167 167 | 
             
              test 'access wrappers with indifferent access' do
         | 
| 168 168 | 
             
                swap_wrapper :another do
         | 
| 169 | 
            -
                  with_form_for @user, :name, : | 
| 169 | 
            +
                  with_form_for @user, :name, wrapper: "another"
         | 
| 170 170 | 
             
                  assert_select "section.custom_wrapper div.another_wrapper label"
         | 
| 171 171 | 
             
                  assert_select "section.custom_wrapper div.another_wrapper input.string"
         | 
| 172 172 | 
             
                end
         | 
| @@ -175,8 +175,8 @@ class WrapperTest < ActionView::TestCase | |
| 175 175 | 
             
              test 'do not duplicate label classes for different inputs' do
         | 
| 176 176 | 
             
                swap_wrapper :default, self.custom_wrapper_with_label_html_option do
         | 
| 177 177 | 
             
                  with_concat_form_for(@user) do |f|
         | 
| 178 | 
            -
                    concat f.input :name, : | 
| 179 | 
            -
                    concat f.input :email, : | 
| 178 | 
            +
                    concat f.input :name, required: false
         | 
| 179 | 
            +
                    concat f.input :email, as: :email, required: true
         | 
| 180 180 | 
             
                  end
         | 
| 181 181 |  | 
| 182 182 | 
             
                  assert_select "label.string.optional.extra-label-class[for='user_name']"
         | 
| @@ -187,13 +187,13 @@ class WrapperTest < ActionView::TestCase | |
| 187 187 |  | 
| 188 188 | 
             
              test 'raise error when wrapper not found' do
         | 
| 189 189 | 
             
                assert_raise SimpleForm::WrapperNotFound do
         | 
| 190 | 
            -
                  with_form_for @user, :name, : | 
| 190 | 
            +
                  with_form_for @user, :name, wrapper: :not_found
         | 
| 191 191 | 
             
                end
         | 
| 192 192 | 
             
              end
         | 
| 193 193 |  | 
| 194 194 | 
             
              test 'use wrapper for specified in config mapping' do
         | 
| 195 195 | 
             
                swap_wrapper :another do
         | 
| 196 | 
            -
                  swap SimpleForm, : | 
| 196 | 
            +
                  swap SimpleForm, wrapper_mappings: { string: :another } do
         | 
| 197 197 | 
             
                    with_form_for @user, :name
         | 
| 198 198 | 
             
                    assert_select "section.custom_wrapper div.another_wrapper label"
         | 
| 199 199 | 
             
                    assert_select "section.custom_wrapper div.another_wrapper input.string"
         | 
| @@ -9,26 +9,26 @@ class BooleanInputTest < ActionView::TestCase | |
| 9 9 | 
             
              end
         | 
| 10 10 |  | 
| 11 11 | 
             
              test 'input does not generate the label with the checkbox when label option is false' do
         | 
| 12 | 
            -
                with_input_for @user, :active, :boolean, : | 
| 12 | 
            +
                with_input_for @user, :active, :boolean, label: false
         | 
| 13 13 | 
             
                assert_select 'input[type=checkbox].boolean#user_active'
         | 
| 14 14 | 
             
                assert_no_select 'label'
         | 
| 15 15 | 
             
              end
         | 
| 16 16 |  | 
| 17 17 | 
             
              test 'input uses custom checked value' do
         | 
| 18 18 | 
             
                @user.action = 'on'
         | 
| 19 | 
            -
                with_input_for @user, :action, :boolean, : | 
| 19 | 
            +
                with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
         | 
| 20 20 | 
             
                assert_select 'input[type=checkbox][value=on][checked=checked]'
         | 
| 21 21 | 
             
              end
         | 
| 22 22 |  | 
| 23 23 | 
             
              test 'input uses custom unchecked value' do
         | 
| 24 24 | 
             
                @user.action = 'off'
         | 
| 25 | 
            -
                with_input_for @user, :action, :boolean, : | 
| 25 | 
            +
                with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
         | 
| 26 26 | 
             
                assert_select 'input[type=checkbox][value=on]'
         | 
| 27 27 | 
             
                assert_no_select 'input[checked=checked][value=on]'
         | 
| 28 28 | 
             
              end
         | 
| 29 29 |  | 
| 30 30 | 
             
              test 'input generates hidden input with custom unchecked value' do
         | 
| 31 | 
            -
                with_input_for @user, :action, :boolean, : | 
| 31 | 
            +
                with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
         | 
| 32 32 | 
             
                assert_select 'input[type=hidden][value=off]'
         | 
| 33 33 | 
             
              end
         | 
| 34 34 |  | 
| @@ -39,7 +39,7 @@ class BooleanInputTest < ActionView::TestCase | |
| 39 39 | 
             
              end
         | 
| 40 40 |  | 
| 41 41 | 
             
              test 'input allows changing default boolean style config to nested, generating a default label and a manual hidden field for checkbox' do
         | 
| 42 | 
            -
                swap SimpleForm, : | 
| 42 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 43 43 | 
             
                  with_input_for @user, :active, :boolean
         | 
| 44 44 | 
             
                  assert_select 'label[for=user_active]', 'Active'
         | 
| 45 45 | 
             
                  assert_select 'label.boolean > input.boolean'
         | 
| @@ -48,21 +48,21 @@ class BooleanInputTest < ActionView::TestCase | |
| 48 48 | 
             
              end
         | 
| 49 49 |  | 
| 50 50 | 
             
              test 'input boolean with nested allows :inline_label' do
         | 
| 51 | 
            -
                swap SimpleForm, : | 
| 52 | 
            -
                  with_input_for @user, :active, :boolean, : | 
| 53 | 
            -
                  assert_select 'label.checkbox', : | 
| 51 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 52 | 
            +
                  with_input_for @user, :active, :boolean, label: false, inline_label: 'I am so inline.'
         | 
| 53 | 
            +
                  assert_select 'label.checkbox', text: 'I am so inline.'
         | 
| 54 54 | 
             
                end
         | 
| 55 55 | 
             
              end
         | 
| 56 56 |  | 
| 57 57 | 
             
              test 'input boolean with nested style creates an inline label using the default label text when inline_label option set to true' do
         | 
| 58 | 
            -
                swap SimpleForm, : | 
| 59 | 
            -
                  with_input_for @user, :active, :boolean, : | 
| 60 | 
            -
                  assert_select 'label.checkbox', : | 
| 58 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 59 | 
            +
                  with_input_for @user, :active, :boolean, label: false, inline_label: true
         | 
| 60 | 
            +
                  assert_select 'label.checkbox', text: 'Active'
         | 
| 61 61 | 
             
                end
         | 
| 62 62 | 
             
              end
         | 
| 63 63 |  | 
| 64 64 | 
             
              test 'input boolean with nested generates a manual hidden field for checkbox outside the label, to recreate Rails functionality with valid html5' do
         | 
| 65 | 
            -
                swap SimpleForm, : | 
| 65 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 66 66 | 
             
                  with_input_for @user, :active, :boolean
         | 
| 67 67 |  | 
| 68 68 | 
             
                  assert_select "input[type=hidden][name='user[active]'] + label.boolean > input.boolean"
         | 
| @@ -71,23 +71,23 @@ class BooleanInputTest < ActionView::TestCase | |
| 71 71 | 
             
              end
         | 
| 72 72 |  | 
| 73 73 | 
             
              test 'input boolean with nested generates a disabled hidden field for checkbox outside the label, if the field is disabled' do
         | 
| 74 | 
            -
                swap SimpleForm, : | 
| 75 | 
            -
                  with_input_for @user, :active, :boolean, : | 
| 74 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 75 | 
            +
                  with_input_for @user, :active, :boolean, disabled: true
         | 
| 76 76 |  | 
| 77 77 | 
             
                  assert_select "input[type=hidden][name='user[active]'][disabled] + label.boolean > input.boolean[disabled]"
         | 
| 78 78 | 
             
                end
         | 
| 79 79 | 
             
              end
         | 
| 80 80 |  | 
| 81 81 | 
             
              test 'input accepts changing boolean style to nested through given options' do
         | 
| 82 | 
            -
                with_input_for @user, :active, :boolean, : | 
| 82 | 
            +
                with_input_for @user, :active, :boolean, boolean_style: :nested
         | 
| 83 83 | 
             
                assert_select 'label[for=user_active]', 'Active'
         | 
| 84 84 | 
             
                assert_select 'label.boolean > input.boolean'
         | 
| 85 85 | 
             
                assert_no_select 'input[type=checkbox] + label'
         | 
| 86 86 | 
             
              end
         | 
| 87 87 |  | 
| 88 88 | 
             
              test 'input accepts changing boolean style to inline through given options, when default is nested' do
         | 
| 89 | 
            -
                swap SimpleForm, : | 
| 90 | 
            -
                  with_input_for @user, :active, :boolean, : | 
| 89 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 90 | 
            +
                  with_input_for @user, :active, :boolean, boolean_style: :inline
         | 
| 91 91 | 
             
                  assert_select 'label[for=user_active]', 'Active'
         | 
| 92 92 | 
             
                  assert_select 'input.boolean + label.boolean'
         | 
| 93 93 | 
             
                  assert_no_select 'label > input'
         | 
| @@ -95,16 +95,16 @@ class BooleanInputTest < ActionView::TestCase | |
| 95 95 | 
             
              end
         | 
| 96 96 |  | 
| 97 97 | 
             
              test 'input with nested style allows disabling label' do
         | 
| 98 | 
            -
                swap SimpleForm, : | 
| 99 | 
            -
                  with_input_for @user, :active, :boolean, : | 
| 98 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 99 | 
            +
                  with_input_for @user, :active, :boolean, label: false
         | 
| 100 100 | 
             
                  assert_select 'input.boolean'
         | 
| 101 101 | 
             
                  assert_no_select 'label.boolean'
         | 
| 102 102 | 
             
                end
         | 
| 103 103 | 
             
              end
         | 
| 104 104 |  | 
| 105 105 | 
             
              test 'input with nested style allows customizing input_html' do
         | 
| 106 | 
            -
                swap SimpleForm, : | 
| 107 | 
            -
                  with_input_for @user, :active, :boolean, : | 
| 106 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 107 | 
            +
                  with_input_for @user, :active, :boolean, input_html: { name: 'active_user' }
         | 
| 108 108 | 
             
                  assert_select "input[type=hidden][name=active_user] + label.boolean > input.boolean[name=active_user]"
         | 
| 109 109 | 
             
                end
         | 
| 110 110 | 
             
              end
         | 
| @@ -120,7 +120,7 @@ class BooleanInputTest < ActionView::TestCase | |
| 120 120 |  | 
| 121 121 | 
             
              test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra "checkbox" label wrapper' do
         | 
| 122 122 | 
             
                swap_wrapper do
         | 
| 123 | 
            -
                  swap SimpleForm, : | 
| 123 | 
            +
                  swap SimpleForm, boolean_style: :nested do
         | 
| 124 124 | 
             
                    with_input_for @user, :active, :boolean
         | 
| 125 125 |  | 
| 126 126 | 
             
                    assert_select 'label.boolean + input[type=hidden] + label.checkbox > input.boolean'
         | 
| @@ -130,11 +130,23 @@ class BooleanInputTest < ActionView::TestCase | |
| 130 130 |  | 
| 131 131 | 
             
              test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
         | 
| 132 132 | 
             
                swap_wrapper :default, self.custom_wrapper_without_top_level do
         | 
| 133 | 
            -
                  swap SimpleForm, : | 
| 133 | 
            +
                  swap SimpleForm, boolean_style: :nested do
         | 
| 134 134 | 
             
                    with_input_for @user, :active, :boolean
         | 
| 135 135 |  | 
| 136 136 | 
             
                    assert_select 'input[type=hidden] + label.boolean.checkbox > input.boolean'
         | 
| 137 137 | 
             
                  end
         | 
| 138 138 | 
             
                end
         | 
| 139 139 | 
             
              end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
              test 'input boolean without additional classes should add "checkbox" class to label' do
         | 
| 142 | 
            +
                swap_wrapper :default, self.custom_wrapper_without_top_level do
         | 
| 143 | 
            +
                  swap SimpleForm, boolean_style: :nested, generate_additional_classes_for: [:input] do
         | 
| 144 | 
            +
                    with_input_for @user, :active, :boolean
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                    assert_select 'label'
         | 
| 147 | 
            +
                    assert_select 'label.checkbox'
         | 
| 148 | 
            +
                    assert_no_select 'label.boolean'
         | 
| 149 | 
            +
                  end
         | 
| 150 | 
            +
                end
         | 
| 151 | 
            +
              end
         | 
| 140 152 | 
             
            end
         | 
| @@ -7,27 +7,33 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase | |
| 7 7 | 
             
              end
         | 
| 8 8 |  | 
| 9 9 | 
             
              test 'input check boxes should not include for attribute by default' do
         | 
| 10 | 
            -
                with_input_for @user, :gender, :check_boxes, : | 
| 10 | 
            +
                with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
         | 
| 11 11 | 
             
                assert_select 'label'
         | 
| 12 12 | 
             
                assert_no_select 'label[for=user_gender]'
         | 
| 13 13 | 
             
              end
         | 
| 14 14 |  | 
| 15 15 | 
             
              test 'input check boxes should include for attribute when giving as html option' do
         | 
| 16 | 
            -
                with_input_for @user, :gender, :check_boxes, : | 
| 16 | 
            +
                with_input_for @user, :gender, :check_boxes, collection: [:male, :female], label_html: { for: 'gender' }
         | 
| 17 17 | 
             
                assert_select 'label[for=gender]'
         | 
| 18 18 | 
             
              end
         | 
| 19 19 |  | 
| 20 20 | 
             
              test 'collection input with check_boxes type should not generate required html attribute' do
         | 
| 21 | 
            -
                with_input_for @user, :name, :check_boxes, : | 
| 21 | 
            +
                with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
         | 
| 22 22 | 
             
                assert_select 'input.required'
         | 
| 23 23 | 
             
                assert_no_select 'input[required]'
         | 
| 24 24 | 
             
              end
         | 
| 25 25 |  | 
| 26 | 
            +
              test 'collection input with check_boxes type should not generate aria-required html attribute' do
         | 
| 27 | 
            +
                with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
         | 
| 28 | 
            +
                assert_select 'input.required'
         | 
| 29 | 
            +
                assert_no_select 'input[aria-required]'
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 26 32 | 
             
              test 'input should do automatic collection translation for check_box types using defaults key' do
         | 
| 27 | 
            -
                store_translations(:en, : | 
| 28 | 
            -
                  : | 
| 33 | 
            +
                store_translations(:en, simple_form: { options: { defaults: {
         | 
| 34 | 
            +
                  gender: { male: 'Male', female: 'Female'}
         | 
| 29 35 | 
             
                } } } ) do
         | 
| 30 | 
            -
                  with_input_for @user, :gender, :check_boxes, : | 
| 36 | 
            +
                  with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
         | 
| 31 37 | 
             
                  assert_select 'input[type=checkbox][value=male]'
         | 
| 32 38 | 
             
                  assert_select 'input[type=checkbox][value=female]'
         | 
| 33 39 | 
             
                  assert_select 'label.collection_check_boxes', 'Male'
         | 
| @@ -36,10 +42,10 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase | |
| 36 42 | 
             
              end
         | 
| 37 43 |  | 
| 38 44 | 
             
              test 'input should do automatic collection translation for check_box types using specific object key' do
         | 
| 39 | 
            -
                store_translations(:en, : | 
| 40 | 
            -
                  : | 
| 45 | 
            +
                store_translations(:en, simple_form: { options: { user: {
         | 
| 46 | 
            +
                  gender: { male: 'Male', female: 'Female'}
         | 
| 41 47 | 
             
                } } } ) do
         | 
| 42 | 
            -
                  with_input_for @user, :gender, :check_boxes, : | 
| 48 | 
            +
                  with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
         | 
| 43 49 | 
             
                  assert_select 'input[type=checkbox][value=male]'
         | 
| 44 50 | 
             
                  assert_select 'input[type=checkbox][value=female]'
         | 
| 45 51 | 
             
                  assert_select 'label.collection_check_boxes', 'Male'
         | 
| @@ -50,100 +56,105 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase | |
| 50 56 | 
             
              test 'input check boxes does not wrap the collection by default' do
         | 
| 51 57 | 
             
                with_input_for @user, :active, :check_boxes
         | 
| 52 58 |  | 
| 53 | 
            -
                assert_select 'form input[type=checkbox]', : | 
| 59 | 
            +
                assert_select 'form input[type=checkbox]', count: 2
         | 
| 54 60 | 
             
                assert_no_select 'form ul'
         | 
| 55 61 | 
             
              end
         | 
| 56 62 |  | 
| 63 | 
            +
              test 'input check boxes accepts html options as the last element of collection' do
         | 
| 64 | 
            +
                with_input_for @user, :name, :check_boxes, collection: [['Jose', 'jose', class: 'foo']]
         | 
| 65 | 
            +
                assert_select 'input.foo[type=checkbox][value=jose]'
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 57 68 | 
             
              test 'input check boxes wraps the collection in the configured collection wrapper tag' do
         | 
| 58 | 
            -
                swap SimpleForm, : | 
| 69 | 
            +
                swap SimpleForm, collection_wrapper_tag: :ul do
         | 
| 59 70 | 
             
                  with_input_for @user, :active, :check_boxes
         | 
| 60 71 |  | 
| 61 | 
            -
                  assert_select 'form ul input[type=checkbox]', : | 
| 72 | 
            +
                  assert_select 'form ul input[type=checkbox]', count: 2
         | 
| 62 73 | 
             
                end
         | 
| 63 74 | 
             
              end
         | 
| 64 75 |  | 
| 65 76 | 
             
              test 'input check boxes does not wrap the collection when configured with falsy values' do
         | 
| 66 | 
            -
                swap SimpleForm, : | 
| 77 | 
            +
                swap SimpleForm, collection_wrapper_tag: false do
         | 
| 67 78 | 
             
                  with_input_for @user, :active, :check_boxes
         | 
| 68 79 |  | 
| 69 | 
            -
                  assert_select 'form input[type=checkbox]', : | 
| 80 | 
            +
                  assert_select 'form input[type=checkbox]', count: 2
         | 
| 70 81 | 
             
                  assert_no_select 'form ul'
         | 
| 71 82 | 
             
                end
         | 
| 72 83 | 
             
              end
         | 
| 73 84 |  | 
| 74 85 | 
             
              test 'input check boxes allows overriding the collection wrapper tag at input level' do
         | 
| 75 | 
            -
                swap SimpleForm, : | 
| 76 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 86 | 
            +
                swap SimpleForm, collection_wrapper_tag: :ul do
         | 
| 87 | 
            +
                  with_input_for @user, :active, :check_boxes, collection_wrapper_tag: :section
         | 
| 77 88 |  | 
| 78 | 
            -
                  assert_select 'form section input[type=checkbox]', : | 
| 89 | 
            +
                  assert_select 'form section input[type=checkbox]', count: 2
         | 
| 79 90 | 
             
                  assert_no_select 'form ul'
         | 
| 80 91 | 
             
                end
         | 
| 81 92 | 
             
              end
         | 
| 82 93 |  | 
| 83 94 | 
             
              test 'input check boxes allows disabling the collection wrapper tag at input level' do
         | 
| 84 | 
            -
                swap SimpleForm, : | 
| 85 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 95 | 
            +
                swap SimpleForm, collection_wrapper_tag: :ul do
         | 
| 96 | 
            +
                  with_input_for @user, :active, :check_boxes, collection_wrapper_tag: false
         | 
| 86 97 |  | 
| 87 | 
            -
                  assert_select 'form input[type=checkbox]', : | 
| 98 | 
            +
                  assert_select 'form input[type=checkbox]', count: 2
         | 
| 88 99 | 
             
                  assert_no_select 'form ul'
         | 
| 89 100 | 
             
                end
         | 
| 90 101 | 
             
              end
         | 
| 91 102 |  | 
| 92 103 | 
             
              test 'input check boxes renders the wrapper tag with the configured wrapper class' do
         | 
| 93 | 
            -
                swap SimpleForm, : | 
| 104 | 
            +
                swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
         | 
| 94 105 | 
             
                  with_input_for @user, :active, :check_boxes
         | 
| 95 106 |  | 
| 96 | 
            -
                  assert_select 'form ul.inputs-list input[type=checkbox]', : | 
| 107 | 
            +
                  assert_select 'form ul.inputs-list input[type=checkbox]', count: 2
         | 
| 97 108 | 
             
                end
         | 
| 98 109 | 
             
              end
         | 
| 99 110 |  | 
| 100 111 | 
             
              test 'input check boxes allows giving wrapper class at input level only' do
         | 
| 101 | 
            -
                swap SimpleForm, : | 
| 102 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 112 | 
            +
                swap SimpleForm, collection_wrapper_tag: :ul do
         | 
| 113 | 
            +
                  with_input_for @user, :active, :check_boxes, collection_wrapper_class: 'items-list'
         | 
| 103 114 |  | 
| 104 | 
            -
                  assert_select 'form ul.items-list input[type=checkbox]', : | 
| 115 | 
            +
                  assert_select 'form ul.items-list input[type=checkbox]', count: 2
         | 
| 105 116 | 
             
                end
         | 
| 106 117 | 
             
              end
         | 
| 107 118 |  | 
| 108 119 | 
             
              test 'input check boxes uses both configured and given wrapper classes for wrapper tag' do
         | 
| 109 | 
            -
                swap SimpleForm, : | 
| 110 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 120 | 
            +
                swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
         | 
| 121 | 
            +
                  with_input_for @user, :active, :check_boxes, collection_wrapper_class: 'items-list'
         | 
| 111 122 |  | 
| 112 | 
            -
                  assert_select 'form ul.inputs-list.items-list input[type=checkbox]', : | 
| 123 | 
            +
                  assert_select 'form ul.inputs-list.items-list input[type=checkbox]', count: 2
         | 
| 113 124 | 
             
                end
         | 
| 114 125 | 
             
              end
         | 
| 115 126 |  | 
| 116 127 | 
             
              test 'input check boxes wraps each item in the configured item wrapper tag' do
         | 
| 117 | 
            -
                swap SimpleForm, : | 
| 128 | 
            +
                swap SimpleForm, item_wrapper_tag: :li do
         | 
| 118 129 | 
             
                  with_input_for @user, :active, :check_boxes
         | 
| 119 130 |  | 
| 120 | 
            -
                  assert_select 'form li input[type=checkbox]', : | 
| 131 | 
            +
                  assert_select 'form li input[type=checkbox]', count: 2
         | 
| 121 132 | 
             
                end
         | 
| 122 133 | 
             
              end
         | 
| 123 134 |  | 
| 124 135 | 
             
              test 'input check boxes does not wrap items when configured with falsy values' do
         | 
| 125 | 
            -
                swap SimpleForm, : | 
| 136 | 
            +
                swap SimpleForm, item_wrapper_tag: false do
         | 
| 126 137 | 
             
                  with_input_for @user, :active, :check_boxes
         | 
| 127 138 |  | 
| 128 | 
            -
                  assert_select 'form input[type=checkbox]', : | 
| 139 | 
            +
                  assert_select 'form input[type=checkbox]', count: 2
         | 
| 129 140 | 
             
                  assert_no_select 'form li'
         | 
| 130 141 | 
             
                end
         | 
| 131 142 | 
             
              end
         | 
| 132 143 |  | 
| 133 144 | 
             
              test 'input check boxes allows overriding the item wrapper tag at input level' do
         | 
| 134 | 
            -
                swap SimpleForm, : | 
| 135 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 145 | 
            +
                swap SimpleForm, item_wrapper_tag: :li do
         | 
| 146 | 
            +
                  with_input_for @user, :active, :check_boxes, item_wrapper_tag: :dl
         | 
| 136 147 |  | 
| 137 | 
            -
                  assert_select 'form dl input[type=checkbox]', : | 
| 148 | 
            +
                  assert_select 'form dl input[type=checkbox]', count: 2
         | 
| 138 149 | 
             
                  assert_no_select 'form li'
         | 
| 139 150 | 
             
                end
         | 
| 140 151 | 
             
              end
         | 
| 141 152 |  | 
| 142 153 | 
             
              test 'input check boxes allows disabling the item wrapper tag at input level' do
         | 
| 143 | 
            -
                swap SimpleForm, : | 
| 144 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 154 | 
            +
                swap SimpleForm, item_wrapper_tag: :ul do
         | 
| 155 | 
            +
                  with_input_for @user, :active, :check_boxes, item_wrapper_tag: false
         | 
| 145 156 |  | 
| 146 | 
            -
                  assert_select 'form input[type=checkbox]', : | 
| 157 | 
            +
                  assert_select 'form input[type=checkbox]', count: 2
         | 
| 147 158 | 
             
                  assert_no_select 'form li'
         | 
| 148 159 | 
             
                end
         | 
| 149 160 | 
             
              end
         | 
| @@ -151,41 +162,41 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase | |
| 151 162 | 
             
              test 'input check boxes wraps items in a span tag by default' do
         | 
| 152 163 | 
             
                with_input_for @user, :active, :check_boxes
         | 
| 153 164 |  | 
| 154 | 
            -
                assert_select 'form span input[type=checkbox]', : | 
| 165 | 
            +
                assert_select 'form span input[type=checkbox]', count: 2
         | 
| 155 166 | 
             
              end
         | 
| 156 167 |  | 
| 157 168 | 
             
              test 'input check boxes renders the item wrapper tag with a default class "checkbox"' do
         | 
| 158 | 
            -
                with_input_for @user, :active, :check_boxes, : | 
| 169 | 
            +
                with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
         | 
| 159 170 |  | 
| 160 | 
            -
                assert_select 'form li.checkbox input[type=checkbox]', : | 
| 171 | 
            +
                assert_select 'form li.checkbox input[type=checkbox]', count: 2
         | 
| 161 172 | 
             
              end
         | 
| 162 173 |  | 
| 163 174 | 
             
              test 'input check boxes renders the item wrapper tag with the configured item wrapper class' do
         | 
| 164 | 
            -
                swap SimpleForm, : | 
| 175 | 
            +
                swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
         | 
| 165 176 | 
             
                  with_input_for @user, :active, :check_boxes
         | 
| 166 177 |  | 
| 167 | 
            -
                  assert_select 'form li.checkbox.item input[type=checkbox]', : | 
| 178 | 
            +
                  assert_select 'form li.checkbox.item input[type=checkbox]', count: 2
         | 
| 168 179 | 
             
                end
         | 
| 169 180 | 
             
              end
         | 
| 170 181 |  | 
| 171 182 | 
             
              test 'input check boxes allows giving item wrapper class at input level only' do
         | 
| 172 | 
            -
                swap SimpleForm, : | 
| 173 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 183 | 
            +
                swap SimpleForm, item_wrapper_tag: :li do
         | 
| 184 | 
            +
                  with_input_for @user, :active, :check_boxes, item_wrapper_class: 'item'
         | 
| 174 185 |  | 
| 175 | 
            -
                  assert_select 'form li.checkbox.item input[type=checkbox]', : | 
| 186 | 
            +
                  assert_select 'form li.checkbox.item input[type=checkbox]', count: 2
         | 
| 176 187 | 
             
                end
         | 
| 177 188 | 
             
              end
         | 
| 178 189 |  | 
| 179 190 | 
             
              test 'input check boxes uses both configured and given item wrapper classes for item wrapper tag' do
         | 
| 180 | 
            -
                swap SimpleForm, : | 
| 181 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 191 | 
            +
                swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
         | 
| 192 | 
            +
                  with_input_for @user, :active, :check_boxes, item_wrapper_class: 'inline'
         | 
| 182 193 |  | 
| 183 | 
            -
                  assert_select 'form li.checkbox.item.inline input[type=checkbox]', : | 
| 194 | 
            +
                  assert_select 'form li.checkbox.item.inline input[type=checkbox]', count: 2
         | 
| 184 195 | 
             
                end
         | 
| 185 196 | 
             
              end
         | 
| 186 197 |  | 
| 187 198 | 
             
              test 'input check boxes respects the nested boolean style config, generating nested label > input' do
         | 
| 188 | 
            -
                swap SimpleForm, : | 
| 199 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 189 200 | 
             
                  with_input_for @user, :active, :check_boxes
         | 
| 190 201 |  | 
| 191 202 | 
             
                  assert_select 'label.checkbox > input#user_active_true[type=checkbox]'
         | 
| @@ -197,7 +208,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase | |
| 197 208 | 
             
              end
         | 
| 198 209 |  | 
| 199 210 | 
             
              test 'input check boxes with nested style overrides configured item wrapper tag, forcing the :label' do
         | 
| 200 | 
            -
                swap SimpleForm, : | 
| 211 | 
            +
                swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
         | 
| 201 212 | 
             
                  with_input_for @user, :active, :check_boxes
         | 
| 202 213 |  | 
| 203 214 | 
             
                  assert_select 'label.checkbox > input'
         | 
| @@ -206,8 +217,8 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase | |
| 206 217 | 
             
              end
         | 
| 207 218 |  | 
| 208 219 | 
             
              test 'input check boxes with nested style overrides given item wrapper tag, forcing the :label' do
         | 
| 209 | 
            -
                swap SimpleForm, : | 
| 210 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 220 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 221 | 
            +
                  with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
         | 
| 211 222 |  | 
| 212 223 | 
             
                  assert_select 'label.checkbox > input'
         | 
| 213 224 | 
             
                  assert_no_select 'li'
         | 
| @@ -215,8 +226,8 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase | |
| 215 226 | 
             
              end
         | 
| 216 227 |  | 
| 217 228 | 
             
              test 'input check boxes with nested style accepts giving extra wrapper classes' do
         | 
| 218 | 
            -
                swap SimpleForm, : | 
| 219 | 
            -
                  with_input_for @user, :active, :check_boxes, : | 
| 229 | 
            +
                swap SimpleForm, boolean_style: :nested do
         | 
| 230 | 
            +
                  with_input_for @user, :active, :check_boxes, item_wrapper_class: "inline"
         | 
| 220 231 |  | 
| 221 232 | 
             
                  assert_select 'label.checkbox.inline > input'
         | 
| 222 233 | 
             
                end
         |