2011-03-02 01:11:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Locomotive::Liquid::Tags::Editable::Content do
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
Locomotive::Liquid::Tags::Editable::Content.any_instance.stubs(:end_tag).returns(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'syntax' do
|
|
|
|
|
|
|
|
it 'should have a valid syntax' do
|
|
|
|
["slug", "slug, inherit: true"].each do |markup|
|
|
|
|
lambda do
|
|
|
|
Locomotive::Liquid::Tags::Editable::Content.new('content', markup, ["{% content %}"], {})
|
|
|
|
end.should_not raise_error
|
|
|
|
end
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
context 'output' do
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
before :each do
|
2011-11-26 06:24:34 +00:00
|
|
|
Locomotive::EditableElement.any_instance.stubs(:content).returns("test string")
|
2011-03-02 01:11:40 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
context 'inheriting from a parent' do
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
before :each do
|
2011-08-25 21:28:56 +00:00
|
|
|
@parent = FactoryGirl.build(:page)
|
|
|
|
@child = FactoryGirl.build(:page)
|
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
@child.stubs(:parent).returns(@parent)
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
it 'should return the parents field if inherit is set' do
|
|
|
|
@element = @parent.editable_elements.create(:slug => 'test')
|
|
|
|
@child.stubs(:raw_template).returns("{% content test, inherit: true %}")
|
|
|
|
template = Liquid::Template.parse(@child.raw_template)
|
|
|
|
text = template.render!(liquid_context(:page => @child))
|
|
|
|
text.should match /test string/
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
it 'should raise an exception if it cant find the field' do
|
|
|
|
@child.stubs(:raw_template).returns("{% content test, inherit: true %}")
|
|
|
|
template = Liquid::Template.parse(@child.raw_template)
|
2011-08-25 21:28:56 +00:00
|
|
|
lambda do
|
2011-03-02 01:11:40 +00:00
|
|
|
template.render!(liquid_context(:page => @child))
|
|
|
|
end.should raise_error
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
after :each do
|
|
|
|
@parent.editable_elements.destroy_all
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
context 'reading from the same page' do
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
before :each do
|
2011-08-25 21:28:56 +00:00
|
|
|
@page = FactoryGirl.build(:page)
|
2011-03-02 01:11:40 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
it 'should return the previously defined field' do
|
|
|
|
@element = @page.editable_elements.create(:slug => 'test')
|
|
|
|
@page.stubs(:raw_template).returns("{% content test %}")
|
|
|
|
template = Liquid::Template.parse(@page.raw_template)
|
|
|
|
text = template.render!(liquid_context(:page => @page))
|
|
|
|
text.should match /test string/
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
it 'should raise an exception if it wasnt defined' do
|
|
|
|
@page.stubs(:raw_template).returns("{% content test %}")
|
|
|
|
template = Liquid::Template.parse(@page.raw_template)
|
|
|
|
lambda do
|
|
|
|
template.render!(liquid_context(:page => @page))
|
|
|
|
end.should raise_error
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
after :each do
|
|
|
|
@page.editable_elements.destroy_all
|
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
end
|
2011-08-25 21:28:56 +00:00
|
|
|
|
2011-03-02 01:11:40 +00:00
|
|
|
# ___ helpers methods ___ #
|
|
|
|
|
|
|
|
def liquid_context(options = {})
|
2011-08-25 21:28:56 +00:00
|
|
|
::Liquid::Context.new({}, {},
|
2011-03-02 01:11:40 +00:00
|
|
|
{
|
|
|
|
:page => options[:page]
|
|
|
|
}, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|