2010-06-16 14:43:29 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
describe Locomotive::Liquid::Drops::Contents do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
before(:each) do
|
2011-08-19 12:55:15 +00:00
|
|
|
# Reload the file (needed for spork)
|
|
|
|
load File.join(Rails.root, 'lib', 'locomotive', 'liquid', 'drops', 'contents.rb')
|
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
@site = Factory.build(:site)
|
|
|
|
@content_type = Factory.build(:content_type, :site => @site, :slug => 'projects')
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
it 'retrieves a content type from a slug' do
|
|
|
|
@site.content_types.expects(:where).with(:slug => 'projects')
|
|
|
|
render_template '{{ contents.projects }}'
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-07-01 00:15:45 +00:00
|
|
|
describe '#group_by' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
it 'orders contents' do
|
|
|
|
@site.content_types.stubs(:where).returns([@content_type])
|
|
|
|
@content_type.contents.klass.expects(:group_by_category).with(:ordered_contents)
|
|
|
|
render_template '{% for group in contents.projects.group_by_category %} {{ group.name }} {% endfor %}'
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
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
|
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
def render_template(template = '', assigns = {})
|
|
|
|
assigns = {
|
2010-10-12 15:26:05 +00:00
|
|
|
'contents' => Locomotive::Liquid::Drops::Contents.new
|
2010-06-16 14:43:29 +00:00
|
|
|
}.merge(assigns)
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-10-12 15:26:05 +00:00
|
|
|
Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { :site => @site }))
|
2010-06-16 14:43:29 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-08-19 12:55:15 +00:00
|
|
|
def populate_content_type
|
|
|
|
@content_type.order_by = :_slug
|
|
|
|
@content_type.contents.build(:_slug => 'item1')
|
|
|
|
@content_type.contents.build(:_slug => 'item2')
|
|
|
|
@content_type.contents.build(:_slug => 'item3')
|
|
|
|
end
|
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|