From 5f6de568d83a0b419f66705f087d59d09105aba6 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Mon, 30 Jul 2018 13:06:10 +0200 Subject: [PATCH] added a few tests for the trim extra --- test/pagy/extras/trim_test.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/pagy/extras/trim_test.rb b/test/pagy/extras/trim_test.rb index 2a40f0ac2..bd2cf45da 100644 --- a/test/pagy/extras/trim_test.rb +++ b/test/pagy/extras/trim_test.rb @@ -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("1") + link.call(10).must_equal("10") + pagy = Pagy.new(count: 1000, params: {a:3,b:4}) + link = frontend.pagy_link_proc(pagy) + link.call(1).must_equal("1") + link.call(10).must_equal("10") + end + + end + +describe "#pagy_nav_compact" do before do @array = (1..103).to_a.extend(Pagy::Array::PageMethod)