mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
check checkboxes with array of strings as :checked option
This commit is contained in:
parent
acb39848ae
commit
e0aadf12e3
2 changed files with 10 additions and 1 deletions
|
@ -49,7 +49,7 @@ module ActionView
|
||||||
accept = if current_value.respond_to?(:call)
|
accept = if current_value.respond_to?(:call)
|
||||||
current_value.call(item)
|
current_value.call(item)
|
||||||
else
|
else
|
||||||
Array(current_value).include?(value)
|
Array(current_value).map(&:to_s).include?(value.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
if accept
|
if accept
|
||||||
|
|
|
@ -195,6 +195,15 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
||||||
assert_no_select 'input[type=checkbox][value=2][checked=checked]'
|
assert_no_select 'input[type=checkbox][value=2][checked=checked]'
|
||||||
end
|
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
|
test 'collection check boxes accepts a single checked value' do
|
||||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => 3
|
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => 3
|
||||||
|
|
Loading…
Reference in a new issue