"
end
it 'renders last page' do
pagy = Pagy.new(count: 103, page: 6)
- frontend.pagy_materialize_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_materialize_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
diff --git a/test/pagy/extras/navs_test.rb b/test/pagy/extras/navs_test.rb
index df7257789..b2f4f9173 100644
--- a/test/pagy/extras/navs_test.rb
+++ b/test/pagy/extras/navs_test.rb
@@ -6,32 +6,32 @@
describe Pagy::Frontend do
- let(:frontend) { TestView.new }
+ let(:view) { MockView.new }
let(:pagy_test_id) { 'test-id' }
describe "#pagy_nav_js" do
it 'renders first page' do
pagy = Pagy.new(count: 1000, page: 1)
- frontend.pagy_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders intermediate page' do
pagy = Pagy.new(count: 1000, page: 20)
- frontend.pagy_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders last page' do
pagy = Pagy.new(count: 1000, page: 50)
- frontend.pagy_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders with :steps' do
pagy = Pagy.new(count: 1000, page: 20, steps: {0 => [1,2,2,1], 500 => [2,3,3,2]})
- frontend.pagy_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
@@ -41,19 +41,19 @@
it 'renders first page' do
pagy = Pagy.new(count: 103, page: 1)
- frontend.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \
"
‹ Prev Page of 6 Next › "
end
it 'renders intermediate page' do
pagy = Pagy.new(count: 103, page: 3)
- frontend.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \
"
‹ Prev Page of 6 Next › "
end
it 'renders last page' do
pagy = Pagy.new(count: 103, page: 6)
- frontend.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \
"
‹ Prev Page of 6 Next › "
end
diff --git a/test/pagy/extras/searchkick_test.rb b/test/pagy/extras/searchkick_test.rb
index 9995f45f4..de6dc2f92 100644
--- a/test/pagy/extras/searchkick_test.rb
+++ b/test/pagy/extras/searchkick_test.rb
@@ -2,7 +2,7 @@
# frozen_string_literal: true
require_relative '../../test_helper'
-require_relative '../../test_helper/searchkick'
+require_relative '../../mock_helpers/searchkick'
require 'pagy/extras/overflow'
SimpleCov.command_name 'elasticsearch' if ENV['RUN_SIMPLECOV']
@@ -12,19 +12,19 @@
describe '#pagy_search' do
it 'extends the class with #pagy_search' do
- SearchkickModel.must_respond_to :pagy_search
+ MockSearchkick::Model.must_respond_to :pagy_search
end
it 'returns class and arguments' do
- SearchkickModel.pagy_search('a', b:2).must_equal [SearchkickModel, 'a', {b: 2}, nil]
- args = SearchkickModel.pagy_search('a', b:2){|a| a*2}
+ MockSearchkick::Model.pagy_search('a', b:2).must_equal [MockSearchkick::Model, 'a', {b: 2}, nil]
+ args = MockSearchkick::Model.pagy_search('a', b:2){|a| a*2}
block = args[-1]
- args.must_equal [SearchkickModel, 'a', {b: 2}, block]
+ args.must_equal [MockSearchkick::Model, 'a', {b: 2}, block]
end
it 'adds the caller and arguments' do
- SearchkickModel.pagy_search('a', b:2).results.must_equal [SearchkickModel, 'a', {b: 2}, nil, :results]
- SearchkickModel.pagy_search('a', b:2).a('b', 2).must_equal [SearchkickModel, 'a', {b: 2}, nil, :a, 'b', 2]
+ MockSearchkick::Model.pagy_search('a', b:2).results.must_equal [MockSearchkick::Model, 'a', {b: 2}, nil, :results]
+ MockSearchkick::Model.pagy_search('a', b:2).a('b', 2).must_equal [MockSearchkick::Model, 'a', {b: 2}, nil, :a, 'b', 2]
end
end
@@ -33,37 +33,37 @@
describe Pagy::Backend do
- let(:backend) { TestController.new }
+ let(:controller) { MockController.new }
describe "#pagy_searchkick" do
before do
- @collection = TestCollection.new((1..1000).to_a)
+ @collection = MockCollection.new
end
it 'paginates response with defaults' do
- pagy, response = backend.send(:pagy_searchkick, SearchkickModel.pagy_search('a'){'B-'})
+ pagy, response = controller.send(:pagy_searchkick, MockSearchkick::Model.pagy_search('a'){'B-'})
results = response.results
pagy.must_be_instance_of Pagy
pagy.count.must_equal 1000
pagy.items.must_equal Pagy::VARS[:items]
- pagy.page.must_equal backend.params[:page]
+ pagy.page.must_equal controller.params[:page]
results.count.must_equal Pagy::VARS[:items]
results.must_equal ["R-B-a-41", "R-B-a-42", "R-B-a-43", "R-B-a-44", "R-B-a-45", "R-B-a-46", "R-B-a-47", "R-B-a-48", "R-B-a-49", "R-B-a-50", "R-B-a-51", "R-B-a-52", "R-B-a-53", "R-B-a-54", "R-B-a-55", "R-B-a-56", "R-B-a-57", "R-B-a-58", "R-B-a-59", "R-B-a-60"]
end
it 'paginates results with defaults' do
- pagy, results = backend.send(:pagy_searchkick, SearchkickModel.pagy_search('a').results)
+ pagy, results = controller.send(:pagy_searchkick, MockSearchkick::Model.pagy_search('a').results)
pagy.must_be_instance_of Pagy
pagy.count.must_equal 1000
pagy.items.must_equal Pagy::VARS[:items]
- pagy.page.must_equal backend.params[:page]
+ pagy.page.must_equal controller.params[:page]
results.count.must_equal Pagy::VARS[:items]
results.must_equal ["R-a-41", "R-a-42", "R-a-43", "R-a-44", "R-a-45", "R-a-46", "R-a-47", "R-a-48", "R-a-49", "R-a-50", "R-a-51", "R-a-52", "R-a-53", "R-a-54", "R-a-55", "R-a-56", "R-a-57", "R-a-58", "R-a-59", "R-a-60"]
end
it 'paginates with vars' do
- pagy, results = backend.send(:pagy_searchkick, SearchkickModel.pagy_search('b').results, page: 2, items: 10, link_extra: 'X')
+ pagy, results = controller.send(:pagy_searchkick, MockSearchkick::Model.pagy_search('b').results, page: 2, items: 10, link_extra: 'X')
pagy.must_be_instance_of Pagy
pagy.count.must_equal 1000
pagy.items.must_equal 10
@@ -74,7 +74,7 @@
end
it 'paginates with overflow' do
- pagy, results = backend.send(:pagy_searchkick, SearchkickModel.pagy_search('b').results, page: 200, items: 10, link_extra: 'X', overflow: :last_page)
+ pagy, results = controller.send(:pagy_searchkick, MockSearchkick::Model.pagy_search('b').results, page: 200, items: 10, link_extra: 'X', overflow: :last_page)
pagy.must_be_instance_of Pagy
pagy.count.must_equal 1000
pagy.items.must_equal 10
@@ -90,7 +90,7 @@
it 'gets defaults' do
vars = {}
- merged = backend.send :pagy_searchkick_get_vars, nil, vars
+ merged = controller.send :pagy_searchkick_get_vars, nil, vars
merged.keys.must_include :page
merged.keys.must_include :items
merged[:page].must_equal 3
@@ -99,7 +99,7 @@
it 'gets vars' do
vars = {page: 2, items: 10, link_extra: 'X'}
- merged = backend.send :pagy_searchkick_get_vars, nil, vars
+ merged = controller.send :pagy_searchkick_get_vars, nil, vars
merged.keys.must_include :page
merged.keys.must_include :items
merged.keys.must_include :link_extra
@@ -113,7 +113,7 @@
describe 'Pagy.new_from_searchkick' do
it 'paginates results with defaults' do
- results = SearchkickModel.search('a')
+ results = MockSearchkick::Model.search('a')
pagy = Pagy.new_from_searchkick(results)
pagy.must_be_instance_of Pagy
pagy.count.must_equal 1000
@@ -122,7 +122,7 @@
end
it 'paginates results with vars' do
- results = SearchkickModel.search('b', page: 2, per_page: 15)
+ results = MockSearchkick::Model.search('b', page: 2, per_page: 15)
pagy = Pagy.new_from_searchkick(results, link_extra: 'X')
pagy.must_be_instance_of Pagy
pagy.count.must_equal 1000
diff --git a/test/pagy/extras/semantic_test.rb b/test/pagy/extras/semantic_test.rb
index 0047e627a..7920c3ca8 100644
--- a/test/pagy/extras/semantic_test.rb
+++ b/test/pagy/extras/semantic_test.rb
@@ -6,26 +6,26 @@
describe Pagy::Frontend do
- let(:frontend) { TestView.new }
+ let(:view) { MockView.new }
let(:pagy_test_id) { 'test-id' }
describe "#pagy_semantic_nav" do
it 'renders first page' do
pagy = Pagy.new(count: 1000, page: 1)
- frontend.pagy_semantic_nav(pagy).must_equal \
+ view.pagy_semantic_nav(pagy).must_equal \
"
"
end
it 'renders intermediate page' do
pagy = Pagy.new(count: 1000, page: 20)
- frontend.pagy_semantic_nav(pagy).must_equal \
+ view.pagy_semantic_nav(pagy).must_equal \
"
"
end
it 'renders last page' do
pagy = Pagy.new(count: 1000, page: 50)
- frontend.pagy_semantic_nav(pagy).must_equal \
+ view.pagy_semantic_nav(pagy).must_equal \
"
"
end
@@ -35,25 +35,25 @@
it 'renders first page' do
pagy = Pagy.new(count: 1000, page: 1)
- frontend.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders intermediate page' do
pagy = Pagy.new(count: 1000, page: 20)
- frontend.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders last page' do
pagy = Pagy.new(count: 1000, page: 50)
- frontend.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders with :steps' do
pagy = Pagy.new(count: 1000, page: 20, steps: {0 => [1,2,2,1], 500 => [2,3,3,2]})
- frontend.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
@@ -63,19 +63,19 @@
it 'renders first page' do
pagy = Pagy.new(count: 103, page: 1)
- frontend.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders intermediate page' do
pagy = Pagy.new(count: 103, page: 3)
- frontend.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders last page' do
pagy = Pagy.new(count: 103, page: 6)
- frontend.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
diff --git a/test/pagy/extras/shared_combo_test.rb b/test/pagy/extras/shared_combo_test.rb
index 78883a795..065b2e824 100644
--- a/test/pagy/extras/shared_combo_test.rb
+++ b/test/pagy/extras/shared_combo_test.rb
@@ -10,34 +10,34 @@
# add tests for oj and pagy_id
describe Pagy::Frontend do
- let(:frontend) { TestSimpleView.new }
+ let(:view) { MockView.new('http://example.com:3000/foo?') }
describe "#pagy_marked_link" do
it 'should return the marked link' do
pagy = Pagy.new(count: 100, page: 4)
- frontend.instance_eval do
+ view.instance_eval do
pagy_marked_link(pagy_link_proc(pagy)).must_equal(
"
"
)
end
pagy = Pagy.new(count: 100, page: 4, page_param: 'p')
- frontend.instance_eval do
+ view.instance_eval do
pagy_marked_link(pagy_link_proc(pagy)).must_equal(
"
"
)
end
pagy = Pagy.new(count: 100, page: 4, items_param: 'i')
- frontend.instance_eval do
+ view.instance_eval do
pagy_marked_link(pagy_link_proc(pagy)).must_equal(
"
"
)
end
pagy = Pagy.new(count: 100, page: 4, page_param: 'p', items_param: 'i')
- frontend.instance_eval do
+ view.instance_eval do
pagy_marked_link(pagy_link_proc(pagy)).must_equal(
"
"
)
@@ -52,7 +52,7 @@
it 'renders items selector with trim' do
pagy = Pagy.new count: 1000, page: 3
- frontend.pagy_items_selector_js(pagy, 'test-id').must_equal \
+ view.pagy_items_selector_js(pagy, 'test-id').must_equal \
"
Show items per page "
end
diff --git a/test/pagy/extras/shared_test.rb b/test/pagy/extras/shared_test.rb
index f388f697a..b9a68e4b2 100644
--- a/test/pagy/extras/shared_test.rb
+++ b/test/pagy/extras/shared_test.rb
@@ -12,12 +12,12 @@
# add tests for oj and pagy_id
describe Pagy::Frontend do
- let(:frontend) { TestSimpleView.new }
+ let(:view) { MockView.new('http://example.com:3000/foo?') }
describe "#pagy_json_tag" do
it 'should use oj' do
- frontend.pagy_json_tag(:test_function, 'some-id', 'some-string', 123, true).must_equal \
+ view.pagy_json_tag(:test_function, 'some-id', 'some-string', 123, true).must_equal \
""
end
@@ -40,11 +40,11 @@
it 'should return only the "standard" link' do
pagy = Pagy.new(count: 100, page: 4)
- frontend.instance_eval do
+ view.instance_eval do
pagy_marked_link(pagy_link_proc(pagy)).must_equal("
")
end
pagy = Pagy.new(count: 100, page: 4, page_param: 'p')
- frontend.instance_eval do
+ view.instance_eval do
pagy_marked_link(pagy_link_proc(pagy)).must_equal("
")
end
end
@@ -53,7 +53,7 @@
# we need an intermediate call to get the right caller
def call_pagy_id
- frontend.pagy_id
+ view.pagy_id
end
end
diff --git a/test/pagy/extras/support_test.rb b/test/pagy/extras/support_test.rb
index 18e603b63..ba083d40e 100644
--- a/test/pagy/extras/support_test.rb
+++ b/test/pagy/extras/support_test.rb
@@ -9,36 +9,36 @@
describe Pagy::Frontend do
- let(:frontend) { TestView.new }
+ let(:view) { MockView.new }
describe "#pagy_prev_url" do
it 'returns the prev url for page 1' do
pagy = Pagy.new count: 1000, page: 1
pagy_countless = Pagy::Countless.new(page: 1).finalize(21)
- frontend.pagy_prev_url(pagy).must_be_nil
- frontend.pagy_prev_url(pagy_countless).must_be_nil
+ view.pagy_prev_url(pagy).must_be_nil
+ view.pagy_prev_url(pagy_countless).must_be_nil
end
it 'returns the prev url for page 3' do
pagy = Pagy.new count: 1000, page: 3
pagy_countless = Pagy::Countless.new(page: 3).finalize(21)
- frontend.pagy_prev_url(pagy).must_equal '/foo?page=2'
- frontend.pagy_prev_url(pagy_countless).must_equal '/foo?page=2'
+ view.pagy_prev_url(pagy).must_equal '/foo?page=2'
+ view.pagy_prev_url(pagy_countless).must_equal '/foo?page=2'
end
it 'returns the prev url for page 6' do
pagy = Pagy.new count: 1000, page: 6
pagy_countless = Pagy::Countless.new(page: 6).finalize(21)
- frontend.pagy_prev_url(pagy).must_equal '/foo?page=5'
- frontend.pagy_prev_url(pagy_countless).must_equal '/foo?page=5'
+ view.pagy_prev_url(pagy).must_equal '/foo?page=5'
+ view.pagy_prev_url(pagy_countless).must_equal '/foo?page=5'
end
it 'returns the prev url for last page' do
pagy = Pagy.new count: 1000, page: 50
pagy_countless = Pagy::Countless.new(page: 50).finalize(20)
- frontend.pagy_prev_url(pagy).must_equal '/foo?page=49'
- frontend.pagy_prev_url(pagy_countless).must_equal '/foo?page=49'
+ view.pagy_prev_url(pagy).must_equal '/foo?page=49'
+ view.pagy_prev_url(pagy_countless).must_equal '/foo?page=49'
end
end
@@ -48,29 +48,29 @@
it 'returns the next url for page 1' do
pagy = Pagy.new count: 1000, page: 1
pagy_countless = Pagy::Countless.new(page: 1).finalize(21)
- frontend.pagy_next_url(pagy).must_equal '/foo?page=2'
- frontend.pagy_next_url(pagy_countless).must_equal '/foo?page=2'
+ view.pagy_next_url(pagy).must_equal '/foo?page=2'
+ view.pagy_next_url(pagy_countless).must_equal '/foo?page=2'
end
it 'returns the next url for page 3' do
pagy = Pagy.new count: 1000, page: 3
pagy_countless = Pagy::Countless.new(page: 3).finalize(21)
- frontend.pagy_next_url(pagy).must_equal '/foo?page=4'
- frontend.pagy_next_url(pagy_countless).must_equal '/foo?page=4'
+ view.pagy_next_url(pagy).must_equal '/foo?page=4'
+ view.pagy_next_url(pagy_countless).must_equal '/foo?page=4'
end
it 'returns the url next for page 6' do
pagy = Pagy.new count: 1000, page: 6
pagy_countless = Pagy::Countless.new(page: 6).finalize(21)
- frontend.pagy_next_url(pagy).must_equal '/foo?page=7'
- frontend.pagy_next_url(pagy_countless).must_equal '/foo?page=7'
+ view.pagy_next_url(pagy).must_equal '/foo?page=7'
+ view.pagy_next_url(pagy_countless).must_equal '/foo?page=7'
end
it 'returns the url next for last page' do
pagy = Pagy.new count: 1000, page: 50
pagy_countless = Pagy::Countless.new(page: 50).finalize(20)
- frontend.pagy_next_url(pagy).must_be_nil
- frontend.pagy_next_url(pagy_countless).must_be_nil
+ view.pagy_next_url(pagy).must_be_nil
+ view.pagy_next_url(pagy_countless).must_be_nil
end
end
@@ -80,29 +80,29 @@
it 'renders the prev link for page 1' do
pagy = Pagy.new count: 1000, page: 1
pagy_countless = Pagy::Countless.new(page: 1).finalize(21)
- frontend.pagy_prev_link(pagy).must_equal "
‹ Prev "
- frontend.pagy_prev_link(pagy_countless).must_equal "
‹ Prev "
+ view.pagy_prev_link(pagy).must_equal "
‹ Prev "
+ view.pagy_prev_link(pagy_countless).must_equal "
‹ Prev "
end
it 'renders the prev link for page 3' do
pagy = Pagy.new count: 1000, page: 3
pagy_countless = Pagy::Countless.new(page: 3).finalize(21)
- frontend.pagy_prev_link(pagy).must_equal "
‹ Prev "
- frontend.pagy_prev_link(pagy_countless).must_equal "
‹ Prev "
+ view.pagy_prev_link(pagy).must_equal "
‹ Prev "
+ view.pagy_prev_link(pagy_countless).must_equal "
‹ Prev "
end
it 'renders the prev link for page 6' do
pagy = Pagy.new count: 1000, page: 6
pagy_countless = Pagy::Countless.new(page: 6).finalize(21)
- frontend.pagy_prev_link(pagy).must_equal "
‹ Prev "
- frontend.pagy_prev_link(pagy_countless).must_equal "
‹ Prev "
+ view.pagy_prev_link(pagy).must_equal "
‹ Prev "
+ view.pagy_prev_link(pagy_countless).must_equal "
‹ Prev "
end
it 'renders the prev link for last page' do
pagy = Pagy.new count: 1000, page: 50
pagy_countless = Pagy::Countless.new(page: 50).finalize(20)
- frontend.pagy_prev_link(pagy).must_equal "
‹ Prev "
- frontend.pagy_prev_link(pagy_countless).must_equal "
‹ Prev "
+ view.pagy_prev_link(pagy).must_equal "
‹ Prev "
+ view.pagy_prev_link(pagy_countless).must_equal "
‹ Prev "
end
end
@@ -112,29 +112,29 @@
it 'renders the next link for page 1' do
pagy = Pagy.new count: 1000, page: 1
pagy_countless = Pagy::Countless.new(page: 1).finalize(21)
- frontend.pagy_next_link(pagy).must_equal "
Next › "
- frontend.pagy_next_link(pagy_countless).must_equal "
Next › "
+ view.pagy_next_link(pagy).must_equal "
Next › "
+ view.pagy_next_link(pagy_countless).must_equal "
Next › "
end
it 'renders the next link for page 3' do
pagy = Pagy.new count: 1000, page: 3
pagy_countless = Pagy::Countless.new(page: 3).finalize(21)
- frontend.pagy_next_link(pagy).must_equal "
Next › "
- frontend.pagy_next_link(pagy_countless).must_equal "
Next › "
+ view.pagy_next_link(pagy).must_equal "
Next › "
+ view.pagy_next_link(pagy_countless).must_equal "
Next › "
end
it 'renders the next link for page 6' do
pagy = Pagy.new count: 1000, page: 6
pagy_countless = Pagy::Countless.new(page: 6).finalize(21)
- frontend.pagy_next_link(pagy).must_equal "
Next › "
- frontend.pagy_next_link(pagy_countless).must_equal "
Next › "
+ view.pagy_next_link(pagy).must_equal "
Next › "
+ view.pagy_next_link(pagy_countless).must_equal "
Next › "
end
it 'renders the next link for last page' do
pagy = Pagy.new count: 1000, page: 50
pagy_countless = Pagy::Countless.new(page: 50).finalize(20)
- frontend.pagy_next_link(pagy).must_equal "
Next › "
- frontend.pagy_next_link(pagy_countless).must_equal "
Next › "
+ view.pagy_next_link(pagy).must_equal "
Next › "
+ view.pagy_next_link(pagy_countless).must_equal "
Next › "
end
end
diff --git a/test/pagy/extras/trim_test.rb b/test/pagy/extras/trim_test.rb
index 3b90da911..b17d2804b 100644
--- a/test/pagy/extras/trim_test.rb
+++ b/test/pagy/extras/trim_test.rb
@@ -14,18 +14,18 @@
describe Pagy::Frontend do
- let(:frontend) { TestView.new }
+ let(:view) { MockView.new }
let(:pagy_test_id) { 'test-id' }
describe "#pagy_link_proc" do
it 'returns trimmed link' do
pagy = Pagy.new(count: 1000)
- link = frontend.pagy_link_proc(pagy)
+ link = view.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 = view.pagy_link_proc(pagy)
link.call(1).must_equal("
1 ")
link.call(10).must_equal("
10 ")
end
@@ -36,21 +36,21 @@
it 'renders first page' do
pagy = Pagy.new(count: 103, page: 1)
- html = frontend.pagy_nav(pagy)
+ html = view.pagy_nav(pagy)
html.must_equal \
"
‹ Prev 1 2 3 4 5 6 Next › "
end
it 'renders intermediate page' do
pagy = Pagy.new(count: 103, page: 3)
- html = frontend.pagy_nav(pagy)
+ html = view.pagy_nav(pagy)
html.must_equal \
"
‹ Prev 1 2 3 4 5 6 Next › "
end
it 'renders last page' do
pagy = Pagy.new(count: 103, page: 6)
- html = frontend.pagy_nav(pagy)
+ html = view.pagy_nav(pagy)
html.must_equal \
"
‹ Prev 1 2 3 4 5 6 Next › "
end
@@ -61,29 +61,29 @@
it 'renders first page' do
pagy = Pagy.new(count: 103, page: 1)
- frontend.pagy_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_bootstrap_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_bootstrap_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_bulma_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_bulma_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_foundation_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_foundation_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_materialize_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_materialize_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders intermediate page' do
pagy = Pagy.new(count: 103, page: 3)
- frontend.pagy_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders last page' do
pagy = Pagy.new(count: 103, page: 6)
- frontend.pagy_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
@@ -93,30 +93,30 @@
it 'renders first page' do
pagy = Pagy.new(count: 103, page: 1)
- frontend.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \
"
‹ Prev Page of 6 Next › "
- frontend.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_bulma_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_bulma_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_foundation_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_foundation_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_materialize_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_materialize_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
- frontend.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \
+ view.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \
"
"
end
it 'renders intermediate page' do
pagy = Pagy.new(count: 103, page: 3)
- html = frontend.pagy_combo_nav_js(pagy, pagy_test_id)
+ html = view.pagy_combo_nav_js(pagy, pagy_test_id)
html.must_equal \
"
‹ Prev Page of 6 Next › "
end
it 'renders last page' do
pagy = Pagy.new(count: 103, page: 6)
- html = frontend.pagy_combo_nav_js(pagy, pagy_test_id)
+ html = view.pagy_combo_nav_js(pagy, pagy_test_id)
html.must_equal \
"
‹ Prev Page of 6 Next › "
end
diff --git a/test/pagy/frontend_test.rb b/test/pagy/frontend_test.rb
index 25a0fc51d..d92b14920 100644
--- a/test/pagy/frontend_test.rb
+++ b/test/pagy/frontend_test.rb
@@ -5,85 +5,38 @@
describe Pagy::Frontend do
- let(:frontend) { TestView.new }
+ let(:view) { MockView.new }
describe "#pagy_nav" do
- before do
- @array = (1..103).to_a.extend(Pagy::Array::PageMethod)
- end
-
it 'renders page 1' do
- pagy, _ = @array.pagy(1)
- frontend.pagy_nav(pagy).must_equal \
- ''
+ pagy = Pagy.new count: 103, page: 1
+ view.pagy_nav(pagy).must_equal \
+ "
‹ Prev 1 2 3 4 5 6 Next › "
end
it 'renders page 3' do
- pagy, _ = @array.pagy(3)
- frontend.pagy_nav(pagy).must_equal \
- ''
+ pagy = Pagy.new count: 103, page: 3
+ view.pagy_nav(pagy).must_equal \
+ "
‹ Prev 1 2 3 4 5 6 Next › "
end
it 'renders page 6' do
- pagy, _ = @array.pagy(6)
- frontend.pagy_nav(pagy).must_equal \
- ''
+ pagy = Pagy.new count: 103, page: 6
+ view.pagy_nav(pagy).must_equal \
+ "
‹ Prev 1 2 3 4 5 6 Next › "
end
it 'renders page 10' do
- @array = (1..1000).to_a.extend(Pagy::Array::PageMethod)
- pagy, _ = @array.pagy(10)
- frontend.pagy_nav(pagy).must_equal \
- ''
+ pagy = Pagy.new count: 1000, page: 10
+ view.pagy_nav(pagy).must_equal \
+ "
‹ Prev 1 … 6 7 8 9 10 11 12 13 14 … 50 Next › "
end
it 'renders with link_extras' do
- pagy, _ = @array.pagy(1, link_extra: "X")
- frontend.pagy_nav(pagy).must_include '?page=2" X rel'
+ pagy = Pagy.new count: 103, page: 1, link_extra: "X"
+ view.pagy_nav(pagy).must_include '?page=2" X rel'
end
end
@@ -91,9 +44,8 @@
describe "#pagy_link_proc" do
it 'renders with extras' do
- @array = (1..103).to_a.extend(Pagy::Array::PageMethod)
- pagy, _ = @array.pagy(1)
- frontend.pagy_link_proc(pagy, "X").call(1).must_equal '
1 '
+ pagy = Pagy.new count: 103, page: 1
+ view.pagy_link_proc(pagy, "X").call(1).must_equal '
1 '
end
end
@@ -101,23 +53,23 @@
describe "#pagy_t" do
it 'pluralizes' do
- frontend.pagy_t('pagy.nav.prev').must_equal "‹ Prev"
- frontend.pagy_t('pagy.item_name', count: 0).must_equal "items"
- frontend.pagy_t('pagy.item_name', count: 1).must_equal "item"
- frontend.pagy_t('pagy.item_name', count: 10).must_equal "items"
+ view.pagy_t('pagy.nav.prev').must_equal "‹ Prev"
+ view.pagy_t('pagy.item_name', count: 0).must_equal "items"
+ view.pagy_t('pagy.item_name', count: 1).must_equal "item"
+ view.pagy_t('pagy.item_name', count: 10).must_equal "items"
end
it 'interpolates' do
- frontend.pagy_t('pagy.info.no_items', count: 0).must_equal "No %{item_name} found"
- frontend.pagy_t('pagy.info.single_page', count: 1).must_equal "Displaying
1 %{item_name}"
- frontend.pagy_t('pagy.info.single_page', count: 10).must_equal "Displaying
10 %{item_name}"
- frontend.pagy_t('pagy.info.multiple_pages', count: 10).must_equal "Displaying %{item_name}
%{from}-%{to} of
10 in total"
- frontend.pagy_t('pagy.info.multiple_pages', item_name: 'Products', count: 300, from: 101, to: 125).must_equal "Displaying Products
101-125 of
300 in total"
+ view.pagy_t('pagy.info.no_items', count: 0).must_equal "No %{item_name} found"
+ view.pagy_t('pagy.info.single_page', count: 1).must_equal "Displaying
1 %{item_name}"
+ view.pagy_t('pagy.info.single_page', count: 10).must_equal "Displaying
10 %{item_name}"
+ view.pagy_t('pagy.info.multiple_pages', count: 10).must_equal "Displaying %{item_name}
%{from}-%{to} of
10 in total"
+ view.pagy_t('pagy.info.multiple_pages', item_name: 'Products', count: 300, from: 101, to: 125).must_equal "Displaying Products
101-125 of
300 in total"
end
it 'handles missing paths' do
- frontend.pagy_t('pagy.nav.not_here').must_equal '[translation missing: "pagy.nav.not_here"]'
- frontend.pagy_t('pagy.nav.gap.not_here').must_equal '[translation missing: "pagy.nav.gap.not_here"]'
+ view.pagy_t('pagy.nav.not_here').must_equal '[translation missing: "pagy.nav.not_here"]'
+ view.pagy_t('pagy.nav.gap.not_here').must_equal '[translation missing: "pagy.nav.gap.not_here"]'
end
end
@@ -141,16 +93,16 @@
it 'switches :locale according to @pagy_locale' do
Pagy::I18n.load({locale: 'de'}, {locale: 'en'}, {locale: 'nl'})
- frontend.instance_variable_set(:'@pagy_locale', 'nl')
- frontend.pagy_t('pagy.item_name', count: 1).must_equal "stuk"
- frontend.instance_variable_set(:'@pagy_locale', 'en')
- frontend.pagy_t('pagy.item_name', count: 1).must_equal "item"
- frontend.instance_variable_set(:'@pagy_locale', nil)
- frontend.pagy_t('pagy.item_name', count: 1).must_equal "Eintrag"
- frontend.instance_variable_set(:'@pagy_locale', 'unknown')
- frontend.pagy_t('pagy.item_name', count: 1).must_equal "Eintrag" # silently serves the first loaded locale
+ view.instance_variable_set(:'@pagy_locale', 'nl')
+ view.pagy_t('pagy.item_name', count: 1).must_equal "stuk"
+ view.instance_variable_set(:'@pagy_locale', 'en')
+ view.pagy_t('pagy.item_name', count: 1).must_equal "item"
+ view.instance_variable_set(:'@pagy_locale', nil)
+ view.pagy_t('pagy.item_name', count: 1).must_equal "Eintrag"
+ view.instance_variable_set(:'@pagy_locale', 'unknown')
+ view.pagy_t('pagy.item_name', count: 1).must_equal "Eintrag" # silently serves the first loaded locale
Pagy::I18n.load(locale: 'en') # reset for other tests
- frontend.instance_variable_set(:'@pagy_locale', nil) # reset for other tests
+ view.instance_variable_set(:'@pagy_locale', nil) # reset for other tests
end
end
@@ -158,19 +110,19 @@
describe "#pagy_info" do
it 'renders without i18n path' do
- frontend.pagy_info(Pagy.new count: 0).must_equal "No items found"
- frontend.pagy_info(Pagy.new count: 1).must_equal "Displaying
1 item"
- frontend.pagy_info(Pagy.new count: 13).must_equal "Displaying
13 items"
- frontend.pagy_info(Pagy.new count: 100, page: 3).must_equal "Displaying items
41-60 of
100 in total"
+ view.pagy_info(Pagy.new count: 0).must_equal "No items found"
+ view.pagy_info(Pagy.new count: 1).must_equal "Displaying
1 item"
+ view.pagy_info(Pagy.new count: 13).must_equal "Displaying
13 items"
+ view.pagy_info(Pagy.new count: 100, page: 3).must_equal "Displaying items
41-60 of
100 in total"
end
it 'renders with existing i18n path' do
Pagy::I18n['en'][0]['pagy.info.product.one'] = lambda{|_| 'Product'}
Pagy::I18n['en'][0]['pagy.info.product.other'] = lambda{|_| 'Products'}
- frontend.pagy_info(Pagy.new count: 0, i18n_key: 'pagy.info.product').must_equal "No Products found"
- frontend.pagy_info(Pagy.new count: 1, i18n_key: 'pagy.info.product').must_equal "Displaying
1 Product"
- frontend.pagy_info(Pagy.new count: 13, i18n_key: 'pagy.info.product').must_equal "Displaying
13 Products"
- frontend.pagy_info(Pagy.new count: 100, i18n_key: 'pagy.info.product', page: 3).must_equal "Displaying Products
41-60 of
100 in total"
+ view.pagy_info(Pagy.new count: 0, i18n_key: 'pagy.info.product').must_equal "No Products found"
+ view.pagy_info(Pagy.new count: 1, i18n_key: 'pagy.info.product').must_equal "Displaying
1 Product"
+ view.pagy_info(Pagy.new count: 13, i18n_key: 'pagy.info.product').must_equal "Displaying
13 Products"
+ view.pagy_info(Pagy.new count: 100, i18n_key: 'pagy.info.product', page: 3).must_equal "Displaying Products
41-60 of
100 in total"
Pagy::I18n.load(locale: 'en') # reset for other tests
end
end
@@ -179,26 +131,26 @@
it 'renders basic url' do
pagy = Pagy.new count: 1000, page: 3
- frontend.pagy_url_for(5, pagy). must_equal '/foo?page=5'
- frontend.pagy_url_for(5, pagy, :url). must_equal 'http://example.com:3000/foo?page=5'
+ view.pagy_url_for(5, pagy). must_equal '/foo?page=5'
+ view.pagy_url_for(5, pagy, :url). must_equal 'http://example.com:3000/foo?page=5'
end
it 'renders url with params' do
pagy = Pagy.new count: 1000, page: 3, params: {a: 3, b: 4}
- frontend.pagy_url_for(5, pagy).must_equal "/foo?page=5&a=3&b=4"
- frontend.pagy_url_for(5, pagy, :url).must_equal "http://example.com:3000/foo?page=5&a=3&b=4"
+ view.pagy_url_for(5, pagy).must_equal "/foo?page=5&a=3&b=4"
+ view.pagy_url_for(5, pagy, :url).must_equal "http://example.com:3000/foo?page=5&a=3&b=4"
end
it 'renders url with anchor' do
pagy = Pagy.new count: 1000, page: 3, anchor: '#anchor'
- frontend.pagy_url_for(6, pagy).must_equal '/foo?page=6#anchor'
- frontend.pagy_url_for(6, pagy, :url).must_equal 'http://example.com:3000/foo?page=6#anchor'
+ view.pagy_url_for(6, pagy).must_equal '/foo?page=6#anchor'
+ view.pagy_url_for(6, pagy, :url).must_equal 'http://example.com:3000/foo?page=6#anchor'
end
it 'renders url with params and anchor' do
pagy = Pagy.new count: 1000, page: 3, params: {a: 3, b: 4}, anchor: '#anchor'
- frontend.pagy_url_for(5, pagy).must_equal "/foo?page=5&a=3&b=4#anchor"
- frontend.pagy_url_for(5, pagy, :url).must_equal "http://example.com:3000/foo?page=5&a=3&b=4#anchor"
+ view.pagy_url_for(5, pagy).must_equal "/foo?page=5&a=3&b=4#anchor"
+ view.pagy_url_for(5, pagy, :url).must_equal "http://example.com:3000/foo?page=5&a=3&b=4#anchor"
end
end
@@ -206,7 +158,7 @@
describe '#pagy_get_params' do
it 'overrides params' do
- overridden = TestViewOverride.new
+ overridden = MockView::Overridden.new
pagy = Pagy.new count: 1000, page: 3, params: {a: 3, b: 4}, anchor: '#anchor'
overridden.pagy_url_for(5, pagy).must_equal "/foo?page=5&b=4&k=k#anchor"
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 053415929..beb0d7ec4 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -15,7 +15,6 @@
require 'pagy'
require 'pagy/countless'
require 'rack'
-require_relative 'test_helper/array'
-require_relative 'test_helper/frontend'
-require_relative 'test_helper/backend'
+require_relative 'mock_helpers/view'
+require_relative 'mock_helpers/controller'
require "minitest/autorun"
diff --git a/test/test_helper/array.rb b/test/test_helper/array.rb
deleted file mode 100644
index d73e34c53..000000000
--- a/test/test_helper/array.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# encoding: utf-8
-# frozen_string_literal: true
-
-class Pagy
- module Array
- # extend any array object to get the page method (mostly useful for testing)
- module PageMethod
- # extended_array = (1..100).to_a.extend(Pagy::Array::PageMethods)
- # pagy, paged = extended_array.page(4)
- def pagy(page, vars={})
- vars = VARS.merge(vars) # use merge instead of **vars for ruby versions < 2.*
- .merge(count: count, page: page) # add count and page
- pagy = Pagy.new(vars) # create the pagy object
- paged = self[pagy.offset, pagy.items] # paged using #offset and #items from the pagy object
- return pagy, paged # return the pagy object and the page of items
- end
-
- end
- end
-end
diff --git a/test/test_helper/backend.rb b/test/test_helper/backend.rb
deleted file mode 100644
index b2ad31916..000000000
--- a/test/test_helper/backend.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-# encoding: utf-8
-# frozen_string_literal: true
-
-class TestController
- include Pagy::Backend
- # we ned to explicitly include this because Pagy::Backend
- # does not include it when the test loads this module witout the headers
- include Pagy::Helpers
-
- attr_reader :params
-
- def initialize(params={a: 'a', page: 3})
- @params = params
- end
-
- def request
- @request ||= Rack::Request.new(Rack::MockRequest.env_for('https://example.com:8080/foo?page=1'))
- end
-
- def response
- @response ||= Rack::Response.new
- end
-
-end
-
-class TestCollection < Array
-
- def initialize(*args)
- super
- @collection = self.clone
- end
-
- def offset(value)
- @collection = self[value..-1]
- self
- end
-
- def limit(value)
- @collection[0, value]
- end
-
- def count(*)
- size
- end
-
-end
-
-class TestGroupedCollection < TestCollection
-
- def count(*)
- Hash[@collection.map { |value| [value, value + 1] }]
- end
-
-end
diff --git a/test/test_helper/frontend.rb b/test/test_helper/frontend.rb
deleted file mode 100644
index 1ba4e7332..000000000
--- a/test/test_helper/frontend.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# encoding: utf-8
-# frozen_string_literal: true
-
-class TestView
- include Pagy::Frontend
-
- def request
- Rack::Request.new(Rack::MockRequest.env_for('http://example.com:3000/foo?page=2'))
- end
-end
-
-class TestSimpleView
- include Pagy::Frontend
-
- def request
- Rack::Request.new(Rack::MockRequest.env_for('http://example.com:3000/foo?'))
- end
-end
-
-
-class TestViewOverride < TestView
- def pagy_get_params(params)
- params.except(:a).merge!(k: 'k')
- end
-end
-
-class Hash
- def except!(*keys)
- keys.each { |key| delete(key) }
- self
- end
-
- def except(*keys)
- dup.except!(*keys)
- end
-end
-