| | 1 | require File.dirname(__FILE__) + '/../abstract_unit' |
|---|
| | 2 | |
|---|
| | 3 | class Comment |
|---|
| | 4 | attr_reader :id |
|---|
| | 5 | def save; @id = 1 end |
|---|
| | 6 | def new_record?; @id.nil? end |
|---|
| | 7 | def name |
|---|
| | 8 | @id.nil? ? 'new comment' : "comment ##{@id}" |
|---|
| | 9 | end |
|---|
| | 10 | end |
|---|
| | 11 | |
|---|
| | 12 | class PolymorphicRoutesTest < Test::Unit::TestCase |
|---|
| | 13 | include ActionController::PolymorphicRoutes |
|---|
| | 14 | |
|---|
| | 15 | def setup |
|---|
| | 16 | @comment = Comment.new |
|---|
| | 17 | @comment.save |
|---|
| | 18 | end |
|---|
| | 19 | |
|---|
| | 20 | def test_polymorphic_url_with_object |
|---|
| | 21 | assert_equal "/comment/1", polymorphic_url( @comment, :routing_type => :path ) |
|---|
| | 22 | end |
|---|
| | 23 | |
|---|
| | 24 | def test_polymorphic_url_with_array |
|---|
| | 25 | assert_equal "/comment/1", polymorphic_url( [@comment], :routing_type => :path ) |
|---|
| | 26 | end |
|---|
| | 27 | |
|---|
| | 28 | def comment_path( comment ) |
|---|
| | 29 | "/comment/#{comment.id}" |
|---|
| | 30 | end |
|---|
| | 31 | end |