mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
Allow for hashes with array sorts
PR by @grokse (Kurt Ronshausen)
This commit is contained in:
parent
3c6817cd83
commit
321040ba62
2 changed files with 8 additions and 4 deletions
|
@ -41,7 +41,11 @@ module Ransack
|
||||||
case args
|
case args
|
||||||
when Array
|
when Array
|
||||||
args.each do |sort|
|
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
|
self.sorts << sort
|
||||||
end
|
end
|
||||||
when Hash
|
when Hash
|
||||||
|
|
|
@ -225,7 +225,7 @@ module Ransack
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates sorts based on multiple attributes/directions in array format' do
|
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
|
@s.sorts.should have(2).items
|
||||||
sort1, sort2 = @s.sorts
|
sort1, sort2 = @s.sorts
|
||||||
sort1.should be_a Nodes::Sort
|
sort1.should be_a Nodes::Sort
|
||||||
|
@ -237,7 +237,7 @@ module Ransack
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates sorts based on multiple attributes and uppercase directions in array format' do
|
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
|
@s.sorts.should have(2).items
|
||||||
sort1, sort2 = @s.sorts
|
sort1, sort2 = @s.sorts
|
||||||
sort1.should be_a Nodes::Sort
|
sort1.should be_a Nodes::Sort
|
||||||
|
@ -249,7 +249,7 @@ module Ransack
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates sorts based on multiple attributes and different directions in array format' do
|
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
|
@s.sorts.should have(2).items
|
||||||
sort1, sort2 = @s.sorts
|
sort1, sort2 = @s.sorts
|
||||||
sort1.should be_a Nodes::Sort
|
sort1.should be_a Nodes::Sort
|
||||||
|
|
Loading…
Reference in a new issue