aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-06-22 02:33:12 -0700
committerJosé Valim <jose.valim@gmail.com>2011-06-22 02:33:12 -0700
commit3c8c37984865221bdb6e1ed0a04a30d2785a3b85 (patch)
treed25b67acd7fe1542a2a93d9f7cb8b749031a4e27 /actionpack/test
parent6404f8a194dd56e7167d63b385cab727f378ec8d (diff)
parent237f87089cbb01da50408cc07dffc89a7ebf6854 (diff)
downloadrails-3c8c37984865221bdb6e1ed0a04a30d2785a3b85.tar.gz
rails-3c8c37984865221bdb6e1ed0a04a30d2785a3b85.tar.bz2
rails-3c8c37984865221bdb6e1ed0a04a30d2785a3b85.zip
Merge pull request #1778 from spohlenz/hash-models
Fix nested fields_for when Hash-based model is passed.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/lib/controller/fake_models.rb11
-rw-r--r--actionpack/test/template/form_helper_test.rb16
2 files changed, 27 insertions, 0 deletions
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb
index 67baf369e2..cbef74f992 100644
--- a/actionpack/test/lib/controller/fake_models.rb
+++ b/actionpack/test/lib/controller/fake_models.rb
@@ -170,6 +170,17 @@ class Author < Comment
def post_attributes=(attributes); end
end
+class HashBackedAuthor < Hash
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
+
+ def persisted?; false; end
+
+ def name
+ "hash backed author"
+ end
+end
+
module Blog
def self._railtie
self
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 0507045ad2..bf65a9359b 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -1689,6 +1689,22 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_hash_like_model
+ @author = HashBackedAuthor.new
+
+ 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
+ '<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="hash backed author" />'
+ 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)