From e69eed0e10c0670869aea396cb79002da4f4580a Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Mon, 20 Jun 2011 11:27:04 +0930 Subject: Test for extractable_options? within nested fields_for. This fixes an error when a record object that is a subclass of Hash is passed to fields_for, which is incorrectly interpreted as field options. --- actionpack/test/template/form_helper_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 0507045ad2..4d90e8968d 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1689,6 +1689,24 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_with_hash_like_model + @author = Author.new + def @author.is_a?(klass); klass == Hash; end + def @author.extractable_options?; false; end + + form_for(@post) do |f| + concat f.fields_for(:author, @author) { |af| + concat af.text_field(:name) + } + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + '' + end + + assert_dom_equal expected, output_buffer + end + def test_fields_for output_buffer = fields_for(:post, @post) do |f| concat f.text_field(:title) -- cgit v1.2.3 From 237f87089cbb01da50408cc07dffc89a7ebf6854 Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Wed, 22 Jun 2011 10:54:45 +0930 Subject: Use real hash model in nested fields_for with hash model test --- actionpack/test/template/form_helper_test.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 4d90e8968d..bf65a9359b 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1690,9 +1690,7 @@ class FormHelperTest < ActionView::TestCase end def test_nested_fields_for_with_hash_like_model - @author = Author.new - def @author.is_a?(klass); klass == Hash; end - def @author.extractable_options?; false; end + @author = HashBackedAuthor.new form_for(@post) do |f| concat f.fields_for(:author, @author) { |af| @@ -1701,7 +1699,7 @@ class FormHelperTest < ActionView::TestCase end expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do - '' + '' end assert_dom_equal expected, output_buffer -- cgit v1.2.3