<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -25,6 +25,21 @@ class Series &lt; ActiveRecord::Base
   set_table_name 'projects'
 end
 
+class SpecialProject &lt; Project
+end
+
+class AmazingProject &lt; SpecialProject
+end
+
+class SpecialTask &lt; Task
+end
+
+class SpecialStep &lt; Step
+end
+
+class SpecialTax &lt; Tax
+end
+
 class PolymorphicRoutesTest &lt; ActionController::TestCase
   include ActionController::UrlWriter
   self.default_url_options[:host] = 'example.com'
@@ -37,6 +52,11 @@ class PolymorphicRoutesTest &lt; ActionController::TestCase
     @tax = Tax.new
     @fax = Fax.new
     @series = Series.new
+    @special_project = SpecialProject.new
+    @amazing_project = AmazingProject.new
+    @special_task = SpecialTask.new
+    @special_step = SpecialStep.new
+    @special_tax = SpecialTax.new
   end
 
   def test_with_record
@@ -244,6 +264,171 @@ class PolymorphicRoutesTest &lt; ActionController::TestCase
     end
   end
   
+  # Tests for finding the right route by walking inheritance chain of leaf argument
+  def test_with_superclass_fallback
+    with_test_routes do 
+      @special_project.save
+      assert_equal &quot;http://example.com/projects/#{@special_project.id}&quot;, polymorphic_url(@special_project)
+    end
+  end
+
+  def test_with_superclass_fallback_for_two_levels_of_inheritance
+    with_test_routes do 
+      @amazing_project.save
+      assert_equal &quot;http://example.com/projects/#{@amazing_project.id}&quot;, polymorphic_url(@amazing_project)
+    end
+  end
+
+  def test_with_inheritance_but_no_matching_route
+    with_test_routes do
+      @special_step.save
+      assert_raises(NoMethodError) do
+        polymorphic_url(@special_step)
+      end
+    end
+  end
+
+  def test_with_new_record_and_superclass_fallback
+    with_test_routes do 
+      assert_equal &quot;http://example.com/projects&quot;, polymorphic_url(@special_project)
+    end
+  end
+
+  def test_with_record_and_action_and_superclass_fallback
+    with_test_routes do 
+      assert_equal &quot;http://example.com/projects/new&quot;, polymorphic_url(@special_project, :action =&gt; 'new')
+    end
+  end
+
+  def test_url_helper_prefixed_with_new_and_superclass_fallback
+    with_test_routes do 
+      assert_equal &quot;http://example.com/projects/new&quot;, new_polymorphic_url(@special_project)
+    end
+  end
+
+  def test_url_helper_prefixed_with_edit_and_superclass_fallback
+    with_test_routes do 
+      @special_project.save
+      assert_equal &quot;http://example.com/projects/#{@special_project.id}/edit&quot;, edit_polymorphic_url(@special_project)
+    end
+  end
+
+  def test_url_helper_prefixed_with_edit_with_url_options_and_superclass_fallback
+    with_test_routes do 
+      @special_project.save
+      assert_equal &quot;http://example.com/projects/#{@special_project.id}/edit?param1=10&quot;, edit_polymorphic_url(@special_project, :param1 =&gt; '10')
+    end
+  end
+  
+  def test_url_helper_with_url_options_and_superclass_fallback
+    with_test_routes do 
+      @special_project.save
+      assert_equal &quot;http://example.com/projects/#{@special_project.id}?param1=10&quot;, polymorphic_url(@special_project, :param1 =&gt; '10')
+    end
+  end
+
+  def test_format_option_with_url_options_and_superclass_fallback
+    with_test_routes do 
+      @special_project.save
+      assert_equal &quot;http://example.com/projects/#{@special_project.id}.pdf?param1=10&quot;, polymorphic_url(@special_project, :format =&gt; :pdf, :param1 =&gt; '10')
+    end
+  end
+  def test_id_and_format_option_and_superclass_fallback
+    with_test_routes do 
+      @special_project.save
+      assert_equal &quot;http://example.com/projects/#{@special_project.id}.pdf&quot;, polymorphic_url(:id =&gt; @special_project, :format =&gt; :pdf)
+    end
+  end
+
+  def test_with_nested_and_superclass_fallback
+    with_test_routes do
+      @project.save
+      @special_task.save
+      assert_equal &quot;http://example.com/projects/#{@project.id}/tasks/#{@special_task.id}&quot;, polymorphic_url([@project, @special_task])
+    end
+  end
+
+  def test_with_nested_unsaved_and_superclass_fallback
+    with_test_routes do
+      @project.save
+      assert_equal &quot;http://example.com/projects/#{@project.id}/tasks&quot;, polymorphic_url([@project, @special_task])
+    end
+  end
+  
+  def test_new_with_array_and_namespace_and_superclass_fallback
+    with_admin_test_routes do
+      assert_equal &quot;http://example.com/admin/projects/new&quot;, polymorphic_url([:admin, @special_project], :action =&gt; 'new')
+    end
+  end
+
+  def test_unsaved_with_array_and_namespace_and_superclass_fallback
+    with_admin_test_routes do
+      assert_equal &quot;http://example.com/admin/projects&quot;, polymorphic_url([:admin, @special_project])
+    end
+  end
+
+  def test_nested_unsaved_with_array_and_namespace_and_superclass_fallback
+    with_admin_test_routes do
+      @project.save
+      assert_equal &quot;http://example.com/admin/projects/#{@project.id}/tasks&quot;, polymorphic_url([:admin, @project, @special_task])
+    end
+  end
+
+  def test_nested_with_array_and_namespace_and_superclass_fallback
+    with_admin_test_routes do 
+      @project.save
+      @special_task.save
+      assert_equal &quot;http://example.com/admin/projects/#{@project.id}/tasks/#{@special_task.id}&quot;, polymorphic_url([:admin, @project, @special_task])
+    end
+  end
+  
+  def test_ordering_of_nesting_and_namespace_and_superclass_fallback
+    with_admin_and_site_test_routes do 
+      @project.save
+      @task.save
+      @special_step.save
+      assert_equal &quot;http://example.com/admin/projects/#{@project.id}/site/tasks/#{@task.id}/steps/#{@special_step.id}&quot;, polymorphic_url([:admin, @project, :site, @task, @special_step])
+    end
+  end
+  
+  def test_nesting_with_array_containing_singleton_resource_with_superclass_fallback
+    with_test_routes do
+      @project.save
+      @special_task.save
+      assert_equal &quot;http://example.com/projects/#{@project.id}/bid/tasks/#{@special_task.id}&quot;, polymorphic_url([@project, :bid, @special_task])
+    end
+  end
+
+  def test_nesting_with_array_containing_singleton_resource_and_format_with_superclass_fallback
+    with_test_routes do
+      @project.save
+      @special_task.save
+      assert_equal &quot;http://example.com/projects/#{@project.id}/bid/tasks/#{@special_task.id}.pdf&quot;, polymorphic_url([@project, :bid, @special_task], :format =&gt; :pdf)
+    end
+  end
+
+  def test_nesting_with_array_containing_namespace_and_singleton_resource_with_superclass_fallback
+    with_admin_test_routes do
+      @project.save
+      @special_task.save
+      assert_equal &quot;http://example.com/admin/projects/#{@project.id}/bid/tasks/#{@special_task.id}&quot;, polymorphic_url([:admin, @project, :bid, @special_task])
+    end
+  end
+
+  def test_with_array_containing_single_object_with_superclass_fallback
+    with_test_routes do 
+      @special_project.save
+      assert_equal &quot;http://example.com/projects/#{@special_project.id}&quot;, polymorphic_url([nil, @special_project])
+    end
+  end
+  
+  def test_with_hash_and_superclass_fallback
+    with_test_routes do 
+      @special_project.save
+      assert_equal &quot;http://example.com/projects/#{@special_project.id}&quot;, polymorphic_url(:id =&gt; @special_project)
+    end
+  end
+  
   # Tests for names where .plural.singular doesn't round-trip
   def test_with_irregular_plural_record
     with_test_routes do 
