aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/polymorphic_routes_test.rb27
-rw-r--r--actionpack/test/template/form_helper_test.rb29
2 files changed, 56 insertions, 0 deletions
diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb
index 1dc0502f63..3e72063e9e 100644
--- a/actionpack/test/controller/polymorphic_routes_test.rb
+++ b/actionpack/test/controller/polymorphic_routes_test.rb
@@ -39,6 +39,23 @@ class Test::Unit::TestCase
def article_comment_url(article, comment)
"http://www.example.com/articles/#{article.id}/comments/#{comment.id}"
end
+
+ def admin_articles_url
+ "http://www.example.com/admin/articles"
+ end
+ alias_method :new_admin_article_url, :admin_articles_url
+
+ def admin_article_url(article)
+ "http://www.example.com/admin/articles/#{article.id}"
+ end
+
+ def admin_article_comments_url(article)
+ "http://www.example.com/admin/articles/#{article.id}/comments"
+ end
+
+ def admin_article_comment_url(article, comment)
+ "http://www.example.com/admin/test/articles/#{article.id}/comments/#{comment.id}"
+ end
end
@@ -68,4 +85,14 @@ class PolymorphicRoutesTest < Test::Unit::TestCase
@comment.save
assert_equal(article_comment_url(@article, @comment), polymorphic_url([@article, @comment]))
end
+
+ def test_with_array_and_namespace
+ assert_equal(admin_articles_url, polymorphic_url([:admin, @article], :action => 'new'))
+ assert_equal(admin_articles_url, polymorphic_url([:admin, @article]))
+ @article.save
+ assert_equal(admin_article_url(@article), polymorphic_url([:admin, @article]))
+ assert_equal(admin_article_comments_url(@article), polymorphic_url([:admin, @article, @comment]))
+ @comment.save
+ assert_equal(admin_article_comment_url(@article, @comment), polymorphic_url([:admin, @article, @comment]))
+ end
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index bec754f844..a852f2af17 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -629,6 +629,25 @@ class FormHelperTest < Test::Unit::TestCase
assert_dom_equal expected, _erbout
end
+ def test_form_for_with_existing_object_and_namespace_in_list
+ @post.new_record = false
+ @comment.save
+ _erbout = ''
+ form_for([:admin, @post, @comment]) {}
+
+ expected = %(<form action="#{admin_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_and_namespace_in_list
+ @post.new_record = false
+ _erbout = ''
+ form_for([:admin, @post, @comment]) {}
+
+ expected = %(<form action="#{admin_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 = ''
@@ -660,6 +679,16 @@ class FormHelperTest < Test::Unit::TestCase
end
alias_method :post_comment_path, :comment_path
+ def admin_comments_path(post)
+ "/admin/posts/#{post.id}/comments"
+ end
+ alias_method :admin_post_comments_path, :admin_comments_path
+
+ def admin_comment_path(post, comment)
+ "/admin/posts/#{post.id}/comments/#{comment.id}"
+ end
+ alias_method :admin_post_comment_path, :admin_comment_path
+
def posts_path
"/posts"
end