diff --git a/Gemfile b/Gemfile index 8efce3869..315aaf987 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } # test gem 'rake' -gem 'minitest' +gem 'minitest', '~> 5.12' gem 'minitest-reporters' gem 'rack' gem 'i18n' diff --git a/Gemfile.lock b/Gemfile.lock index 7ba49bed8..fea75eed9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,8 +213,8 @@ GEM jekyll (~> 3.5) jekyll-feed (~> 0.9) jekyll-seo-tag (~> 2.1) - minitest (5.11.3) - minitest-reporters (1.3.6) + minitest (5.12.2) + minitest-reporters (1.4.0) ansi builder minitest (>= 5.0) @@ -283,7 +283,7 @@ DEPENDENCIES codecov github-pages (= 198) i18n - minitest + minitest (~> 5.12) minitest-reporters oj rack diff --git a/test/locales/utils/p11n_test.rb b/test/locales/utils/p11n_test.rb index 3dd6b7557..8af6a90a0 100644 --- a/test/locales/utils/p11n_test.rb +++ b/test/locales/utils/p11n_test.rb @@ -12,12 +12,12 @@ describe :one_other do it "detects that 1 belongs to 'one'" do - p11n[:one_other].call(1).must_equal 'one' + _(p11n[:one_other].call(1)).must_equal 'one' end [0, 0.3, 1.2, 2, 3, 5, 10, 11, 21, 23, 31, 50, 81, 99, 100].each do |count| it "detects that #{count} belongs to 'other'" do - p11n[:one_other].call(count).must_equal 'other' + _(p11n[:one_other].call(count)).must_equal 'other' end end @@ -25,16 +25,16 @@ describe :one_two_other do it "detects that 1 belongs to 'one'" do - p11n[:one_two_other].call(1).must_equal 'one' + _(p11n[:one_two_other].call(1)).must_equal 'one' end it "detects that 2 belongs to 'two'" do - p11n[:one_two_other].call(2).must_equal 'two' + _(p11n[:one_two_other].call(2)).must_equal 'two' end [0, 0.3, 1.2, 3, 5, 10, 11, 21, 23, 31, 50, 81, 99, 100].each do |count| it "detects that #{count} belongs to 'other'" do - p11n[:one_two_other].call(count).must_equal 'other' + _(p11n[:one_two_other].call(count)).must_equal 'other' end end @@ -44,13 +44,13 @@ [0, 0.5, 1, 1.2, 1.8].each do |count| it "detects that #{count} belongs to 'one'" do - p11n[:one_upto_two_other].call(count).must_equal 'one' + _(p11n[:one_upto_two_other].call(count)).must_equal 'one' end end [2, 2.1, 5, 11, 21, 22, 37, 40, 900.5].each do |count| it "detects that #{count} belongs to 'other'" do - p11n[:one_upto_two_other].call(count).must_equal 'other' + _(p11n[:one_upto_two_other].call(count)).must_equal 'other' end end end @@ -59,7 +59,7 @@ [0, 1, 1.2, 2, 5, 11, 21, 22, 27, 99, 1000].each do |count| it "detects that #{count} belongs to 'other'" do - p11n[:other].call(count).must_equal 'other' + _(p11n[:other].call(count)).must_equal 'other' end end @@ -69,25 +69,25 @@ [1, 21, 51, 71, 101, 1031].each do |count| it "detects that #{count} belongs to 'one'" do - p11n[:east_slavic].call(count).must_equal 'one' + _(p11n[:east_slavic].call(count)).must_equal 'one' end end [2, 3, 4, 22, 23, 24, 92, 93, 94].each do |count| it "detects that #{count} belongs to 'few'" do - p11n[:east_slavic].call(count).must_equal 'few' + _(p11n[:east_slavic].call(count)).must_equal 'few' end end [0, 5, 8, 10, 11, 18, 20, 25, 27, 30, 35, 38, 40].each do |count| it "detects that #{count} belongs to 'many'" do - p11n[:east_slavic].call(count).must_equal 'many' + _(p11n[:east_slavic].call(count)).must_equal 'many' end end [1.2, 3.7, 11.5, 20.8, 1004.3].each do |count| it "detects that #{count} in ru is 'other'" do - p11n[:east_slavic].call(count).must_equal 'other' + _(p11n[:east_slavic].call(count)).must_equal 'other' end end @@ -96,24 +96,24 @@ describe :polish do it "detects that 1 belongs to 'one'" do - p11n[:polish].call(1).must_equal 'one' + _(p11n[:polish].call(1)).must_equal 'one' end [2, 3, 4, 22, 23, 24, 92, 93, 94].each do |count| it "detects that #{count} belongs to 'few'" do - p11n[:polish].call(count).must_equal 'few' + _(p11n[:polish].call(count)).must_equal 'few' end end [0, 5, 8, 10, 11, 18, 20, 21, 25, 27, 30, 31, 35, 38, 40, 41, 114].each do |count| it "detects that #{count} belongs to 'many'" do - p11n[:polish].call(count).must_equal 'many' + _(p11n[:polish].call(count)).must_equal 'many' end end [1.2, 3.7, 11.5, 20.8, 1004.3].each do |count| it "detects that #{count} belongs to 'other'" do - p11n[:polish].call(count).must_equal 'other' + _(p11n[:polish].call(count)).must_equal 'other' end end end diff --git a/test/pagy/backend_test.rb b/test/pagy/backend_test.rb index a051736fc..3a8ce3a4c 100644 --- a/test/pagy/backend_test.rb +++ b/test/pagy/backend_test.rb @@ -15,23 +15,23 @@ it 'paginates with defaults' do pagy, records = controller.send(:pagy, @collection) - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal Pagy::VARS[:items] - pagy.page.must_equal controller.params[:page] - records.count.must_equal Pagy::VARS[:items] - records.must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(pagy.page).must_equal controller.params[:page] + _(records.count).must_equal Pagy::VARS[:items] + _(records).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60] end it 'paginates with vars' do pagy, records = controller.send(:pagy, @collection, page: 2, items: 10, link_extra: 'X') - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal 10 - pagy.page.must_equal 2 - pagy.vars[:link_extra].must_equal 'X' - records.count.must_equal 10 - records.must_equal [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' + _(records.count).must_equal 10 + _(records).must_equal [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] end end @@ -45,46 +45,46 @@ it 'gets defaults' do vars = {} merged = controller.send :pagy_get_vars, @collection, vars - merged.keys.must_include :count - merged.keys.must_include :page - merged[:count].must_equal 1000 - merged[:page].must_equal 3 + _(merged.keys).must_include :count + _(merged.keys).must_include :page + _(merged[:count]).must_equal 1000 + _(merged[:page]).must_equal 3 end it 'gets vars' do vars = {page: 2, items: 10, link_extra: 'X'} merged = controller.send :pagy_get_vars, @collection, vars - merged.keys.must_include :count - merged.keys.must_include :page - merged.keys.must_include :items - merged.keys.must_include :link_extra - merged[:count].must_equal 1000 - merged[:page].must_equal 2 - merged[:items].must_equal 10 - merged[:link_extra].must_equal 'X' + _(merged.keys).must_include :count + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged.keys).must_include :link_extra + _(merged[:count]).must_equal 1000 + _(merged[:page]).must_equal 2 + _(merged[:items]).must_equal 10 + _(merged[:link_extra]).must_equal 'X' end it 'works with grouped collections' do @collection = MockCollection::Grouped.new((1..1000).to_a) vars = {page: 2, items: 10, link_extra: 'X'} merged = controller.send :pagy_get_vars, @collection, vars - merged.keys.must_include :count - merged.keys.must_include :page - merged.keys.must_include :items - merged.keys.must_include :link_extra - merged[:count].must_equal 1000 - merged[:page].must_equal 2 - merged[:items].must_equal 10 - merged[:link_extra].must_equal 'X' + _(merged.keys).must_include :count + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged.keys).must_include :link_extra + _(merged[:count]).must_equal 1000 + _(merged[:page]).must_equal 2 + _(merged[:items]).must_equal 10 + _(merged[:link_extra]).must_equal 'X' end it 'overrides count and page' do vars = {count: 10, page: 32} merged = controller.send :pagy_get_vars, @collection, vars - merged.keys.must_include :count - merged[:count].must_equal 10 - merged.keys.must_include :page - merged[:page].must_equal 32 + _(merged.keys).must_include :count + _(merged[:count]).must_equal 10 + _(merged.keys).must_include :page + _(merged[:page]).must_equal 32 end end @@ -95,7 +95,7 @@ collection = MockCollection.new pagy = Pagy.new count: 1000 items = controller.send :pagy_get_items, collection, pagy - items.must_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + _(items).must_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] end end diff --git a/test/pagy/countless_test.rb b/test/pagy/countless_test.rb index bd197d17c..257b02521 100644 --- a/test/pagy/countless_test.rb +++ b/test/pagy/countless_test.rb @@ -18,71 +18,71 @@ let(:last_page) { 3 } it 'raises exception with no retrieved items' do - proc { Pagy::Countless.new(page: 2).finalize(0) }.must_raise Pagy::OverflowError + _(proc { Pagy::Countless.new(page: 2).finalize(0) }).must_raise Pagy::OverflowError end it 'initializes empty collection' do pagy, _ = controller.send(:pagy_countless, @empty_collection, page: 1) - pagy.items.must_equal 20 - pagy.pages.must_equal 1 - pagy.last.must_equal 1 - pagy.from.must_equal 0 - pagy.to.must_equal 0 - pagy.prev.must_be_nil - pagy.next.must_be_nil + _(pagy.items).must_equal 20 + _(pagy.pages).must_equal 1 + _(pagy.last).must_equal 1 + _(pagy.from).must_equal 0 + _(pagy.to).must_equal 0 + _(pagy.prev).must_be_nil + _(pagy.next).must_be_nil end it 'initializes first page' do pagy, _ = controller.send(:pagy_countless, @collection, page: 1) - pagy.must_be_instance_of Pagy::Countless - pagy.items.must_equal 20 - pagy.last.must_equal 2 - pagy.pages.must_equal 2 # current + 1. `Countless` does not know real count - pagy.from.must_equal 1 - pagy.to.must_equal 20 - pagy.prev.must_be_nil - pagy.next.must_equal 2 + _(pagy).must_be_instance_of Pagy::Countless + _(pagy.items).must_equal 20 + _(pagy.last).must_equal 2 + _(pagy.pages).must_equal 2 # current + 1. `Countless` does not know real count + _(pagy.from).must_equal 1 + _(pagy.to).must_equal 20 + _(pagy.prev).must_be_nil + _(pagy.next).must_equal 2 end it 'initializes single full page' do pagy, _ = controller.send(:pagy_countless, MockCollection.new(Array(1..20)), page: 1) - pagy.items.must_equal 20 - pagy.pages.must_equal 1 - pagy.from.must_equal 1 - pagy.to.must_equal 20 - pagy.prev.must_be_nil - pagy.next.must_be_nil + _(pagy.items).must_equal 20 + _(pagy.pages).must_equal 1 + _(pagy.from).must_equal 1 + _(pagy.to).must_equal 20 + _(pagy.prev).must_be_nil + _(pagy.next).must_be_nil end it 'initialize single partial page' do pagy, _ = controller.send(:pagy_countless, MockCollection.new(Array(1..4)), page: 1) - pagy.items.must_equal 4 - pagy.pages.must_equal 1 - pagy.from.must_equal 1 - pagy.to.must_equal 4 - pagy.prev.must_be_nil - pagy.next.must_be_nil + _(pagy.items).must_equal 4 + _(pagy.pages).must_equal 1 + _(pagy.from).must_equal 1 + _(pagy.to).must_equal 4 + _(pagy.prev).must_be_nil + _(pagy.next).must_be_nil end it 'initializes last partial page' do pagy, _ = controller.send(:pagy_countless, @collection, page: last_page) - pagy.items.must_equal 19 - pagy.pages.must_equal last_page - pagy.from.must_equal 41 - pagy.to.must_equal 59 - pagy.prev.must_equal(last_page - 1) - pagy.next.must_be_nil + _(pagy.items).must_equal 19 + _(pagy.pages).must_equal last_page + _(pagy.from).must_equal 41 + _(pagy.to).must_equal 59 + _(pagy.prev).must_equal(last_page - 1) + _(pagy.next).must_be_nil end it 'handles the :cycle variable' do pagy, _ = controller.send(:pagy_countless, @collection, page: last_page, cycle: true) - pagy.items.must_equal 19 - pagy.pages.must_equal last_page - pagy.from.must_equal 41 - pagy.to.must_equal 59 - pagy.prev.must_equal(last_page - 1) - pagy.next.must_equal 1 + _(pagy.items).must_equal 19 + _(pagy.pages).must_equal last_page + _(pagy.from).must_equal 41 + _(pagy.to).must_equal 59 + _(pagy.prev).must_equal(last_page - 1) + _(pagy.next).must_equal 1 end end diff --git a/test/pagy/exceptions_test.rb b/test/pagy/exceptions_test.rb index 16e1ce13d..67a8e9eed 100644 --- a/test/pagy/exceptions_test.rb +++ b/test/pagy/exceptions_test.rb @@ -12,22 +12,22 @@ begin Pagy.new(count: 1, page: 0) rescue Pagy::VariableError => e - e.variable.must_equal :page - e.value.must_equal 0 + _(e.variable).must_equal :page + _(e.value).must_equal 0 end begin Pagy.new(count: 1, page: -10) rescue Pagy::VariableError => e - e.variable.must_equal :page - e.value.must_equal(-10) + _(e.variable).must_equal :page + _(e.value).must_equal(-10) end begin Pagy.new(count: 1, page: 'string') rescue Pagy::VariableError => e - e.variable.must_equal :page - e.value.must_equal 'string' + _(e.variable).must_equal :page + _(e.value).must_equal 'string' end end @@ -35,14 +35,14 @@ begin Pagy.new(count: -10) rescue Pagy::VariableError => e - e.variable.must_equal :count - e.value.must_equal(-10) + _(e.variable).must_equal :count + _(e.value).must_equal(-10) end begin Pagy.new(count: 'string') rescue Pagy::VariableError => e - e.variable.must_equal :count - e.value.must_equal 'string' + _(e.variable).must_equal :count + _(e.value).must_equal 'string' end end @@ -50,15 +50,15 @@ begin Pagy.new(count: 1, page: -10) rescue ArgumentError => e - e.variable.must_equal :page - e.value.must_equal(-10) + _(e.variable).must_equal :page + _(e.value).must_equal(-10) end begin Pagy.new(count: 'string') rescue ArgumentError => e - e.variable.must_equal :count - e.value.must_equal 'string' + _(e.variable).must_equal :count + _(e.value).must_equal 'string' end end diff --git a/test/pagy/extras/arel_test.rb b/test/pagy/extras/arel_test.rb index ff75ff3af..6c06a2a23 100644 --- a/test/pagy/extras/arel_test.rb +++ b/test/pagy/extras/arel_test.rb @@ -17,23 +17,23 @@ it 'paginates with defaults' do pagy, items = controller.send(:pagy_arel, @collection) - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal Pagy::VARS[:items] - pagy.page.must_equal controller.params[:page] - items.size.must_equal Pagy::VARS[:items] - items.must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(pagy.page).must_equal controller.params[:page] + _(items.size).must_equal Pagy::VARS[:items] + _(items).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60] end it 'paginates with vars' do pagy, items = controller.send(:pagy_arel, @collection, page: 2, items: 10, link_extra: 'X') - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal 10 - pagy.page.must_equal 2 - pagy.vars[:link_extra].must_equal 'X' - items.size.must_equal 10 - items.must_equal [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' + _(items.size).must_equal 10 + _(items).must_equal [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] end end @@ -47,46 +47,46 @@ it 'gets defaults' do vars = {} merged = controller.send :pagy_arel_get_vars, @collection, vars - merged.keys.must_include :count - merged.keys.must_include :page - merged[:count].must_equal 1000 - merged[:page].must_equal 3 + _(merged.keys).must_include :count + _(merged.keys).must_include :page + _(merged[:count]).must_equal 1000 + _(merged[:page]).must_equal 3 end it 'gets vars' do vars = {page: 2, items: 10, link_extra: 'X'} merged = controller.send :pagy_arel_get_vars, @collection, vars - merged.keys.must_include :count - merged.keys.must_include :page - merged.keys.must_include :items - merged.keys.must_include :link_extra - merged[:count].must_equal 1000 - merged[:page].must_equal 2 - merged[:items].must_equal 10 - merged[:link_extra].must_equal 'X' + _(merged.keys).must_include :count + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged.keys).must_include :link_extra + _(merged[:count]).must_equal 1000 + _(merged[:page]).must_equal 2 + _(merged[:items]).must_equal 10 + _(merged[:link_extra]).must_equal 'X' end it 'works with grouped collections' do @collection = MockCollection::Grouped.new((1..1000).to_a) vars = {page: 2, items: 10, link_extra: 'X'} merged = controller.send :pagy_arel_get_vars, @collection, vars - merged.keys.must_include :count - merged.keys.must_include :page - merged.keys.must_include :items - merged.keys.must_include :link_extra - merged[:count].must_equal 1000 - merged[:page].must_equal 2 - merged[:items].must_equal 10 - merged[:link_extra].must_equal 'X' + _(merged.keys).must_include :count + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged.keys).must_include :link_extra + _(merged[:count]).must_equal 1000 + _(merged[:page]).must_equal 2 + _(merged[:items]).must_equal 10 + _(merged[:link_extra]).must_equal 'X' end it 'overrides count and page' do vars = {count: 10, page: 32} merged = controller.send :pagy_arel_get_vars, @collection, vars - merged.keys.must_include :count - merged[:count].must_equal 10 - merged.keys.must_include :page - merged[:page].must_equal 32 + _(merged.keys).must_include :count + _(merged[:count]).must_equal 10 + _(merged.keys).must_include :page + _(merged[:page]).must_equal 32 end end diff --git a/test/pagy/extras/array_test.rb b/test/pagy/extras/array_test.rb index a79f51c1a..e23b81eee 100644 --- a/test/pagy/extras/array_test.rb +++ b/test/pagy/extras/array_test.rb @@ -16,23 +16,23 @@ it 'paginates with defaults' do pagy, items = controller.send(:pagy_array, @collection) - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal Pagy::VARS[:items] - pagy.page.must_equal controller.params[:page] - items.count.must_equal Pagy::VARS[:items] - items.must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(pagy.page).must_equal controller.params[:page] + _(items.count).must_equal Pagy::VARS[:items] + _(items).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60] end it 'paginates with vars' do pagy, items = controller.send(:pagy_array, @collection, page: 2, items: 10, link_extra: 'X') - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal 10 - pagy.page.must_equal 2 - pagy.vars[:link_extra].must_equal 'X' - items.count.must_equal 10 - items.must_equal [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' + _(items.count).must_equal 10 + _(items).must_equal [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] end end @@ -46,23 +46,23 @@ it 'gets defaults' do vars = {} merged = controller.send :pagy_array_get_vars, @collection, vars - merged.keys.must_include :count - merged.keys.must_include :page - merged[:count].must_equal 1000 - merged[:page].must_equal 3 + _(merged.keys).must_include :count + _(merged.keys).must_include :page + _(merged[:count]).must_equal 1000 + _(merged[:page]).must_equal 3 end it 'gets vars' do vars = {page: 2, items: 10, link_extra: 'X'} merged = controller.send :pagy_array_get_vars, @collection, vars - merged.keys.must_include :count - merged.keys.must_include :page - merged.keys.must_include :items - merged.keys.must_include :link_extra - merged[:count].must_equal 1000 - merged[:page].must_equal 2 - merged[:items].must_equal 10 - merged[:link_extra].must_equal 'X' + _(merged.keys).must_include :count + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged.keys).must_include :link_extra + _(merged[:count]).must_equal 1000 + _(merged[:page]).must_equal 2 + _(merged[:items]).must_equal 10 + _(merged[:link_extra]).must_equal 'X' end end diff --git a/test/pagy/extras/bootstrap_test.rb b/test/pagy/extras/bootstrap_test.rb index 2abb68ed5..6b29ad301 100644 --- a/test/pagy/extras/bootstrap_test.rb +++ b/test/pagy/extras/bootstrap_test.rb @@ -13,19 +13,19 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_bootstrap_nav(pagy).must_equal \ + _(view.pagy_bootstrap_nav(pagy)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_bootstrap_nav(pagy).must_equal \ + _(view.pagy_bootstrap_nav(pagy)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_bootstrap_nav(pagy).must_equal \ + _(view.pagy_bootstrap_nav(pagy)).must_equal \ "" end @@ -35,25 +35,25 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_bootstrap_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_bootstrap_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_bootstrap_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_bootstrap_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_bootstrap_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_bootstrap_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]}) - view.pagy_bootstrap_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_bootstrap_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) - view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 103, page: 3) - view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 103, page: 6) - view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end diff --git a/test/pagy/extras/bulma_test.rb b/test/pagy/extras/bulma_test.rb index c34417ae8..be6f9a0ae 100644 --- a/test/pagy/extras/bulma_test.rb +++ b/test/pagy/extras/bulma_test.rb @@ -13,20 +13,17 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_bulma_nav(pagy).must_equal \ - "" + _(view.pagy_bulma_nav(pagy)).must_equal "" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_bulma_nav(pagy).must_equal \ - "" + _(view.pagy_bulma_nav(pagy)).must_equal "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_bulma_nav(pagy).must_equal \ - "" + _(view.pagy_bulma_nav(pagy)).must_equal "" end end @@ -35,26 +32,22 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_bulma_nav_js(pagy, pagy_test_id).must_equal \ - "" + _(view.pagy_bulma_nav_js(pagy, pagy_test_id)).must_equal "" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_bulma_nav_js(pagy, pagy_test_id).must_equal \ - "" + _(view.pagy_bulma_nav_js(pagy, pagy_test_id)).must_equal "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_bulma_nav_js(pagy, pagy_test_id).must_equal \ - "" + _(view.pagy_bulma_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]}) - view.pagy_bulma_nav_js(pagy, pagy_test_id).must_equal \ - "" + _(view.pagy_bulma_nav_js(pagy, pagy_test_id)).must_equal "" end end @@ -63,21 +56,18 @@ it 'renders first page' do pagy = Pagy.new(count: 103, page: 1) - view.pagy_bulma_combo_nav_js(pagy, pagy_test_id).must_equal \ - "" + _(view.pagy_bulma_combo_nav_js(pagy, pagy_test_id)).must_equal "" end it 'renders intermediate page' do pagy = Pagy.new(count: 103, page: 3) html = view.pagy_bulma_combo_nav_js(pagy, pagy_test_id) - html.must_equal \ - "" + _(html).must_equal "" end it 'renders last page' do pagy = Pagy.new(count: 103, page: 6) - view.pagy_bulma_combo_nav_js(pagy, pagy_test_id).must_equal \ - "" + _(view.pagy_bulma_combo_nav_js(pagy, pagy_test_id)).must_equal "" end end diff --git a/test/pagy/extras/countless_test.rb b/test/pagy/extras/countless_test.rb index 29c84a165..515a0fb8f 100644 --- a/test/pagy/extras/countless_test.rb +++ b/test/pagy/extras/countless_test.rb @@ -23,44 +23,44 @@ it 'shows current and next for first page' do pagy, _ = controller.send(:pagy_countless, @collection, { size: [1, 4, 4, 1], page: 1 }) - pagy.series.must_equal ['1', 2] - pagy.prev.must_be_nil - pagy.next.must_equal 2 + _(pagy.series).must_equal ['1', 2] + _(pagy.prev).must_be_nil + _(pagy.next).must_equal 2 end it 'shows start-pages, :gap, before-pages, current and next for intermediate page' do pagy, _ = controller.send(:pagy_countless, @collection, {page: 25}) - pagy.series.must_equal [1, :gap, 21, 22, 23, 24, '25', 26] - pagy.prev.must_equal 24 - pagy.next.must_equal 26 + _(pagy.series).must_equal [1, :gap, 21, 22, 23, 24, '25', 26] + _(pagy.prev).must_equal 24 + _(pagy.next).must_equal 26 end it 'shows start-pages, :gap, before-pages, current and next for last page' do pagy, _ = controller.send(:pagy_countless, @collection, {page: last_page}) - pagy.series.must_equal [1, :gap, 46, 47, 48, 49, '50'] - pagy.prev.must_equal 49 - pagy.next.must_be_nil + _(pagy.series).must_equal [1, :gap, 46, 47, 48, 49, '50'] + _(pagy.prev).must_equal 49 + _(pagy.next).must_be_nil end it 'returns empty series for empty :size variable for first page' do pagy, _ = controller.send(:pagy_countless, @collection, {size: [], page: 1}) - pagy.series.must_equal [] - pagy.prev.must_be_nil - pagy.next.must_equal 2 + _(pagy.series).must_equal [] + _(pagy.prev).must_be_nil + _(pagy.next).must_equal 2 end it 'returns empty series for empty :size variable for intermediate page' do pagy, _ = controller.send(:pagy_countless, @collection, {size: [], page: 25}) - pagy.series.must_equal [] - pagy.prev.must_equal 24 - pagy.next.must_equal 26 + _(pagy.series).must_equal [] + _(pagy.prev).must_equal 24 + _(pagy.next).must_equal 26 end it 'returns empty series for empty :size variable for last page' do pagy, _ = controller.send(:pagy_countless, @collection, {size: [], page: last_page}) - pagy.series.must_equal [] - pagy.prev.must_equal 49 - pagy.next.must_be_nil + _(pagy.series).must_equal [] + _(pagy.prev).must_equal 49 + _(pagy.next).must_be_nil end end @@ -71,22 +71,22 @@ it 'sets :page_param from defaults' do Pagy::VARS[:page_param] = :page_number pagy, paged = controller.send(:pagy_countless, @collection) - pagy.page.must_equal 4 - paged.must_equal Array(61..80) + _(pagy.page).must_equal 4 + _(paged).must_equal Array(61..80) end it 'sets :page_param from vars' do Pagy::VARS[:page_param] = :page pagy, paged = controller.send(:pagy_countless, @collection, {page_param: :page_number}) - pagy.page.must_equal 4 - paged.must_equal Array(61..80) + _(pagy.page).must_equal 4 + _(paged).must_equal Array(61..80) end it 'bypasses :page_param with :page variable' do Pagy::VARS[:page_param] = :another_page_number pagy, paged = controller.send(:pagy_countless, @collection, {page_param: :page_number, page: 1}) - pagy.page.must_equal 1 - paged.must_equal Array(1..20) + _(pagy.page).must_equal 1 + _(paged).must_equal Array(1..20) end end diff --git a/test/pagy/extras/elasticsearch_rails_test.rb b/test/pagy/extras/elasticsearch_rails_test.rb index b777e710c..a6a5bb40e 100644 --- a/test/pagy/extras/elasticsearch_rails_test.rb +++ b/test/pagy/extras/elasticsearch_rails_test.rb @@ -12,19 +12,19 @@ describe '#pagy_search' do it 'extends the class with #pagy_search' do - MockElasticsearchRails::Model.must_respond_to :pagy_search + _(MockElasticsearchRails::Model).must_respond_to :pagy_search end it 'returns class and arguments' do - MockElasticsearchRails::Model.pagy_search('a', b:2).must_equal [MockElasticsearchRails::Model, ['a', {b: 2}], nil] + _(MockElasticsearchRails::Model.pagy_search('a', b:2)).must_equal [MockElasticsearchRails::Model, ['a', {b: 2}], nil] args = MockElasticsearchRails::Model.pagy_search('a', b:2){|a| a*2} block = args[-1] - args.must_equal [MockElasticsearchRails::Model, ['a', {b: 2}], block] + _(args).must_equal [MockElasticsearchRails::Model, ['a', {b: 2}], block] end it 'adds the caller and arguments' do - MockElasticsearchRails::Model.pagy_search('a', b:2).records.must_equal [MockElasticsearchRails::Model, ['a', {b: 2}], nil, :records] - MockElasticsearchRails::Model.pagy_search('a', b:2).a('b', 2).must_equal [MockElasticsearchRails::Model, ['a', {b: 2}], nil, :a, 'b', 2] + _(MockElasticsearchRails::Model.pagy_search('a', b:2).records).must_equal [MockElasticsearchRails::Model, ['a', {b: 2}], nil, :records] + _(MockElasticsearchRails::Model.pagy_search('a', b:2).a('b', 2)).must_equal [MockElasticsearchRails::Model, ['a', {b: 2}], nil, :a, 'b', 2] end end @@ -44,44 +44,44 @@ it 'paginates response with defaults' do pagy, response = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::Model.pagy_search('a')) records = response.records - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal Pagy::VARS[:items] - pagy.page.must_equal controller.params[:page] - records.count.must_equal Pagy::VARS[:items] - records.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"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(pagy.page).must_equal controller.params[:page] + _(records.count).must_equal Pagy::VARS[:items] + _(records).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 records with defaults' do pagy, records = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::Model.pagy_search('a').records) - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal Pagy::VARS[:items] - pagy.page.must_equal controller.params[:page] - records.count.must_equal Pagy::VARS[:items] - records.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"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(pagy.page).must_equal controller.params[:page] + _(records.count).must_equal Pagy::VARS[:items] + _(records).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, records = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::Model.pagy_search('b').records, page: 2, items: 10, link_extra: 'X') - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal 10 - pagy.page.must_equal 2 - pagy.vars[:link_extra].must_equal 'X' - records.count.must_equal 10 - records.must_equal ["R-b-11", "R-b-12", "R-b-13", "R-b-14", "R-b-15", "R-b-16", "R-b-17", "R-b-18", "R-b-19", "R-b-20"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' + _(records.count).must_equal 10 + _(records).must_equal ["R-b-11", "R-b-12", "R-b-13", "R-b-14", "R-b-15", "R-b-16", "R-b-17", "R-b-18", "R-b-19", "R-b-20"] end it 'paginates with overflow' do pagy, records = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::Model.pagy_search('b').records, 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 - pagy.page.must_equal 100 - pagy.vars[:link_extra].must_equal 'X' - records.count.must_equal 10 - records.must_equal ["R-b-991", "R-b-992", "R-b-993", "R-b-994", "R-b-995", "R-b-996", "R-b-997", "R-b-998", "R-b-999", "R-b-1000"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 100 + _(pagy.vars[:link_extra]).must_equal 'X' + _(records.count).must_equal 10 + _(records).must_equal ["R-b-991", "R-b-992", "R-b-993", "R-b-994", "R-b-995", "R-b-996", "R-b-997", "R-b-998", "R-b-999", "R-b-1000"] end end @@ -95,44 +95,44 @@ it 'paginates response with defaults' do pagy, response = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::ModelES7.pagy_search('a')) records = response.records - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal Pagy::VARS[:items] - pagy.page.must_equal controller.params[:page] - records.count.must_equal Pagy::VARS[:items] - records.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"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(pagy.page).must_equal controller.params[:page] + _(records.count).must_equal Pagy::VARS[:items] + _(records).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 records with defaults' do pagy, records = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::ModelES7.pagy_search('a').records) - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal Pagy::VARS[:items] - pagy.page.must_equal controller.params[:page] - records.count.must_equal Pagy::VARS[:items] - records.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"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(pagy.page).must_equal controller.params[:page] + _(records.count).must_equal Pagy::VARS[:items] + _(records).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, records = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::ModelES7.pagy_search('b').records, page: 2, items: 10, link_extra: 'X') - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal 10 - pagy.page.must_equal 2 - pagy.vars[:link_extra].must_equal 'X' - records.count.must_equal 10 - records.must_equal ["R-b-11", "R-b-12", "R-b-13", "R-b-14", "R-b-15", "R-b-16", "R-b-17", "R-b-18", "R-b-19", "R-b-20"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' + _(records.count).must_equal 10 + _(records).must_equal ["R-b-11", "R-b-12", "R-b-13", "R-b-14", "R-b-15", "R-b-16", "R-b-17", "R-b-18", "R-b-19", "R-b-20"] end it 'paginates with overflow' do pagy, records = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::Model.pagy_search('b').records, 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 - pagy.page.must_equal 100 - pagy.vars[:link_extra].must_equal 'X' - records.count.must_equal 10 - records.must_equal ["R-b-991", "R-b-992", "R-b-993", "R-b-994", "R-b-995", "R-b-996", "R-b-997", "R-b-998", "R-b-999", "R-b-1000"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 100 + _(pagy.vars[:link_extra]).must_equal 'X' + _(records.count).must_equal 10 + _(records).must_equal ["R-b-991", "R-b-992", "R-b-993", "R-b-994", "R-b-995", "R-b-996", "R-b-997", "R-b-998", "R-b-999", "R-b-1000"] end end @@ -142,21 +142,21 @@ it 'gets defaults' do vars = {} merged = controller.send :pagy_elasticsearch_rails_get_vars, nil, vars - merged.keys.must_include :page - merged.keys.must_include :items - merged[:page].must_equal 3 - merged[:items].must_equal 20 + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged[:page]).must_equal 3 + _(merged[:items]).must_equal 20 end it 'gets vars' do vars = {page: 2, items: 10, link_extra: 'X'} merged = controller.send :pagy_elasticsearch_rails_get_vars, nil, vars - merged.keys.must_include :page - merged.keys.must_include :items - merged.keys.must_include :link_extra - merged[:page].must_equal 2 - merged[:items].must_equal 10 - merged[:link_extra].must_equal 'X' + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged.keys).must_include :link_extra + _(merged[:page]).must_equal 2 + _(merged[:items]).must_equal 10 + _(merged[:link_extra]).must_equal 'X' end end @@ -166,20 +166,20 @@ it 'paginates response with defaults' do response = MockElasticsearchRails::Model.search('a') pagy = Pagy.new_from_elasticsearch_rails(response) - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal 10 - pagy.page.must_equal 1 + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 1 end it 'paginates response with vars' do response = MockElasticsearchRails::Model.search('b', from: 15, size: 15) pagy = Pagy.new_from_elasticsearch_rails(response, link_extra: 'X') - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal 15 - pagy.page.must_equal 2 - pagy.vars[:link_extra].must_equal 'X' + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 15 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' end end diff --git a/test/pagy/extras/foundation_test.rb b/test/pagy/extras/foundation_test.rb index 8f09d3b59..f957f0dfe 100644 --- a/test/pagy/extras/foundation_test.rb +++ b/test/pagy/extras/foundation_test.rb @@ -13,19 +13,19 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_foundation_nav(pagy).must_equal \ + _(view.pagy_foundation_nav(pagy)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_foundation_nav(pagy).must_equal \ + _(view.pagy_foundation_nav(pagy)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_foundation_nav(pagy).must_equal \ + _(view.pagy_foundation_nav(pagy)).must_equal \ "" end @@ -35,25 +35,25 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_foundation_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_foundation_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_foundation_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_foundation_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_foundation_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_foundation_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]}) - view.pagy_foundation_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_foundation_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) - view.pagy_foundation_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_foundation_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 103, page: 3) - view.pagy_foundation_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_foundation_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 103, page: 6) - view.pagy_foundation_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_foundation_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end diff --git a/test/pagy/extras/headers_test.rb b/test/pagy/extras/headers_test.rb index 0246c701b..9619e83c6 100644 --- a/test/pagy/extras/headers_test.rb +++ b/test/pagy/extras/headers_test.rb @@ -16,27 +16,27 @@ it 'returns the full headers hash' do pagy, _records = @controller.send(:pagy, @collection) - @controller.send(:pagy_headers, pagy).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"next\", ; rel=\"last\"", "Current-Page"=>3, "Page-Items"=>20, "Total-Pages"=>50, "Total-Count"=>1000}) + _(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"next\", ; rel=\"last\"", "Current-Page"=>3, "Page-Items"=>20, "Total-Pages"=>50, "Total-Count"=>1000}) end it 'returns custom headers hash' do pagy, _records = @controller.send(:pagy, @collection, headers:{items:'Per-Page', count: 'Total', pages:false}) - @controller.send(:pagy_headers, pagy).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"next\", ; rel=\"last\"", "Per-Page"=>20, "Total"=>1000}) + _(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"next\", ; rel=\"last\"", "Per-Page"=>20, "Total"=>1000}) end it 'returns the countless headers hash' do pagy, _records = @controller.send(:pagy_countless, @collection) - @controller.send(:pagy_headers, pagy).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"next\"", "Current-Page"=>3, "Page-Items"=>20}) + _(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"next\"", "Current-Page"=>3, "Page-Items"=>20}) end it 'omit prev on first page' do pagy, _records = @controller.send(:pagy, @collection, page: 1) - @controller.send(:pagy_headers, pagy).must_equal({"Link"=>"; rel=\"first\", ; rel=\"next\", ; rel=\"last\"", "Current-Page"=>1, "Page-Items"=>20, "Total-Pages"=>50, "Total-Count"=>1000}) + _(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"; rel=\"first\", ; rel=\"next\", ; rel=\"last\"", "Current-Page"=>1, "Page-Items"=>20, "Total-Pages"=>50, "Total-Count"=>1000}) end it 'omit next on last page' do pagy, _records = @controller.send(:pagy, @collection, page: 50) - @controller.send(:pagy_headers, pagy).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"last\"", "Current-Page"=>50, "Page-Items"=>20, "Total-Pages"=>50, "Total-Count"=>1000}) + _(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"last\"", "Current-Page"=>50, "Page-Items"=>20, "Total-Pages"=>50, "Total-Count"=>1000}) end end @@ -51,7 +51,7 @@ it 'returns the full headers hash' do pagy, _records = @controller.send(:pagy, @collection) @controller.send(:pagy_headers_merge, pagy) - @controller.send(:response).headers.must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"next\", ; rel=\"last\"", "Current-Page"=>3, "Page-Items"=>20, "Total-Pages"=>50, "Total-Count"=>1000}) + _(@controller.send(:response).headers).must_equal({"Link"=>"; rel=\"first\", ; rel=\"prev\", ; rel=\"next\", ; rel=\"last\"", "Current-Page"=>3, "Page-Items"=>20, "Total-Pages"=>50, "Total-Count"=>1000}) end end diff --git a/test/pagy/extras/i18n_test.rb b/test/pagy/extras/i18n_test.rb index d99f93a10..bab9fcde8 100644 --- a/test/pagy/extras/i18n_test.rb +++ b/test/pagy/extras/i18n_test.rb @@ -14,14 +14,14 @@ describe "#pagy_t with I18n" do it 'pluralizes' do - 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' + _(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 'handles missing paths' do - view.pagy_t('pagy.nav.not_here').must_equal 'translation missing: en.pagy.nav.not_here' + _(view.pagy_t('pagy.nav.not_here')).must_equal 'translation missing: en.pagy.nav.not_here' end end @@ -29,20 +29,20 @@ describe '#pagy_info with I18n' do it 'renders info' do - 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" + _(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 ::I18n.locale = 'en' custom_dictionary = File.join(File.dirname(__FILE__), 'i18n.yml') ::I18n.load_path += [custom_dictionary] - view.pagy_info(Pagy.new count: 0, i18n_key: 'activerecord.models.product').must_equal "No Products found" - view.pagy_info(Pagy.new count: 1, i18n_key: 'activerecord.models.product').must_equal "Displaying 1 Product" - view.pagy_info(Pagy.new count: 13, i18n_key: 'activerecord.models.product').must_equal "Displaying 13 Products" - view.pagy_info(Pagy.new count: 100, i18n_key: 'activerecord.models.product', page: 3).must_equal "Displaying Products 41-60 of 100 in total" + _(view.pagy_info(Pagy.new count: 0, i18n_key: 'activerecord.models.product')).must_equal "No Products found" + _(view.pagy_info(Pagy.new count: 1, i18n_key: 'activerecord.models.product')).must_equal "Displaying 1 Product" + _(view.pagy_info(Pagy.new count: 13, i18n_key: 'activerecord.models.product')).must_equal "Displaying 13 Products" + _(view.pagy_info(Pagy.new count: 100, i18n_key: 'activerecord.models.product', page: 3)).must_equal "Displaying Products 41-60 of 100 in total" end end diff --git a/test/pagy/extras/items_test.rb b/test/pagy/extras/items_test.rb index fb526a42c..45d68d7d2 100644 --- a/test/pagy/extras/items_test.rb +++ b/test/pagy/extras/items_test.rb @@ -23,27 +23,27 @@ [:pagy_get_vars, :pagy_countless_get_vars].each do |method| merged = controller.send method, @collection, vars - merged.keys.must_include :items - merged[:items].must_be_nil + _(merged.keys).must_include :items + _(merged[:items]).must_be_nil end merged = controller.send :pagy_elasticsearch_rails_get_vars, nil, vars - merged.keys.must_include :items - merged[:items].must_equal 20 + _(merged.keys).must_include :items + _(merged[:items]).must_equal 20 end it 'uses the vars' do vars = {items: 15} # force items params = {:a=>"a", :page=>3, :items=>12} controller = MockController.new params - controller.params.must_equal params + _(controller.params).must_equal params [:pagy, :pagy_countless].each do |method| pagy, _ = controller.send method, @collection, vars - pagy.items.must_equal 15 + _(pagy.items).must_equal 15 end [[:pagy_elasticsearch_rails, MockElasticsearchRails::Model], [:pagy_searchkick, MockSearchkick::Model]].each do |meth, mod| pagy, _ = controller.send meth, mod.pagy_search('a').records, vars - pagy.items.must_equal 15 + _(pagy.items).must_equal 15 end end @@ -51,15 +51,15 @@ vars = {} params = {:a=>"a", :page=>3, :items=>12} controller = MockController.new params - controller.params.must_equal params + _(controller.params).must_equal params [:pagy, :pagy_countless].each do |method| pagy, _ = controller.send method, @collection, vars - pagy.items.must_equal 12 + _(pagy.items).must_equal 12 end [[:pagy_elasticsearch_rails, MockElasticsearchRails::Model], [:pagy_searchkick, MockSearchkick::Model]].each do |meth, mod| pagy, _ = controller.send meth, mod.pagy_search('a').records, vars - pagy.items.must_equal 12 + _(pagy.items).must_equal 12 end end @@ -67,15 +67,15 @@ vars = {items: 21} params = {:a=>"a", :page=>3, :items=>12} controller = MockController.new params - controller.params.must_equal params + _(controller.params).must_equal params [:pagy, :pagy_countless].each do |method| pagy, _ = controller.send method, @collection, vars - pagy.items.must_equal 21 + _(pagy.items).must_equal 21 end [[:pagy_elasticsearch_rails, MockElasticsearchRails::Model], [:pagy_searchkick, MockSearchkick::Model]].each do |meth, mod| pagy, _ = controller.send meth, mod.pagy_search('a').records, vars - pagy.items.must_equal 21 + _(pagy.items).must_equal 21 end end @@ -83,15 +83,15 @@ vars = {} params = {:a=>"a", :page=>3, :items=>120} controller = MockController.new params - controller.params.must_equal params + _(controller.params).must_equal params [:pagy, :pagy_countless].each do |method| pagy, _ = controller.send method, @collection, vars - pagy.items.must_equal 100 + _(pagy.items).must_equal 100 end [[:pagy_elasticsearch_rails, MockElasticsearchRails::Model], [:pagy_searchkick, MockSearchkick::Model]].each do |meth, mod| pagy, _ = controller.send meth, mod.pagy_search('a').records, vars - pagy.items.must_equal 100 + _(pagy.items).must_equal 100 end end @@ -99,15 +99,15 @@ vars = {max_items: nil} params = {:a=>"a", :items=>1000} controller = MockController.new params - controller.params.must_equal params + _(controller.params).must_equal params [:pagy, :pagy_countless].each do |method| pagy, _ = controller.send method, @collection, vars - pagy.items.must_equal 1000 + _(pagy.items).must_equal 1000 end [[:pagy_elasticsearch_rails, MockElasticsearchRails::Model], [:pagy_searchkick, MockSearchkick::Model]].each do |meth, mod| pagy, _ = controller.send meth, mod.pagy_search('a').records, vars - pagy.items.must_equal 1000 + _(pagy.items).must_equal 1000 end end @@ -115,16 +115,16 @@ vars = {} params = {:a=>"a", :items=>1000} controller = MockController.new params - controller.params.must_equal params + _(controller.params).must_equal params Pagy::VARS[:max_items] = nil [:pagy, :pagy_countless].each do |method| pagy, _ = controller.send method, @collection, vars - pagy.items.must_equal 1000 + _(pagy.items).must_equal 1000 end [[:pagy_elasticsearch_rails, MockElasticsearchRails::Model], [:pagy_searchkick, MockSearchkick::Model]].each do |meth, mod| pagy, _ = controller.send meth, mod.pagy_search('a').records, vars - pagy.items.must_equal 1000 + _(pagy.items).must_equal 1000 end Pagy::VARS[:max_items] = 100 # reset default end @@ -133,15 +133,15 @@ vars = {items_param: :custom} params = {:a=>"a", :page=>3, :items_param=>:custom, :custom=>14} controller = MockController.new params - controller.params.must_equal params + _(controller.params).must_equal params [:pagy, :pagy_countless].each do |method| pagy, _ = controller.send method, @collection, vars - pagy.items.must_equal 14 + _(pagy.items).must_equal 14 end [[:pagy_elasticsearch_rails, MockElasticsearchRails::Model], [:pagy_searchkick, MockSearchkick::Model]].each do |meth, mod| pagy, _ = controller.send meth, mod.pagy_search('a').records, vars - pagy.items.must_equal 14 + _(pagy.items).must_equal 14 end end @@ -149,16 +149,16 @@ vars = {} params = {:a=>"a", :page=>3, :custom=>15} controller = MockController.new params - controller.params.must_equal params + _(controller.params).must_equal params Pagy::VARS[:items_param] = :custom [:pagy, :pagy_countless].each do |method| pagy, _ = controller.send method, @collection, vars - pagy.items.must_equal 15 + _(pagy.items).must_equal 15 end [[:pagy_elasticsearch_rails, MockElasticsearchRails::Model], [:pagy_searchkick, MockSearchkick::Model]].each do |meth, mod| pagy, _ = controller.send meth, mod.pagy_search('a').records, vars - pagy.items.must_equal 15 + _(pagy.items).must_equal 15 end Pagy::VARS[:items_param] = :items # reset default end @@ -175,27 +175,27 @@ it 'renders basic url' do pagy = Pagy.new count: 1000, page: 3 - view.pagy_url_for(5, pagy).must_equal '/foo?page=5&items=20' + _(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&items=20' end it 'renders basic url and items var' do pagy = Pagy.new count: 1000, page: 3, items: 50 - view.pagy_url_for(5, pagy).must_equal '/foo?page=5&items=50' + _(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&items=50' end it 'renders url with items_params' do pagy = Pagy.new count: 1000, page: 3, items_param: :custom - view.pagy_url_for(5, pagy).must_equal '/foo?page=5&custom=20' + _(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&custom=20' end it 'renders url with anchor' do pagy = Pagy.new count: 1000, page: 3, anchor: '#anchor' - view.pagy_url_for(6, pagy).must_equal '/foo?page=6&items=20#anchor' + _(view.pagy_url_for(6, pagy)).must_equal '/foo?page=6&items=20#anchor' end it 'renders url with params and anchor' do pagy = Pagy.new count: 1000, page: 3, params: {a: 3, b: 4}, anchor: '#anchor', items: 40 - view.pagy_url_for(5, pagy).must_equal "/foo?page=5&a=3&b=4&items=40#anchor" + _(view.pagy_url_for(5, pagy)).must_equal "/foo?page=5&a=3&b=4&items=40#anchor" end end @@ -204,7 +204,7 @@ it 'renders items selector' do @pagy = Pagy.new count: 1000, page: 3 - view.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/materialize_test.rb b/test/pagy/extras/materialize_test.rb index a02eec1e9..af759743b 100644 --- a/test/pagy/extras/materialize_test.rb +++ b/test/pagy/extras/materialize_test.rb @@ -13,20 +13,20 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_materialize_nav(pagy).must_equal \ + _(view.pagy_materialize_nav(pagy)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_materialize_nav(pagy).must_equal \ + _(view.pagy_materialize_nav(pagy)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_materialize_nav(pagy).must_equal \ + _(view.pagy_materialize_nav(pagy)).must_equal \ "" end @@ -36,25 +36,25 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_materialize_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_materialize_nav_js(pagy, pagy_test_id)).must_equal \ "
" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_materialize_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_materialize_nav_js(pagy, pagy_test_id)).must_equal \ "
" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_materialize_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_materialize_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]}) - view.pagy_materialize_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_materialize_nav_js(pagy, pagy_test_id)).must_equal \ "
" end @@ -64,19 +64,19 @@ it 'renders first page' do pagy = Pagy.new(count: 103, page: 1) - view.pagy_materialize_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_materialize_combo_nav_js(pagy, pagy_test_id)).must_equal \ "
" end it 'renders intermediate page' do pagy = Pagy.new(count: 103, page: 3) - view.pagy_materialize_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_materialize_combo_nav_js(pagy, pagy_test_id)).must_equal \ "
" end it 'renders last page' do pagy = Pagy.new(count: 103, page: 6) - view.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/metadata_test.rb b/test/pagy/extras/metadata_test.rb index b3b7050f5..377121e3b 100644 --- a/test/pagy/extras/metadata_test.rb +++ b/test/pagy/extras/metadata_test.rb @@ -16,24 +16,24 @@ end it 'defines all metadata' do - Pagy::VARS[:metadata].must_equal [:scaffold_url, :first_url, :prev_url, :page_url, :next_url, :last_url, :count, :page, :items, :vars, :pages, :last, :from, :to, :prev, :next, :series, :sequels] + _(Pagy::VARS[:metadata]).must_equal [:scaffold_url, :first_url, :prev_url, :page_url, :next_url, :last_url, :count, :page, :items, :vars, :pages, :last, :from, :to, :prev, :next, :series, :sequels] end it 'returns the full pagy metadata' do pagy, _records = @controller.send(:pagy, @collection) - @controller.send(:pagy_metadata, pagy).must_equal( + _(@controller.send(:pagy_metadata, pagy)).must_equal( {:scaffold_url=>"/foo?page=__pagy_page__", :first_url=>"/foo?page=1", :prev_url=>"/foo?page=2", :page_url=>"/foo?page=3", :next_url=>"/foo?page=4", :last_url=>"/foo?page=50", :count=>1000, :page=>3, :items=>20, :vars=>{:page=>3, :items=>20, :outset=>0, :size=>[1, 4, 4, 1], :page_param=>:page, :params=>{}, :anchor=>"", :link_extra=>"", :i18n_key=>"pagy.item_name", :cycle=>false, :steps=>false, :metadata=>[:scaffold_url, :first_url, :prev_url, :page_url, :next_url, :last_url, :count, :page, :items, :vars, :pages, :last, :from, :to, :prev, :next, :series, :sequels], :count=>1000}, :pages=>50, :last=>50, :from=>41, :to=>60, :prev=>2, :next=>4, :series=>[1, 2, "3", 4, 5, 6, 7, :gap, 50], :sequels=>{"0"=>[1, 2, "3", 4, 5, 6, 7, :gap, 50]}} ) end it 'checks for unknown metadata' do pagy, _records = @controller.send(:pagy, @collection, metadata: [:page, :unknown_key]) - proc { @controller.send(:pagy_metadata, pagy)}.must_raise Pagy::VariableError + _(proc { @controller.send(:pagy_metadata, pagy)}).must_raise Pagy::VariableError end it 'returns only specific metadata' do pagy, _records = @controller.send(:pagy, @collection, metadata: [:scaffold_url, :page, :count, :prev, :next, :pages]) - @controller.send(:pagy_metadata, pagy).must_equal( + _(@controller.send(:pagy_metadata, pagy)).must_equal( {:scaffold_url=>"/foo?page=__pagy_page__", :page=>3, :count=>1000, :prev=>2, :next=>4, :pages=>50} ) end diff --git a/test/pagy/extras/navs_test.rb b/test/pagy/extras/navs_test.rb index b2f4f9173..9ae94a97b 100644 --- a/test/pagy/extras/navs_test.rb +++ b/test/pagy/extras/navs_test.rb @@ -13,25 +13,25 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.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) - view.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) - view.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]}) - view.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) - view.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 103, page: 3) - view.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 103, page: 6) - view.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end diff --git a/test/pagy/extras/overflow_test.rb b/test/pagy/extras/overflow_test.rb index b6d5a0490..34d7c039e 100644 --- a/test/pagy/extras/overflow_test.rb +++ b/test/pagy/extras/overflow_test.rb @@ -20,7 +20,7 @@ describe "variables" do it 'has vars defaults' do - Pagy::VARS[:overflow].must_equal :empty_page # default for countless + _(Pagy::VARS[:overflow]).must_equal :empty_page # default for countless end end @@ -28,9 +28,9 @@ describe "#overflow?" do it 'must be overflow?' do - @pagy.must_be :overflow? - @pagy_countless.must_be :overflow? - Pagy.new(vars.merge(page:2)).wont_be :overflow? + _(@pagy).must_be :overflow? + _(@pagy_countless).must_be :overflow? + _(Pagy.new(vars.merge(page:2))).wont_be :overflow? end end @@ -40,34 +40,34 @@ it 'works in :last_page mode' do pagy = Pagy.new(vars.merge(overflow: :last_page)) - pagy.must_be_instance_of Pagy - pagy.page.must_equal pagy.last - pagy.vars[:page].must_equal 100 - pagy.offset.must_equal 100 - pagy.items.must_equal 3 - pagy.from.must_equal 101 - pagy.to.must_equal 103 - pagy.prev.must_equal 10 + _(pagy).must_be_instance_of Pagy + _(pagy.page).must_equal pagy.last + _(pagy.vars[:page]).must_equal 100 + _(pagy.offset).must_equal 100 + _(pagy.items).must_equal 3 + _(pagy.from).must_equal 101 + _(pagy.to).must_equal 103 + _(pagy.prev).must_equal 10 end it 'raises OverflowError in :exception mode' do - proc { Pagy.new(vars.merge(overflow: :exception)) }.must_raise Pagy::OverflowError - proc { Pagy::Countless.new(countless_vars.merge(overflow: :exception)).finalize(0) }.must_raise Pagy::OverflowError + _(proc { Pagy.new(vars.merge(overflow: :exception)) }).must_raise Pagy::OverflowError + _(proc { Pagy::Countless.new(countless_vars.merge(overflow: :exception)).finalize(0) }).must_raise Pagy::OverflowError end it 'works in :empty_page mode' do pagy = Pagy.new(vars.merge(overflow: :empty_page)) - pagy.page.must_equal 100 - pagy.offset.must_equal 0 - pagy.items.must_equal 0 - pagy.from.must_equal 0 - pagy.to.must_equal 0 - pagy.prev.must_equal pagy.last + _(pagy.page).must_equal 100 + _(pagy.offset).must_equal 0 + _(pagy.items).must_equal 0 + _(pagy.from).must_equal 0 + _(pagy.to).must_equal 0 + _(pagy.prev).must_equal pagy.last end it 'raises Pagy::VariableError' do - proc { Pagy.new(vars.merge(overflow: :unknown)) }.must_raise Pagy::VariableError - proc { Pagy::Countless.new(countless_vars.merge(overflow: :unknown)).finalize(0) }.must_raise Pagy::VariableError + _(proc { Pagy.new(vars.merge(overflow: :unknown)) }).must_raise Pagy::VariableError + _(proc { Pagy::Countless.new(countless_vars.merge(overflow: :unknown)).finalize(0) }).must_raise Pagy::VariableError end end @@ -77,14 +77,14 @@ it 'computes series for last page' do pagy = Pagy.new(vars.merge(overflow: :empty_page)) series = pagy.series - series.must_equal [1, 2, 3, :gap, 9, 10, 11] - pagy.page.must_equal 100 + _(series).must_equal [1, 2, 3, :gap, 9, 10, 11] + _(pagy.page).must_equal 100 end it 'computes empty series' do series = @pagy_countless.series - series.must_equal [] - @pagy_countless.page.must_equal 100 + _(series).must_equal [] + _(@pagy_countless.page).must_equal 100 end end diff --git a/test/pagy/extras/searchkick_test.rb b/test/pagy/extras/searchkick_test.rb index d2142ceed..dc2ac556b 100644 --- a/test/pagy/extras/searchkick_test.rb +++ b/test/pagy/extras/searchkick_test.rb @@ -12,33 +12,33 @@ describe '#pagy_search' do it 'extends the class with #pagy_search' do - MockSearchkick::Model.must_respond_to :pagy_search + _(MockSearchkick::Model).must_respond_to :pagy_search end it 'returns class and arguments' do - MockSearchkick::Model.pagy_search('a', b:2).must_equal [MockSearchkick::Model, ['a', {b: 2}], nil] + _(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 [MockSearchkick::Model, ['a', {b: 2}], block] + _(args).must_equal [MockSearchkick::Model, ['a', {b: 2}], block] end it 'allows the term argument to be optional' do - MockSearchkick::Model.pagy_search(b:2).must_equal [MockSearchkick::Model, [{b: 2}], nil] + _(MockSearchkick::Model.pagy_search(b:2)).must_equal [MockSearchkick::Model, [{b: 2}], nil] args = MockSearchkick::Model.pagy_search(b:2){|a| a*2} block = args[-1] - args.must_equal [MockSearchkick::Model, [{b: 2}], block] + _(args).must_equal [MockSearchkick::Model, [{b: 2}], block] end it 'adds an empty option hash' do - MockSearchkick::Model.pagy_search('a').must_equal [MockSearchkick::Model, ['a', {}], nil] + _(MockSearchkick::Model.pagy_search('a')).must_equal [MockSearchkick::Model, ['a', {}], nil] args = MockSearchkick::Model.pagy_search('a'){|a| a*2} block = args[-1] - args.must_equal [MockSearchkick::Model, ['a', {}], block] + _(args).must_equal [MockSearchkick::Model, ['a', {}], block] end it 'adds the caller and arguments' do - 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] + _(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 @@ -58,44 +58,44 @@ it 'paginates response with defaults' do 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 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"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(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 = 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 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"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal Pagy::VARS[:items] + _(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 = 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 - pagy.page.must_equal 2 - pagy.vars[:link_extra].must_equal 'X' - results.count.must_equal 10 - results.must_equal ["R-b-11", "R-b-12", "R-b-13", "R-b-14", "R-b-15", "R-b-16", "R-b-17", "R-b-18", "R-b-19", "R-b-20"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' + _(results.count).must_equal 10 + _(results).must_equal ["R-b-11", "R-b-12", "R-b-13", "R-b-14", "R-b-15", "R-b-16", "R-b-17", "R-b-18", "R-b-19", "R-b-20"] end it 'paginates with overflow' do 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 - pagy.page.must_equal 100 - pagy.vars[:link_extra].must_equal 'X' - results.count.must_equal 10 - results.must_equal ["R-b-991", "R-b-992", "R-b-993", "R-b-994", "R-b-995", "R-b-996", "R-b-997", "R-b-998", "R-b-999", "R-b-1000"] + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 100 + _(pagy.vars[:link_extra]).must_equal 'X' + _(results.count).must_equal 10 + _(results).must_equal ["R-b-991", "R-b-992", "R-b-993", "R-b-994", "R-b-995", "R-b-996", "R-b-997", "R-b-998", "R-b-999", "R-b-1000"] end end @@ -105,21 +105,21 @@ it 'gets defaults' do 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 - merged[:items].must_equal 20 + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged[:page]).must_equal 3 + _(merged[:items]).must_equal 20 end it 'gets vars' do vars = {page: 2, items: 10, link_extra: 'X'} 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 - merged[:page].must_equal 2 - merged[:items].must_equal 10 - merged[:link_extra].must_equal 'X' + _(merged.keys).must_include :page + _(merged.keys).must_include :items + _(merged.keys).must_include :link_extra + _(merged[:page]).must_equal 2 + _(merged[:items]).must_equal 10 + _(merged[:link_extra]).must_equal 'X' end end @@ -129,20 +129,20 @@ it 'paginates results with defaults' do results = MockSearchkick::Model.search('a') pagy = Pagy.new_from_searchkick(results) - pagy.must_be_instance_of Pagy - pagy.count.must_equal 1000 - pagy.items.must_equal 1000 - pagy.page.must_equal 1 + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 1000 + _(pagy.page).must_equal 1 end it 'paginates results with vars' do 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 - pagy.items.must_equal 15 - pagy.page.must_equal 2 - pagy.vars[:link_extra].must_equal 'X' + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 15 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' end end diff --git a/test/pagy/extras/semantic_test.rb b/test/pagy/extras/semantic_test.rb index 7920c3ca8..2f448117b 100644 --- a/test/pagy/extras/semantic_test.rb +++ b/test/pagy/extras/semantic_test.rb @@ -13,19 +13,19 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.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) - view.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) - view.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) - view.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) - view.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) - view.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]}) - view.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) - view.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_semantic_combo_nav_js(pagy, pagy_test_id)).must_equal \ "
Page of 6
" end it 'renders intermediate page' do pagy = Pagy.new(count: 103, page: 3) - view.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_semantic_combo_nav_js(pagy, pagy_test_id)).must_equal \ "
Page of 6
" end it 'renders last page' do pagy = Pagy.new(count: 103, page: 6) - view.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_semantic_combo_nav_js(pagy, pagy_test_id)).must_equal \ "
Page of 6
" end diff --git a/test/pagy/extras/shared_combo_test.rb b/test/pagy/extras/shared_combo_test.rb index 065b2e824..a8c067fc6 100644 --- a/test/pagy/extras/shared_combo_test.rb +++ b/test/pagy/extras/shared_combo_test.rb @@ -16,33 +16,16 @@ it 'should return the marked link' do pagy = Pagy.new(count: 100, page: 4) - view.instance_eval do - pagy_marked_link(pagy_link_proc(pagy)).must_equal( - "" - ) - end + _(view.pagy_marked_link(view.pagy_link_proc(pagy))).must_equal "" pagy = Pagy.new(count: 100, page: 4, page_param: 'p') - view.instance_eval do - pagy_marked_link(pagy_link_proc(pagy)).must_equal( - "" - ) - end + _(view.pagy_marked_link(view.pagy_link_proc(pagy))).must_equal "" pagy = Pagy.new(count: 100, page: 4, items_param: 'i') - view.instance_eval do - pagy_marked_link(pagy_link_proc(pagy)).must_equal( - "" - ) - end + _(view.pagy_marked_link(view.pagy_link_proc(pagy))).must_equal "" pagy = Pagy.new(count: 100, page: 4, page_param: 'p', items_param: 'i') - view.instance_eval do - pagy_marked_link(pagy_link_proc(pagy)).must_equal( - "" - ) - end - + _(view.pagy_marked_link(view.pagy_link_proc(pagy))).must_equal "" end @@ -52,8 +35,7 @@ it 'renders items selector with trim' do pagy = Pagy.new count: 1000, page: 3 - view.pagy_items_selector_js(pagy, 'test-id').must_equal \ - "Show items per page" + _(view.pagy_items_selector_js(pagy, 'test-id')).must_equal "Show items per page" end end diff --git a/test/pagy/extras/shared_test.rb b/test/pagy/extras/shared_test.rb index b9a68e4b2..c16292d89 100644 --- a/test/pagy/extras/shared_test.rb +++ b/test/pagy/extras/shared_test.rb @@ -17,7 +17,7 @@ describe "#pagy_json_tag" do it 'should use oj' do - view.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 @@ -29,9 +29,9 @@ it 'should return different SHA1 ids' do id1 = call_pagy_id id2 = call_pagy_id - id1.must_be_kind_of String - id2.must_be_kind_of String - id1.must_be :!=, id2 + _(id1).must_be_kind_of String + _(id2).must_be_kind_of String + _(id1).must_be :!=, id2 end end @@ -40,13 +40,9 @@ it 'should return only the "standard" link' do pagy = Pagy.new(count: 100, page: 4) - view.instance_eval do - pagy_marked_link(pagy_link_proc(pagy)).must_equal("") - end + _(view.pagy_marked_link(view.pagy_link_proc(pagy))).must_equal("") pagy = Pagy.new(count: 100, page: 4, page_param: 'p') - view.instance_eval do - pagy_marked_link(pagy_link_proc(pagy)).must_equal("") - end + _(view.pagy_marked_link(view.pagy_link_proc(pagy))).must_equal("") end end diff --git a/test/pagy/extras/support_test.rb b/test/pagy/extras/support_test.rb index ba083d40e..ae056d10f 100644 --- a/test/pagy/extras/support_test.rb +++ b/test/pagy/extras/support_test.rb @@ -16,29 +16,29 @@ 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) - view.pagy_prev_url(pagy).must_be_nil - view.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) - view.pagy_prev_url(pagy).must_equal '/foo?page=2' - view.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) - view.pagy_prev_url(pagy).must_equal '/foo?page=5' - view.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) - view.pagy_prev_url(pagy).must_equal '/foo?page=49' - view.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) - view.pagy_next_url(pagy).must_equal '/foo?page=2' - view.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) - view.pagy_next_url(pagy).must_equal '/foo?page=4' - view.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) - view.pagy_next_url(pagy).must_equal '/foo?page=7' - view.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) - view.pagy_next_url(pagy).must_be_nil - view.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) - view.pagy_prev_link(pagy).must_equal "‹ Prev" - view.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) - view.pagy_prev_link(pagy).must_equal "‹ Prev" - view.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) - view.pagy_prev_link(pagy).must_equal "‹ Prev" - view.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) - view.pagy_prev_link(pagy).must_equal "‹ Prev" - view.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) - view.pagy_next_link(pagy).must_equal "Next ›" - view.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) - view.pagy_next_link(pagy).must_equal "Next ›" - view.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) - view.pagy_next_link(pagy).must_equal "Next ›" - view.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) - view.pagy_next_link(pagy).must_equal "Next ›" - view.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 6bff241ad..9f7609e64 100644 --- a/test/pagy/extras/trim_test.rb +++ b/test/pagy/extras/trim_test.rb @@ -38,7 +38,7 @@ view = MockView.new("http://example.com:3000/foo#{generated}") pagy = Pagy.new(count: 1000, page: page) link = view.pagy_link_proc(pagy) - link.call(page).must_equal("#{page}") + _(link.call(page)).must_equal("#{page}") end end @@ -49,22 +49,19 @@ it 'renders first page' do pagy = Pagy.new(count: 103, page: 1) html = view.pagy_nav(pagy) - html.must_equal \ - "" + _(html).must_equal "" end it 'renders intermediate page' do pagy = Pagy.new(count: 103, page: 3) html = view.pagy_nav(pagy) - html.must_equal \ - "" + _(html).must_equal "" end it 'renders last page' do pagy = Pagy.new(count: 103, page: 6) html = view.pagy_nav(pagy) - html.must_equal \ - "" + _(html).must_equal "" end end @@ -73,30 +70,22 @@ it 'renders first page' do pagy = Pagy.new(count: 103, page: 1) - view.pagy_nav_js(pagy, pagy_test_id).must_equal \ - "" - view.pagy_bootstrap_nav_js(pagy, pagy_test_id).must_equal \ - "" - view.pagy_bulma_nav_js(pagy, pagy_test_id).must_equal \ - "" - view.pagy_foundation_nav_js(pagy, pagy_test_id).must_equal \ - "" - view.pagy_materialize_nav_js(pagy, pagy_test_id).must_equal \ - "
" - view.pagy_semantic_nav_js(pagy, pagy_test_id).must_equal \ - "
" + _(view.pagy_nav_js(pagy, pagy_test_id)).must_equal "" + _(view.pagy_bootstrap_nav_js(pagy, pagy_test_id)).must_equal "" + _(view.pagy_bulma_nav_js(pagy, pagy_test_id)).must_equal "" + _(view.pagy_foundation_nav_js(pagy, pagy_test_id)).must_equal "" + _(view.pagy_materialize_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) - view.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) - view.pagy_nav_js(pagy, pagy_test_id).must_equal \ - "" + _(view.pagy_nav_js(pagy, pagy_test_id)).must_equal "" end end @@ -105,32 +94,24 @@ it 'renders first page' do pagy = Pagy.new(count: 103, page: 1) - view.pagy_combo_nav_js(pagy, pagy_test_id).must_equal \ - "" - view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id).must_equal \ - "" - view.pagy_bulma_combo_nav_js(pagy, pagy_test_id).must_equal \ - "" - view.pagy_foundation_combo_nav_js(pagy, pagy_test_id).must_equal \ - "" - view.pagy_materialize_combo_nav_js(pagy, pagy_test_id).must_equal \ - "
" - view.pagy_semantic_combo_nav_js(pagy, pagy_test_id).must_equal \ - "
Page of 6
" + _(view.pagy_combo_nav_js(pagy, pagy_test_id)).must_equal "" + _(view.pagy_bootstrap_combo_nav_js(pagy, pagy_test_id)).must_equal "" + _(view.pagy_bulma_combo_nav_js(pagy, pagy_test_id)).must_equal "" + _(view.pagy_foundation_combo_nav_js(pagy, pagy_test_id)).must_equal "" + _(view.pagy_materialize_combo_nav_js(pagy, pagy_test_id)).must_equal "
" + _(view.pagy_semantic_combo_nav_js(pagy, pagy_test_id)).must_equal "
Page of 6
" end it 'renders intermediate page' do pagy = Pagy.new(count: 103, page: 3) html = view.pagy_combo_nav_js(pagy, pagy_test_id) - html.must_equal \ - "" + _(html).must_equal "" end it 'renders last page' do pagy = Pagy.new(count: 103, page: 6) html = view.pagy_combo_nav_js(pagy, pagy_test_id) - html.must_equal \ - "" + _(html).must_equal "" end end diff --git a/test/pagy/extras/uikit_test.rb b/test/pagy/extras/uikit_test.rb index bf2adb1fb..560364a38 100644 --- a/test/pagy/extras/uikit_test.rb +++ b/test/pagy/extras/uikit_test.rb @@ -13,19 +13,19 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_uikit_nav(pagy).must_equal \ + _(view.pagy_uikit_nav(pagy)).must_equal \ "" end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_uikit_nav(pagy).must_equal \ + _(view.pagy_uikit_nav(pagy)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_uikit_nav(pagy).must_equal \ + _(view.pagy_uikit_nav(pagy)).must_equal \ "" end @@ -35,19 +35,19 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_uikit_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_uikit_nav_js(pagy, pagy_test_id)).must_equal \ "
    " end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_uikit_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_uikit_nav_js(pagy, pagy_test_id)).must_equal \ "
      " end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_uikit_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_uikit_nav_js(pagy, pagy_test_id)).must_equal \ "
        " end @@ -57,19 +57,19 @@ it 'renders first page' do pagy = Pagy.new(count: 1000, page: 1) - view.pagy_uikit_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_uikit_combo_nav_js(pagy, pagy_test_id)).must_equal \ "
        Page of 50
        Next ›
        " end it 'renders intermediate page' do pagy = Pagy.new(count: 1000, page: 20) - view.pagy_uikit_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_uikit_combo_nav_js(pagy, pagy_test_id)).must_equal \ "" end it 'renders last page' do pagy = Pagy.new(count: 1000, page: 50) - view.pagy_uikit_combo_nav_js(pagy, pagy_test_id).must_equal \ + _(view.pagy_uikit_combo_nav_js(pagy, pagy_test_id)).must_equal \ "
        ‹ Prev
        Page of 50
        " end diff --git a/test/pagy/frontend_test.rb b/test/pagy/frontend_test.rb index 977334047..72af9a9a8 100644 --- a/test/pagy/frontend_test.rb +++ b/test/pagy/frontend_test.rb @@ -11,32 +11,32 @@ it 'renders page 1' do pagy = Pagy.new count: 103, page: 1 - view.pagy_nav(pagy).must_equal \ + _(view.pagy_nav(pagy)).must_equal \ "" end it 'renders page 3' do pagy = Pagy.new count: 103, page: 3 - view.pagy_nav(pagy).must_equal \ + _(view.pagy_nav(pagy)).must_equal \ "" end it 'renders page 6' do pagy = Pagy.new count: 103, page: 6 - view.pagy_nav(pagy).must_equal \ + _(view.pagy_nav(pagy)).must_equal \ "" end it 'renders page 10' do pagy = Pagy.new count: 1000, page: 10 - view.pagy_nav(pagy).must_equal \ + _(view.pagy_nav(pagy)).must_equal \ "" end it 'renders with link_extras' do pagy = Pagy.new count: 103, page: 1, link_extra: "X" - view.pagy_nav(pagy).must_include '?page=2" X rel' + _(view.pagy_nav(pagy)).must_include '?page=2" X rel' end end @@ -45,7 +45,7 @@ it 'renders with extras' do pagy = Pagy.new count: 103, page: 1 - view.pagy_link_proc(pagy, "X").call(1).must_equal '1' + _(view.pagy_link_proc(pagy, "X").call(1)).must_equal '1' end end @@ -53,23 +53,23 @@ describe "#pagy_t" do it 'pluralizes' do - 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" + _(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 - 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" + _(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 - 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"]' + _(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 @@ -77,30 +77,30 @@ describe "Pagy::I18n" do it 'loads custom :locale, :filepath and :pluralize' do - proc{ Pagy::I18n.load(locale: 'xx') }.must_raise Errno::ENOENT - proc{ Pagy::I18n.load(locale: 'xx', filepath: Pagy.root.join('locales', 'en.yml'))}.must_raise Pagy::VariableError - proc{ Pagy::I18n.load(locale: 'en', filepath: Pagy.root.join('locales', 'xx.yml')) }.must_raise Errno::ENOENT + _(proc{ Pagy::I18n.load(locale: 'xx') }).must_raise Errno::ENOENT + _(proc{ Pagy::I18n.load(locale: 'xx', filepath: Pagy.root.join('locales', 'en.yml'))}).must_raise Pagy::VariableError + _(proc{ Pagy::I18n.load(locale: 'en', filepath: Pagy.root.join('locales', 'xx.yml')) }).must_raise Errno::ENOENT custom_dictionary = File.join(File.dirname(__FILE__), 'custom.yml') Pagy::I18n.load(locale: 'custom', filepath: custom_dictionary) - Pagy::I18n.t('custom', 'pagy.nav.prev').must_equal "‹ Custom Prev" + _(Pagy::I18n.t('custom', 'pagy.nav.prev')).must_equal "‹ Custom Prev" Pagy::I18n.load(locale: 'en', pluralize: lambda{|_| 'one' }) # returns always 'one' regardless the count - Pagy::I18n.t(nil, 'pagy.item_name', count: 0).must_equal "item" - Pagy::I18n.t('en', 'pagy.item_name', count: 0).must_equal "item" - Pagy::I18n.t('en', 'pagy.item_name', count: 1).must_equal "item" - Pagy::I18n.t('en', 'pagy.item_name', count: 10).must_equal "item" + _(Pagy::I18n.t(nil, 'pagy.item_name', count: 0)).must_equal "item" + _(Pagy::I18n.t('en', 'pagy.item_name', count: 0)).must_equal "item" + _(Pagy::I18n.t('en', 'pagy.item_name', count: 1)).must_equal "item" + _(Pagy::I18n.t('en', 'pagy.item_name', count: 10)).must_equal "item" Pagy::I18n.load(locale: 'en') # reset for other tests end it 'switches :locale according to @pagy_locale' do Pagy::I18n.load({locale: 'de'}, {locale: 'en'}, {locale: 'nl'}) view.instance_variable_set(:'@pagy_locale', 'nl') - view.pagy_t('pagy.item_name', count: 1).must_equal "stuk" + _(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.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.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 + _(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 view.instance_variable_set(:'@pagy_locale', nil) # reset for other tests end @@ -110,19 +110,19 @@ describe "#pagy_info" do it 'renders without i18n path' do - 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" + _(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'} - 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" + _(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 @@ -131,26 +131,26 @@ it 'renders basic url' do pagy = Pagy.new count: 1000, page: 3 - 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' + _(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} - 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" + _(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' - 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' + _(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' - 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" + _(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 @@ -160,7 +160,7 @@ it 'overrides params' do 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" + _(overridden.pagy_url_for(5, pagy)).must_equal "/foo?page=5&b=4&k=k#anchor" end end diff --git a/test/pagy_test.rb b/test/pagy_test.rb index 23f85ccb7..0c0028bfd 100644 --- a/test/pagy_test.rb +++ b/test/pagy_test.rb @@ -8,7 +8,7 @@ let(:pagy) { Pagy.new count: 100, page: 4 } it 'has version' do - Pagy::VERSION.wont_be_nil + _(Pagy::VERSION).wont_be_nil end describe "#initialize" do @@ -18,254 +18,258 @@ end it 'initializes' do - pagy.must_be_instance_of Pagy - Pagy.new(count: 100).must_be_instance_of Pagy - Pagy.new(count: '100').must_be_instance_of Pagy - Pagy.new(count: 100, page: '2').must_be_instance_of Pagy - Pagy.new(count: 100, page: '').must_be_instance_of Pagy - Pagy.new(count: 100, items: '10').must_be_instance_of Pagy - proc { Pagy.new({}) }.must_raise Pagy::VariableError - proc { Pagy.new(count: 100, page: 0) }.must_raise Pagy::VariableError - proc { Pagy.new(count: 100, page: 2, items: 0) }.must_raise Pagy::VariableError - proc { Pagy.new(count: 100, page: 2, size: [1, 2, 3]).series }.must_raise Pagy::VariableError - proc { Pagy.new(count: 100, page: 2, size: [1, 2, 3, '4']).series }.must_raise Pagy::VariableError - proc { Pagy.new(count: 100, page: '11') }.must_raise Pagy::OverflowError - e = proc { Pagy.new(count: 100, page: 12) }.must_raise Pagy::OverflowError - e.pagy.must_be_instance_of Pagy + _(pagy).must_be_instance_of Pagy + _(Pagy.new(count: 100)).must_be_instance_of Pagy + _(Pagy.new(count: '100')).must_be_instance_of Pagy + _(Pagy.new(count: 100, page: '2')).must_be_instance_of Pagy + _(Pagy.new(count: 100, page: '')).must_be_instance_of Pagy + _(Pagy.new(count: 100, items: '10')).must_be_instance_of Pagy + _(proc { Pagy.new({}) }).must_raise Pagy::VariableError + _(proc { Pagy.new(count: 100, page: 0) }).must_raise Pagy::VariableError + _(proc { Pagy.new(count: 100, page: 2, items: 0) }).must_raise Pagy::VariableError + _(proc { Pagy.new(count: 100, page: 2, size: [1, 2, 3]).series }).must_raise Pagy::VariableError + _(proc { Pagy.new(count: 100, page: 2, size: [1, 2, 3, '4']).series }).must_raise Pagy::VariableError + _(proc { Pagy.new(count: 100, page: '11') }).must_raise Pagy::OverflowError + _(proc { Pagy.new(count: 100, page: 12) }).must_raise Pagy::OverflowError + begin + Pagy.new(count: 100, page: 12) + rescue => e + _(e.pagy).must_be_instance_of Pagy + end end it 'initializes count 0' do pagy = Pagy.new @vars.merge(count: 0) - pagy.pages.must_equal 1 - pagy.last.must_equal 1 - pagy.offset.must_equal 0 - pagy.from.must_equal 0 - pagy.to.must_equal 0 - pagy.prev.must_be_nil - pagy.next.must_be_nil + _(pagy.pages).must_equal 1 + _(pagy.last).must_equal 1 + _(pagy.offset).must_equal 0 + _(pagy.from).must_equal 0 + _(pagy.to).must_equal 0 + _(pagy.prev).must_be_nil + _(pagy.next).must_be_nil end it 'initializes single page' do pagy = Pagy.new @vars.merge(count: 8) - pagy.pages.must_equal 1 - pagy.last.must_equal 1 - pagy.offset.must_equal 0 - pagy.from.must_equal 1 - pagy.to.must_equal 8 - pagy.prev.must_be_nil - pagy.next.must_be_nil + _(pagy.pages).must_equal 1 + _(pagy.last).must_equal 1 + _(pagy.offset).must_equal 0 + _(pagy.from).must_equal 1 + _(pagy.to).must_equal 8 + _(pagy.prev).must_be_nil + _(pagy.next).must_be_nil end it 'initializes page 1 of 2' do pagy = Pagy.new @vars.merge(count: 15) - pagy.pages.must_equal 2 - pagy.last.must_equal 2 - pagy.offset.must_equal 0 - pagy.from.must_equal 1 - pagy.to.must_equal 10 - pagy.prev.must_be_nil - pagy.next.must_equal 2 + _(pagy.pages).must_equal 2 + _(pagy.last).must_equal 2 + _(pagy.offset).must_equal 0 + _(pagy.from).must_equal 1 + _(pagy.to).must_equal 10 + _(pagy.prev).must_be_nil + _(pagy.next).must_equal 2 end it 'initializes page 2 of 2' do pagy = Pagy.new @vars.merge(count: 15, page: 2) - pagy.pages.must_equal 2 - pagy.last.must_equal 2 - pagy.offset.must_equal 10 - pagy.from.must_equal 11 - pagy.to.must_equal 15 - pagy.prev.must_equal 1 - pagy.page.must_equal 2 - pagy.next.must_be_nil + _(pagy.pages).must_equal 2 + _(pagy.last).must_equal 2 + _(pagy.offset).must_equal 10 + _(pagy.from).must_equal 11 + _(pagy.to).must_equal 15 + _(pagy.prev).must_equal 1 + _(pagy.page).must_equal 2 + _(pagy.next).must_be_nil end it 'initializes page 1' do pagy = Pagy.new @vars.merge(page: 1) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 0 - pagy.from.must_equal 1 - pagy.to.must_equal 10 - pagy.prev.must_be_nil - pagy.page.must_equal 1 - pagy.next.must_equal 2 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 0 + _(pagy.from).must_equal 1 + _(pagy.to).must_equal 10 + _(pagy.prev).must_be_nil + _(pagy.page).must_equal 1 + _(pagy.next).must_equal 2 end it 'initializes page 2' do pagy = Pagy.new @vars.merge(page: 2) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 10 - pagy.from.must_equal 11 - pagy.to.must_equal 20 - pagy.prev.must_equal 1 - pagy.page.must_equal 2 - pagy.next.must_equal 3 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 10 + _(pagy.from).must_equal 11 + _(pagy.to).must_equal 20 + _(pagy.prev).must_equal 1 + _(pagy.page).must_equal 2 + _(pagy.next).must_equal 3 end it 'initializes page 3' do pagy = Pagy.new @vars.merge(page: 3) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 20 - pagy.from.must_equal 21 - pagy.to.must_equal 30 - pagy.prev.must_equal 2 - pagy.page.must_equal 3 - pagy.next.must_equal 4 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 20 + _(pagy.from).must_equal 21 + _(pagy.to).must_equal 30 + _(pagy.prev).must_equal 2 + _(pagy.page).must_equal 3 + _(pagy.next).must_equal 4 end it 'initializes page 4' do pagy = Pagy.new @vars.merge(page: 4) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 30 - pagy.from.must_equal 31 - pagy.to.must_equal 40 - pagy.prev.must_equal 3 - pagy.page.must_equal 4 - pagy.next.must_equal 5 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 30 + _(pagy.from).must_equal 31 + _(pagy.to).must_equal 40 + _(pagy.prev).must_equal 3 + _(pagy.page).must_equal 4 + _(pagy.next).must_equal 5 end it 'initializes page 5' do pagy = Pagy.new @vars.merge(page: 5) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 40 - pagy.from.must_equal 41 - pagy.to.must_equal 50 - pagy.prev.must_equal 4 - pagy.page.must_equal 5 - pagy.next.must_equal 6 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 40 + _(pagy.from).must_equal 41 + _(pagy.to).must_equal 50 + _(pagy.prev).must_equal 4 + _(pagy.page).must_equal 5 + _(pagy.next).must_equal 6 end it 'initializes page 6' do pagy = Pagy.new @vars.merge(page: 6) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 50 - pagy.from.must_equal 51 - pagy.to.must_equal 60 - pagy.prev.must_equal 5 - pagy.page.must_equal 6 - pagy.next.must_equal 7 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 50 + _(pagy.from).must_equal 51 + _(pagy.to).must_equal 60 + _(pagy.prev).must_equal 5 + _(pagy.page).must_equal 6 + _(pagy.next).must_equal 7 end it 'initializes page 7' do pagy = Pagy.new @vars.merge(page: 7) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 60 - pagy.from.must_equal 61 - pagy.to.must_equal 70 - pagy.prev.must_equal 6 - pagy.page.must_equal 7 - pagy.next.must_equal 8 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 60 + _(pagy.from).must_equal 61 + _(pagy.to).must_equal 70 + _(pagy.prev).must_equal 6 + _(pagy.page).must_equal 7 + _(pagy.next).must_equal 8 end it 'initializes page 8' do pagy = Pagy.new @vars.merge(page: 8) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 70 - pagy.from.must_equal 71 - pagy.to.must_equal 80 - pagy.prev.must_equal 7 - pagy.page.must_equal 8 - pagy.next.must_equal 9 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 70 + _(pagy.from).must_equal 71 + _(pagy.to).must_equal 80 + _(pagy.prev).must_equal 7 + _(pagy.page).must_equal 8 + _(pagy.next).must_equal 9 end it 'initializes page 9' do pagy = Pagy.new @vars.merge(page: 9) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 80 - pagy.from.must_equal 81 - pagy.to.must_equal 90 - pagy.prev.must_equal 8 - pagy.page.must_equal 9 - pagy.next.must_equal 10 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 80 + _(pagy.from).must_equal 81 + _(pagy.to).must_equal 90 + _(pagy.prev).must_equal 8 + _(pagy.page).must_equal 9 + _(pagy.next).must_equal 10 end it 'initializes page 10' do pagy = Pagy.new @vars.merge(page: 10) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 10 - pagy.offset.must_equal 90 - pagy.from.must_equal 91 - pagy.to.must_equal 100 - pagy.prev.must_equal 9 - pagy.page.must_equal 10 - pagy.next.must_equal 11 + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 10 + _(pagy.offset).must_equal 90 + _(pagy.from).must_equal 91 + _(pagy.to).must_equal 100 + _(pagy.prev).must_equal 9 + _(pagy.page).must_equal 10 + _(pagy.next).must_equal 11 end it 'initializes page 11' do pagy = Pagy.new @vars.merge(page: 11) - pagy.count.must_equal 103 - pagy.pages.must_equal 11 - pagy.last.must_equal 11 - pagy.items.must_equal 3 - pagy.offset.must_equal 100 - pagy.from.must_equal 101 - pagy.to.must_equal 103 - pagy.prev.must_equal 10 - pagy.page.must_equal 11 - pagy.next.must_be_nil + _(pagy.count).must_equal 103 + _(pagy.pages).must_equal 11 + _(pagy.last).must_equal 11 + _(pagy.items).must_equal 3 + _(pagy.offset).must_equal 100 + _(pagy.from).must_equal 101 + _(pagy.to).must_equal 103 + _(pagy.prev).must_equal 10 + _(pagy.page).must_equal 11 + _(pagy.next).must_be_nil end it 'initializes outset page 1' do pagy = Pagy.new(count: 87, page: 1, outset: 10, items: 10) - pagy.offset.must_equal 10 - pagy.items.must_equal 10 - pagy.from.must_equal 1 - pagy.to.must_equal 10 - pagy.pages.must_equal 9 + _(pagy.offset).must_equal 10 + _(pagy.items).must_equal 10 + _(pagy.from).must_equal 1 + _(pagy.to).must_equal 10 + _(pagy.pages).must_equal 9 end it 'initializes outset page 9' do pagy = Pagy.new(count: 87, page: 9, outset: 10, items: 10) - pagy.offset.must_equal 90 - pagy.items.must_equal 7 - pagy.from.must_equal 81 - pagy.to.must_equal 87 - pagy.pages.must_equal 9 + _(pagy.offset).must_equal 90 + _(pagy.items).must_equal 7 + _(pagy.from).must_equal 81 + _(pagy.to).must_equal 87 + _(pagy.pages).must_equal 9 end it 'initializes items of last page of one' do - Pagy.new(items: 10, count: 0).items.must_equal 10 - Pagy.new(items: 10, count: 4).items.must_equal 4 - Pagy.new(items: 10, count: 10).items.must_equal 10 + _(Pagy.new(items: 10, count: 0).items).must_equal 10 + _(Pagy.new(items: 10, count: 4).items).must_equal 4 + _(Pagy.new(items: 10, count: 10).items).must_equal 10 end it 'initializes items of last page of many' do - Pagy.new(items: 10, count: 14, page: 2).items.must_equal 4 - Pagy.new(items: 10, count: 20, page: 2).items.must_equal 10 + _(Pagy.new(items: 10, count: 14, page: 2).items).must_equal 4 + _(Pagy.new(items: 10, count: 20, page: 2).items).must_equal 10 end it 'handles the :cycle variable' do pagy = Pagy.new(count: 100, page: 10, items: 10, cycle: true) - pagy.prev.must_equal(9) - pagy.next.must_equal 1 + _(pagy.prev).must_equal(9) + _(pagy.next).must_equal 1 end end @@ -277,7 +281,7 @@ :count, :page, :items, :vars, # input :offset, :pages, :last, :from, :to, :prev, :next, :series # output ].each do |meth| - pagy.must_respond_to meth + _(pagy).must_respond_to meth end end @@ -286,12 +290,12 @@ describe "variables" do it 'has vars defaults' do - Pagy::VARS[:page].must_equal 1 - Pagy::VARS[:items].must_equal 20 - Pagy::VARS[:outset].must_equal 0 - Pagy::VARS[:size].must_equal [1, 4, 4, 1] - Pagy::VARS[:page_param].must_equal :page - Pagy::VARS[:params].must_equal({}) + _(Pagy::VARS[:page]).must_equal 1 + _(Pagy::VARS[:items]).must_equal 20 + _(Pagy::VARS[:outset]).must_equal 0 + _(Pagy::VARS[:size]).must_equal [1, 4, 4, 1] + _(Pagy::VARS[:page_param]).must_equal :page + _(Pagy::VARS[:params]).must_equal({}) end end @@ -316,7 +320,7 @@ def series_for(page, *expected) expected.each_with_index do |value, index| vars = instance_variable_get(:"@vars#{index}").merge(page: page) - Pagy.new(vars).series.must_equal value + _(Pagy.new(vars).series).must_equal value end end @@ -409,23 +413,23 @@ def series_for(page, *expected) end it 'computes series for count 0' do - Pagy.new(@vars3.merge(count: 0)).series.must_equal ["1"] + _(Pagy.new(@vars3.merge(count: 0)).series).must_equal ["1"] end it 'computes series for single page' do - Pagy.new(@vars3.merge(count: 8)).series.must_equal ["1"] + _(Pagy.new(@vars3.merge(count: 8)).series).must_equal ["1"] end it 'computes series for 1 of 2 pages' do - Pagy.new(@vars3.merge(count: 15)).series.must_equal ["1", 2] + _(Pagy.new(@vars3.merge(count: 15)).series).must_equal ["1", 2] end it 'computes series for 2 of 2 pages' do - Pagy.new(@vars3.merge(count: 15, page: 2)).series.must_equal [1, "2"] + _(Pagy.new(@vars3.merge(count: 15, page: 2)).series).must_equal [1, "2"] end it 'computes an empty series' do - Pagy.new(@vars3.merge(count: 100, size: [])).series.must_equal [] + _(Pagy.new(@vars3.merge(count: 100, size: [])).series).must_equal [] end end