Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8601: fix2.diff

File fix2.diff, 1.6 kB (added by lotswholetime, 2 years ago)

Fixes another issue with array being modified in place. Added tests.

  • actionpack/test/controller/polymorphic_routes_test.rb

    old new  
     1require File.dirname(__FILE__) + '/../abstract_unit' 
     2 
     3class 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 
     10end 
     11 
     12class 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 
     31end 
  • actionpack/lib/action_controller/polymorphic_routes.rb

    old new  
    1111        when record.respond_to?(:new_record?) && record.new_record? 
    1212          :plural 
    1313        else 
    14           args = [record_or_hash_or_array] 
     14          args = Array(record_or_hash_or_array).dup 
    1515          :singular 
    1616        end 
    1717