add tests

This commit is contained in:
dinedine 2011-01-18 01:19:18 +01:00
parent bc32848f6a
commit d5464aa782
3 changed files with 41 additions and 14 deletions

View File

@ -34,6 +34,10 @@ class ContentInstance
self.content_type.site_id
end
def highlighted_field_value
self.send(self.content_type.highlighted_field._name)
end
def visible?
self._visible || self._visible.nil?
end
@ -60,10 +64,6 @@ class ContentInstance
Locomotive::Liquid::Drops::Content.new(self)
end
def highlighted_field_value
self.send(self.content_type.highlighted_field._name)
end
protected
def set_slug

View File

@ -4,18 +4,21 @@ describe Locomotive::Liquid::Drops::Page do
before(:each) do
@home = Factory.build(:page)
@home.stubs(:children).returns([
Page.new(:title => 'Child #1'),
Page.new(:title => 'Child #2'),
Page.new(:title => 'Child #3')
])
@home.children.last.stubs(:children).returns([
Page.new(:title => 'Child #3.1'),
Page.new(:title => 'Child #3.2')
])
end
context '#rendering' do
context '#rendering tree' do
before(:each) do
@home.stubs(:children).returns([
Page.new(:title => 'Child #1'),
Page.new(:title => 'Child #2'),
Page.new(:title => 'Child #3')
])
@home.children.last.stubs(:children).returns([
Page.new(:title => 'Child #3.1'),
Page.new(:title => 'Child #3.2')
])
end
context '#children' do
@ -37,6 +40,22 @@ describe Locomotive::Liquid::Drops::Page do
end
context '#rendering page title' do
it 'renders the title of a normal page' do
render_template('{{ home.title }}').should == 'Home page'
end
it 'renders the content instance highlighted field instead for a templatized page' do
templatized = Factory.build(:page, :title => 'Lorem ipsum template', :templatized => true)
content_instance = Locomotive::Liquid::Drops::Content.new(mock('content_instance', :highlighted_field_value => 'Locomotive rocks !'))
render_template('{{ page.title }}', 'page' => templatized, 'content_instance' => content_instance).should == 'Locomotive rocks !'
end
end
def render_template(template = '', assigns = {})
assigns = {
'home' => @home

View File

@ -52,6 +52,14 @@ describe ContentInstance do
end
describe '#requirements' do
it 'has public access to the highlighted field value' do
build_content.highlighted_field_value.should == 'Locomotive'
end
end
def build_content(options = {})
@content_type.contents.build({ :title => 'Locomotive', :description => 'Lorem ipsum....' }.merge(options))
end