diff --git a/lib/simple_form/action_view_extensions/builder.rb b/lib/simple_form/action_view_extensions/builder.rb index 050e1c82..89979dac 100644 --- a/lib/simple_form/action_view_extensions/builder.rb +++ b/lib/simple_form/action_view_extensions/builder.rb @@ -139,7 +139,8 @@ module SimpleForm def render_collection(attribute, collection, value_method, text_method, options={}, html_options={}) #:nodoc: collection_wrapper_tag = options.has_key?(:collection_wrapper_tag) ? options[:collection_wrapper_tag] : SimpleForm.collection_wrapper_tag - collection_wrapper_class = options.has_key?(:collection_wrapper_class) ? options[:collection_wrapper_class] : SimpleForm.collection_wrapper_class + collection_wrapper_class = [SimpleForm.collection_wrapper_class, options[:collection_wrapper_class]].compact + collection_wrapper_class = nil if collection_wrapper_class.empty? item_wrapper_tag = options.has_key?(:item_wrapper_tag) ? options[:item_wrapper_tag] : SimpleForm.item_wrapper_tag rendered_collection = collection.map do |item| diff --git a/test/action_view_extensions/builder_test.rb b/test/action_view_extensions/builder_test.rb index 48ae5443..e9383a9c 100644 --- a/test/action_view_extensions/builder_test.rb +++ b/test/action_view_extensions/builder_test.rb @@ -138,6 +138,15 @@ class BuilderTest < ActionView::TestCase end end + test 'collection radio uses both configured and given classes for collection wrapper tag' do + swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => :'inputs-list' do + with_collection_radio @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_class => :'items-list' + + assert_select 'form ul.inputs-list.items-list input[type=radio][value=true]#user_active_true' + assert_select 'form ul.inputs-list.items-list input[type=radio][value=false]#user_active_false' + end + end + test 'collection radio uses no class for collection wrapper tag by default' do swap SimpleForm, :collection_wrapper_tag => :ul do with_collection_radio @user, :active, [true, false], :to_s, :to_s @@ -335,6 +344,15 @@ class BuilderTest < ActionView::TestCase end end + test 'collection check box uses both configured and given classes for collection wrapper tag' do + swap SimpleForm, :collection_wrapper_tag => :ul, :collection_wrapper_class => :'inputs-list' do + with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_class => :'items-list' + + assert_select 'form ul.inputs-list.items-list input[type=checkbox][value=true]#user_active_true' + assert_select 'form ul.inputs-list.items-list input[type=checkbox][value=false]#user_active_false' + end + end + test 'collection check box uses no class for collection wrapper tag by default' do swap SimpleForm, :collection_wrapper_tag => :ul do with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s