Allow for hashes with array sorts
This commit is contained in:
parent
674bdc9ef1
commit
8a1760f111
|
@ -41,7 +41,11 @@ module Ransack
|
|||
case args
|
||||
when Array
|
||||
args.each do |sort|
|
||||
sort = Nodes::Sort.extract(@context, sort)
|
||||
if sort.kind_of? Hash
|
||||
sort = Nodes::Sort.new(@context).build(sort)
|
||||
else
|
||||
sort = Nodes::Sort.extract(@context, sort)
|
||||
end
|
||||
self.sorts << sort
|
||||
end
|
||||
when Hash
|
||||
|
|
|
@ -241,7 +241,7 @@ module Ransack
|
|||
end
|
||||
|
||||
it 'creates sorts based on multiple attributes/directions in array format' do
|
||||
@s.sorts = ['id desc', 'name asc']
|
||||
@s.sorts = ['id desc', { :name => 'name', :dir => 'asc' }]
|
||||
@s.sorts.should have(2).items
|
||||
sort1, sort2 = @s.sorts
|
||||
sort1.should be_a Nodes::Sort
|
||||
|
@ -253,7 +253,7 @@ module Ransack
|
|||
end
|
||||
|
||||
it 'creates sorts based on multiple attributes and uppercase directions in array format' do
|
||||
@s.sorts = ['id DESC', 'name ASC']
|
||||
@s.sorts = ['id DESC', { :name => 'name', :dir => 'ASC' }]
|
||||
@s.sorts.should have(2).items
|
||||
sort1, sort2 = @s.sorts
|
||||
sort1.should be_a Nodes::Sort
|
||||
|
@ -265,7 +265,7 @@ module Ransack
|
|||
end
|
||||
|
||||
it 'creates sorts based on multiple attributes and different directions in array format' do
|
||||
@s.sorts = ['id DESC', 'name']
|
||||
@s.sorts = ['id DESC', { :name => 'name', :dir => nil }]
|
||||
@s.sorts.should have(2).items
|
||||
sort1, sort2 = @s.sorts
|
||||
sort1.should be_a Nodes::Sort
|
||||
|
|
Loading…
Reference in New Issue