aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/form_helper_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-05 19:10:59 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-05 19:10:59 +0000
commit5dd3db86157ce2bd08c4ec07826d3aaf5c29f458 (patch)
treedfaa4c5731772c1d5a9f59d76fa3a76cbb4b51df /actionpack/test/template/form_helper_test.rb
parentb83efadb32fe55ba7a7d23d650a8adc1a351eab7 (diff)
downloadrails-5dd3db86157ce2bd08c4ec07826d3aaf5c29f458.tar.gz
rails-5dd3db86157ce2bd08c4ec07826d3aaf5c29f458.tar.bz2
rails-5dd3db86157ce2bd08c4ec07826d3aaf5c29f458.zip
Resources: url_for([parent, child]) generates /parents/1/children/2 for the nested resource. Likewise with the other simply helpful methods like form_for and link_to. Closes #6432.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6951 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/template/form_helper_test.rb')
-rw-r--r--actionpack/test/template/form_helper_test.rb57
1 files changed, 53 insertions, 4 deletions
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index c9e7aeaeb3..c504190960 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -15,8 +15,21 @@ silence_warnings do
@new_record
end
end
+
+ class Comment
+ attr_reader :id
+ attr_reader :post_id
+ def save; @id = 1; @post_id = 1 end
+ def new_record?; @id.nil? end
+ def name
+ @id.nil? ? 'new comment' : "comment ##{@id}"
+ end
+ end
end
+class Comment::Nested < Comment; end
+
+
class FormHelperTest < Test::Unit::TestCase
include ActionView::Helpers::FormHelper
include ActionView::Helpers::FormTagHelper
@@ -28,6 +41,7 @@ class FormHelperTest < Test::Unit::TestCase
def setup
@post = Post.new
+ @comment = Comment.new
def @post.errors()
Class.new{
def on(field); "can't be empty" if field == "author_name"; end
@@ -579,6 +593,25 @@ class FormHelperTest < Test::Unit::TestCase
assert_equal expected, _erbout
end
+ def test_form_for_with_existing_object_in_list
+ @post.new_record = false
+ @comment.save
+ _erbout = ''
+ form_for([@post, @comment]) {}
+
+ expected = %(<form action="#{comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /></div></form>)
+ assert_dom_equal expected, _erbout
+ end
+
+ def test_form_for_with_new_object_in_list
+ @post.new_record = false
+ _erbout = ''
+ form_for([@post, @comment]) {}
+
+ expected = %(<form action="#{comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>)
+ assert_dom_equal expected, _erbout
+ end
+
def test_form_for_with_existing_object_and_custom_url
_erbout = ''
@@ -600,11 +633,27 @@ class FormHelperTest < Test::Unit::TestCase
protected
- def polymorphic_path(record)
- if record.new_record?
- "/posts"
+ def comments_path(post)
+ "/posts/#{post.id}/comments"
+ end
+
+ def comment_path(post, comment)
+ "/posts/#{post.id}/comments/#{comment.id}"
+ end
+
+ def polymorphic_path(object, *nested_objects)
+ if nested_objects.empty?
+ if object.new_record?
+ "/posts"
+ else
+ "/posts/#{object.id}"
+ end
else
- "/posts/#{record.id}"
+ if object.new_record?
+ "/posts/123/comments"
+ else
+ "/posts/123/comments/#{object.id}"
+ end
end
end
end