diff options
author | virusman <virusman@virusman.ru> | 2012-12-26 23:53:42 +0400 |
---|---|---|
committer | virusman <virusman@virusman.ru> | 2012-12-27 00:37:35 +0400 |
commit | c009e86fe12cb04e4359ce5ec063364561a6252c (patch) | |
tree | 7d698e571bf6448c6f7c92665c90781028849643 | |
parent | 899cae25ecd0f5b187cfc1a56c55ed2936885c21 (diff) | |
download | rails-c009e86fe12cb04e4359ce5ec063364561a6252c.tar.gz rails-c009e86fe12cb04e4359ce5ec063364561a6252c.tar.bz2 rails-c009e86fe12cb04e4359ce5ec063364561a6252c.zip |
Test nested fields with AssociationProxy mockup & fix AssociationProxy support in form helper
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 516492ca30..7e4f5fa65c 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1802,7 +1802,7 @@ module ActionView association = convert_to_model(association) if association.respond_to?(:persisted?) - association = [association] if @object.send(association_name).is_a?(Array) + association = [association] if @object.send(association_name).respond_to?(:to_ary) elsif !association.respond_to?(:to_ary) association = @object.send(association_name) end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index c730e3ab74..cc098b6be7 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -2164,6 +2164,29 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + class FakeAssociatonProxy + def to_ary + [1, 2, 3] + end + end + + def test_nested_fields_for_with_child_index_option_override_on_a_nested_attributes_collection_association_with_proxy + @post.comments = FakeAssociatonProxy.new + + form_for(@post) do |f| + concat f.fields_for(:comments, Comment.new(321), :child_index => 'abc') { |cf| + concat cf.text_field(:name) + } + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do + '<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" type="text" value="comment #321" />' + + '<input id="post_comments_attributes_abc_id" name="post[comments_attributes][abc][id]" type="hidden" value="321" />' + end + + assert_dom_equal expected, output_buffer + end + def test_nested_fields_for_index_method_with_existing_records_on_a_nested_attributes_collection_association @post.comments = Array.new(2) { |id| Comment.new(id + 1) } |