aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-07 21:35:01 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-07 21:35:01 +0000
commitc7df5bd6ac256cf75631f8c59c1de1f96df02b17 (patch)
tree540eb0ff609ddbec455e24002ee2b78e79e123ff /actionpack/test/controller
parent5600776e309b9c84f0cc075391b6130d07d83cfd (diff)
downloadrails-c7df5bd6ac256cf75631f8c59c1de1f96df02b17.tar.gz
rails-c7df5bd6ac256cf75631f8c59c1de1f96df02b17.tar.bz2
rails-c7df5bd6ac256cf75631f8c59c1de1f96df02b17.zip
More nested polymorphic url helper fixes. Closes #6432, references #8601.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6960 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/polymorphic_routes_test.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb
new file mode 100644
index 0000000000..1d11eeda47
--- /dev/null
+++ b/actionpack/test/controller/polymorphic_routes_test.rb
@@ -0,0 +1,70 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+class Article
+ attr_reader :id
+ def save; @id = 1 end
+ def new_record?; @id.nil? end
+ def name
+ @id.nil? ? 'new post' : "post ##{@id}"
+ end
+end
+
+class Comment
+ attr_reader :id
+ def post_id; 1 end
+ def save; @id = 1 end
+ def new_record?; @id.nil? end
+ def name
+ @id.nil? ? 'new comment' : "comment ##{@id}"
+ end
+end
+
+class Comment::Nested < Comment; end
+
+class Test::Unit::TestCase
+ protected
+ def articles_url
+ 'http://www.example.com/articles'
+ end
+ alias_method :new_article_url, :articles_url
+
+ def article_url(article)
+ "http://www.example.com/articles/#{article.id}"
+ end
+
+ def article_comments_url(article)
+ "http://www.example.com/articles/#{article.id}/comments"
+ end
+
+ def article_comment_url(article, comment)
+ "http://www.example.com/articles/#{article.id}/comments/#{comment.id}"
+ end
+end
+
+
+class PolymorphicRoutesTest < Test::Unit::TestCase
+ include ActionController::PolymorphicRoutes
+
+ def setup
+ @article = Article.new
+ @comment = Comment.new
+ end
+
+ def test_with_record
+ assert_equal(articles_url, polymorphic_url(@article, :action => 'new'))
+ assert_equal(articles_url, polymorphic_url(@article))
+ @article.save
+ assert_equal(article_url(@article), polymorphic_url(@article))
+ end
+
+ def test_with_hash
+ @article.save
+ assert_equal(article_url(@article), polymorphic_url(:id => @article))
+ end
+
+ def test_with_array
+ assert_equal(article_comments_url(@article), polymorphic_url([@article, @comment]))
+ @comment.save
+ assert_equal(article_comment_url(@article, @comment), polymorphic_url([@article, @comment]))
+ end
+end