engine/spec/lib/locomotive/liquid/drops/contents_spec.rb

61 lines
1.7 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Locomotive::Liquid::Drops::Contents do
before(:each) do
2011-08-25 21:28:56 +00:00
@site = FactoryGirl.build(:site)
@content_type = FactoryGirl.build(:content_type, :site => @site, :slug => 'projects')
end
it 'retrieves a content type from a slug' do
@site.content_types.expects(:where).with(:slug => 'projects')
render_template '{{ contents.projects }}'
end
describe '#group_by' do
it 'orders entries' do
@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
2011-08-19 12:55:15 +00:00
describe Locomotive::Liquid::Drops::ProxyCollection do
before(:each) do
populate_content_type
@proxy_collection = Locomotive::Liquid::Drops::ProxyCollection.new(@content_type)
@proxy_collection.context = {}
end
it 'provides its size like an Array' do
@proxy_collection.size.should == @proxy_collection.length
end
it 'can be enumerated using each_with_index' do
@proxy_collection.each_with_index do |item, index|
item._slug.should == "item#{index + 1}"
end
end
end
def render_template(template = '', assigns = {})
assigns = {
2010-10-12 15:26:05 +00:00
'contents' => Locomotive::Liquid::Drops::Contents.new
}.merge(assigns)
2010-10-12 15:26:05 +00:00
Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { :site => @site }))
end
2011-08-19 12:55:15 +00:00
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')
2011-08-19 12:55:15 +00:00
end
end