Skip to content

Commit

Permalink
better tests and stricter rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed May 21, 2021
1 parent d82e95c commit 842de05
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 51 deletions.
11 changes: 2 additions & 9 deletions .rubocop.yml
Expand Up @@ -11,12 +11,13 @@ AllCops:
Exclude:
- ___*/**/* # '___' prefixed dirs are excluded
- vendor/bundle/**/* # avoid Error: RuboCop found unsupported Ruby version 2.1 in `TargetRubyVersion` parameter (in vendor/bundle/ruby/3.0.0/gems/rainbow-3.0.0/.rubocop.yml).
# and also the extra weird "Unable to find gem panolint; is the gem installed? Gem::MissingSpecError" in all ruby versions

# No, thank you!
Layout:
Enabled: false

# affect performance
# bad for performance
Metrics:
Enabled: false

Expand All @@ -34,11 +35,3 @@ Style/StringLiterals:
Enabled: true
Exclude:
- test/**/*
Style/HashSyntax:
Enabled: true
Exclude:
- test/**/*
Style/SymbolArray:
Enabled: true
Exclude:
- test/**/*
4 changes: 2 additions & 2 deletions test/pagy/console_test.rb
Expand Up @@ -16,8 +16,8 @@ module PagyConsole
_(Pagy::VARS[:url]).must_equal 'http://www.example.com/subdir'
end
it 'includes Pagy::Backend and Pagy::Frontend' do
_(PagyConsole <= Pagy::Backend).must_equal true
_(PagyConsole <= Pagy::Frontend).must_equal true
assert PagyConsole <= Pagy::Backend
assert PagyConsole <= Pagy::Frontend
end
it 'requires extras' do
PagyConsole.pagy_extras :array, :navs
Expand Down
30 changes: 30 additions & 0 deletions test/pagy/deprecation_test.rb
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require_relative '../test_helper'

describe 'pagy/deprecation' do

describe 'Pagy.deprecated_var' do
it 'deprecates arg and returns right value' do
assert_output('', "[PAGY WARNING] deprecated use of `var` var will not be supported in 5.0! Use `new_var: \"new-value\"` instead.") do
_(Pagy.deprecated_var(:var, 'deprecated-val', :new_var, 'new-value')).must_equal 'new-value'
end
end
end

describe 'Pagy.deprecated_arg' do
it 'deprecates arg and returns right value' do
assert_output('', "[PAGY WARNING] deprecated use of positional `arg` arg will not be supported in 5.0! Use only the keyword arg `new_key: \"new-value\"` instead.") do
_(Pagy.deprecated_arg(:arg, 'deprecated-val', :new_key, 'new-value')).must_equal 'new-value'
end
end
end

describe 'Pagy.deprecated_order' do
it 'deprecates arg order and returns them inverted' do
assert_output('', "[PAGY WARNING] inverted use of pagy/page in pagy_url_for will not be supported in 5.0! Use pagy_url_for(pagy, page) instead.") do
_(Pagy.deprecated_order('page', 'pagy')).must_equal %w[pagy page]
end
end
end
end
27 changes: 0 additions & 27 deletions test/pagy/derecation_test.rb

This file was deleted.

18 changes: 9 additions & 9 deletions test/pagy/extras/items_test.rb
Expand Up @@ -46,44 +46,44 @@ def test_items_vars_params(items, vars, params)
it 'uses the vars' do
items = 15
vars = { items: items } # force items
params = { :a => "a", :page => 3, :items => 12 }
params = { a: "a", page: 3, items: 12 }
test_items_vars_params(items, vars, params)
end
it 'uses the params' do
items = 12
vars = {}
params = { :a => "a", :page => 3, :items => items }
params = { a: "a", page: 3, items: items }
test_items_vars_params(items, vars, params)
end
it 'uses the params without page' do
items = 12
vars = {}
params = { :a => "a", :items => items }
params = { a: "a", items: items }
test_items_vars_params(items, vars, params)
end

it 'overrides the params' do
items = 21
vars = { items: items }
params = { :a => "a", :page => 3, :items => 12 }
params = { a: "a", page: 3, items: 12 }
test_items_vars_params(items, vars, params)
end
it 'uses the max_items default' do
items = 100
vars = {}
params = { :a => "a", :page => 3, :items => 120 }
params = { a: "a", page: 3, items: 120 }
test_items_vars_params(items, vars, params)
end
it 'doesn\'t limit the items from vars' do
items = 1000
vars = { max_items: nil }
params = { :a => "a", :items => 1000 }
params = { a: "a", items: 1000 }
test_items_vars_params(items, vars, params)
end
it 'doesn\'t limit the items from default' do
items = 1000
vars = {}
params = { :a => "a", :items => items }
params = { a: "a", items: items }

Pagy::VARS[:max_items] = nil
test_items_vars_params(items, vars, params)
Expand All @@ -92,13 +92,13 @@ def test_items_vars_params(items, vars, params)
it 'uses items_param from vars' do
items = 14
vars = { items_param: :custom }
params = { :a => "a", :page => 3, :items_param => :custom, :custom => items }
params = { a: "a", page: 3, items_param: :custom, custom: items }
test_items_vars_params(items, vars, params)
end
it 'uses items_param from default' do
items = 15
vars = {}
params = { :a => "a", :page => 3, :custom => 15 }
params = { a: "a", page: 3, custom: 15 }

Pagy::VARS[:items_param] = :custom
test_items_vars_params(items, vars, params)
Expand Down
8 changes: 4 additions & 4 deletions test/pagy/extras/searchkick_test.rb
Expand Up @@ -49,7 +49,7 @@
_(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"]
_(results).must_rematch
end
it 'paginates results with defaults' do
pagy, results = controller.send(:pagy_searchkick, MockSearchkick::Model.pagy_search('a').results)
Expand All @@ -58,7 +58,7 @@
_(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"]
_(results).must_rematch
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')
Expand All @@ -68,7 +68,7 @@
_(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"]
_(results).must_rematch
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)
Expand All @@ -78,7 +78,7 @@
_(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"]
_(results).must_rematch
end
end

Expand Down
65 changes: 65 additions & 0 deletions test/pagy/extras/searchkick_test.rb.rematch
@@ -0,0 +1,65 @@
---
"[1] pagy/extras/searchkick::controller_methods::#pagy_searchkick#test_0001_paginates response with defaults":
- 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
"[1] pagy/extras/searchkick::controller_methods::#pagy_searchkick#test_0004_paginates with overflow":
- 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
"[1] pagy/extras/searchkick::controller_methods::#pagy_searchkick#test_0002_paginates results with defaults":
- 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
"[1] pagy/extras/searchkick::controller_methods::#pagy_searchkick#test_0003_paginates with vars":
- 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

0 comments on commit 842de05

Please sign in to comment.