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

49 lines
1.5 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Locomotive::Liquid::Drops::ContentEntry do
before(:each) do
@list = mock('list')
@list.stubs(:all).returns(true)
@category = Locomotive::Liquid::Drops::ContentEntry.new(mock('category', :projects => @list))
end
context '#accessing a has_many relationship' do
it 'loops through the list' do
template = %({% for project in category.projects %}{{ project }},{% endfor %})
2012-03-28 15:33:20 +00:00
@list.expects(:ordered).returns(%w(a b))
render(template, { 'category' => @category }).should == 'a,b,'
end
it 'filters the list' do
template = %({% with_scope order_by: 'name ASC', active: true %}{% for project in category.projects %}{{ project }},{% endfor %}{% endwith_scope %})
2012-03-28 15:33:20 +00:00
@list.expects(:order_by).with(['name', 'ASC']).returns(%w(a b))
@list.expects(:where).with({ 'active' => true }).returns(@list)
render(template, { 'category' => @category }).should == 'a,b,'
end
it 'filters the list and uses the default order' do
template = %({% with_scope active: true %}{% for project in category.projects %}{{ project }},{% endfor %}{% endwith_scope %})
2012-03-28 15:33:20 +00:00
@list.expects(:ordered).returns(%w(a b))
@list.expects(:where).with({ 'active' => true }).returns(@list)
render(template, { 'category' => @category }).should == 'a,b,'
end
end
def render(template, assigns = {})
liquid_context = ::Liquid::Context.new(assigns, {}, {})
output = ::Liquid::Template.parse(template).render(liquid_context)
output.gsub(/\n\s{0,}/, '')
end
end