Changeset 824
- Timestamp:
- 04/19/08 11:35:55 (4 months ago)
- Files:
-
- trunk/radiant/spec/models/standard_tags_spec.rb (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/radiant/spec/models/standard_tags_spec.rb
r815 r824 3 3 describe "Standard Tags" do 4 4 scenario :users_and_pages, :file_not_found, :snippets 5 5 6 6 specify '<r:page> should allow access to the current page' do 7 7 page(:home) … … 9 9 page.should render(%{<r:find url="/radius"><r:title /> | <r:page:title /></r:find>}).as('Radius | Home') 10 10 end 11 11 12 12 specify '<r:breadcrumb>, <r:slug>, <r:title>, and <r:url>' do 13 13 page(:home) … … 17 17 end 18 18 end 19 19 20 20 specify '<r:url> with a relative URL root should scope to the relative root' do 21 21 page(:home).should render("<r:url />").with_relative_root("/foo").as("/foo/") 22 22 end 23 23 24 24 specify '<r:parent>' do 25 25 page(:parent) … … 28 28 page.should render('<r:children:each><r:parent:title /></r:children:each>').as(@page.title * page.children.count) 29 29 end 30 30 31 31 specify '<r:if_parent>' do 32 32 page.should render('<r:if_parent>true</r:if_parent>').as('true') 33 33 page(:home).should render('<r:if_parent>true</r:if_parent>').as('') 34 34 end 35 35 36 36 specify '<r:unless_parent>' do 37 37 page.should render('<r:unless_parent>true</r:unless_parent>').as('') 38 38 page(:home).should render('<r:unless_parent>true</r:unless_parent>').as('true') 39 39 end 40 40 41 41 specify '<r:if_children>' do 42 42 page(:home).should render('<r:if_children>true</r:if_children>').as('true') 43 43 page(:childless).should render('<r:if_children>true</r:if_children>').as('') 44 44 end 45 45 46 46 specify '<r:unless_children>' do 47 47 page(:home).should render('<r:unless_children>true</r:unless_children>').as('') 48 48 page(:childless).should render('<r:unless_children>true</r:unless_children>').as('true') 49 49 end 50 50 51 51 specify '<r:children:each>' do 52 52 page(:parent) 53 53 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 ') 55 55 end 56 56 specify '<r:children:each> order attributes' do … … 69 69 end 70 70 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 ') 72 72 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 ') 73 73 end … … 92 92 page.should render(page_children_each_tags(%{order="asdf"})).with_error(message) 93 93 end 94 94 95 95 specify '<r:children:each:header>' do 96 96 tags = '<r:children:each><r:header>[<r:date format="%b/%y" />] </r:header><r:slug /> </r:children:each>' … … 113 113 page(:news).should render(tags).as(expected) 114 114 end 115 115 116 116 specify '<r:children:count>' do 117 117 page(:parent).should render('<r:children:count />').as('3') 118 118 end 119 119 120 120 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 123 123 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') 125 125 page.should render(page_children_first_tags(%{limit="5"})).as('a') 126 126 page.should render(page_children_first_tags(%{offset="3" limit="5"})).as('d') … … 132 132 page(:first).should render('<r:children:first:title />').as('') 133 133 end 134 134 135 135 specify '<r:children:last>' do 136 136 page(:parent).should render('<r:children:last:title />').as('Child 3') … … 147 147 page(:first).should render('<r:children:last:title />').as('') 148 148 end 149 149 150 150 specify '<r:content>' do 151 151 page.should render('<r:content />').as('Assorted body.') … … 177 177 page(:parent).should render('<r:children:each><r:content /> </r:children:each>').as(expected) 178 178 end 179 179 180 180 specify '<r:if_content> without "part" attribute' do 181 181 page.should render('<r:if_content>true</r:if_content>').as('true') … … 187 187 page.should render('<r:if_content part="asdf">true</r:if_content>').as('') 188 188 end 189 189 190 190 specify '<r:unless_content> without "part" attribute' do 191 191 page.should render('<r:unless_content>false</r:unless_content>').as('') … … 197 197 page.should render('<r:unless_content part="asdf">false</r:unless_content>').as('false') 198 198 end 199 199 200 200 specify '<r:author>' do 201 201 page.should render('<r:author />').as('Admin') … … 204 204 page(:no_user).should render('<r:author />').as('') 205 205 end 206 206 207 207 specify '<r:date>' do 208 208 page(:dated) … … 228 228 page.should render(%Q(<r:date format="#{format}" />) ).as(expected) 229 229 end 230 230 231 231 specify '<r:link>' do 232 232 page.should render('<r:link />').as('<a href="/assorted/">Assorted</a>') … … 249 249 page(:assorted).should render('<r:link />').with_relative_root('/foo').as('<a href="/foo/assorted/">Assorted</a>') 250 250 end 251 251 252 252 specify '<r:snippet>' do 253 253 page.should render('<r:snippet name="first" />').as('test') … … 268 268 page(:child).should render('<r:snippet name="recursive" />').as("Great GrandchildGrandchildChild") 269 269 end 270 270 271 271 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 275 275 specify '<r:comment>' do 276 276 page.should render('just a <r:comment>small </r:comment>test').as('just a test') 277 277 end 278 278 279 279 specify '<r:navigation> simple case' do 280 280 tags = %{<r:navigation urls="Home: / | Assorted: /assorted/ | Parent: /parent/"> … … 326 326 page(:radius).should render(tags).as(expected) 327 327 end 328 329 328 329 330 330 specify '<r:find>' do 331 331 page.should render(%{<r:find url="/parent/child/"><r:title /></r:find>}).as('Child') … … 346 346 page(:great_grandchild).should render(%{<r:find url="../../../child-2"><r:title/></r:find>}).as("Child 2") 347 347 end 348 348 349 349 specify '<r:escape_html>' do 350 350 page.should render('<r:escape_html><strong>a bold move</strong></r:escape_html>').as('<strong>a bold move</strong>') 351 351 end 352 352 353 353 specify '<r:rfc1123_date>' do 354 354 page(:dated).should render('<r:rfc1123_date />').as('Wed, 11 Jan 2006 00:00:00 GMT') 355 355 end 356 356 357 357 specify '<r:breadcrumbs>' do 358 358 expected = %{<a href="/">Home</a> > <a href="/parent/">Parent</a> > <a href="/parent/child/">Child</a> > <a href="/parent/child/grandchild/">Grandchild</a> > Great Grandchild} … … 371 371 page(:assorted).should render('<r:breadcrumbs />').with_relative_root('/foo').as(expected) 372 372 end 373 373 374 374 specify '<r:if_url> with "matches" attribute' do 375 375 page.should render('<r:if_url matches="a.sorted/$">true</r:if_url>').as('true') … … 393 393 page.should render('<r:if_url>test</r:if_url>').with_error("`if_url' tag must contain a `matches' attribute.") 394 394 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 405 412 specify '<r:unless_url> without "ignore_case" attribute' do 406 413 page.should render('<r:unless_url matches="asSorted/$">true</r:unless_url>').as('') … … 415 422 page.should render('<r:unless_url>test</r:unless_url>').with_error("`unless_url' tag must contain a `matches' attribute.") 416 423 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 466 509 describe "<r:if_ancestor_or_self>" do 467 510 it "should render the tag's content when the current page is an ancestor of tag.locals.page" do 468 511 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 471 514 it "should not render the tag's content when current page is not an ancestor of tag.locals.page" do 472 515 page(:parent).should render(%{<r:find url="/radius"><r:if_ancestor_or_self>true</r:if_ancestor_or_self></r:find>}).as('') 473 516 end 474 517 end 475 518 476 519 describe "<r:if_self>" do 477 520 it "should render the tag's content when the current page is the same as the local contextual page" do 478 521 page(:home).should render(%{<r:find url="/"><r:if_self>true</r:if_self></r:find>}).as('true') 479 522 end 480 523 481 524 it "should not render the tag's content when the current page is not the same as the local contextual page" do 482 525 page(:radius).should render(%{<r:find url="/"><r:if_self>true</r:if_self></r:find>}).as('') … … 485 528 486 529 private 487 530 488 531 def page(symbol = nil) 489 532 if symbol.nil? … … 493 536 end 494 537 end 495 538 496 539 def page_children_each_tags(attr = nil) 497 540 attr = ' ' + attr unless attr.nil? 498 541 "<r:children:each#{attr}><r:slug /> </r:children:each>" 499 542 end 500 543 501 544 def page_children_first_tags(attr = nil) 502 545 attr = ' ' + attr unless attr.nil? 503 546 "<r:children:first#{attr}><r:slug /></r:children:first>" 504 547 end 505 548 506 549 def page_children_last_tags(attr = nil) 507 550 attr = ' ' + attr unless attr.nil? 508 551 "<r:children:last#{attr}><r:slug /></r:children:last>" 509 552 end 510 553 511 554 def page_eachable_children(page) 512 555 page.children.select(&:published?).reject(&:virtual)
