Sha256: 88d2873a2b48958efef0d149ce3129a88cb98ce95d36b7a738ce7df1d41712d8

Contents?: true

Size: 1.45 KB

Versions: 21

Compression:

Stored size: 1.45 KB

Contents

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 %})

      @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 %})

      @list.expects(:filtered).with({ 'active' => true }, ['name', 'ASC']).returns(%w(a b))

      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 %})

      @list.expects(:filtered).with({ 'active' => true }, nil).returns(%w(a b))

      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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
locomotive_cms-2.5.4 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.5.3 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.5.2 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.5.1 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.5.0 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.5.0.rc3 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.5.0.rc2 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.5.0.rc1 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.4.1 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.4.0 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.3.1 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.3.0 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.2.3 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.2.2 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.2.1 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.2.0 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.1.4 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.1.3 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.1.2 spec/lib/locomotive/liquid/drops/content_entry_spec.rb
locomotive_cms-2.1.1 spec/lib/locomotive/liquid/drops/content_entry_spec.rb