Merge branch 'issue-720'
This commit is contained in:
commit
5ae7ffbb26
|
@ -194,7 +194,7 @@ module SimpleForm
|
|||
# end
|
||||
def simple_fields_for(*args, &block)
|
||||
options = args.extract_options!
|
||||
options[:wrapper] ||= self.options[:wrapper]
|
||||
options[:wrapper] = self.options[:wrapper] if options[:wrapper].nil?
|
||||
options[:defaults] ||= self.options[:defaults]
|
||||
|
||||
if self.class < ActionView::Helpers::FormBuilder
|
||||
|
|
|
@ -21,34 +21,34 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
# COLLECTION RADIO
|
||||
test 'collection radio accepts a collection and generate inputs from value method' do
|
||||
test "collection radio accepts a collection and generate inputs from value method" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_select 'form input[type=radio][value=true]#user_active_true'
|
||||
assert_select 'form input[type=radio][value=false]#user_active_false'
|
||||
end
|
||||
|
||||
test 'collection radio accepts a collection and generate inputs from label method' do
|
||||
test "collection radio accepts a collection and generate inputs from label method" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_select 'form label.collection_radio_buttons[for=user_active_true]', 'true'
|
||||
assert_select 'form label.collection_radio_buttons[for=user_active_false]', 'false'
|
||||
end
|
||||
|
||||
test 'collection radio handles camelized collection values for labels correctly' do
|
||||
test "collection radio handles camelized collection values for labels correctly" do
|
||||
with_collection_radio_buttons @user, :active, ['Yes', 'No'], :to_s, :to_s
|
||||
|
||||
assert_select 'form label.collection_radio_buttons[for=user_active_yes]', 'Yes'
|
||||
assert_select 'form label.collection_radio_buttons[for=user_active_no]', 'No'
|
||||
end
|
||||
|
||||
test 'collection radio should sanitize collection values for labels correctly' do
|
||||
test "collection radio should sanitize collection values for labels correctly" do
|
||||
with_collection_radio_buttons @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
|
||||
assert_select 'label.collection_radio_buttons[for=user_name_099]', '$0.99'
|
||||
assert_select 'label.collection_radio_buttons[for=user_name_199]', '$1.99'
|
||||
end
|
||||
|
||||
test 'collection radio checks the correct value to local variables' do
|
||||
test "collection radio checks the correct value to local variables" do
|
||||
user = User.new
|
||||
user.active = false
|
||||
with_collection_radio_buttons user, :active, [true, false], :to_s, :to_s
|
||||
|
@ -57,20 +57,20 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form input[type=radio][value=false][checked=checked]'
|
||||
end
|
||||
|
||||
test 'collection radio accepts checked item' do
|
||||
test "collection radio accepts checked item" do
|
||||
with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => true
|
||||
|
||||
assert_select 'form input[type=radio][value=true][checked=checked]'
|
||||
assert_no_select 'form input[type=radio][value=false][checked=checked]'
|
||||
end
|
||||
|
||||
test 'collection radio accepts checked item which has a value of false' do
|
||||
test "collection radio accepts checked item which has a value of false" do
|
||||
with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => false
|
||||
assert_no_select 'form input[type=radio][value=true][checked=checked]'
|
||||
assert_select 'form input[type=radio][value=false][checked=checked]'
|
||||
end
|
||||
|
||||
test 'collection radio accepts multiple disabled items' do
|
||||
test "collection radio accepts multiple disabled items" do
|
||||
collection = [[1, true], [0, false], [2, 'other']]
|
||||
with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => [true, false]
|
||||
|
||||
|
@ -79,7 +79,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=radio][value=other][disabled=disabled]'
|
||||
end
|
||||
|
||||
test 'collection radio accepts single disable item' do
|
||||
test "collection radio accepts single disable item" do
|
||||
collection = [[1, true], [0, false]]
|
||||
with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => true
|
||||
|
||||
|
@ -87,7 +87,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=radio][value=false][disabled=disabled]'
|
||||
end
|
||||
|
||||
test 'collection radio accepts html options as input' do
|
||||
test "collection radio accepts html options as input" do
|
||||
collection = [[1, true], [0, false]]
|
||||
with_collection_radio_buttons @user, :active, collection, :last, :first, {}, :class => 'special-radio'
|
||||
|
||||
|
@ -95,34 +95,34 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form input[type=radio][value=false].special-radio#user_active_false'
|
||||
end
|
||||
|
||||
test 'collection radio wraps the collection in the given collection wrapper tag' do
|
||||
test "collection radio wraps the collection in the given collection wrapper tag" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
|
||||
|
||||
assert_select 'form ul input[type=radio]', :count => 2
|
||||
end
|
||||
|
||||
test 'collection radio does not render any wrapper tag by default' do
|
||||
test "collection radio does not render any wrapper tag by default" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_select 'form input[type=radio]', :count => 2
|
||||
assert_no_select 'form ul'
|
||||
end
|
||||
|
||||
test 'collection radio does not wrap the collection when given falsy values' do
|
||||
test "collection radio does not wrap the collection when given falsy values" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
|
||||
|
||||
assert_select 'form input[type=radio]', :count => 2
|
||||
assert_no_select 'form ul'
|
||||
end
|
||||
|
||||
test 'collection radio uses the given class for collection wrapper tag' do
|
||||
test "collection radio uses the given class for collection wrapper tag" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
||||
:collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
|
||||
|
||||
assert_select 'form ul.items-list input[type=radio]', :count => 2
|
||||
end
|
||||
|
||||
test 'collection radio uses no class for collection wrapper tag when no wrapper tag is given' do
|
||||
test "collection radio uses no class for collection wrapper tag when no wrapper tag is given" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
||||
:collection_wrapper_class => "items-list"
|
||||
|
||||
|
@ -131,41 +131,41 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select '.items-list'
|
||||
end
|
||||
|
||||
test 'collection radio uses no class for collection wrapper tag by default' do
|
||||
test "collection radio uses no class for collection wrapper tag by default" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
|
||||
|
||||
assert_select 'form ul'
|
||||
assert_no_select 'form ul[class]'
|
||||
end
|
||||
|
||||
test 'collection radio wrap items in a span tag by default' do
|
||||
test "collection radio wrap items in a span tag by default" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_select 'form span input[type=radio][value=true]#user_active_true + label'
|
||||
assert_select 'form span input[type=radio][value=false]#user_active_false + label'
|
||||
end
|
||||
|
||||
test 'collection radio wraps each item in the given item wrapper tag' do
|
||||
test "collection radio wraps each item in the given item wrapper tag" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
|
||||
|
||||
assert_select 'form li input[type=radio]', :count => 2
|
||||
end
|
||||
|
||||
test 'collection radio does not wrap each item when given explicitly falsy value' do
|
||||
test "collection radio does not wrap each item when given explicitly falsy value" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
|
||||
|
||||
assert_select 'form input[type=radio]'
|
||||
assert_no_select 'form span input[type=radio]'
|
||||
end
|
||||
|
||||
test 'collection radio uses the given class for item wrapper tag' do
|
||||
test "collection radio uses the given class for item wrapper tag" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
||||
:item_wrapper_tag => :li, :item_wrapper_class => "inline"
|
||||
|
||||
assert_select "form li.inline input[type=radio]", :count => 2
|
||||
end
|
||||
|
||||
test 'collection radio uses no class for item wrapper tag when no wrapper tag is given' do
|
||||
test "collection radio uses no class for item wrapper tag when no wrapper tag is given" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
||||
:item_wrapper_tag => nil, :item_wrapper_class => "inline"
|
||||
|
||||
|
@ -174,7 +174,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select '.inline'
|
||||
end
|
||||
|
||||
test 'collection radio uses no class for item wrapper tag by default' do
|
||||
test "collection radio uses no class for item wrapper tag by default" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
|
||||
:item_wrapper_tag => :li
|
||||
|
||||
|
@ -182,14 +182,14 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select "form li[class]"
|
||||
end
|
||||
|
||||
test 'collection radio does not wrap input inside the label' do
|
||||
test "collection radio does not wrap input inside the label" do
|
||||
with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_select 'form input[type=radio] + label'
|
||||
assert_no_select 'form label input'
|
||||
end
|
||||
|
||||
test 'collection radio accepts a block to render the label as radio button wrapper' do
|
||||
test "collection radio accepts a block to render the label as radio button wrapper" do
|
||||
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label { b.radio_button }
|
||||
end
|
||||
|
@ -198,7 +198,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'label[for=user_active_false] > input#user_active_false[type=radio]'
|
||||
end
|
||||
|
||||
test 'collection radio accepts a block to change the order of label and radio button' do
|
||||
test "collection radio accepts a block to change the order of label and radio button" do
|
||||
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label + b.radio_button
|
||||
end
|
||||
|
@ -207,7 +207,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'label[for=user_active_false] + input#user_active_false[type=radio]'
|
||||
end
|
||||
|
||||
test 'collection radio with block helpers accept extra html options' do
|
||||
test "collection radio with block helpers accept extra html options" do
|
||||
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:class => "radio_button") + b.radio_button(:class => "radio_button")
|
||||
end
|
||||
|
@ -216,7 +216,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'label.radio_button[for=user_active_false] + input#user_active_false.radio_button[type=radio]'
|
||||
end
|
||||
|
||||
test 'collection radio with block helpers allows access to current text and value' do
|
||||
test "collection radio with block helpers allows access to current text and value" do
|
||||
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:"data-value" => b.value) { b.radio_button + b.text }
|
||||
end
|
||||
|
@ -229,7 +229,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'collection radio with block helpers allows access to the current object item in the collection to access extra properties' do
|
||||
test "collection radio with block helpers allows access to the current object item in the collection to access extra properties" do
|
||||
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:class => b.object) { b.radio_button + b.text }
|
||||
end
|
||||
|
@ -242,7 +242,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'collection_radio helper is deprecated in favor of collection_radio_buttons' do
|
||||
test "collection_radio helper is deprecated in favor of collection_radio_buttons" do
|
||||
assert_deprecated "[SIMPLE_FORM] The `collection_radio` helper is deprecated, " \
|
||||
"please use `collection_radio_buttons` instead" do
|
||||
with_concat_form_for(@user) do |f|
|
||||
|
@ -255,7 +255,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
# COLLECTION CHECK BOX
|
||||
test 'collection check box accepts a collection and generate a serie of checkboxes for value method' do
|
||||
test "collection check box accepts a collection and generate a serie of checkboxes for value method" do
|
||||
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
||||
|
||||
|
@ -263,14 +263,14 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form input#user_tag_ids_2[type=checkbox][value=2]'
|
||||
end
|
||||
|
||||
test 'collection check box generates only one hidden field for the entire collection, to ensure something will be sent back to the server when posting an empty collection' do
|
||||
test "collection check box generates only one hidden field for the entire collection, to ensure something will be sent back to the server when posting an empty collection" do
|
||||
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
||||
|
||||
assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", :count => 1
|
||||
end
|
||||
|
||||
test 'collection check box accepts a collection and generate a serie of checkboxes with labels for label method' do
|
||||
test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
|
||||
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
||||
|
||||
|
@ -278,20 +278,20 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form label.collection_check_boxes[for=user_tag_ids_2]', 'Tag 2'
|
||||
end
|
||||
|
||||
test 'collection check box handles camelized collection values for labels correctly' do
|
||||
test "collection check box handles camelized collection values for labels correctly" do
|
||||
with_collection_check_boxes @user, :active, ['Yes', 'No'], :to_s, :to_s
|
||||
|
||||
assert_select 'form label.collection_check_boxes[for=user_active_yes]', 'Yes'
|
||||
assert_select 'form label.collection_check_boxes[for=user_active_no]', 'No'
|
||||
end
|
||||
|
||||
test 'collection check box should sanitize collection values for labels correctly' do
|
||||
test "collection check box should sanitize collection values for labels correctly" do
|
||||
with_collection_check_boxes @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
|
||||
assert_select 'label.collection_check_boxes[for=user_name_099]', '$0.99'
|
||||
assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99'
|
||||
end
|
||||
|
||||
test 'collection check box checks the correct value to local variables' do
|
||||
test "collection check box checks the correct value to local variables" do
|
||||
user = User.new
|
||||
user.tag_ids = [1, 3]
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
|
@ -302,7 +302,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
||||
end
|
||||
|
||||
test 'collection check box accepts selected values as :checked option' do
|
||||
test "collection check box accepts selected values as :checked option" do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
|
||||
|
||||
|
@ -311,7 +311,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
||||
end
|
||||
|
||||
test 'collection check boxes accepts selected string values as :checked option' do
|
||||
test "collection check boxes accepts selected string values as :checked option" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => ['1', '3']
|
||||
|
||||
|
@ -320,7 +320,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'input[type=checkbox][value=2][checked=checked]'
|
||||
end
|
||||
|
||||
test 'collection check box accepts a single checked value' do
|
||||
test "collection check box accepts a single checked value" do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => 3
|
||||
|
||||
|
@ -329,7 +329,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
||||
end
|
||||
|
||||
test 'collection check box accepts selected values as :checked option and override the model values' do
|
||||
test "collection check box accepts selected values as :checked option and override the model values" do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
@user.tag_ids = [2]
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
|
||||
|
@ -339,7 +339,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
||||
end
|
||||
|
||||
test 'collection check box accepts multiple disabled items' do
|
||||
test "collection check box accepts multiple disabled items" do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => [1, 3]
|
||||
|
||||
|
@ -348,7 +348,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
||||
end
|
||||
|
||||
test 'collection check box accepts single disable item' do
|
||||
test "collection check box accepts single disable item" do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => 1
|
||||
|
||||
|
@ -357,7 +357,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
||||
end
|
||||
|
||||
test 'collection check box accepts a proc to disabled items' do
|
||||
test "collection check box accepts a proc to disabled items" do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
|
||||
|
||||
|
@ -366,7 +366,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
||||
end
|
||||
|
||||
test 'collection check box accepts html options' do
|
||||
test "collection check box accepts html options" do
|
||||
collection = [[1, 'Tag 1'], [2, 'Tag 2']]
|
||||
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, :class => 'check'
|
||||
|
||||
|
@ -374,7 +374,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form input.check[type=checkbox][value=2]'
|
||||
end
|
||||
|
||||
test 'collection check box with fields for' do
|
||||
test "collection check box with fields for" do
|
||||
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.fields_for(:post) do |p|
|
||||
|
@ -389,34 +389,34 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form label.collection_check_boxes[for=user_post_tag_ids_2]', 'Tag 2'
|
||||
end
|
||||
|
||||
test 'collection check boxes wraps the collection in the given collection wrapper tag' do
|
||||
test "collection check boxes wraps the collection in the given collection wrapper tag" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
|
||||
|
||||
assert_select 'form ul input[type=checkbox]', :count => 2
|
||||
end
|
||||
|
||||
test 'collection check boxes does not render any wrapper tag by default' do
|
||||
test "collection check boxes does not render any wrapper tag by default" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_select 'form input[type=checkbox]', :count => 2
|
||||
assert_no_select 'form ul'
|
||||
end
|
||||
|
||||
test 'collection check boxes does not wrap the collection when given falsy values' do
|
||||
test "collection check boxes does not wrap the collection when given falsy values" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
|
||||
|
||||
assert_select 'form input[type=checkbox]', :count => 2
|
||||
assert_no_select 'form ul'
|
||||
end
|
||||
|
||||
test 'collection check boxes uses the given class for collection wrapper tag' do
|
||||
test "collection check boxes uses the given class for collection wrapper tag" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
||||
:collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
|
||||
|
||||
assert_select 'form ul.items-list input[type=checkbox]', :count => 2
|
||||
end
|
||||
|
||||
test 'collection check boxes uses no class for collection wrapper tag when no wrapper tag is given' do
|
||||
test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
||||
:collection_wrapper_class => "items-list"
|
||||
|
||||
|
@ -425,40 +425,40 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select '.items-list'
|
||||
end
|
||||
|
||||
test 'collection check boxes uses no class for collection wrapper tag by default' do
|
||||
test "collection check boxes uses no class for collection wrapper tag by default" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
|
||||
|
||||
assert_select 'form ul'
|
||||
assert_no_select 'form ul[class]'
|
||||
end
|
||||
|
||||
test 'collection check boxes wrap items in a span tag by default' do
|
||||
test "collection check boxes wrap items in a span tag by default" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_select 'form span input[type=checkbox]', :count => 2
|
||||
end
|
||||
|
||||
test 'collection check boxes wraps each item in the given item wrapper tag' do
|
||||
test "collection check boxes wraps each item in the given item wrapper tag" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
|
||||
|
||||
assert_select 'form li input[type=checkbox]', :count => 2
|
||||
end
|
||||
|
||||
test 'collection check boxes does not wrap each item when given explicitly falsy value' do
|
||||
test "collection check boxes does not wrap each item when given explicitly falsy value" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
|
||||
|
||||
assert_select 'form input[type=checkbox]'
|
||||
assert_no_select 'form span input[type=checkbox]'
|
||||
end
|
||||
|
||||
test 'collection check boxes uses the given class for item wrapper tag' do
|
||||
test "collection check boxes uses the given class for item wrapper tag" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
||||
:item_wrapper_tag => :li, :item_wrapper_class => "inline"
|
||||
|
||||
assert_select "form li.inline input[type=checkbox]", :count => 2
|
||||
end
|
||||
|
||||
test 'collection check boxes uses no class for item wrapper tag when no wrapper tag is given' do
|
||||
test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
||||
:item_wrapper_tag => nil, :item_wrapper_class => "inline"
|
||||
|
||||
|
@ -467,7 +467,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select '.inline'
|
||||
end
|
||||
|
||||
test 'collection check boxes uses no class for item wrapper tag by default' do
|
||||
test "collection check boxes uses no class for item wrapper tag by default" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
|
||||
:item_wrapper_tag => :li
|
||||
|
||||
|
@ -475,14 +475,14 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_no_select "form li[class]"
|
||||
end
|
||||
|
||||
test 'collection check box does not wrap input inside the label' do
|
||||
test "collection check box does not wrap input inside the label" do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_select 'form input[type=checkbox] + label'
|
||||
assert_no_select 'form label input'
|
||||
end
|
||||
|
||||
test 'collection check boxes accepts a block to render the label as check box wrapper' do
|
||||
test "collection check boxes accepts a block to render the label as check box wrapper" do
|
||||
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label { b.check_box }
|
||||
end
|
||||
|
@ -491,7 +491,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'label[for=user_active_false] > input#user_active_false[type=checkbox]'
|
||||
end
|
||||
|
||||
test 'collection check boxes accepts a block to change the order of label and check box' do
|
||||
test "collection check boxes accepts a block to change the order of label and check box" do
|
||||
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label + b.check_box
|
||||
end
|
||||
|
@ -500,7 +500,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'label[for=user_active_false] + input#user_active_false[type=checkbox]'
|
||||
end
|
||||
|
||||
test 'collection check boxes with block helpers accept extra html options' do
|
||||
test "collection check boxes with block helpers accept extra html options" do
|
||||
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:class => "check_box") + b.check_box(:class => "check_box")
|
||||
end
|
||||
|
@ -509,7 +509,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'label.check_box[for=user_active_false] + input#user_active_false.check_box[type=checkbox]'
|
||||
end
|
||||
|
||||
test 'collection check boxes with block helpers allows access to current text and value' do
|
||||
test "collection check boxes with block helpers allows access to current text and value" do
|
||||
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:"data-value" => b.value) { b.check_box + b.text }
|
||||
end
|
||||
|
@ -522,7 +522,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'collection check boxes with block helpers allows access to the current object item in the collection to access extra properties' do
|
||||
test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
|
||||
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:class => b.object) { b.check_box + b.text }
|
||||
end
|
||||
|
@ -536,7 +536,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
# SIMPLE FIELDS
|
||||
test 'simple fields for is available and yields an instance of FormBuilder' do
|
||||
test "simple fields for is available and yields an instance of FormBuilder" do
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.simple_fields_for(:posts) do |posts_form|
|
||||
assert posts_form.instance_of?(SimpleForm::FormBuilder)
|
||||
|
@ -544,7 +544,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'fields for with a hash like model yeilds an instance of FormBuilder' do
|
||||
test "fields for with a hash like model yeilds an instance of FormBuilder" do
|
||||
with_concat_form_for(:user) do |f|
|
||||
f.simple_fields_for(:author, HashBackedAuthor.new) do |author|
|
||||
assert author.instance_of?(SimpleForm::FormBuilder)
|
||||
|
@ -555,7 +555,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select "input[name='user[author][name]'][value='hash backed author']"
|
||||
end
|
||||
|
||||
test 'fields for yields an instance of CustomBuilder if main builder is a CustomBuilder' do
|
||||
test "fields for yields an instance of CustomBuilder if main builder is a CustomBuilder" do
|
||||
with_custom_form_for(:user) do |f|
|
||||
f.simple_fields_for(:company) do |company|
|
||||
assert company.instance_of?(CustomFormBuilder)
|
||||
|
@ -563,7 +563,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'fields for yields an instance of FormBuilder if it was set in options' do
|
||||
test "fields for yields an instance of FormBuilder if it was set in options" do
|
||||
with_custom_form_for(:user) do |f|
|
||||
f.simple_fields_for(:company, :builder => SimpleForm::FormBuilder) do |company|
|
||||
assert company.instance_of?(SimpleForm::FormBuilder)
|
||||
|
@ -571,7 +571,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'fields inherites wrapper option from the parent form' do
|
||||
test "fields inherites wrapper option from the parent form" do
|
||||
swap_wrapper :another do
|
||||
simple_form_for(:user, :wrapper => :another) do |f|
|
||||
f.simple_fields_for(:company) do |company|
|
||||
|
@ -580,4 +580,14 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "fields overrides wrapper option from the parent form" do
|
||||
swap_wrapper :another do
|
||||
simple_form_for(:user, :wrapper => :another) do |f|
|
||||
f.simple_fields_for(:company, :wrapper => false) do |company|
|
||||
assert_equal false, company.options[:wrapper]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue