pagelux 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/pagelux/query_paginator.rb +1 -1
- data/lib/pagelux/version.rb +1 -1
- data/pagelux.gemspec +2 -1
- data/spec/query_paginator_spec.rb +27 -5
- data/spec/query_spec.rb +11 -5
- data/spec/spec_helper.rb +8 -0
- data/spec/support/db_connection.rb +6 -0
- data/spec/support/query.rb +1 -15
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71e370b775e3f741c799079db211a151e684ed4b
|
4
|
+
data.tar.gz: bc64214d693c26bbb172534a91af47ad75dd7b2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8173fc58874fae1ac61bcde84bdbb8306208994aa1bf0bdcd0553925c79b5f41de2ef6fdbf66bd410689171fc01af056c0a3341ace02c0883b1a3bc606506de6
|
7
|
+
data.tar.gz: 7721ba2cf925c31074241d3a1679e034ba70d88850f11a292d38e0d83dbc67226ac106cec9bf8cfba61a24724f72b835fcd1ba7b812c90e6c4fc18260b8c6728
|
data/README.md
CHANGED
@@ -22,6 +22,15 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Contributing
|
24
24
|
|
25
|
+
Test database can be created with this:
|
26
|
+
createdb pagelux_test
|
27
|
+
|
28
|
+
In pgsql you will need to setup the table:
|
29
|
+
|
30
|
+
psql -d pagelux_test
|
31
|
+
|
32
|
+
CREATE TABLE queries (n int);
|
33
|
+
|
25
34
|
1. Fork it
|
26
35
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
36
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
@@ -38,8 +38,8 @@ module Pagelux
|
|
38
38
|
|
39
39
|
def normalize_page(n)
|
40
40
|
n = (n || self.class.default_page).to_i
|
41
|
-
n = self.class.default_page if n < self.class.default_page
|
42
41
|
n = n > last_page ? last_page : n
|
42
|
+
n = self.class.default_page if n < self.class.default_page
|
43
43
|
n
|
44
44
|
end
|
45
45
|
|
data/lib/pagelux/version.rb
CHANGED
data/pagelux.gemspec
CHANGED
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
21
|
+
spec.add_dependency 'activerecord'
|
22
22
|
|
23
|
+
spec.add_development_dependency 'pg'
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
spec.add_development_dependency 'rspec'
|
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Pagelux::QueryPaginator do
|
4
|
-
let(:query) {
|
4
|
+
let(:query) {
|
5
|
+
(1..13).to_a.each do |n|
|
6
|
+
Query.create!(n: n)
|
7
|
+
end
|
8
|
+
|
9
|
+
Query.all
|
10
|
+
}
|
5
11
|
let(:paginator) { Pagelux::QueryPaginator.new(query) }
|
6
12
|
# let(:results) { paginator.paginate(params) }
|
7
13
|
|
@@ -45,23 +51,39 @@ describe Pagelux::QueryPaginator do
|
|
45
51
|
paginator.page.should == 3
|
46
52
|
end
|
47
53
|
end
|
54
|
+
|
55
|
+
context "when the query count is 0" do
|
56
|
+
let(:query) { Query.all }
|
57
|
+
|
58
|
+
let(:params) {
|
59
|
+
{
|
60
|
+
page: nil,
|
61
|
+
limit: 200
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
it "uses the first page" do
|
66
|
+
paginator.paginate(params)
|
67
|
+
paginator.page.should == 1
|
68
|
+
end
|
69
|
+
end
|
48
70
|
end
|
49
71
|
|
50
72
|
describe 'query pagination' do
|
51
|
-
let(:results) { paginator.paginate({page: page, limit: 5}) }
|
73
|
+
let(:results) { paginator.paginate({page: page, limit: 5}).map(&:n) }
|
52
74
|
|
53
75
|
context 'when on first page' do
|
54
76
|
let(:page) { 1 }
|
55
77
|
|
56
78
|
it "will return the right records" do
|
57
|
-
results.should == (
|
79
|
+
results.should == (1..5).to_a
|
58
80
|
end
|
59
81
|
end
|
60
82
|
|
61
83
|
context 'when on middle page' do
|
62
84
|
let(:page) { 2 }
|
63
85
|
it "will return the right records for a middle page" do
|
64
|
-
results.should == (
|
86
|
+
results.should == (6..10).to_a
|
65
87
|
end
|
66
88
|
end
|
67
89
|
|
@@ -69,7 +91,7 @@ describe Pagelux::QueryPaginator do
|
|
69
91
|
let(:page) { 3 }
|
70
92
|
|
71
93
|
it "will return the right records no the last page" do
|
72
|
-
results.should == (
|
94
|
+
results.should == (11..13).to_a
|
73
95
|
end
|
74
96
|
end
|
75
97
|
end
|
data/spec/query_spec.rb
CHANGED
@@ -35,21 +35,27 @@ describe Pagelux::Query do
|
|
35
35
|
|
36
36
|
describe 'query pagination' do
|
37
37
|
let(:limit) { 5 }
|
38
|
-
let(:sample_query) {
|
39
|
-
|
38
|
+
let(:sample_query) {
|
39
|
+
(1..13).to_a.each do |n|
|
40
|
+
Query.create!(n: n)
|
41
|
+
end
|
42
|
+
Query.all
|
43
|
+
}
|
44
|
+
|
45
|
+
let(:results) { paginator.perform(sample_query).map(&:n) }
|
40
46
|
|
41
47
|
context 'when on first page' do
|
42
48
|
let(:page) { 1 }
|
43
49
|
|
44
50
|
it "will return the right records" do
|
45
|
-
results.should == (
|
51
|
+
results.should == (1..5).to_a
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
55
|
context 'when on middle page' do
|
50
56
|
let(:page) { 2 }
|
51
57
|
it "will return the right records for a middle page" do
|
52
|
-
results.should == (
|
58
|
+
results.should == (6..10).to_a
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
@@ -57,7 +63,7 @@ describe Pagelux::Query do
|
|
57
63
|
let(:page) { 3 }
|
58
64
|
|
59
65
|
it "will return the right records no the last page" do
|
60
|
-
results.should == (
|
66
|
+
results.should == (11..13).to_a
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'pg'
|
3
|
+
|
4
|
+
require_relative './support/db_connection'
|
1
5
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
2
6
|
|
3
7
|
$: << File.dirname(__FILE__) + "/../lib"
|
@@ -19,4 +23,8 @@ RSpec.configure do |config|
|
|
19
23
|
# the seed, which is printed after each run.
|
20
24
|
# --seed 1234
|
21
25
|
config.order = 'random'
|
26
|
+
|
27
|
+
config.before do
|
28
|
+
Query.delete_all
|
29
|
+
end
|
22
30
|
end
|
data/spec/support/query.rb
CHANGED
@@ -1,16 +1,2 @@
|
|
1
|
-
|
2
|
-
class Query < Struct.new(:items, :index)
|
3
|
-
|
4
|
-
def offset(page_num)
|
5
|
-
self.index = page_num
|
6
|
-
self
|
7
|
-
end
|
8
|
-
|
9
|
-
def limit(num)
|
10
|
-
items.slice(index, num)
|
11
|
-
end
|
12
|
-
|
13
|
-
def count
|
14
|
-
items.length
|
15
|
-
end
|
1
|
+
class Query < ActiveRecord::Base
|
16
2
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagelux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rae Bonfanti
|
@@ -11,8 +11,36 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-12-
|
14
|
+
date: 2013-12-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: activerecord
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pg
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
16
44
|
- !ruby/object:Gem::Dependency
|
17
45
|
name: bundler
|
18
46
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,6 +105,7 @@ files:
|
|
77
105
|
- spec/query_paginator_spec.rb
|
78
106
|
- spec/query_spec.rb
|
79
107
|
- spec/spec_helper.rb
|
108
|
+
- spec/support/db_connection.rb
|
80
109
|
- spec/support/query.rb
|
81
110
|
homepage: ''
|
82
111
|
licenses:
|
@@ -107,4 +136,5 @@ test_files:
|
|
107
136
|
- spec/query_paginator_spec.rb
|
108
137
|
- spec/query_spec.rb
|
109
138
|
- spec/spec_helper.rb
|
139
|
+
- spec/support/db_connection.rb
|
110
140
|
- spec/support/query.rb
|