forked from mislav/will_paginate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage_number_spec.rb
65 lines (54 loc) · 1.96 KB
/
page_number_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'spec_helper'
require 'will_paginate/page_number'
describe WillPaginate::PageNumber do
describe "valid" do
subject { described_class.new('12', 'page') }
it { should eq(12) }
its(:inspect) { should eq('page 12') }
it { should be_a(WillPaginate::PageNumber) }
it { should be_instance_of(WillPaginate::PageNumber) }
it { should be_a(Numeric) }
it { should be_a(Fixnum) }
it { should_not be_instance_of(Fixnum) }
it "passes the PageNumber=== type check" do |variable|
(WillPaginate::PageNumber === subject).should be
end
it "passes the Numeric=== type check" do |variable|
(Numeric === subject).should be
(Fixnum === subject).should be
end
end
describe "invalid" do
def create(value, name = 'page')
described_class.new(value, name)
end
it "errors out on non-int values" do
lambda { create(nil) }.should raise_error(WillPaginate::InvalidPage)
lambda { create('') }.should raise_error(WillPaginate::InvalidPage)
lambda { create('Schnitzel') }.should raise_error(WillPaginate::InvalidPage)
end
it "errors out on zero or less" do
lambda { create(0) }.should raise_error(WillPaginate::InvalidPage)
lambda { create(-1) }.should raise_error(WillPaginate::InvalidPage)
end
it "doesn't error out on zero for 'offset'" do
lambda { create(0, 'offset') }.should_not raise_error
lambda { create(-1, 'offset') }.should raise_error(WillPaginate::InvalidPage)
end
end
describe "coercion method" do
it "defaults to 'page' name" do
num = WillPaginate::PageNumber(12)
num.inspect.should eq('page 12')
end
it "accepts a custom name" do
num = WillPaginate::PageNumber(12, 'monkeys')
num.inspect.should eq('monkeys 12')
end
it "doesn't affect PageNumber instances" do
num = WillPaginate::PageNumber(12)
num2 = WillPaginate::PageNumber(num)
num2.object_id.should eq(num.object_id)
end
end
end