Permalink
Browse files

Merge pull request #6176 from nashby/checkboxes

check checkboxes with array of strings as :checked option
  • Loading branch information...
2 parents a966868 + e0aadf1 commit f54a35c4eab3d923f650cdd384b388e1b2a9be11 @josevalim josevalim committed May 5, 2012
@@ -49,7 +49,7 @@ def default_html_options_for_collection(item, value) #:nodoc:
accept = if current_value.respond_to?(:call)
current_value.call(item)
else
- Array(current_value).include?(value)
+ Array(current_value).map(&:to_s).include?(value.to_s)
end
if accept
@@ -195,6 +195,15 @@ def with_collection_check_boxes(*args, &block)
assert_no_select '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 boxes accepts a single checked value' do
collection = (1..3).map{|i| [i, "Category #{i}"] }
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => 3

0 comments on commit f54a35c

Please sign in to comment.