diff options
author | Erkki Eilonen <erkki@itech.ee> | 2008-05-14 17:07:21 +0300 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-05-21 20:23:58 +0100 |
commit | 6e3521e6134e7f0d0b27834266e41354290c4e7e (patch) | |
tree | af9a2ba2d0a388e9e4ba348cc0adb4305e7d6355 /actionpack | |
parent | 19d7b1d22bd68af00244ddc3e1f35cec187e9120 (diff) | |
download | rails-6e3521e6134e7f0d0b27834266e41354290c4e7e.tar.gz rails-6e3521e6134e7f0d0b27834266e41354290c4e7e.tar.bz2 rails-6e3521e6134e7f0d0b27834266e41354290c4e7e.zip |
Improve check_box_checked? to use include? for Array values. [#193 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 6d97038da9..0962be2c79 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -616,6 +616,8 @@ module ActionView value != 0 when String value == checked_value + when Array + value.include?(checked_value) else value.to_i != 0 end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 4538b6dc6f..af99e6243d 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -181,6 +181,17 @@ class FormHelperTest < ActionView::TestCase '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />', check_box("post", "secret?") ) + + @post.secret = ['0'] + assert_dom_equal( + '<input id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />', + check_box("post", "secret") + ) + @post.secret = ['1'] + assert_dom_equal( + '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />', + check_box("post", "secret") + ) end def test_check_box_with_explicit_checked_and_unchecked_values |