Changeset 1668

Show
Ignore:
Timestamp:
02/29/08 00:26:28 (3 months ago)
Author:
pdcawley
Message:

More UrlPolicy? work.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/comments_controller.rb

    r1665 r1668  
    1414      else 
    1515        redirect_to article_path(@article) 
     16      end 
     17    end 
     18  end 
     19 
     20  def show 
     21    @comment = @article.comments.find_by_guid(params[:id]) 
     22 
     23    respond_to do |format| 
     24      format.html do 
     25        redirect_to article_path(@article) + "\##{dom_id(@comment)}" 
    1626      end 
    1727    end 
  • trunk/app/controllers/feedback_controller.rb

    r1602 r1668  
    44  session :new_session => false 
    55  before_filter :login_required, :only => [:update, :destroy] 
    6   before_filter :get_article, :only => [:create, :update
     6  before_filter :get_article, :only => [:create, :update, :show
    77 
    88  cache_sweeper :blog_sweeper 
     
    1313      format.html do 
    1414        if params[:article_id] 
    15           article = this_blog.requested_article(params) 
     15          article = Article.find_by_params_hash(params) 
    1616          redirect_to "#{article_path(article)}\##{@page_title.underscore}" 
    1717        else 
  • trunk/app/controllers/trackbacks_controller.rb

    r1645 r1668  
    3030    @trackbacks = 
    3131      if params[:article_id] 
    32         this_blog.requested_article(params).published_trackbacks 
     32        Article.find_by_params_hash(params).published_trackbacks 
    3333      else 
    3434        this_blog.published_trackbacks.find(:all, this_blog.rss_limit_params(:order => 'created_at DESC')) 
  • trunk/app/models/comment.rb

    r1555 r1668  
    5050  end 
    5151 
     52  def to_params(builder) 
     53    builder.comment_params(self) 
     54  end 
     55 
     56  def to_param 
     57    guid 
     58  end 
     59 
    5260  protected 
    5361 
  • trunk/app/models/url_policy.rb

    r1666 r1668  
    1818    with_options(:only_path => true) do |o| 
    1919      case args.first 
     20      when nil 
     21        raise ArgumentError, "Argument cannot be nil" 
    2022      when ActiveRecord::Base 
    2123        o.url_for_object(*args) 
     
    5557  end 
    5658 
     59  def comment_params(comment) 
     60    returning(:controller => 'comments', :action => 'show') do |params| 
     61      article_params(comment.article).each do |k,v| 
     62        next if k == :controller || k == :action 
     63        params["article_#{k}".to_sym] = v 
     64      end 
     65      params[:id] = comment.to_param 
     66    end 
     67  end 
    5768end 
  • trunk/spec/models/url_policy_spec.rb

    r1666 r1668  
    1010  end 
    1111 
    12   it "#url_for(contents(:article3)) should == /2004/06/01/article-3" do 
     12  it "#url_for(contents(:article3)) should == /articles/2004/06/01/article-3" do 
    1313    UrlPolicy.instance.url_for(contents(:article3)).should == '/articles/2004/06/01/article-3' 
     14  end 
     15 
     16  it "#url_for(<comment on article 3>).should == /2004/06/01/article-3/comments/#\{comment.guid}" do 
     17    article = contents(:article3) 
     18    comment = article.comments.build(:author => 'Piers Cawley', :body => "body") 
     19    comment.save(false) 
     20    UrlPolicy.instance.url_for(comment).should == "/articles/2004/06/01/article-3/comments/#{comment.guid}" 
    1421  end 
    1522 
     
    1825  end 
    1926 
    20   it "#edit_url_for(contents(:article3)) should == /2004/06/01/article-3/edit" do 
     27  it "#edit_url_for(contents(:article3)) should == /articles/2004/06/01/article-3/edit" do 
    2128    UrlPolicy.instance.edit_url_for(contents(:article3)).should == '/articles/2004/06/01/article-3/edit' 
    2229  end