Created
March 15, 2011 18:01
-
-
Save javierv/871153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From efca1d103a9bafe89ade34833d5d43a4d5f093ae Mon Sep 17 00:00:00 2001 | |
From: =?UTF-8?q?Javier=20Mart=C3=ADn?= <elretirao@elretirao.net> | |
Date: Tue, 15 Mar 2011 18:58:13 +0100 | |
Subject: [PATCH] Test case and documentation about collection_check_boxes labels should behave. | |
According to W3C, "The label element may contain at most one descendant input element, button element, select element, or textarea element." | |
--- | |
lib/simple_form/action_view_extensions/builder.rb | 7 ++++--- | |
test/action_view_extensions/builder_test.rb | 8 ++++++++ | |
2 files changed, 12 insertions(+), 3 deletions(-) | |
diff --git a/lib/simple_form/action_view_extensions/builder.rb b/lib/simple_form/action_view_extensions/builder.rb | |
index 4a1442f..6e72ee3 100644 | |
--- a/lib/simple_form/action_view_extensions/builder.rb | |
+++ b/lib/simple_form/action_view_extensions/builder.rb | |
@@ -57,11 +57,12 @@ module SimpleForm | |
# end | |
# | |
# <input name="user[options][]" type="hidden" value="" /> | |
+ # <label class="collection_check_boxes" for="user_options_true"> | |
# <input id="user_options_true" name="user[options][]" type="checkbox" value="true" /> | |
- # <label class="collection_check_boxes" for="user_options_true">Yes</label> | |
- # <input name="user[options][]" type="hidden" value="" /> | |
+ # Yes</label> | |
+ # <label class="collection_check_boxes" for="user_options_false"> | |
# <input id="user_options_false" name="user[options][]" type="checkbox" value="false" /> | |
- # <label class="collection_check_boxes" for="user_options_false">No</label> | |
+ # No</label> | |
# | |
# == Options | |
# | |
diff --git a/test/action_view_extensions/builder_test.rb b/test/action_view_extensions/builder_test.rb | |
index a8df9fd..0d70211 100644 | |
--- a/test/action_view_extensions/builder_test.rb | |
+++ b/test/action_view_extensions/builder_test.rb | |
@@ -147,6 +147,14 @@ class BuilderTest < ActionView::TestCase | |
assert_select 'form label.collection_check_boxes[for=user_tag_ids_2]', 'Tag 2' | |
end | |
+ test 'collection check box generates one checkbox inside each label' do | |
+ collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')] | |
+ with_collection_check_boxes @user, :tag_ids, collection, :id, :name | |
+ | |
+ assert_select 'form label.collection_check_boxes[for=user_tag_ids_1] input', 1 | |
+ assert_select 'form label.collection_check_boxes[for=user_tag_ids_2] input', 1 | |
+ end | |
+ | |
test 'collection check box handles camelized collection values for labels correctly' do | |
with_collection_check_boxes @user, :active, ['Yes', 'No'], :to_s, :to_s | |
-- | |
1.7.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment