added .parent method to Page drop

This commit is contained in:
Rytis Lukoševičius 2011-08-14 11:34:08 +03:00
parent b23f2697e9
commit 025d5a7dda
3 changed files with 24 additions and 0 deletions

View File

@ -12,6 +12,10 @@ module Locomotive
def slug
self._source.templatized? ? self._source.content_type.slug.singularize : self._source.slug
end
def parent
@parent ||= self._source.parent.to_liquid
end
def children
@children ||= liquify(*self._source.children)

View File

@ -98,6 +98,14 @@ Factory.define :page do |p|
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
end
Factory.define :sub_page, :parent => :page do |p|
p.title 'Subpage'
p.slug 'subpage'
p.published true
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
p.parent { Page.where(:slug => "index").first || Factory(:page) }
end
## Snippets ##
Factory.define :snippet do |s|

View File

@ -40,6 +40,18 @@ describe Locomotive::Liquid::Drops::Page do
end
end
context '#parent' do
before(:each) do
@sub_page = Factory.build(:sub_page, :meta_keywords => 'Sub Libidinous, Angsty', :meta_description => "Sub Quite the combination.")
end
it 'renders title of parent page' do
content = render_template '{{ sub_page.parent.title }}', {'sub_page' => @sub_page}
content.should == "Home page"
end
end
context '#rendering page title' do