aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-04-11 19:43:50 -0700
committerSantiago Pastorino <santiago@wyeworks.com>2012-04-11 19:43:50 -0700
commit1db54dffaffb83c7a1dacb4db7e4204c7bd1ddba (patch)
tree5059445ba4132d1ed16c688c7a39870d8707625f /actionpack/test
parente177525d6f6d0f7cf781171ae1c0ef91df7eb4f9 (diff)
parent47cbfbb98a2a4ccb6d434998183f24be4e2bb1c1 (diff)
downloadrails-1db54dffaffb83c7a1dacb4db7e4204c7bd1ddba.tar.gz
rails-1db54dffaffb83c7a1dacb4db7e4204c7bd1ddba.tar.bz2
rails-1db54dffaffb83c7a1dacb4db7e4204c7bd1ddba.zip
Merge pull request #5746 from jmbejar/index_method_form_builder
Add method FormBuilder#index
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/template/form_helper_test.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index f13296a175..3fa3898ec8 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -1835,6 +1835,56 @@ class FormHelperTest < ActionView::TestCase
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) }
+
+ form_for(@post) do |f|
+ expected = 0
+ @post.comments.each do |comment|
+ f.fields_for(:comments, comment) { |cf|
+ assert_equal cf.index, expected
+ expected += 1
+ }
+ end
+ end
+ end
+
+ def test_nested_fields_for_index_method_with_existing_and_new_records_on_a_nested_attributes_collection_association
+ @post.comments = [Comment.new(321), Comment.new]
+
+ form_for(@post) do |f|
+ expected = 0
+ @post.comments.each do |comment|
+ f.fields_for(:comments, comment) { |cf|
+ assert_equal cf.index, expected
+ expected += 1
+ }
+ end
+ end
+ end
+
+ def test_nested_fields_for_index_method_with_existing_records_on_a_supplied_nested_attributes_collection
+ @post.comments = Array.new(2) { |id| Comment.new(id + 1) }
+
+ form_for(@post) do |f|
+ expected = 0
+ f.fields_for(:comments, @post.comments) { |cf|
+ assert_equal cf.index, expected
+ expected += 1
+ }
+ end
+ end
+
+ def test_nested_fields_for_index_method_with_child_index_option_override_on_a_nested_attributes_collection_association
+ @post.comments = []
+
+ form_for(@post) do |f|
+ f.fields_for(:comments, Comment.new(321), :child_index => 'abc') { |cf|
+ assert_equal cf.index, 'abc'
+ }
+ end
+ end
+
def test_nested_fields_uses_unique_indices_for_different_collection_associations
@post.comments = [Comment.new(321)]
@post.tags = [Tag.new(123), Tag.new(456)]