require File.dirname(__FILE__) + '/../spec_helper' describe Orthor::Site, "orthor site dsl" do describe "base attributes" do before(:all) do Orthor::Site.define do cache_for 7200 layout :application end end it 'should allow a http cache time to be set' do Orthor::Site.cache_for.should == 7200 end it 'should allow setting of a layout' do Orthor::Site.layout.should == :application end [ :categories, :feeds, :pages, :static_pages, :queries ].each do |collection| it "should have a #{collection} array" do Orthor::Site.send(collection).should == [] end end end describe "default values" do before(:all) do Orthor::Site.define do end end it 'should set a default cache for time' do Orthor::Site.cache_for.should == 0 end it 'should set a default layout' do Orthor::Site.layout.should == :orthor_layout end end describe "children" do before(:all) do Orthor::Site.define do page "/", :id => "home" query "/news", :id => "latest-news" category "/writings" do page "/writings/why" feed "/writings.rss", :id => "our-writings" query "/latest", :id => "latest-article" category "/writings/announcements" do page "/3rd-level" end end end @category_1 = Orthor::Site.categories.first @category_2 = @category_1.categories.first @feed = @category_1.feeds.first @page_1 = Orthor::Site.pages.first @page_2 = @category_1.pages.first @page_3 = @category_2.pages.first @query = Orthor::Site.queries.first @query_1 = @category_1.queries.first end it 'should return all resources defined in the dsl' do Orthor::Site.resources.length.should == 8 Orthor::Site.resources.should include(@category_1) Orthor::Site.resources.should include(@category_2) Orthor::Site.resources.should include(@feed) Orthor::Site.resources.should include(@page_1) Orthor::Site.resources.should include(@page_2) Orthor::Site.resources.should include(@page_3) Orthor::Site.resources.should include(@query) Orthor::Site.resources.should include(@query_1) end end describe "categories" do before(:all) do Orthor::Site.define do category "/writings", :id => "blog-writings", :template => :writing, :cache_for => 900, :view => "writings/index", :page_path => "/writings/:id" do page "/writings/why" feed "/writings.rss", :id => "our-writings", :name => "Our Writings" category "/writings/announcements", :page_path => "/writings/announcements/:id", :cache_for => 300, :template => :announcement do page "/3rd-level" end end end @category = Orthor::Site.categories.first @category_2 = Orthor::Site.categories.first.categories.first end it "should have one category at the top level" do Orthor::Site.categories.length.should == 1 end it "should allow you to set a custom view file" do @category.view.should == "writings/index" end it "should allow setting of a template" do @category.template.should == :writing @category_2.template.should == :announcement end it "should support categories in categories" do @category.categories.length.should == 1 end it "should support pages in categories" do @category.pages.length.should == 1 end it "id should be inferred from the path if none is given" do @category_2.id.should == "announcements" end it "should support pages in categories in categories" do @category_2.pages.length.should == 1 end it "should support a child page path attribute" do @category.page_path.should == "/writings/:id" end it "should support setting the orthor id" do @category.id.should == "blog-writings" end it "should support specifying http cache time" do @category.cache_for.should == 900 @category_2.cache_for.should == 300 end it "should support feeds specific to categories" do @category.feeds.length.should == 1 end end describe "pages" do before(:all) do Orthor::Site.define do page "/about-us", :id => "about" page "/history", :id => "our-history", :template => :basic page "/contact" page "/", :cache_for => 3600, :id => "homepage", :view => "public/home", :template => :brief end @page_1 = Orthor::Site.pages[0] @page_2 = Orthor::Site.pages[1] @page_3 = Orthor::Site.pages[2] @page_4 = Orthor::Site.pages[3] end it 'should support multiple pages' do Orthor::Site.pages.length.should == 4 end it 'should support storing a page path' do @page_1.path.should == "/about-us" @page_4.path.should == "/" end it "should allow setting of template" do @page_2.template.should == :basic @page_4.template.should == :brief end it "should be able to specify a view to render" do @page_4.view.should == "public/home" @page_1.view.should be_nil end it "id should be inferred from the path if none is given" do @page_3.id.should == "contact" end it "id should be 2nd argument if any is given" do @page_1.id.should == "about" end it 'should allow setting specific http cache lengths' do @page_1.cache_for.should == 0 # sites default @page_4.cache_for.should == 3600 end it 'should support setting an id' do @page_4.id.should == "homepage" end end describe "queries" do before(:all) do Orthor::Site.define do query "/news", :id => "news", :template => :query query "/latest-release" end @query_1 = Orthor::Site.queries.first @query_2 = Orthor::Site.queries.last end it "should support multiple queries" do Orthor::Site.queries.length.should == 2 end it "should support setting a template" do @query_1.template.should == :query end it "should support setting a query id" do @query_1.id.should == "news" end it "should infer id from path when none is given" do @query_2.id.should == "latest-release" end end describe "with layout" do before(:all) do Orthor::Site.define do with_template :spike do page "/" category "/news" do template :spike_v2 end end with_template :jet do query "/latest-news" page "/about" end end @page_1 = Orthor::Site.pages[0] @page_2 = Orthor::Site.pages[1] @query = Orthor::Site.queries[0] @category = Orthor::Site.categories[0] end it "should respect with_template" do @page_1.template.should == :spike @page_2.template.should == :jet @query.template.should == :jet end it "should allow with_template to be overriden" do @category.template.should == :spike_v2 end end describe "feeds" do before(:all) do Orthor::Site.define do feed "/blog.rss", :id => "orthor-blog", :name => "Our blag" feed "/bookmarks.rss", :name => "Our bookmarks" end @feed_1 = Orthor::Site.feeds.first @feed_2 = Orthor::Site.feeds.last end it "should support multiple feeds" do Orthor::Site.feeds.length.should == 2 end it "should support setting a feeds id" do @feed_1.id.should == "orthor-blog" end it "id should be inferred from the path if none is given" do @feed_2.id.should == "bookmarks.rss" end it 'should support setting a feeds name' do @feed_1.name.should == "Our blag" @feed_2.name.should == "Our bookmarks" end it 'should store the given path' do @feed_1.path.should == "/blog.rss" @feed_2.path.should == "/bookmarks.rss" end end describe 'static pages' do before(:all) do Orthor::Site.define do static_page "/about-us" static_page "/contact" static_page "/", :cache_for => 3600, :view => :blah, :controller => :asdf end @page_1 = Orthor::Site.static_pages[0] @page_2 = Orthor::Site.static_pages[1] @page_3 = Orthor::Site.static_pages[2] end it 'should support multiple pages' do Orthor::Site.static_pages.length.should == 3 end it 'should support setting action' do @page_3.view.should == :blah end it 'should support setting controller' do @page_3.controller.should == :asdf end it 'should support storing page path' do @page_1.path.should == "/about-us" @page_3.path.should == "/" end it 'should allow setting specific http cache lengths' do @page_3.cache_for.should == 3600 end end describe 'finding by path' do before(:all) do Orthor::Site.define do page "/" category "/writings", :page_path => "/writings/:id" do page "/writings/why" feed "/writings.rss", :id => "our-writings", :name => "Our Writings" category "/writings/announcements", :page_path => "/writings/announcements/:id" do page "/3rd-level" end end end @home = Orthor::Site.pages.first @writings = Orthor::Site.categories.first @feed = @writings.feeds.first @announcements = @writings.categories.first @third_level = @announcements.pages.first end it 'should be able to find pages by path' do Orthor::Site.find_resource_by_path("/").should == @home Orthor::Site.find_resource_by_path("/3rd-level").should == @third_level end it 'should be able to find feeds by path' do Orthor::Site.find_resource_by_path("/writings.rss").should == @feed end it 'should be able to find categories by path' do Orthor::Site.find_resource_by_path("/writings").should == @writings Orthor::Site.find_resource_by_path("/writings/announcements").should == @announcements end it 'should find the parent category by page path' do Orthor::Site.find_resource_by_page_path("/writings/announcements/first-entry", "first-entry").should == @announcements Orthor::Site.find_resource_by_page_path("/writings/first-writing", "first-writing").should == @writings end end describe 'meta data' do before(:all) do Orthor::Site.define do keywords "asdf, bob, frank" description "a site being defined" page "/features", :keywords => "features", :description => "feature page description" category "/news", :keywords => "category", :description => "category description" page "/ihavenothing" end @page_with_meta = Orthor::Site.pages.first @category = Orthor::Site.categories.first @page_no_meta = Orthor::Site.pages.last end it 'should allow setting of meta data at a site level' do Orthor::Site.keywords.should == "asdf, bob, frank" Orthor::Site.description.should == "a site being defined" end it 'should allow setting of meta data at a page level' do @page_with_meta.keywords.should == "features" @page_with_meta.description.should == "feature page description" end it 'should allow setting of meta data at a category level' do @category.keywords.should == "category" @category.description.should == "category description" end it 'should default to sites meta data if none given' do @page_no_meta.keywords.should == "asdf, bob, frank" @page_no_meta.description.should == "a site being defined" end end end