1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use real hash model in nested fields_for with hash model test

This commit is contained in:
Sam Pohlenz 2011-06-22 10:54:45 +09:30
parent e69eed0e10
commit 237f87089c
2 changed files with 13 additions and 4 deletions

View file

@ -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

View file

@ -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
'<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="new author" />'
'<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