Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URL generation when explicitly passing params to link helpers #874

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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