Skip to content

Commit

Permalink
Merge pull request #874 from 5t111111/fix-url-when-passing-params-to-…
Browse files Browse the repository at this point in the history
…link-helper

Fix URL generation when explicitly passing params to link helpers
  • Loading branch information
yuki24 committed Sep 25, 2017
2 parents 4169936 + 900f967 commit e2a0863
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion kaminari-core/lib/kaminari/helpers/tags.rb
Expand Up @@ -24,7 +24,14 @@ def initialize(template, params: {}, param_name: nil, theme: nil, views_prefix:
@params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
@params = @params.with_indifferent_access
@params.except!(*PARAM_KEY_BLACKLIST)
@params.merge! params
# params in Rails 5 may not be a Hash either,
# so it must be converted to a Hash to be merged into @params
unless params.empty?
ActiveSupport::Deprecation.warn 'Explicitly passing params to helpers could be removed in the future.'
params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
params = params.with_indifferent_access
@params.merge! params
end
end

def to_s(locals = {}) #:nodoc:
Expand Down
14 changes: 14 additions & 0 deletions kaminari-core/test/helpers/tags_test.rb
Expand Up @@ -67,6 +67,20 @@ class TagTest < ActionView::TestCase
end
end

sub_test_case "when passing nested params" do
setup do
self.params[:filter] = ActionController::Parameters.new({status: 'active'})
end

test 'for first page' do
assert_match(/users\?filter%5Bstatus%5D=active/, Kaminari::Helpers::Tag.new(self, params: self.params).page_url_for(1))
end

test 'for other page' do
assert_match(/users\?filter%5Bstatus%5D=active&page=2/, Kaminari::Helpers::Tag.new(self, params: self.params).page_url_for(2))
end
end

sub_test_case "with param_name = 'foo.page' option" do
setup do
self.params['foo.page'] = 2
Expand Down

0 comments on commit e2a0863

Please sign in to comment.