Changeset 942

Show
Ignore:
Timestamp:
11/10/07 22:32:55 (1 year ago)
Author:
iv..@gweezlebur.com
Message:

Merki: page implementations, pages specs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • apps/merki/trunk/app/models/page.rb

    r938 r942  
     1require 'cgi' 
     2 
    13class Page < DataMapper::Base 
    24  ## props 
    35  property :title, :string 
    46  property :body, :text 
     7  property :converted_body, :text 
    58   
    69  ## relationships 
     
    811  # belongs_to :author, :class => 'User'  
    912   
     13  ## callbacks 
     14  before_save :parse 
     15   
    1016  ## validations 
    1117  validates_presence_of :title, :body 
     18   
     19  ## class methods 
     20   
     21  def self.find_by_slug(slug) 
     22    find_by_title(CGI.unescape(slug)) 
     23  end 
     24   
     25   
     26  ## instance methods 
     27   
     28  def parse(preprocessed_body = self.body) 
     29    ## TODO: parse for internal links 
     30    self.converted_body = RedCloth.new(preprocessed_body).to_html 
     31  end 
     32   
     33  ## Private 
     34   
     35  ## Protected 
    1236end 
    1337 
  • apps/merki/trunk/config/dependencies.rb

    r931 r942  
    3535# dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0" 
    3636 
     37dependencies "RedCloth", "merb_helpers" 
     38 
    3739Merb::Server.after_app_loads do 
    3840  ### Add dependencies here that must load after the application loads: 
  • apps/merki/trunk/config/router.rb

    r930 r942  
    2222puts "Compiling routes.." 
    2323Merb::Router.prepare do |r| 
    24   # RESTful routes 
    25   # r.resources :posts 
     24  r.resources :pages 
    2625 
    27   # Default route, usually you don't want to change this 
    28   r.default_routes 
    29    
    30   # Change this for your home page to be available at / 
    31   # r.match('/').to(:controller => 'whatever', :action =>'index') 
     26  r.match('/').to(:controller => 'pages', :action =>'index') 
    3227end 
  • apps/merki/trunk/spec/models/page_spec.rb

    r941 r942  
    7474   
    7575  it "should have a converted_body" do 
    76     pending "Needs implementation" 
    7776    @page.converted_body = "converted to textile" 
    7877    @page.converted_body.should == "converted to textile" 
     
    8079   
    8180  it "should use textile to convert body to converted_body" do 
    82     pending "Needs implementation" 
    8381    @page.body = textile_text 
     82    @page.parse 
    8483    @page.converted_body.should == textile_text_as_html 
    8584  end 
     
    9998  end 
    10099   
     100  it "should return body as to_text" do 
     101    pending "Needs implementation"     
     102    @page.body = lorem_text 
     103    @page.to_text.should == lorem_text 
     104  end 
     105   
    101106  it "should be valid with all attributes" do 
    102107    @page.attributes = valid_page_attributes 
     
    113118   
    114119  it "should be able to find Pages by URL slug" do 
    115     pending "incomplete" 
    116120    page = mock("Page") 
    117121    Page.should_receive(:find_by_title).with("Sample Page").once.