The content liquid drop is now contents (plural).
This commit is contained in:
parent
0f1b4f59d3
commit
0926286318
@ -1,50 +0,0 @@
|
|||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Locomotive::Liquid::Drops::Content do
|
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
@site = FactoryGirl.build(:site)
|
|
||||||
content_type = FactoryGirl.build(:content_type)
|
|
||||||
content_type.entries_custom_fields.build :label => 'anything', :type => 'string'
|
|
||||||
content_type.entries_custom_fields.build :label => 'published_at', :type => 'date'
|
|
||||||
@content = content_type.entries.build({
|
|
||||||
:meta_keywords => 'Libidinous, Angsty',
|
|
||||||
:meta_description => "Quite the combination.",
|
|
||||||
:published_at => Date.today })
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
|
||||||
subject { @content.published_at = (Time.now + 1.days); render_template('{% if content.published_at > today %}In the future{% endif %}') }
|
|
||||||
it { should == 'In the future' }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'equality' do
|
|
||||||
subject { render_template('{% if content.published_at == today %}Today{% endif %}') }
|
|
||||||
it { should == 'Today' }
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_template(template = '', assigns = {})
|
|
||||||
assigns = { 'content' => @content, 'today' => Date.today }.merge(assigns)
|
|
||||||
Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { :site => @site }))
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
@ -4,57 +4,47 @@ describe Locomotive::Liquid::Drops::Contents do
|
|||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@site = FactoryGirl.build(:site)
|
@site = FactoryGirl.build(:site)
|
||||||
@content_type = FactoryGirl.build(:content_type, :site => @site, :slug => 'projects')
|
content_type = FactoryGirl.build(:content_type)
|
||||||
|
content_type.entries_custom_fields.build :label => 'anything', :type => 'string'
|
||||||
|
content_type.entries_custom_fields.build :label => 'published_at', :type => 'date'
|
||||||
|
@content = content_type.entries.build({
|
||||||
|
:meta_keywords => 'Libidinous, Angsty',
|
||||||
|
:meta_description => "Quite the combination.",
|
||||||
|
:published_at => Date.today })
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'retrieves a content type from a slug' do
|
describe 'meta_keywords' do
|
||||||
@site.content_types.expects(:where).with(:slug => 'projects')
|
subject { render_template('{{ content.meta_keywords }}') }
|
||||||
render_template '{{ contents.projects }}'
|
it { should == @content.meta_keywords }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#group_by' do
|
describe 'meta_description' do
|
||||||
|
subject { render_template('{{ content.meta_description }}') }
|
||||||
it 'orders entries' do
|
it { should == @content.meta_description }
|
||||||
@site.content_types.stubs(:where).returns([@content_type])
|
|
||||||
@content_type.entries.klass.expects(:group_by_select_option).with(:ordered_entries)
|
|
||||||
render_template '{% for group in contents.projects.group_by_category %} {{ group.name }} {% endfor %}'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Locomotive::Liquid::Drops::ProxyCollection do
|
describe 'date comparaison' do
|
||||||
|
|
||||||
before(:each) do
|
describe 'older than' do
|
||||||
populate_content_type
|
subject { @content.published_at = 3.days.ago; render_template('{% if content.published_at < today %}In the past{% endif %}') }
|
||||||
@proxy_collection = Locomotive::Liquid::Drops::ProxyCollection.new(@content_type)
|
it { should == 'In the past' }
|
||||||
@proxy_collection.context = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'provides its size like an Array' do
|
describe 'more recent than' do
|
||||||
@proxy_collection.size.should == @proxy_collection.length
|
subject { @content.published_at = (Time.now + 1.days); render_template('{% if content.published_at > today %}In the future{% endif %}') }
|
||||||
|
it { should == 'In the future' }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can be enumerated using each_with_index' do
|
describe 'equality' do
|
||||||
@proxy_collection.each_with_index do |item, index|
|
subject { render_template('{% if content.published_at == today %}Today{% endif %}') }
|
||||||
item._slug.should == "item#{index + 1}"
|
it { should == 'Today' }
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_template(template = '', assigns = {})
|
def render_template(template = '', assigns = {})
|
||||||
assigns = {
|
assigns = { 'content' => @content, 'today' => Date.today }.merge(assigns)
|
||||||
'contents' => Locomotive::Liquid::Drops::Contents.new
|
|
||||||
}.merge(assigns)
|
|
||||||
|
|
||||||
Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { :site => @site }))
|
Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { :site => @site }))
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate_content_type
|
|
||||||
@content_type.order_by = :_slug
|
|
||||||
@content_type.entries.build(:_slug => 'item1')
|
|
||||||
@content_type.entries.build(:_slug => 'item2')
|
|
||||||
@content_type.entries.build(:_slug => 'item3')
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user