2010-05-02 23:33:17 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
describe Layout do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
it 'should have a valid factory' do
|
|
|
|
Factory.build(:layout).should be_valid
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
## validations ##
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
it 'should validate presence of content_for_layout in value' do
|
|
|
|
layout = Factory.build(:layout, :value => 'without content_for_layout')
|
|
|
|
layout.should_not be_valid
|
|
|
|
layout.errors[:value].should == ["should contain 'content_for_layout' liquid tag"]
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
context 'dealing with page parts' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
before(:each) do
|
2010-05-09 12:44:53 +00:00
|
|
|
@layout = Factory.build(:layout)
|
2010-05-02 23:33:17 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
it 'should have 2 parts' do
|
2010-05-09 12:44:53 +00:00
|
|
|
@layout.send(:build_parts_from_value)
|
2010-07-20 10:15:53 +00:00
|
|
|
@layout.parts.size.should == 2
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
@layout.parts.first.name.should == 'Body'
|
|
|
|
@layout.parts.first.slug.should == 'layout'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 15:00:02 +00:00
|
|
|
@layout.parts.last.name.should == 'Left sidebar'
|
|
|
|
@layout.parts.last.slug.should == 'left_sidebar'
|
2010-05-02 23:33:17 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-09 12:44:53 +00:00
|
|
|
it 'should not add parts to pages if layout does not change' do
|
|
|
|
@layout.stubs(:value_changed?).returns(false)
|
|
|
|
page = Factory.build(:page, :layout => @layout, :site => nil)
|
|
|
|
page.expects(:update_parts!).never
|
|
|
|
@layout.pages << page
|
|
|
|
@layout.save
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-09 12:44:53 +00:00
|
|
|
it 'should add parts to pages if layout changes' do
|
2010-07-23 20:09:54 +00:00
|
|
|
@layout.value = @layout.value + "..."
|
2010-05-09 12:44:53 +00:00
|
|
|
page = Factory.build(:page, :layout => @layout, :site => nil)
|
|
|
|
page.expects(:update_parts!)
|
|
|
|
@layout.pages << page
|
|
|
|
@layout.save
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
context 'parsing liquid template' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
before(:each) do
|
|
|
|
@layout = Factory.build(:layout)
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
it 'should not raise an error if template is empty' do
|
|
|
|
@layout.template.should be_nil
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|