diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2010-06-19 22:35:54 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-20 00:15:41 +0200 |
commit | ed3f042e99949526f483d1f567e40031deea33d3 (patch) | |
tree | c8c4332b2d93be2a39202bf49a556586bc354cd0 /actionpack/test | |
parent | 65ce3d12971afd15de6ea22a2fc5af3ba1faf124 (diff) | |
download | rails-ed3f042e99949526f483d1f567e40031deea33d3.tar.gz rails-ed3f042e99949526f483d1f567e40031deea33d3.tar.bz2 rails-ed3f042e99949526f483d1f567e40031deea33d3.zip |
Make polymorphic_url and scaffolding work with uncountable resources [#3930 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/activerecord/polymorphic_routes_test.rb | 1 | ||||
-rw-r--r-- | actionpack/test/controller/record_identifier_test.rb | 23 |
2 files changed, 22 insertions, 2 deletions
diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 9f5e8ec657..6e1e6cdd20 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -381,6 +381,7 @@ class PolymorphicRoutesTest < ActionController::TestCase with_test_routes do @series.save assert_equal "http://example.com/series/#{@series.id}", polymorphic_url(@series) + assert_equal "http://example.com/series", polymorphic_url(Series.new) end end diff --git a/actionpack/test/controller/record_identifier_test.rb b/actionpack/test/controller/record_identifier_test.rb index 813dedc80d..6a84475758 100644 --- a/actionpack/test/controller/record_identifier_test.rb +++ b/actionpack/test/controller/record_identifier_test.rb @@ -13,6 +13,19 @@ class Comment end end +class Sheep + extend ActiveModel::Naming + include ActiveModel::Conversion + + attr_reader :id + def to_key; id ? [id] : nil end + def save; @id = 1 end + def new_record?; @id.nil? end + def name + @id.nil? ? 'new sheep' : "sheep ##{@id}" + end +end + class Comment::Nested < Comment; end class Test::Unit::TestCase @@ -20,7 +33,7 @@ class Test::Unit::TestCase def comments_url 'http://www.example.com/comments' end - + def comment_url(comment) "http://www.example.com/comments/#{comment.id}" end @@ -35,6 +48,7 @@ class RecordIdentifierTest < Test::Unit::TestCase @record = @klass.new @singular = 'comment' @plural = 'comments' + @uncountable = Sheep end def test_dom_id_with_new_record @@ -58,7 +72,7 @@ class RecordIdentifierTest < Test::Unit::TestCase def test_dom_class assert_equal @singular, dom_class(@record) end - + def test_dom_class_with_prefix assert_equal "custom_prefix_#{@singular}", dom_class(@record, :custom_prefix) end @@ -79,6 +93,11 @@ class RecordIdentifierTest < Test::Unit::TestCase assert_equal @plural, plural_class_name(@klass) end + def test_uncountable + assert_equal true, uncountable?(@uncountable) + assert_equal false, uncountable?(@klass) + end + private def method_missing(method, *args) RecordIdentifier.send(method, *args) |