Skip to content

Commit

Permalink
extended must_rematch to other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed May 12, 2021
1 parent d217965 commit 9265cd2
Show file tree
Hide file tree
Showing 14 changed files with 602 additions and 134 deletions.
16 changes: 8 additions & 8 deletions test/pagy/extras/elasticsearch_rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
_(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"]
_(records).must_rematch
end
it 'paginates records with defaults' do
pagy, records = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::Model.pagy_search('a').records)
Expand All @@ -45,7 +45,7 @@
_(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"]
_(records).must_rematch
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')
Expand All @@ -55,7 +55,7 @@
_(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"]
_(records).must_rematch
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)
Expand All @@ -65,7 +65,7 @@
_(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"]
_(records).must_rematch
end
end

Expand All @@ -81,7 +81,7 @@
_(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"]
_(records).must_rematch
end
it 'paginates records with defaults' do
pagy, records = controller.send(:pagy_elasticsearch_rails, MockElasticsearchRails::ModelES7.pagy_search('a').records)
Expand All @@ -90,7 +90,7 @@
_(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"]
_(records).must_rematch
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')
Expand All @@ -100,7 +100,7 @@
_(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"]
_(records).must_rematch
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)
Expand All @@ -110,7 +110,7 @@
_(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"]
_(records).must_rematch
end
end

Expand Down
129 changes: 129 additions & 0 deletions test/pagy/extras/elasticsearch_rails_test.rb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
pagy/extras/elasticsearch_rails::controller_methods::#pagy_elasticsearch_rails#test_0002_paginates records with defaults 1:
- 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/extras/elasticsearch_rails::controller_methods::#pagy_elasticsearch_rails#test_0001_paginates response with defaults 1:
- 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/extras/elasticsearch_rails::controller_methods::#pagy_elasticsearch_rails#test_0003_paginates with vars 1:
- 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/extras/elasticsearch_rails::controller_methods::#pagy_elasticsearch_rails#test_0004_paginates with overflow 1:
- 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/extras/elasticsearch_rails::controller_methods::#pagy_elasticsearch7_rails#test_0004_paginates with overflow 1:
- 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/extras/elasticsearch_rails::controller_methods::#pagy_elasticsearch7_rails#test_0002_paginates records with defaults 1:
- 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/extras/elasticsearch_rails::controller_methods::#pagy_elasticsearch7_rails#test_0001_paginates response with defaults 1:
- 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/extras/elasticsearch_rails::controller_methods::#pagy_elasticsearch7_rails#test_0003_paginates with vars 1:
- 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
22 changes: 11 additions & 11 deletions test/pagy/extras/headers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
end
it 'returns the full headers hash' do
pagy, _records = @controller.send(:pagy, @collection)
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"prev\", <https://example.com:8080/foo?page=4>; rel=\"next\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Current-Page"=>"3", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
_(@controller.send(:pagy_headers_hash, pagy)).must_equal({"Link"=>{"first"=>"https://example.com:8080/foo?page=1", "prev"=>"https://example.com:8080/foo?page=2", "next"=>"https://example.com:8080/foo?page=4", "last"=>"https://example.com:8080/foo?page=50"}, "Current-Page"=>"3", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
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"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"prev\", <https://example.com:8080/foo?page=4>; rel=\"next\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Per-Page"=>"20", "Total"=>"1000"})
_(@controller.send(:pagy_headers_hash, pagy)).must_equal({"Link"=>{"first"=>"https://example.com:8080/foo?page=1", "prev"=>"https://example.com:8080/foo?page=2", "next"=>"https://example.com:8080/foo?page=4", "last"=>"https://example.com:8080/foo?page=50"}, "Per-Page"=>"20", "Total"=>"1000"})
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
end
it 'returns the countless headers hash' do
pagy, _records = @controller.send(:pagy_countless, @collection)
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"prev\", <https://example.com:8080/foo?page=4>; rel=\"next\"", "Current-Page"=>"3", "Page-Items"=>"20"})
_(@controller.send(:pagy_headers_hash, pagy)).must_equal({"Link"=>{"first"=>"https://example.com:8080/foo?page=1", "prev"=>"https://example.com:8080/foo?page=2", "next"=>"https://example.com:8080/foo?page=4"}, "Current-Page"=>"3", "Page-Items"=>"20"})
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
end
it 'omit prev on first page' do
pagy, _records = @controller.send(:pagy, @collection, page: 1)
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"next\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Current-Page"=>"1", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
_(@controller.send(:pagy_headers_hash, pagy)).must_equal({"Link"=>{"first"=>"https://example.com:8080/foo?page=1", "next"=>"https://example.com:8080/foo?page=2", "last"=>"https://example.com:8080/foo?page=50"}, "Current-Page"=>"1", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
end
it 'omit next on last page' do
pagy, _records = @controller.send(:pagy, @collection, page: 50)
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=49>; rel=\"prev\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Current-Page"=>"50", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
_(@controller.send(:pagy_headers_hash, pagy)).must_equal({"Link"=>{"first"=>"https://example.com:8080/foo?page=1", "prev"=>"https://example.com:8080/foo?page=49", "last"=>"https://example.com:8080/foo?page=50"}, "Current-Page"=>"50", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
end
end

Expand All @@ -46,7 +46,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"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"prev\", <https://example.com:8080/foo?page=4>; rel=\"next\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Current-Page"=>"3", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
_(@controller.send(:response).headers).must_rematch
end
end
end
93 changes: 93 additions & 0 deletions test/pagy/extras/headers_test.rb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
pagy/extras/headers::#pagy_headers#test_0001_returns the full headers hash 1:
Link: <https://example.com:8080/foo?page=1>; rel="first", <https://example.com:8080/foo?page=2>;
rel="prev", <https://example.com:8080/foo?page=4>; rel="next", <https://example.com:8080/foo?page=50>;
rel="last"
Current-Page: '3'
Page-Items: '20'
Total-Pages: '50'
Total-Count: '1000'
pagy/extras/headers::#pagy_headers#test_0001_returns the full headers hash 2:
Link:
first: https://example.com:8080/foo?page=1
prev: https://example.com:8080/foo?page=2
next: https://example.com:8080/foo?page=4
last: https://example.com:8080/foo?page=50
Current-Page: '3'
Page-Items: '20'
Total-Pages: '50'
Total-Count: '1000'
pagy/extras/headers::#pagy_headers#test_0002_returns custom headers hash 1:
Link: <https://example.com:8080/foo?page=1>; rel="first", <https://example.com:8080/foo?page=2>;
rel="prev", <https://example.com:8080/foo?page=4>; rel="next", <https://example.com:8080/foo?page=50>;
rel="last"
Per-Page: '20'
Total: '1000'
pagy/extras/headers::#pagy_headers#test_0002_returns custom headers hash 2:
Link:
first: https://example.com:8080/foo?page=1
prev: https://example.com:8080/foo?page=2
next: https://example.com:8080/foo?page=4
last: https://example.com:8080/foo?page=50
Per-Page: '20'
Total: '1000'
pagy/extras/headers::#pagy_headers#test_0003_returns the countless headers hash 1:
Link: <https://example.com:8080/foo?page=1>; rel="first", <https://example.com:8080/foo?page=2>;
rel="prev", <https://example.com:8080/foo?page=4>; rel="next"
Current-Page: '3'
Page-Items: '20'
pagy/extras/headers::#pagy_headers#test_0003_returns the countless headers hash 2:
Link:
first: https://example.com:8080/foo?page=1
prev: https://example.com:8080/foo?page=2
next: https://example.com:8080/foo?page=4
Current-Page: '3'
Page-Items: '20'
pagy/extras/headers::#pagy_headers#test_0005_omit next on last page 1:
Link: <https://example.com:8080/foo?page=1>; rel="first", <https://example.com:8080/foo?page=49>;
rel="prev", <https://example.com:8080/foo?page=50>; rel="last"
Current-Page: '50'
Page-Items: '20'
Total-Pages: '50'
Total-Count: '1000'
pagy/extras/headers::#pagy_headers#test_0005_omit next on last page 2:
Link:
first: https://example.com:8080/foo?page=1
prev: https://example.com:8080/foo?page=49
last: https://example.com:8080/foo?page=50
Current-Page: '50'
Page-Items: '20'
Total-Pages: '50'
Total-Count: '1000'
pagy/extras/headers::#pagy_headers#test_0004_omit prev on first page 1:
Link: <https://example.com:8080/foo?page=1>; rel="first", <https://example.com:8080/foo?page=2>;
rel="next", <https://example.com:8080/foo?page=50>; rel="last"
Current-Page: '1'
Page-Items: '20'
Total-Pages: '50'
Total-Count: '1000'
pagy/extras/headers::#pagy_headers#test_0004_omit prev on first page 2:
Link:
first: https://example.com:8080/foo?page=1
next: https://example.com:8080/foo?page=2
last: https://example.com:8080/foo?page=50
Current-Page: '1'
Page-Items: '20'
Total-Pages: '50'
Total-Count: '1000'
pagy/extras/headers::#pagy_headers_merge#test_0001_returns the full headers hash 1: !ruby/hash-with-ivars:Rack::Utils::HeaderHash
ivars:
:@names:
link: Link
current-page: Current-Page
page-items: Page-Items
total-pages: Total-Pages
total-count: Total-Count
elements:
Link: <https://example.com:8080/foo?page=1>; rel="first", <https://example.com:8080/foo?page=2>;
rel="prev", <https://example.com:8080/foo?page=4>; rel="next", <https://example.com:8080/foo?page=50>;
rel="last"
Current-Page: '3'
Page-Items: '20'
Total-Pages: '50'
Total-Count: '1000'
24 changes: 12 additions & 12 deletions test/pagy/extras/i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@

describe '#pagy_info with I18n' do
it 'renders info' do
_(view.pagy_info(Pagy.new(count: 0))).must_equal '<span class="pagy-info">No items found</span>'
_(view.pagy_info(Pagy.new(count: 1))).must_equal '<span class="pagy-info">Displaying <b>1</b> item</span>'
_(view.pagy_info(Pagy.new(count: 13))).must_equal '<span class="pagy-info">Displaying <b>13</b> items</span>'
_(view.pagy_info(Pagy.new(count: 100, page: 3))).must_equal '<span class="pagy-info">Displaying items <b>41-60</b> of <b>100</b> in total</span>'
_(view.pagy_info(Pagy.new(count: 0))).must_rematch
_(view.pagy_info(Pagy.new(count: 1))).must_rematch
_(view.pagy_info(Pagy.new(count: 13))).must_rematch
_(view.pagy_info(Pagy.new(count: 100, page: 3))).must_rematch
end
it 'renders with existing i18n key' do
::I18n.locale = 'en'
custom_dictionary = Pagy.root.parent.join('test', 'files', 'i18n.yml')
::I18n.load_path += [custom_dictionary]
_(view.pagy_info(Pagy.new(count: 0, i18n_key: 'activerecord.models.product'))).must_equal '<span class="pagy-info">No Products found</span>'
_(view.pagy_info(Pagy.new(count: 1, i18n_key: 'activerecord.models.product'))).must_equal '<span class="pagy-info">Displaying <b>1</b> Product</span>'
_(view.pagy_info(Pagy.new(count: 13, i18n_key: 'activerecord.models.product'))).must_equal '<span class="pagy-info">Displaying <b>13</b> Products</span>'
_(view.pagy_info(Pagy.new(count: 100, i18n_key: 'activerecord.models.product', page: 3))).must_equal '<span class="pagy-info">Displaying Products <b>41-60</b> of <b>100</b> in total</span>'
_(view.pagy_info(Pagy.new(count: 0), i18n_key: 'activerecord.models.product')).must_equal '<span class="pagy-info">No Products found</span>'
_(view.pagy_info(Pagy.new(count: 1), i18n_key: 'activerecord.models.product')).must_equal '<span class="pagy-info">Displaying <b>1</b> Product</span>'
_(view.pagy_info(Pagy.new(count: 13), i18n_key: 'activerecord.models.product')).must_equal '<span class="pagy-info">Displaying <b>13</b> Products</span>'
_(view.pagy_info(Pagy.new(count: 100, page: 3), i18n_key: 'activerecord.models.product')).must_equal '<span class="pagy-info">Displaying Products <b>41-60</b> of <b>100</b> in total</span>'
_(view.pagy_info(Pagy.new(count: 0, i18n_key: 'activerecord.models.product'))).must_rematch
_(view.pagy_info(Pagy.new(count: 1, i18n_key: 'activerecord.models.product'))).must_rematch
_(view.pagy_info(Pagy.new(count: 13, i18n_key: 'activerecord.models.product'))).must_rematch
_(view.pagy_info(Pagy.new(count: 100, i18n_key: 'activerecord.models.product', page: 3))).must_rematch
_(view.pagy_info(Pagy.new(count: 0), i18n_key: 'activerecord.models.product')).must_rematch
_(view.pagy_info(Pagy.new(count: 1), i18n_key: 'activerecord.models.product')).must_rematch
_(view.pagy_info(Pagy.new(count: 13), i18n_key: 'activerecord.models.product')).must_rematch
_(view.pagy_info(Pagy.new(count: 100, page: 3), i18n_key: 'activerecord.models.product')).must_rematch
end
end
end
Loading

0 comments on commit 9265cd2

Please sign in to comment.