Changeset 824

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

Convert some tag specs to nested describes.

Files:

Legend:

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

    r815 r824  
    33describe "Standard Tags" do 
    44  scenario :users_and_pages, :file_not_found, :snippets 
    5    
     5 
    66  specify '<r:page> should allow access to the current page' do 
    77    page(:home) 
     
    99    page.should render(%{<r:find url="/radius"><r:title /> | <r:page:title /></r:find>}).as('Radius | Home') 
    1010  end 
    11    
     11 
    1212  specify '<r:breadcrumb>, <r:slug>, <r:title>, and <r:url>' do 
    1313    page(:home) 
     
    1717    end 
    1818  end 
    19    
     19 
    2020  specify '<r:url> with a relative URL root should scope to the relative root' do 
    2121    page(:home).should render("<r:url />").with_relative_root("/foo").as("/foo/") 
    2222  end 
    23    
     23 
    2424  specify '<r:parent>' do 
    2525    page(:parent) 
     
    2828    page.should render('<r:children:each><r:parent:title /></r:children:each>').as(@page.title * page.children.count) 
    2929  end 
    30    
     30 
    3131  specify '<r:if_parent>' do 
    3232    page.should render('<r:if_parent>true</r:if_parent>').as('true') 
    3333    page(:home).should render('<r:if_parent>true</r:if_parent>').as('') 
    3434  end 
    35    
     35 
    3636  specify '<r:unless_parent>' do 
    3737    page.should render('<r:unless_parent>true</r:unless_parent>').as('') 
    3838    page(:home).should render('<r:unless_parent>true</r:unless_parent>').as('true') 
    3939  end 
    40    
     40 
    4141  specify '<r:if_children>' do 
    4242    page(:home).should render('<r:if_children>true</r:if_children>').as('true') 
    4343    page(:childless).should render('<r:if_children>true</r:if_children>').as('') 
    4444  end 
    45    
     45 
    4646  specify '<r:unless_children>' do 
    4747    page(:home).should render('<r:unless_children>true</r:unless_children>').as('') 
    4848    page(:childless).should render('<r:unless_children>true</r:unless_children>').as('true') 
    4949  end 
    50    
     50 
    5151  specify '<r:children:each>' do 
    5252    page(:parent) 
    5353    page.should render('<r:children:each><r:title /> </r:children:each>').as('Child Child 2 Child 3 ') 
    54     page.should render('<r:children:each><r:page><r:slug />/<r:child:slug /> </r:page></r:children:each>').as('parent/child parent/child-2 parent/child-3 ')     
     54    page.should render('<r:children:each><r:page><r:slug />/<r:child:slug /> </r:page></r:children:each>').as('parent/child parent/child-2 parent/child-3 ') 
    5555  end 
    5656  specify '<r:children:each> order attributes' do 
     
    6969  end 
    7070  specify '<r:children:each> should not list virtual pages' do 
    71     page.should render('<r:children:each><r:slug /> </r:children:each>').as('a b c d e f g h i j ')  
     71    page.should render('<r:children:each><r:slug /> </r:children:each>').as('a b c d e f g h i j ') 
    7272    page.should render('<r:children:each status="all"><r:slug /> </r:children:each>').as('a b c d e f g h i j draft ') 
    7373  end 
     
    9292    page.should render(page_children_each_tags(%{order="asdf"})).with_error(message) 
    9393  end 
    94    
     94 
    9595  specify '<r:children:each:header>' do 
    9696    tags = '<r:children:each><r:header>[<r:date format="%b/%y" />] </r:header><r:slug /> </r:children:each>' 
     
    113113    page(:news).should render(tags).as(expected) 
    114114  end 
    115    
     115 
    116116  specify '<r:children:count>' do 
    117117    page(:parent).should render('<r:children:count />').as('3') 
    118118  end 
    119    
     119 
    120120  specify '<r:children:first>' do 
    121     page(:parent).should render('<r:children:first:title />').as('Child')  
    122   end   
     121    page(:parent).should render('<r:children:first:title />').as('Child') 
     122  end 
    123123  specify '<r:children:first> with attributes' do 
    124     page.should render(page_children_first_tags).as('a')  
     124    page.should render(page_children_first_tags).as('a') 
    125125    page.should render(page_children_first_tags(%{limit="5"})).as('a') 
    126126    page.should render(page_children_first_tags(%{offset="3" limit="5"})).as('d') 
     
    132132    page(:first).should render('<r:children:first:title />').as('') 
    133133  end 
    134    
     134 
    135135  specify '<r:children:last>' do 
    136136    page(:parent).should render('<r:children:last:title />').as('Child 3') 
     
    147147    page(:first).should render('<r:children:last:title />').as('') 
    148148  end 
    149    
     149 
    150150  specify '<r:content>' do 
    151151    page.should render('<r:content />').as('Assorted body.') 
     
    177177    page(:parent).should render('<r:children:each><r:content /> </r:children:each>').as(expected) 
    178178  end 
    179    
     179 
    180180  specify '<r:if_content> without "part" attribute' do 
    181181    page.should render('<r:if_content>true</r:if_content>').as('true') 
     
    187187    page.should render('<r:if_content part="asdf">true</r:if_content>').as('') 
    188188  end 
    189    
     189 
    190190  specify '<r:unless_content> without "part" attribute' do 
    191191    page.should render('<r:unless_content>false</r:unless_content>').as('') 
     
    197197    page.should render('<r:unless_content part="asdf">false</r:unless_content>').as('false') 
    198198  end 
    199    
     199 
    200200  specify '<r:author>' do 
    201201    page.should render('<r:author />').as('Admin') 
     
    204204    page(:no_user).should render('<r:author />').as('') 
    205205  end 
    206    
     206 
    207207  specify '<r:date>' do 
    208208    page(:dated) 
     
    228228    page.should render(%Q(<r:date format="#{format}" />) ).as(expected) 
    229229  end 
    230    
     230 
    231231  specify '<r:link>' do 
    232232    page.should render('<r:link />').as('<a href="/assorted/">Assorted</a>') 
     
    249249    page(:assorted).should render('<r:link />').with_relative_root('/foo').as('<a href="/foo/assorted/">Assorted</a>') 
    250250  end 
    251    
     251 
    252252  specify '<r:snippet>' do 
    253253    page.should render('<r:snippet name="first" />').as('test') 
     
    268268    page(:child).should render('<r:snippet name="recursive" />').as("Great GrandchildGrandchildChild") 
    269269  end 
    270    
     270 
    271271  specify '<r:random>' do 
    272     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)$/)  
    273   end 
    274    
     272    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)$/) 
     273  end 
     274 
    275275  specify '<r:comment>' do 
    276276    page.should render('just a <r:comment>small </r:comment>test').as('just a test') 
    277277  end 
    278    
     278 
    279279  specify '<r:navigation> simple case' do 
    280280    tags = %{<r:navigation urls="Home: / | Assorted: /assorted/ | Parent: /parent/"> 
     
    326326    page(:radius).should render(tags).as(expected) 
    327327  end 
    328    
    329    
     328 
     329 
    330330  specify '<r:find>' do 
    331331    page.should render(%{<r:find url="/parent/child/"><r:title /></r:find>}).as('Child') 
     
    346346    page(:great_grandchild).should render(%{<r:find url="../../../child-2"><r:title/></r:find>}).as("Child 2") 
    347347  end 
    348    
     348 
    349349  specify '<r:escape_html>' do 
    350350    page.should render('<r:escape_html><strong>a bold move</strong></r:escape_html>').as('&lt;strong&gt;a bold move&lt;/strong&gt;') 
    351351  end 
    352    
     352 
    353353  specify '<r:rfc1123_date>' do 
    354354    page(:dated).should render('<r:rfc1123_date />').as('Wed, 11 Jan 2006 00:00:00 GMT') 
    355355  end 
    356    
     356 
    357357  specify '<r:breadcrumbs>' do 
    358358    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} 
     
    371371    page(:assorted).should render('<r:breadcrumbs />').with_relative_root('/foo').as(expected) 
    372372  end 
    373    
     373 
    374374  specify '<r:if_url> with "matches" attribute' do 
    375375    page.should render('<r:if_url matches="a.sorted/$">true</r:if_url>').as('true') 
     
    393393    page.should render('<r:if_url>test</r:if_url>').with_error("`if_url' tag must contain a `matches' attribute.") 
    394394  end 
    395    
    396   specify '<r:unless_url> with "matches" attribute' do 
    397     page.should render('<r:unless_url matches="a.sorted/$">true</r:unless_url>').as('') 
    398   end 
    399   specify '<r:unless_url> with "matches" attribute that does not match' do 
    400     page.should render('<r:unless_url matches="fancypants">true</r:unless_url>').as('true') 
    401   end 
    402   specify '<r:unless_url> with "matches" attribute set to a malformatted regexp' do 
    403     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\\/$/") 
    404   end 
     395 
     396  describe "<r:unless_url>" do 
     397    describe "with 'matches' attribute" do 
     398      it "should not render the contained block if the page URL matches" do 
     399        page.should render('<r:unless_url matches="a.sorted/$">true</r:unless_url>').as('') 
     400      end 
     401       
     402      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       
     406      it "set to a malformatted regexp should render an error" do 
     407        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\\/$/") 
     408      end 
     409    end 
     410  end 
     411 
    405412  specify '<r:unless_url> without "ignore_case" attribute' do 
    406413    page.should render('<r:unless_url matches="asSorted/$">true</r:unless_url>').as('') 
     
    415422    page.should render('<r:unless_url>test</r:unless_url>').with_error("`unless_url' tag must contain a `matches' attribute.") 
    416423  end 
    417    
    418   specify '<r:cycle>' do 
    419     page.should render('<r:cycle values="first, second" /> <r:cycle values="first, second" />').as('first second') 
    420   end 
    421   specify '<r:cycle> returns to beginning' do 
    422     page.should render('<r:cycle values="first, second" /> <r:cycle values="first, second" /> <r:cycle values="first, second" />').as('first second first') 
    423   end 
    424   specify '<r:cycle> default name' do 
    425     page.should render('<r:cycle values="first, second" /> <r:cycle values="first, second" name="cycle" />').as('first second') 
    426   end 
    427   specify '<r:cycle> keeps separate counters' do 
    428     page.should render('<r:cycle values="first, second" /> <r:cycle values="one, two" name="numbers" /> <r:cycle values="first, second" /> <r:cycle values="one, two" name="numbers" />').as('first one second two') 
    429   end 
    430   specify '<r:cycle> resets counter' do 
    431     page.should render('<r:cycle values="first, second" /> <r:cycle values="first, second" reset="true"/>').as('first first') 
    432   end 
    433   specify '<r:cycle> names empty' do 
    434     page.should render('<r:cycle />').with_error("`cycle' tag must contain a `values' attribute.") 
    435   end 
    436    
    437   specify '<r:if_dev>' do 
    438     page.should render('-<r:if_dev>dev</r:if_dev>-').as('-dev-').on('dev.site.com') 
    439     page.should render('-<r:if_dev>dev</r:if_dev>-').as('--') 
    440   end 
    441   specify '<r:if_dev> on included page' do 
    442     page.should render('-<r:find url="/devtags/"><r:content part="if_dev" /></r:find>-').as('-dev-').on('dev.site.com') 
    443     page.should render('-<r:find url="/devtags/"><r:content part="if_dev" /></r:find>-').as('--') 
    444   end 
    445    
    446   specify '<r:unless_dev>' do 
    447     page.should render('-<r:unless_dev>not dev</r:unless_dev>-').as('--').on('dev.site.com') 
    448     page.should render('-<r:unless_dev>not dev</r:unless_dev>-').as('-not dev-') 
    449   end 
    450   specify '<r:unless_dev> on included page' do 
    451     page.should render('-<r:find url="/devtags/"><r:content part="unless_dev" /></r:find>-').as('--').on('dev.site.com') 
    452     page.should render('-<r:find url="/devtags/"><r:content part="unless_dev" /></r:find>-').as('-not dev-') 
    453   end 
    454    
    455   specify '<r:status>' do 
    456     status_tag = "<r:status/>" 
    457     status_tag_lc = "<r:status downcase='true'/>" 
    458     page(:a).should render(status_tag).as("Published") 
    459     page(:a).should render(status_tag_lc).as("published") 
    460     page(:hidden).should render(status_tag).as("Hidden") 
    461     page(:hidden).should render(status_tag_lc).as("hidden") 
    462     page(:draft).should render(status_tag).as("Draft") 
    463     page(:draft).should render(status_tag_lc).as("draft") 
    464   end 
    465    
     424 
     425  describe "<r:cycle>" do 
     426    it "should render passed values in succession" do 
     427      page.should render('<r:cycle values="first, second" /> <r:cycle values="first, second" />').as('first second') 
     428    end 
     429 
     430    it "should return to the beginning of the cycle when reaching the end" do 
     431      page.should render('<r:cycle values="first, second" /> <r:cycle values="first, second" /> <r:cycle values="first, second" />').as('first second first') 
     432    end 
     433 
     434    it "should use a default cycle name of 'cycle'" do 
     435      page.should render('<r:cycle values="first, second" /> <r:cycle values="first, second" name="cycle" />').as('first second') 
     436    end 
     437 
     438    it "should maintain separate cycle counters" do 
     439      page.should render('<r:cycle values="first, second" /> <r:cycle values="one, two" name="numbers" /> <r:cycle values="first, second" /> <r:cycle values="one, two" name="numbers" />').as('first one second two') 
     440    end 
     441 
     442    it "should reset the counter" do 
     443      page.should render('<r:cycle values="first, second" /> <r:cycle values="first, second" reset="true"/>').as('first first') 
     444    end 
     445 
     446    it "should require the values attribute" do 
     447      page.should render('<r:cycle />').with_error("`cycle' tag must contain a `values' attribute.") 
     448    end 
     449  end 
     450 
     451  describe "<r:if_dev>" do 
     452    it "should render the contained block when on the dev site" do 
     453      page.should render('-<r:if_dev>dev</r:if_dev>-').as('-dev-').on('dev.site.com') 
     454    end 
     455 
     456    it "should not render the contained block when not on the dev site" do 
     457      page.should render('-<r:if_dev>dev</r:if_dev>-').as('--') 
     458    end 
     459 
     460    describe "on an included page" do 
     461      it "should render the contained block when on the dev site" do 
     462        page.should render('-<r:find url="/devtags/"><r:content part="if_dev" /></r:find>-').as('-dev-').on('dev.site.com') 
     463      end 
     464 
     465      it "should not render the contained block when not on the dev site" do 
     466        page.should render('-<r:find url="/devtags/"><r:content part="if_dev" /></r:find>-').as('--') 
     467      end 
     468    end 
     469  end 
     470 
     471  describe "<r:unless_dev>" do 
     472    it "should not render the contained block when not on the dev site" do 
     473      page.should render('-<r:unless_dev>not dev</r:unless_dev>-').as('--').on('dev.site.com') 
     474    end 
     475 
     476    it "should render the contained block when not on the dev site" do 
     477      page.should render('-<r:unless_dev>not dev</r:unless_dev>-').as('-not dev-') 
     478    end 
     479 
     480    describe "on an included page" do 
     481      it "should not render the contained block when not on the dev site" do 
     482        page.should render('-<r:find url="/devtags/"><r:content part="unless_dev" /></r:find>-').as('--').on('dev.site.com') 
     483      end 
     484 
     485      it "should render the contained block when not on the dev site" do 
     486        page.should render('-<r:find url="/devtags/"><r:content part="unless_dev" /></r:find>-').as('-not dev-') 
     487      end 
     488    end 
     489  end 
     490 
     491  describe "<r:status>" do 
     492    it "should render the status of the current page" do 
     493      status_tag = "<r:status/>" 
     494      page(:a).should render(status_tag).as("Published")       
     495      page(:hidden).should render(status_tag).as("Hidden") 
     496      page(:draft).should render(status_tag).as("Draft")       
     497    end 
     498     
     499    describe "with the downcase attribute set to 'true'" do 
     500      it "should render the lowercased status of the current page" do 
     501        status_tag_lc = "<r:status downcase='true'/>" 
     502        page(:a).should render(status_tag_lc).as("published") 
     503        page(:hidden).should render(status_tag_lc).as("hidden") 
     504        page(:draft).should render(status_tag_lc).as("draft")         
     505      end 
     506    end 
     507  end 
     508 
    466509  describe "<r:if_ancestor_or_self>" do 
    467510    it "should render the tag's content when the current page is an ancestor of tag.locals.page" do 
    468511      page(:radius).should render(%{<r:find url="/"><r:if_ancestor_or_self>true</r:if_ancestor_or_self></r:find>}).as('true') 
    469     end    
    470    
     512    end 
     513 
    471514    it "should not render the tag's content when current page is not an ancestor of tag.locals.page" do 
    472515      page(:parent).should render(%{<r:find url="/radius"><r:if_ancestor_or_self>true</r:if_ancestor_or_self></r:find>}).as('') 
    473516    end 
    474517  end 
    475    
     518 
    476519  describe "<r:if_self>" do 
    477520    it "should render the tag's content when the current page is the same as the local contextual page" do 
    478521      page(:home).should render(%{<r:find url="/"><r:if_self>true</r:if_self></r:find>}).as('true') 
    479522    end 
    480      
     523 
    481524    it "should not render the tag's content when the current page is not the same as the local contextual page" do 
    482525      page(:radius).should render(%{<r:find url="/"><r:if_self>true</r:if_self></r:find>}).as('') 
     
    485528 
    486529  private 
    487      
     530 
    488531    def page(symbol = nil) 
    489532      if symbol.nil? 
     
    493536      end 
    494537    end 
    495      
     538 
    496539    def page_children_each_tags(attr = nil) 
    497540      attr = ' ' + attr unless attr.nil? 
    498541      "<r:children:each#{attr}><r:slug /> </r:children:each>" 
    499542    end 
    500      
     543 
    501544    def page_children_first_tags(attr = nil) 
    502545      attr = ' ' + attr unless attr.nil? 
    503546      "<r:children:first#{attr}><r:slug /></r:children:first>" 
    504547    end 
    505      
     548 
    506549    def page_children_last_tags(attr = nil) 
    507550      attr = ' ' + attr unless attr.nil? 
    508551      "<r:children:last#{attr}><r:slug /></r:children:last>" 
    509552    end 
    510      
     553 
    511554    def page_eachable_children(page) 
    512555      page.children.select(&:published?).reject(&:virtual)