@@ -252,6 +437,13 @@ class PolymorphicRoutesTest &lt; ActionController::TestCase
     end
   end
   
+  def test_with_irregular_plural_record_and_superclass_fallback
+    with_test_routes do 
+      @special_tax.save
+      assert_equal &quot;http://example.com/taxes/#{@special_tax.id}&quot;, polymorphic_url(@special_tax)
+    end
+  end
+  
   def test_with_irregular_plural_new_record
     with_test_routes do 
       assert_equal &quot;http://example.com/taxes&quot;, polymorphic_url(@tax)</diff>
      <filename>actionpack/test/activerecord/polymorphic_routes_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cdf60e46cc01e5f7b14e95a0b7d914516fcdcbc1</id>
    </parent>
    <parent>
      <id>f9d3aabd885e589d69b013fad62b4486657607db</id>
    </parent>
  </parents>
  <author>
    <name>Luke Melia</name>
    <email>luke@lukemelia.com</email>
  </author>
  <url>http://github.com/lukemelia/rails/commit/99b1835b4c88a8f9016498398bc4bc13f1c4f762</url>
  <id>99b1835b4c88a8f9016498398bc4bc13f1c4f762</id>
  <committed-date>2009-08-02T20:58:20-07:00</committed-date>
  <authored-date>2009-08-02T20:57:44-07:00</authored-date>
  <message>Add extra flexibility for STI to polymorphic_url by walking the inheritance chain for the last argument if the route is not found using the normal convention.</message>
  <tree>f55758168d387b536995bf25319b2c9e0b90138e</tree>
  <committer>
    <name>Luke Melia</name>
    <email>luke@lukemelia.com</email>
  </committer>
</commit>
