From 8cc60d81363069710e277ed03fdbaf8872895f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Mota?= Date: Sat, 12 Jan 2013 16:48:25 +0000 Subject: Collection radio buttons and collection check boxes through FormBuilder render the provided block. In the case of having a form_for method being called, the block for each collection would not be passed and thus the result expected was always the same. This patch passes the block to the original method like it would be assumed. --- actionpack/test/template/form_helper_test.rb | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 247068de4e..9e06f0be94 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1120,6 +1120,28 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_for_with_collection_radio_buttons_with_custom_builder_block + post = Post.new + def post.active; false; end + form_for(post) do |f| + rendered_radio_buttons = f.collection_radio_buttons(:active, [true, false], :to_s, :to_s) do |b| + b.label { b.radio_button + b.text } + end + concat rendered_radio_buttons + end + + expected = whole_form("/posts", "new_post" , "new_post") do + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + def test_form_for_with_collection_check_boxes post = Post.new def post.tag_ids; [1, 3]; end @@ -1141,6 +1163,33 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_for_with_collection_check_boxes_with_custom_builder_block + post = Post.new + def post.tag_ids; [1, 3]; end + collection = (1..3).map{|i| [i, "Tag #{i}"] } + form_for(post) do |f| + rendered_check_boxes = f.collection_check_boxes(:tag_ids, collection, :first, :last) do |b| + b.label { b.check_box + b.text } + end + concat rendered_check_boxes + end + + expected = whole_form("/posts", "new_post" , "new_post") do + "" + + "" + + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + def test_form_for_with_file_field_generate_multipart Post.send :attr_accessor, :file -- cgit v1.2.3