Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
148 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Pagy | ||
|
||
class VariableError < ArgumentError | ||
attr_reader :pagy | ||
|
||
def initialize(pagy) | ||
@pagy = pagy | ||
end | ||
|
||
def variable | ||
message =~ /expected :([\w]+)/ | ||
$1.to_sym if $1 | ||
end | ||
|
||
def value | ||
pagy.vars[variable] | ||
end | ||
end | ||
|
||
class OverflowError < VariableError; end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# encoding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
require_relative '../test_helper' | ||
|
||
|
||
describe Pagy::VariableError do | ||
|
||
describe "#variable and #value" do | ||
|
||
it 'raises for non overflow pages' do | ||
begin | ||
Pagy.new(count: 1, page: 0) | ||
rescue Pagy::VariableError => e | ||
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) | ||
end | ||
|
||
begin | ||
Pagy.new(count: 1, page: 'string') | ||
rescue Pagy::VariableError => e | ||
e.variable.must_equal :page | ||
e.value.must_equal 'string' | ||
end | ||
end | ||
|
||
it 'raises for other variables' do | ||
begin | ||
Pagy.new(count: -10) | ||
rescue Pagy::VariableError => e | ||
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' | ||
end | ||
end | ||
|
||
it 'rescues as ArgumentError (backward compatible)' do | ||
begin | ||
Pagy.new(count: 1, page: -10) | ||
rescue ArgumentError => e | ||
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' | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters