From 0daaa0dcdaa7ba4381a9bac621576611572512bf Mon Sep 17 00:00:00 2001 From: Hanfei Shen Date: Tue, 22 May 2012 18:49:45 +0800 Subject: [PATCH 1/2] add spec --- spec/controllers/main_controller_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/controllers/main_controller_spec.rb b/spec/controllers/main_controller_spec.rb index 62de161c92..f51625b454 100644 --- a/spec/controllers/main_controller_spec.rb +++ b/spec/controllers/main_controller_spec.rb @@ -107,7 +107,22 @@ end end controller.list_entries.length.should == @players.size + end + + it "ordering of associated collection records number less than 100 shoud be grouped by desc" do + @players = 99.times.map do + FactoryGirl.create :player + end + + controller.list_entries.to_a.first.should == @players.last + end + + it "ordering of associated collection records number over 100 shoud be grouped by desc" do + @players = 100.times.map do + FactoryGirl.create :player + end + controller.list_entries.to_a.first.should == @players.last end end From 8bc726478007a54eac85a5c90f0c98d7e2cc0257 Mon Sep 17 00:00:00 2001 From: Hanfei Shen Date: Thu, 24 May 2012 13:59:18 +0800 Subject: [PATCH 2/2] fix order Thanks to https://github.com/sferik/rails_admin/issues/1144#issuecomment-5889906 --- app/controllers/rails_admin/main_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/rails_admin/main_controller.rb b/app/controllers/rails_admin/main_controller.rb index 678ba34c3c..50851fcd4b 100644 --- a/app/controllers/rails_admin/main_controller.rb +++ b/app/controllers/rails_admin/main_controller.rb @@ -123,7 +123,7 @@ def get_collection(model_config, scope, pagination) options = {} options = options.merge(:page => (params[:page] || 1).to_i, :per => (params[:per] || model_config.list.items_per_page)) if pagination options = options.merge(:include => associations) unless associations.blank? - options = options.merge(get_sort_hash(model_config)) unless params[:associated_collection] + options = options.merge(get_sort_hash(model_config)) options = options.merge(:query => params[:query]) if params[:query].present? options = options.merge(:filters => params[:f]) if params[:f].present? options = options.merge(:bulk_ids => params[:bulk_ids]) if params[:bulk_ids]