mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
Refactored the code to remove the item_wrapper and collection_wrapper with nil value. Closes #291
This commit is contained in:
parent
978e3a2ab0
commit
8f7bfcadee
2 changed files with 25 additions and 7 deletions
|
@ -134,8 +134,8 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def render_collection(attribute, collection, value_method, text_method, options={}, html_options={}) #:nodoc:
|
||||
collection_wrapper_tag = (options[:collection_wrapper_tag] || options[:collection_wrapper_tag] === false) ? options[:collection_wrapper_tag] : SimpleForm.collection_wrapper_tag
|
||||
item_wrapper_tag = (options[:item_wrapper_tag] || options[:item_wrapper_tag] === false) ? options[:item_wrapper_tag] : SimpleForm.item_wrapper_tag
|
||||
collection_wrapper_tag = options.has_key?(:collection_wrapper_tag) ? options[:collection_wrapper_tag] : SimpleForm.collection_wrapper_tag
|
||||
item_wrapper_tag = options.has_key?(:item_wrapper_tag) ? options[:item_wrapper_tag] : SimpleForm.item_wrapper_tag
|
||||
|
||||
rendered_collection = collection.map do |item|
|
||||
value = value_for_collection(item, value_method)
|
||||
|
|
|
@ -97,10 +97,21 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'collection radio does not wrap the collection in the explicitly false collection wrapper tag' do
|
||||
with_collection_radio @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false, :item_wrapper_tag => false
|
||||
swap SimpleForm, :collection_wrapper_tag => :ul do
|
||||
with_collection_radio @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
|
||||
|
||||
assert_select 'form > input[type=radio][value=true]#user_active_true'
|
||||
assert_select 'form > input[type=radio][value=false]#user_active_false'
|
||||
assert_no_select 'form ul'
|
||||
assert_no_select 'form ul'
|
||||
end
|
||||
end
|
||||
|
||||
test 'collection radio does not wrap the collection in the explicitly nil collection wrapper tag' do
|
||||
swap SimpleForm, :collection_wrapper_tag => :ul do
|
||||
with_collection_radio @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => nil
|
||||
|
||||
assert_no_select 'form ul'
|
||||
assert_no_select 'form ul'
|
||||
end
|
||||
end
|
||||
|
||||
test 'collection radio does not wrap the collection by default' do
|
||||
|
@ -128,8 +139,15 @@ class BuilderTest < ActionView::TestCase
|
|||
test 'collection radio does not wrap each label/radio in the explicitly false item wrapper tag' do
|
||||
with_collection_radio @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
|
||||
|
||||
assert_select 'form > input[type=radio][value=true]#user_active_true'
|
||||
assert_select 'form > input[type=radio][value=false]#user_active_false'
|
||||
assert_no_select 'form span input[type=radio][value=true]#user_active_true'
|
||||
assert_no_select 'form span input[type=radio][value=false]#user_active_false'
|
||||
end
|
||||
|
||||
test 'collection radio does not wrap each label/radio in the explicitly nil item wrapper tag' do
|
||||
with_collection_radio @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => nil
|
||||
|
||||
assert_no_select 'form span input[type=radio][value=true]#user_active_true'
|
||||
assert_no_select 'form span input[type=radio][value=false]#user_active_false'
|
||||
end
|
||||
|
||||
test 'collection radio wrap items in a span tag by default' do
|
||||
|
|
Loading…
Reference in a new issue