Skip to content
Browse files

Improve check_box_checked? to use include? for Array values. [#193 st…

…ate:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent 19d7b1d commit 6e3521e6134e7f0d0b27834266e41354290c4e7e @erkki erkki committed with lifo May 14, 2008
Showing with 13 additions and 0 deletions.
  1. +2 −0 actionpack/lib/action_view/helpers/form_helper.rb
  2. +11 −0 actionpack/test/template/form_helper_test.rb
View
2 actionpack/lib/action_view/helpers/form_helper.rb
@@ -616,6 +616,8 @@ def check_box_checked?(value, checked_value)
value != 0
when String
value == checked_value
+ when Array
+ value.include?(checked_value)
else
value.to_i != 0
end
View
11 actionpack/test/template/form_helper_test.rb
@@ -181,6 +181,17 @@ def test_check_box
'<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

0 comments on commit 6e3521e

Please sign in to comment.
Something went wrong with that request. Please try again.