Changeset 1128

Show
Ignore:
Timestamp:
12/22/07 14:07:06 (1 year ago)
Author:
e.@brainspl.at
Message:

fix url(:post, @post) where @post responds to :to_param. use to_param instead of id when available

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Rakefile

    r1123 r1128  
    130130Spec::Rake::SpecTask.new('rcov') do |t| 
    131131  t.spec_opts = ["--format", "specdoc", "--colour"] 
     132  t.rcov_opts = ["--exclude","gems"] 
    132133  t.spec_files = Dir['spec/**/*_spec.rb'].sort 
    133134  t.libs = ['lib', 'server/lib' ] 
  • trunk/lib/merb/router.rb

    r1104 r1128  
    142142                params[segment] || fallback[segment] 
    143143              else 
    144                 if params.respond_to?(segment) 
     144                if segment == :id && params.respond_to?(:to_param)  
     145                  params.to_param 
     146                elsif params.respond_to?(segment) 
    145147                  params.send(segment) 
    146148                else 
  • trunk/spec/fixtures/models/router_spec_models.rb

    r380 r1128  
    1919  end   
    2020end 
     21 
     22 
     23class Blog 
     24  def id 
     25    42 
     26  end 
     27  def to_param 
     28    "hello#{id}" 
     29  end 
     30end     
  • trunk/spec/spec_helpers/url_shared_behaviour.rb

    r1079 r1128  
    5656  it "should handle an object as the second arg" do 
    5757    c = new_url_controller(@resource_routes, :controller => "blogs", :action => "show") 
    58     blog = mock("blog") 
    59     blog.should_receive(:id).once.and_return(7) 
     58    blog = Blog.new 
    6059    url = c.url(:blog, blog) 
    61     url.should == "/blogs/7
     60    url.should == "/blogs/hello42
    6261  end 
    6362   
    6463  it "should point to /blogs/:blog_id if @blog is not new_record" do 
    6564    c = new_url_controller(@resource_routes, :controller => "blogs", :action => "index") 
    66     blog = mock("blog") 
    67     blog.should_receive(:id).once.and_return(7) 
     65    blog = Blog.new 
    6866    blog.should_receive(:new_record?).once.and_return(false) 
    6967    url = c.url(:blog, blog) 
    70     url.should == "/blogs/7
     68    url.should == "/blogs/hello42
    7169  end 
    7270   
    7371  it "should point to /blogs/ if @blog is new_record" do 
    7472    c = new_url_controller(@resource_routes, :controller => "blogs", :action => "index") 
    75     blog = mock("blog") 
     73    blog = Blog.new 
    7674    blog.should_receive(:new_record?).once.and_return(true) 
    7775    url = c.url(:blog, blog)