Changeset 825

Show
Ignore:
Timestamp:
04/19/08 11:35:58 (5 months ago)
Author:
seancribbs
Message:

Convert some more tag specs to nested describes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/radiant/spec/models/standard_tags_spec.rb

    r824 r825  
    269269  end 
    270270 
    271   specify '<r:random>' do 
     271  it '<r:random> should render a randomly selected contained <r:option>' do 
    272272    page.should render("<r:random> <r:option>1</r:option> <r:option>2</r:option> <r:option>3</r:option> </r:random>").matching(/^(1|2|3)$/) 
    273273  end 
    274274 
    275   specify '<r:comment>' do 
     275  it '<r:comment> should render nothing it contains' do 
    276276    page.should render('just a <r:comment>small </r:comment>test').as('just a test') 
    277277  end 
     
    327327  end 
    328328 
    329  
    330   specify '<r:find>' do 
    331     page.should render(%{<r:find url="/parent/child/"><r:title /></r:find>}).as('Child') 
    332   end 
    333   specify '<r:find> without url' do 
    334     page.should render(%{<r:find />}).with_error("`find' tag must contain `url' attribute") 
    335   end 
    336   specify '<r:find> with nonexistant url' do 
    337     page.should render(%{<r:find url="/asdfsdf/"><r:title /></r:find>}).as('') 
    338   end 
    339   specify '<r:find> with nonexistant url and file not found' do 
    340     page.should render(%{<r:find url="/gallery/asdfsdf/"><r:title /></r:find>}).as('') 
    341   end 
    342   specify '<r:find> with children' do 
    343     page.should render(%{<r:find url="/parent/"><r:children:each><r:slug /> </r:children:each></r:find>}).as('child child-2 child-3 ') 
    344   end 
    345   specify '<r:find> with relative url' do 
    346     page(:great_grandchild).should render(%{<r:find url="../../../child-2"><r:title/></r:find>}).as("Child 2") 
    347   end 
    348  
    349   specify '<r:escape_html>' do 
     329  describe "<r:find>" do 
     330    it "should change the local page to the page specified in the 'url' attribute" do 
     331      page.should render(%{<r:find url="/parent/child/"><r:title /></r:find>}).as('Child') 
     332    end 
     333 
     334    it "should render an error without the 'url' attribute" do 
     335      page.should render(%{<r:find />}).with_error("`find' tag must contain `url' attribute") 
     336    end 
     337 
     338    it "should render nothing when the 'url' attribute does not point to a page" do 
     339      page.should render(%{<r:find url="/asdfsdf/"><r:title /></r:find>}).as('') 
     340    end 
     341 
     342    it "should render nothing when the 'url' attribute does not point to a page and a custom 404 page exists" do 
     343      page.should render(%{<r:find url="/gallery/asdfsdf/"><r:title /></r:find>}).as('') 
     344    end 
     345 
     346    it "should scope contained tags to the found page" do 
     347      page.should render(%{<r:find url="/parent/"><r:children:each><r:slug /> </r:children:each></r:find>}).as('child child-2 child-3 ') 
     348    end 
     349 
     350    it "should accept a path relative to the current page" do 
     351      page(:great_grandchild).should render(%{<r:find url="../../../child-2"><r:title/></r:find>}).as("Child 2") 
     352    end 
     353  end 
     354 
     355  it '<r:escape_html> should escape HTML-related characters into entities' do 
    350356    page.should render('<r:escape_html><strong>a bold move</strong></r:escape_html>').as('&lt;strong&gt;a bold move&lt;/strong&gt;') 
    351357  end 
    352358 
    353   specify '<r:rfc1123_date>' do 
     359  it '<r:rfc1123_date> should render an RFC1123-compatible date' do 
    354360    page(:dated).should render('<r:rfc1123_date />').as('Wed, 11 Jan 2006 00:00:00 GMT') 
    355361  end 
    356362 
    357   specify '<r:breadcrumbs>' do 
    358     expected = %{<a href="/">Home</a> &gt; <a href="/parent/">Parent</a> &gt; <a href="/parent/child/">Child</a> &gt; <a href="/parent/child/grandchild/">Grandchild</a> &gt; Great Grandchild} 
    359     page(:great_grandchild).should render('<r:breadcrumbs />').as(expected) 
    360   end 
    361   specify '<r:breadcrumbs> with separator attribute' do 
    362     expected = %{<a href="/">Home</a> :: Parent} 
    363     page(:parent).should render('<r:breadcrumbs separator=" :: " />').as(expected) 
    364   end 
    365   specify '<r:breadcrumbs> with nolinks attribute' do 
    366     expected = %{Home &gt; Parent} 
    367     page(:parent).should render('<r:breadcrumbs nolinks="true" />').as(expected) 
    368   end 
    369   specify '<r:breadcrumbs> with a relative URL root should scope to the relative root' do 
    370     expected = '<a href="/foo/">Home</a> &gt; Assorted' 
    371     page(:assorted).should render('<r:breadcrumbs />').with_relative_root('/foo').as(expected) 
    372   end 
    373  
    374   specify '<r:if_url> with "matches" attribute' do 
    375     page.should render('<r:if_url matches="a.sorted/$">true</r:if_url>').as('true') 
    376   end 
    377   specify '<r:if_url> with "matches" attribute that does not match' do 
    378     page.should render('<r:if_url matches="fancypants">true</r:if_url>').as('') 
    379   end 
    380   specify '<r:if_url> with "matches" attribute set to a malformatted regexp' do 
    381     page.should render('<r:if_url matches="as(sorted/$">true</r:if_url>').with_error("Malformed regular expression in `matches' argument of `if_url' tag: unmatched (: /as(sorted\\/$/") 
    382   end 
    383   specify '<r:if_url> without "ignore_case" attribute' do 
    384     page.should render('<r:if_url matches="asSorted/$">true</r:if_url>').as('true') 
    385   end 
    386   specify '<r:if_url> with "ignore_case" attribute set to "true"' do 
    387     page.should render('<r:if_url matches="asSorted/$" ignore_case="true">true</r:if_url>').as('true') 
    388   end 
    389   specify '<r:if_url> with "ignore_case" attribute set to "false"' do 
    390     page.should render('<r:if_url matches="asSorted/$" ignore_case="false">true</r:if_url>').as('') 
    391   end 
    392   specify '<r:if_url> with no attributes' do 
    393     page.should render('<r:if_url>test</r:if_url>').with_error("`if_url' tag must contain a `matches' attribute.") 
     363  describe "<r:breadcrumbs>" do 
     364    it "should render a series of breadcrumb links separated by &gt;" do 
     365      expected = %{<a href="/">Home</a> &gt; <a href="/parent/">Parent</a> &gt; <a href="/parent/child/">Child</a> &gt; <a href="/parent/child/grandchild/">Grandchild</a> &gt; Great Grandchild} 
     366      page(:great_grandchild).should render('<r:breadcrumbs />').as(expected) 
     367    end 
     368 
     369    it "with a 'separator' attribute should use the separator instead of &gt;" do 
     370      expected = %{<a href="/">Home</a> :: Parent} 
     371      page(:parent).should render('<r:breadcrumbs separator=" :: " />').as(expected) 
     372    end 
     373 
     374    it "with a 'nolinks' attribute set to 'true' should not render links" do 
     375      expected = %{Home &gt; Parent} 
     376      page(:parent).should render('<r:breadcrumbs nolinks="true" />').as(expected) 
     377    end 
     378 
     379    it "with a relative URL root should scope links to the relative root" do 
     380      expected = '<a href="/foo/">Home</a> &gt; Assorted' 
     381      page(:assorted).should render('<r:breadcrumbs />').with_relative_root('/foo').as(expected) 
     382    end 
     383  end 
     384 
     385  describe "<r:if_url>" do 
     386    describe "with 'matches' attribute" do 
     387      it "should render the contained block if the page URL matches" do 
     388        page.should render('<r:if_url matches="a.sorted/$">true</r:if_url>').as('true') 
     389      end 
     390 
     391      it "should not render the contained block if the page URL does not match" do 
     392        page.should render('<r:if_url matches="fancypants">true</r:if_url>').as('') 
     393      end 
     394 
     395      it "set to a malformatted regexp should render an error" do 
     396        page.should render('<r:if_url matches="as(sorted/$">true</r:if_url>').with_error("Malformed regular expression in `matches' argument of `if_url' tag: unmatched (: /as(sorted\\/$/") 
     397      end 
     398 
     399      it "without 'ignore_case' attribute should ignore case by default" do 
     400        page.should render('<r:if_url matches="asSorted/$">true</r:if_url>').as('true') 
     401      end 
     402 
     403      describe "with 'ignore_case' attribute" do 
     404        it "set to 'true' should use a case-insensitive match" do 
     405          page.should render('<r:if_url matches="asSorted/$" ignore_case="true">true</r:if_url>').as('true') 
     406        end 
     407 
     408        it "set to 'false' should use a case-sensitive match" do 
     409          page.should render('<r:if_url matches="asSorted/$" ignore_case="false">true</r:if_url>').as('') 
     410        end 
     411      end 
     412    end 
     413 
     414    it "with no attributes should render an error" do 
     415      page.should render('<r:if_url>test</r:if_url>').with_error("`if_url' tag must contain a `matches' attribute.") 
     416    end 
    394417  end 
    395418 
     
    399422        page.should render('<r:unless_url matches="a.sorted/$">true</r:unless_url>').as('') 
    400423      end 
    401        
     424 
    402425      it "should render the contained block if the page URL does not match" do 
    403         page.should render('<r:unless_url matches="fancypants">true</r:unless_url>').as('true')         
    404       end 
    405        
     426        page.should render('<r:unless_url matches="fancypants">true</r:unless_url>').as('true') 
     427      end 
     428 
    406429      it "set to a malformatted regexp should render an error" do 
    407430        page.should render('<r:unless_url matches="as(sorted/$">true</r:unless_url>').with_error("Malformed regular expression in `matches' argument of `unless_url' tag: unmatched (: /as(sorted\\/$/") 
    408431      end 
    409     end 
    410   end 
    411  
    412   specify '<r:unless_url> without "ignore_case" attribute' do 
    413     page.should render('<r:unless_url matches="asSorted/$">true</r:unless_url>').as('') 
    414   end 
    415   specify '<r:unless_url> with "ignore_case" attribute set to "true"' do 
    416     page.should render('<r:unless_url matches="asSorted/$" ignore_case="true">true</r:unless_url>').as('') 
    417   end 
    418   specify '<r:unless_url> with "ignore_case" attribute set to "false"' do 
    419     page.should render('<r:unless_url matches="asSorted/$" ignore_case="false">true</r:unless_url>').as('true') 
    420   end 
    421   specify '<r:unless_url> with no attributes' do 
    422     page.should render('<r:unless_url>test</r:unless_url>').with_error("`unless_url' tag must contain a `matches' attribute.") 
     432 
     433      it "without 'ignore_case' attribute should ignore case by default" do 
     434        page.should render('<r:unless_url matches="asSorted/$">true</r:unless_url>').as('') 
     435      end 
     436 
     437      describe "with 'ignore_case' attribute" do 
     438        it "set to 'true' should use a case-insensitive match" do 
     439          page.should render('<r:unless_url matches="asSorted/$">true</r:unless_url>').as('') 
     440        end 
     441 
     442        it "set to 'false' should use a case-sensitive match" do 
     443          page.should render('<r:unless_url matches="asSorted/$" ignore_case="false">true</r:unless_url>').as('true') 
     444        end 
     445      end 
     446    end 
     447 
     448    it "with no attributes should render an error" do 
     449      page.should render('<r:unless_url>test</r:unless_url>').with_error("`unless_url' tag must contain a `matches' attribute.") 
     450    end 
    423451  end 
    424452 
     
    492520    it "should render the status of the current page" do 
    493521      status_tag = "<r:status/>" 
    494       page(:a).should render(status_tag).as("Published")       
     522      page(:a).should render(status_tag).as("Published") 
    495523      page(:hidden).should render(status_tag).as("Hidden") 
    496       page(:draft).should render(status_tag).as("Draft")       
    497     end 
    498      
     524      page(:draft).should render(status_tag).as("Draft") 
     525    end 
     526 
    499527    describe "with the downcase attribute set to 'true'" do 
    500528      it "should render the lowercased status of the current page" do 
     
    502530        page(:a).should render(status_tag_lc).as("published") 
    503531        page(:hidden).should render(status_tag_lc).as("hidden") 
    504         page(:draft).should render(status_tag_lc).as("draft")         
     532        page(:draft).should render(status_tag_lc).as("draft") 
    505533      end 
    506534    end