2010-06-21 15:46:17 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
describe Locomotive::Liquid::Drops::Page do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
before(:each) do
|
2011-08-25 21:28:56 +00:00
|
|
|
site = FactoryGirl.build(:site)
|
|
|
|
@home = FactoryGirl.build(:page, :site => site, :meta_keywords => 'Libidinous, Angsty', :meta_description => "Quite the combination.")
|
2010-06-21 15:46:17 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-01-18 00:19:18 +00:00
|
|
|
context '#rendering tree' do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@home.stubs(:children).returns([
|
2011-11-26 06:24:34 +00:00
|
|
|
Locomotive::Page.new(:title => 'Child #1'),
|
|
|
|
Locomotive::Page.new(:title => 'Child #2'),
|
|
|
|
Locomotive::Page.new(:title => 'Child #3')
|
2011-01-18 00:19:18 +00:00
|
|
|
])
|
|
|
|
@home.children.last.stubs(:children).returns([
|
2011-11-26 06:24:34 +00:00
|
|
|
Locomotive::Page.new(:title => 'Child #3.1'),
|
|
|
|
Locomotive::Page.new(:title => 'Child #3.2')
|
2011-01-18 00:19:18 +00:00
|
|
|
])
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
context '#children' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
it 'renders title of all children pages' do
|
|
|
|
content = render_template '{% for child in home.children %}{{ child.title }},{% endfor %}'
|
|
|
|
content.should == 'Child #1,Child #2,Child #3,'
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
context '#sub children' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
it 'renders title of all sub children pages' do
|
|
|
|
content = render_template '{% for child in home.children.last.children %}{{ child.title }},{% endfor %}'
|
|
|
|
content.should == 'Child #3.1,Child #3.2,'
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-08-14 08:34:08 +00:00
|
|
|
context '#parent' do
|
|
|
|
before(:each) do
|
2011-08-25 21:28:56 +00:00
|
|
|
@sub_page = FactoryGirl.build(:sub_page, :meta_keywords => 'Sub Libidinous, Angsty', :meta_description => "Sub Quite the combination.")
|
2011-08-14 08:34:08 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-08-14 08:34:08 +00:00
|
|
|
it 'renders title of parent page' do
|
2012-02-16 01:45:14 +00:00
|
|
|
content = render_template '{{ sub_page.parent.title }}', { 'sub_page' => @sub_page }
|
2011-08-14 08:34:08 +00:00
|
|
|
content.should == "Home page"
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-08-14 08:34:08 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-08-14 08:34:57 +00:00
|
|
|
context '#breadcrumbs' do
|
|
|
|
before(:each) do
|
2011-08-25 21:28:56 +00:00
|
|
|
@sub_page = FactoryGirl.build(:sub_page, :meta_keywords => 'Sub Libidinous, Angsty', :meta_description => "Sub Quite the combination.")
|
2012-02-16 01:45:14 +00:00
|
|
|
@sub_page.stubs(:ancestors_and_self).returns([FactoryGirl.build(:page), @sub_page])
|
2011-08-14 08:34:57 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-08-14 08:34:57 +00:00
|
|
|
it 'renders breadcrumbs of current page' do
|
2012-02-16 01:45:14 +00:00
|
|
|
content = render_template '{% for crumb in sub_page.breadcrumbs %}{{ crumb.title }},{% endfor %}', { 'sub_page' => @sub_page }
|
2011-08-14 08:34:57 +00:00
|
|
|
content.should == 'Home page,Subpage,'
|
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-01-18 00:19:18 +00:00
|
|
|
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
|
2011-08-25 21:28:56 +00:00
|
|
|
templatized = FactoryGirl.build(:page, :title => 'Lorem ipsum template', :templatized => true)
|
2011-01-18 00:19:18 +00:00
|
|
|
|
2012-02-16 01:45:14 +00:00
|
|
|
content_entry = Locomotive::Liquid::Drops::ContentEntry.new(mock('content_entry', :_label => 'Locomotive rocks !'))
|
2011-01-18 00:19:18 +00:00
|
|
|
|
2011-12-22 23:45:32 +00:00
|
|
|
render_template('{{ page.title }}', 'page' => templatized, 'content_entry' => content_entry).should == 'Locomotive rocks !'
|
2011-01-18 00:19:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-12-22 23:45:32 +00:00
|
|
|
|
2012-03-06 21:55:45 +00:00
|
|
|
context '#rendering page with editable_elements' do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@site = FactoryGirl.create(:site)
|
|
|
|
@home = @site.pages.root.first
|
|
|
|
@home.update_attributes :raw_template => "{% block body %}{% editable_short_text 'body' %}Lorem ipsum{% endeditable_short_text %}{% endblock %}"
|
|
|
|
@home.editable_elements.first.content = 'Lorem ipsum'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the text of the editable field' do
|
|
|
|
render_template('{{ home.body }}').should == 'Lorem ipsum'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-10-04 01:35:40 +00:00
|
|
|
describe 'published?' do
|
|
|
|
subject { render_template('{{ home.published? }}') }
|
|
|
|
it { should == @home.published?.to_s }
|
|
|
|
end
|
2011-12-22 23:45:32 +00:00
|
|
|
|
2011-10-04 01:35:40 +00:00
|
|
|
describe 'listed?' do
|
|
|
|
subject { render_template('{{ home.listed? }}') }
|
|
|
|
it { should == @home.listed?.to_s }
|
|
|
|
end
|
2011-01-18 00:19:18 +00:00
|
|
|
|
2011-04-29 20:10:13 +00:00
|
|
|
describe 'meta_keywords' do
|
|
|
|
subject { render_template('{{ home.meta_keywords }}') }
|
|
|
|
it { should == @home.meta_keywords }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'meta_description' do
|
|
|
|
subject { render_template('{{ home.meta_description }}') }
|
|
|
|
it { should == @home.meta_description }
|
|
|
|
end
|
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
def render_template(template = '', assigns = {})
|
|
|
|
assigns = {
|
|
|
|
'home' => @home
|
|
|
|
}.merge(assigns)
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
Liquid::Template.parse(template).render assigns
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|