1
0
Fork 0
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:
jonatack 2014-01-08 01:46:21 +01:00
parent 3c6817cd83
commit 321040ba62
2 changed files with 8 additions and 4 deletions

View file

@ -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

View file

@ -225,7 +225,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
@ -237,7 +237,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
@ -249,7 +249,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