Skip to content

Commit

Permalink
added a few tests for the trim extra
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jul 30, 2018
1 parent 89d40a2 commit 5f6de56
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion test/pagy/extras/trim_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,33 @@

let(:frontend) { TestView.new }

describe "#pagy_nav_compact" do
describe "#pagy_trim_url" do

it 'trims urls' do
frontend.pagy_trim_url('foo/bar?page=1', 'page=1').must_equal('foo/bar')
frontend.pagy_trim_url('foo/bar?a=page&page=1', 'page=1').must_equal('foo/bar?a=page')
frontend.pagy_trim_url('foo/bar?a=page&page=1&b=4', 'page=1').must_equal('foo/bar?a=page&b=4')
frontend.pagy_trim_url('foo/bar?a=page&page=1&b=4&my_page=1', 'page=1').must_equal('foo/bar?a=page&b=4&my_page=1')
end

end

describe "#pagy_link_proc" do

it 'returns trimmed link' do
pagy = Pagy.new(count: 1000)
link = frontend.pagy_link_proc(pagy)
link.call(1).must_equal("<a href=\"/foo\" >1</a>")
link.call(10).must_equal("<a href=\"/foo?page=10\" >10</a>")
pagy = Pagy.new(count: 1000, params: {a:3,b:4})
link = frontend.pagy_link_proc(pagy)
link.call(1).must_equal("<a href=\"/foo?a=3&b=4\" >1</a>")
link.call(10).must_equal("<a href=\"/foo?page=10&a=3&b=4\" >10</a>")
end

end

describe "#pagy_nav_compact" do

before do
@array = (1..103).to_a.extend(Pagy::Array::PageMethod)
Expand Down

0 comments on commit 5f6de56

Please sign in to comment.