2011-04-29 20:10:13 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Locomotive::Liquid::Drops::Content do
|
|
|
|
|
|
|
|
before(:each) do
|
2011-08-25 21:28:56 +00:00
|
|
|
@site = FactoryGirl.build(:site)
|
|
|
|
content_type = FactoryGirl.build(:content_type)
|
2011-12-05 14:29:32 +00:00
|
|
|
content_type.contents_custom_fields.build :label => 'anything', :kind => 'string'
|
|
|
|
content_type.contents_custom_fields.build :label => 'published_at', :kind => 'date'
|
2011-07-01 00:15:45 +00:00
|
|
|
@content = content_type.contents.build({
|
|
|
|
:meta_keywords => 'Libidinous, Angsty',
|
|
|
|
:meta_description => "Quite the combination.",
|
|
|
|
:published_at => Date.today })
|
2011-04-29 20:10:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'meta_keywords' do
|
|
|
|
subject { render_template('{{ content.meta_keywords }}') }
|
|
|
|
it { should == @content.meta_keywords }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'meta_description' do
|
|
|
|
subject { render_template('{{ content.meta_description }}') }
|
|
|
|
it { should == @content.meta_description }
|
|
|
|
end
|
|
|
|
|
2011-07-01 00:15:45 +00:00
|
|
|
describe 'date comparaison' do
|
|
|
|
|
|
|
|
describe 'older than' do
|
|
|
|
subject { @content.published_at = 3.days.ago; render_template('{% if content.published_at < today %}In the past{% endif %}') }
|
|
|
|
it { should == 'In the past' }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'more recent than' do
|
2011-07-05 22:33:34 +00:00
|
|
|
subject { @content.published_at = (Time.now + 1.days); render_template('{% if content.published_at > today %}In the future{% endif %}') }
|
2011-07-01 00:15:45 +00:00
|
|
|
it { should == 'In the future' }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'equality' do
|
|
|
|
subject { render_template('{% if content.published_at == today %}Today{% endif %}') }
|
|
|
|
it { should == 'Today' }
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-04-29 20:10:13 +00:00
|
|
|
def render_template(template = '', assigns = {})
|
2011-07-01 00:15:45 +00:00
|
|
|
assigns = { 'content' => @content, 'today' => Date.today }.merge(assigns)
|
2011-04-29 20:10:13 +00:00
|
|
|
Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { :site => @site }))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|