fix issue #186 (Liquid and throws errors)

did committed Apr 29, 2014
commit 8a354dac780f8ffbe387353336cdcd84a986d47c
Showing 3 changed files with 14 additions and 3 deletions
locomotive/wagon/liquid/drops/content_types.rb b/lib/locomotive/wagon/liquid/drops/content_types.rb +4 -2
@@ @@ -104,8 +104,10 @@ module Locomotive
return unless @collection.blank?
# define the default order_by if not set
- if @context['with_scope'] && !@context['with_scope']['order_by'].blank? && !%w(manually position).include?(@content_type.order_by)
- @context['with_scope']['order_by'] = @content_type.order_by + '.' + @content_type.order_direction
+ if @context['with_scope'] && @context['with_scope']['order_by'].blank? && !%w(manually position).include?(@content_type.order_by)
+ field = @content_type.order_by || 'created_at'
+ direction = @content_type.order_direction || 'asc'
+ @context['with_scope']['order_by'] = "#{field}.#{direction}"
end
@collection = apply_scope(@content_type.entries)
spec/fixtures/default/app/views/pages/filtered.liquid.haml +5 -1
@@ @@ -5,10 +5,14 @@ title: Various uses of the with_scope tag
{% assign end = '2012-06-10 23:59:59' %}
{% assign prices = '5.0,5.5' | split: ',' | map: 'to_f' %}
- {% with_scope date.gte: begin, date.lte: end, city: /Kansas/, state.ne: 'Illinois', tags: 'awesome', tags.nin: 'bad', price.in: prices %}
+ {% with_scope date.gte: begin, date.lte: end, city: /Kansas/, state.ne: 'Illinois', tags: 'awesome', tags.nin: 'bad', price.in: prices, order_by: 'price.desc' %}
events={{ contents.events.count }}.
{% endwith_scope %}
+ {% with_scope tags.in: 'awesome', order_by: 'price.desc' %}
+ first event={{ contents.events.first.place }}.
+ {% endwith_scope %}
+
{% assign featured = false %}
{% with_scope featured: featured %}
spec/integration/server/with_scope_spec.rb +5 -0
@@ @@ -22,4 +22,9 @@ describe 'Complex with_scope conditions' do
last_response.body.should =~ /bands=2./
end
+ it 'returns the first band in the right order' do
+ get '/filtered'
+ last_response.body.should =~ /first event=Browne's Market/
+ end
+
end
\ No newline at end of file