diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-01-31 17:46:31 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-02 09:40:23 -0200 |
commit | 21eba34718660b96b45cbb594d557b7e84bfed4f (patch) | |
tree | 8f6d590dfe9077708ac823e2494a9740adf2d267 /actionpack | |
parent | 15206885eb58978465e5f79a4f20cc3c3766de10 (diff) | |
download | rails-21eba34718660b96b45cbb594d557b7e84bfed4f.tar.gz rails-21eba34718660b96b45cbb594d557b7e84bfed4f.tar.bz2 rails-21eba34718660b96b45cbb594d557b7e84bfed4f.zip |
Add collection_radio_buttons and collection_check_boxes to FormBuilder
[Carlos Antonio da Silva + Rafael Mendonça França]
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_collections_helper.rb | 10 | ||||
-rw-r--r-- | actionpack/test/template/form_collections_helper_test.rb | 29 |
2 files changed, 30 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/form_collections_helper.rb b/actionpack/lib/action_view/helpers/form_collections_helper.rb index 27b214f34c..9280902e7c 100644 --- a/actionpack/lib/action_view/helpers/form_collections_helper.rb +++ b/actionpack/lib/action_view/helpers/form_collections_helper.rb @@ -9,5 +9,15 @@ module ActionView Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block) end end + + class FormBuilder + def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}) + @template.collection_radio_buttons(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options)) + end + + def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}) + @template.collection_check_boxes(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options)) + end + end end end diff --git a/actionpack/test/template/form_collections_helper_test.rb b/actionpack/test/template/form_collections_helper_test.rb index 647fe47d04..995cfdae87 100644 --- a/actionpack/test/template/form_collections_helper_test.rb +++ b/actionpack/test/template/form_collections_helper_test.rb @@ -179,6 +179,20 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select 'label[for=user_active_false] > input#user_active_false[type=radio]' end + test 'collection radio buttons with fields for' do + collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] + concat(fields_for(:post) do |p| + p.collection_radio_buttons :category_id, collection, :id, :name + end) + + assert_select 'input#post_category_id_1[type=radio][value=1]' + assert_select 'input#post_category_id_2[type=radio][value=2]' + + assert_select 'label.collection_radio_buttons[for=post_category_id_1]', 'Category 1' + assert_select 'label.collection_radio_buttons[for=post_category_id_2]', 'Category 2' + end + + # COLLECTION CHECK BOXES test 'collection check boxes accepts a collection and generate a serie of checkboxes for value method' do collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] @@ -281,19 +295,16 @@ class FormCollectionsHelperTest < ActionView::TestCase end test 'collection check boxes with fields for' do - skip "test collection check boxes with fields for (and radio buttons as well)" collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] - concat(form_for(:user) do |f| - f.fields_for(:post) do |p| - p.collection_check_boxes :category_ids, collection, :id, :name - end + concat(fields_for(:post) do |p| + p.collection_check_boxes :category_ids, collection, :id, :name end) - assert_select 'input#user_post_category_ids_1[type=checkbox][value=1]' - assert_select 'input#user_post_category_ids_2[type=checkbox][value=2]' + assert_select 'input#post_category_ids_1[type=checkbox][value=1]' + assert_select 'input#post_category_ids_2[type=checkbox][value=2]' - assert_select 'label.collection_check_boxes[for=user_post_category_ids_1]', 'Category 1' - assert_select 'label.collection_check_boxes[for=user_post_category_ids_2]', 'Category 2' + assert_select 'label.collection_check_boxes[for=post_category_ids_1]', 'Category 1' + assert_select 'label.collection_check_boxes[for=post_category_ids_2]', 'Category 2' end test 'collection check boxeses wraps the collection in the given collection wrapper tag' do |