Skip to content

Commit

Permalink
Merge pull request #467 from eneagoe/master
Browse files Browse the repository at this point in the history
Fixes sort on polymorphic association #421
  • Loading branch information
jonatack committed Nov 10, 2014
2 parents 660361b + 4f1858c commit 98529fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ransack/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/ransack/helpers/form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Helpers
router = ActionDispatch::Routing::RouteSet.new
router.draw do
resources :people
resources :notes
get ':controller(/:action(/:id(.:format)))'
end

Expand Down Expand Up @@ -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' })
Expand Down

0 comments on commit 98529fb

Please sign in to comment.