with_scope also takes care of order_by (pull request #278)
This commit is contained in:
parent
4cccff065a
commit
7ab8110e41
@ -55,7 +55,8 @@ module Locomotive
|
||||
end
|
||||
|
||||
def ordered_entries(conditions = {})
|
||||
self.entries.order_by([order_by_definition]).where(conditions)
|
||||
_order_by_definition = (conditions || {}).delete(:order_by).try(:split) || self.order_by_definition
|
||||
self.entries.order_by([_order_by_definition]).where(conditions)
|
||||
end
|
||||
|
||||
def groupable?
|
||||
|
@ -5,4 +5,4 @@ Feature: Has Many Association
|
||||
|
||||
Scenario: Paginating a has many association
|
||||
Given I have a site set up
|
||||
Then I should be able to view a paginaed list of a has many association
|
||||
Then I should be able to view a paginated list of a has many association
|
||||
|
@ -56,7 +56,7 @@ Given %r{^I set up a many_to_many relationship between "([^"]*)" and "([^"]*)"$}
|
||||
last_model.save
|
||||
end
|
||||
|
||||
Then /^I should be able to view a paginaed list of a has many association$/ do
|
||||
Then /^I should be able to view a paginated list of a has many association$/ do
|
||||
# Create models
|
||||
step %{I have an "Articles" model which has many "Comments"}
|
||||
|
||||
|
@ -24,6 +24,12 @@ describe Locomotive::Liquid::Tags::WithScope do
|
||||
attributes['category'].should == 'posts'
|
||||
end
|
||||
|
||||
it 'allows order_by option' do
|
||||
scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'order_by:\'name DESC\'', ["{% endwith_scope %}"], {})
|
||||
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), ::Liquid::Context.new)
|
||||
attributes['order_by'].should == 'name DESC'
|
||||
end
|
||||
|
||||
it 'stores attributes in the context' do
|
||||
template = ::Liquid::Template.parse("{% with_scope active:true title:'foo' %}{{ with_scope.active }}-{{ with_scope.title }}{% endwith_scope %}")
|
||||
text = template.render
|
||||
|
@ -89,6 +89,12 @@ describe Locomotive::ContentType do
|
||||
@content_type.ordered_entries.collect(&:name).should == %w(Sacha Did)
|
||||
end
|
||||
|
||||
it 'returns a list of contents ordered through condition {order_by: "name asc"}' do
|
||||
@content_type.order_by = @content_type.entries_custom_fields.where(:name => 'name').first._id
|
||||
@content_type.order_direction = 'desc'
|
||||
@content_type.ordered_entries(:order_by => 'name asc').collect(&:name).should == %w(Did Sacha)
|
||||
end
|
||||
|
||||
it 'returns a list of entries ordered by a Date column when first instance is missing the value' do
|
||||
@content_type.order_by = @content_type.entries_custom_fields.where(:name => 'active_at').first._id
|
||||
@content_2.update_attribute :active_at, Date.parse('01/01/2001')
|
||||
|
Loading…
Reference in New Issue
Block a user