Skip to content

Commit

Permalink
Another fix on the path builder
Browse files Browse the repository at this point in the history
  • Loading branch information
srosa committed Nov 21, 2013
1 parent 71fc5ae commit 29c4922
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/neat_pages/helpers/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ def li(content, css_class='', options={})
end

def path_to(page)
"#{@base_url}?" +
@params.map { |k,v| "#{k}=#{v}" if k != 'page' }.compact.join('&') +
(@params.empty? ? '' : '&') +
"page=#{page}"
qs = @params.map { |k,v| "#{k}=#{v}" if k != 'page' }.compact.join('&')

"#{@base_url}?#{qs}" + (qs.empty? ? '' : '&') + "page=#{page}"
end

def reset_builder
Expand Down
9 changes: 9 additions & 0 deletions spec/neat_pages/helpers/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
specify { builder.path_to(6).should eql 'http://www.test.dev?sort=1&filter=type&page=6' }
end
end

context "and the params page=5" do
let(:request) { request_mock(host: 'www.test.dev', env: { 'action_dispatch.request.query_parameters' => { 'page' => 5 } })}
let(:builder) { NeatPages::Helpers::Builder.new(double, request) }

context "when asking for the path_to page 6" do
specify { builder.path_to(6).should eql 'http://www.test.dev?page=6' }
end
end
end
end

Expand Down

0 comments on commit 29c4922

Please sign in to comment.