Skip to content

Commit

Permalink
Paginate preserves multi-value parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
nibble committed Apr 19, 2013
1 parent 3ab6a41 commit bc40299
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ramaze/helper/paginate.rb
Expand Up @@ -226,6 +226,11 @@ def link(g, n, text = n, hash = {})

action = Current.action
params = request.params.merge(@var.to_s => n)
params.keys.each do |p|
if params[p].is_a?(Array) and not p.end_with?('[]')
params["#{p}[]"] = params.delete(p)
end
end
hash[:href] = action.node.r(action.path, params)

g.a(hash){ text }
Expand Down
25 changes: 25 additions & 0 deletions spec/ramaze/helper/paginate.rb
Expand Up @@ -32,6 +32,13 @@ def iteration
pager.each{|item| out << item }
out.inspect
end

def preserve_params
request.params['single'] = 'zero'
request.params['multiple'] = %w[ one two three ]
pager = paginate(ALPHA)
pager.navigation
end
end

describe Ramaze::Helper::Paginate do
Expand Down Expand Up @@ -275,5 +282,23 @@ def iteration

end

it 'preserves single value params' do
doc = Nokogiri::HTML(get("/array/preserve_params").body)
params = doc.search("//a").first[:href].split('?').last.split('&')
params.should.include 'single=zero'
params.should.not.include 'single[]'.escape(:cgi) + '=zero'
end

it 'preserves multi value params' do
doc = Nokogiri::HTML(get("/array/preserve_params").body)
params = doc.search("//a").first[:href].split('?').last.split('&')
params.should.not.include 'multiple=one'
params.should.not.include 'multiple=two'
params.should.not.include 'multiple=three'
params.should.include 'multiple[]'.escape(:cgi) + '=one'
params.should.include 'multiple[]'.escape(:cgi) + '=two'
params.should.include 'multiple[]'.escape(:cgi) + '=three'
end

end
end

0 comments on commit bc40299

Please sign in to comment.