|
5 | 5 |
|
6 | 6 | describe Pagy::Backend do |
7 | 7 |
|
8 | | - let(:backend) { TestController.new } |
| 8 | + let(:controller) { MockController.new } |
9 | 9 |
|
10 | 10 | describe "#pagy" do |
11 | 11 |
|
12 | 12 | before do |
13 | | - @collection = TestCollection.new((1..1000).to_a) |
| 13 | + @collection = MockCollection.new |
14 | 14 | end |
15 | 15 |
|
16 | 16 | it 'paginates with defaults' do |
17 | | - pagy, records = backend.send(:pagy, @collection) |
| 17 | + pagy, records = controller.send(:pagy, @collection) |
18 | 18 | pagy.must_be_instance_of Pagy |
19 | 19 | pagy.count.must_equal 1000 |
20 | 20 | pagy.items.must_equal Pagy::VARS[:items] |
21 | | - pagy.page.must_equal backend.params[:page] |
| 21 | + pagy.page.must_equal controller.params[:page] |
22 | 22 | records.count.must_equal Pagy::VARS[:items] |
23 | 23 | records.must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60] |
24 | 24 | end |
25 | 25 |
|
26 | 26 | it 'paginates with vars' do |
27 | | - pagy, records = backend.send(:pagy, @collection, page: 2, items: 10, link_extra: 'X') |
| 27 | + pagy, records = controller.send(:pagy, @collection, page: 2, items: 10, link_extra: 'X') |
28 | 28 | pagy.must_be_instance_of Pagy |
29 | 29 | pagy.count.must_equal 1000 |
30 | 30 | pagy.items.must_equal 10 |
|
39 | 39 | describe "#pagy_get_vars" do |
40 | 40 |
|
41 | 41 | before do |
42 | | - @collection = TestCollection.new((1..1000).to_a) |
| 42 | + @collection = MockCollection.new |
43 | 43 | end |
44 | 44 |
|
45 | 45 | it 'gets defaults' do |
46 | 46 | vars = {} |
47 | | - merged = backend.send :pagy_get_vars, @collection, vars |
| 47 | + merged = controller.send :pagy_get_vars, @collection, vars |
48 | 48 | merged.keys.must_include :count |
49 | 49 | merged.keys.must_include :page |
50 | 50 | merged[:count].must_equal 1000 |
|
53 | 53 |
|
54 | 54 | it 'gets vars' do |
55 | 55 | vars = {page: 2, items: 10, link_extra: 'X'} |
56 | | - merged = backend.send :pagy_get_vars, @collection, vars |
| 56 | + merged = controller.send :pagy_get_vars, @collection, vars |
57 | 57 | merged.keys.must_include :count |
58 | 58 | merged.keys.must_include :page |
59 | 59 | merged.keys.must_include :items |
|
65 | 65 | end |
66 | 66 |
|
67 | 67 | it 'works with grouped collections' do |
68 | | - @collection = TestGroupedCollection.new((1..1000).to_a) |
| 68 | + @collection = MockCollection::Grouped.new((1..1000).to_a) |
69 | 69 | vars = {page: 2, items: 10, link_extra: 'X'} |
70 | | - merged = backend.send :pagy_get_vars, @collection, vars |
| 70 | + merged = controller.send :pagy_get_vars, @collection, vars |
71 | 71 | merged.keys.must_include :count |
72 | 72 | merged.keys.must_include :page |
73 | 73 | merged.keys.must_include :items |
|
80 | 80 |
|
81 | 81 | it 'overrides count and page' do |
82 | 82 | vars = {count: 10, page: 32} |
83 | | - merged = backend.send :pagy_get_vars, @collection, vars |
| 83 | + merged = controller.send :pagy_get_vars, @collection, vars |
84 | 84 | merged.keys.must_include :count |
85 | 85 | merged[:count].must_equal 10 |
86 | 86 | merged.keys.must_include :page |
|
92 | 92 | describe "#pagy_get_items" do |
93 | 93 |
|
94 | 94 | it 'gets items' do |
95 | | - collection = TestCollection.new((1..1000).to_a) |
| 95 | + collection = MockCollection.new |
96 | 96 | pagy = Pagy.new count: 1000 |
97 | | - items = backend.send :pagy_get_items, collection, pagy |
| 97 | + items = controller.send :pagy_get_items, collection, pagy |
98 | 98 | items.must_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
99 | 99 | end |
100 | 100 |
|
|
0 commit comments