Permalink
Browse files

handle array of strings in :checked option

  • Loading branch information...
1 parent 204fa86 commit 84ba5a34420ea34d5cc19bec80ae64f4ff54bd62 @nashby committed May 6, 2012
Showing with 11 additions and 3 deletions.
  1. +1 −1 lib/simple_form/action_view_extensions/builder.rb
  2. +10 −2 test/action_view_extensions/builder_test.rb
@@ -223,7 +223,7 @@ def default_html_options_for_collection(item, value, options, html_options) #:no
accept = if current_option.respond_to?(:call)
current_option.call(item)
else
- Array(current_option).include?(value)
+ Array(current_option).map(&:to_s).include?(value.to_s)
end
if accept
@@ -63,7 +63,7 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
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
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]'
@@ -302,7 +302,6 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
end
-
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]
@@ -312,6 +311,15 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
end
+ 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']
+
+ assert_select 'input[type=checkbox][value=1][checked=checked]'
+ assert_select 'input[type=checkbox][value=3][checked=checked]'
+ assert_no_select 'input[type=checkbox][value=2][checked=checked]'
+ end
+
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

0 comments on commit 84ba5a3

Please sign in to comment.