diff --git a/lib/ransack/helpers/form_helper.rb b/lib/ransack/helpers/form_helper.rb index 421c43064..0f69895a4 100644 --- a/lib/ransack/helpers/form_helper.rb +++ b/lib/ransack/helpers/form_helper.rb @@ -83,7 +83,7 @@ def sort_link(search, attribute, *args) sort_params = [] Array(sort_fields).each do |sort_field| - attr_name, new_dir = sort_field.to_s.downcase.split(/\s+/) + attr_name, new_dir = sort_field.to_s.split(/\s+/) current_dir = nil # if the user didn't specify the sort direction, detect the previous diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index ffa0b4b30..ec9fa5aa7 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -7,6 +7,7 @@ module Helpers router = ActionDispatch::Routing::RouteSet.new router.draw do resources :people + resources :notes get ':controller(/:action(/:id(.:format)))' end @@ -266,6 +267,25 @@ module Helpers should match /Full Name/ } end + + describe "#sort_link on polymorphic association should preserves association model name case" do + subject { @controller.view_context + .sort_link([:main_app, Note.search()], + :notable_of_Person_type_name, "Notable", :controller => 'notes') + } + it { + should match( + if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./ + /notes\?q%5Bs%5D=notable_of_Person_type_name\+asc/ + else + /notes\?q(%5B|\[)s(%5D|\])=notable_of_Person_type_name\+asc/ + end + ) + } + it { should match /sort_link/ } + it { should match /Notable/ } + end + context 'view has existing parameters' do before do @controller.view_context.params.merge!({ :exist => 'existing' })