mongoid_will_paginate 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +13 -0
- data/README +0 -0
- data/Rakefile +1 -0
- data/lib/mongoid_will_paginate/criteria.rb +19 -0
- data/lib/mongoid_will_paginate/version.rb +3 -0
- data/lib/mongoid_will_paginate.rb +4 -0
- data/mongoid_will_paginate.gemspec +25 -0
- data/spec/mongoid_will_paginate_spec.rb +35 -0
- data/spec/rails_app.rb +9 -0
- data/spec/spec_helper.rb +21 -0
- metadata +90 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'will_paginate/collection'
|
2
|
+
|
3
|
+
module MongoidWillPaginate
|
4
|
+
module Criteria
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
def paginate(options = {})
|
9
|
+
page = options[:page] || 1
|
10
|
+
per_page = options[:per_page] || WillPaginate.per_page
|
11
|
+
total = options[:total_entries] || self.count
|
12
|
+
|
13
|
+
WillPaginate::Collection.create(page, per_page, total) do |pager|
|
14
|
+
pager.replace self.skip(pager.offset).limit(pager.per_page).to_a
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mongoid_will_paginate/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mongoid_will_paginate"
|
7
|
+
s.version = MongoidWillPaginate::VERSION
|
8
|
+
s.authors = ["Hck"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.summary = %q{Simple native pagination extension for will_paginate}
|
11
|
+
s.description = %q{Simple native pagination extension for will_paginate using mongoid skip and limit methods}
|
12
|
+
|
13
|
+
s.rubyforge_project = "mongoid_will_paginate"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
|
23
|
+
s.add_runtime_dependency "mongoid", [">= 2.1.0"]
|
24
|
+
s.add_runtime_dependency "will_paginate", [">= 3.0.0"]
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path('./spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe MongoidWillPaginate::Criteria do
|
4
|
+
before :all do
|
5
|
+
class Document
|
6
|
+
include ::Mongoid::Document
|
7
|
+
field :title, type: String
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe :paginate do
|
12
|
+
context 'called in a Mongoid::Criteria' do
|
13
|
+
before :each do
|
14
|
+
@docs = 15.times.map{|i| Document.create title: 'document title'}
|
15
|
+
15.times{Document.create title: 'document title 2'}
|
16
|
+
|
17
|
+
@criteria = Document.where(title: 'document title')
|
18
|
+
end
|
19
|
+
|
20
|
+
context '& paginate params specified' do
|
21
|
+
subject {@criteria.paginate page: 2, per_page: 5}
|
22
|
+
it {should be_a_instance_of WillPaginate::Collection}
|
23
|
+
its(:to_a) {should == @docs[5..9]}
|
24
|
+
its(:total_entries) {should == @criteria.count}
|
25
|
+
end
|
26
|
+
|
27
|
+
context '& paginate parameters not specified' do
|
28
|
+
subject {@criteria.paginate}
|
29
|
+
it {should be_a_instance_of WillPaginate::Collection}
|
30
|
+
its(:to_a) {should == @docs}
|
31
|
+
its(:total_entries) {should == @criteria.count}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/rails_app.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'action_controller/railtie'
|
2
|
+
require 'action_view/railtie'
|
3
|
+
require 'digest/md5'
|
4
|
+
|
5
|
+
app = Class.new(Rails::Application)
|
6
|
+
app.config.secret_token = Digest::MD5.hexdigest("mongoid_will_paginate")
|
7
|
+
app.config.session_store :cookie_store, :key => "_test_rails_app_session"
|
8
|
+
app.config.active_support.deprecation = :log
|
9
|
+
app.initialize!
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'rails'
|
5
|
+
require 'mongoid'
|
6
|
+
require 'will_paginate'
|
7
|
+
require 'mongoid_will_paginate'
|
8
|
+
|
9
|
+
require File.join(File.dirname(__FILE__), 'rails_app')
|
10
|
+
require 'rspec/rails'
|
11
|
+
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.mock_with :rspec
|
16
|
+
config.before :each do
|
17
|
+
Mongoid.master.collections.select{|c| c.name !~ /system/}.each(&:drop)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Mongoid.configure{|c| c.master = Mongo::Connection.new.db("test_mongoid_will_paginate")}
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_will_paginate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hck
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &14745080 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *14745080
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mongoid
|
27
|
+
requirement: &14741940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *14741940
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: will_paginate
|
38
|
+
requirement: &14741060 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 3.0.0
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *14741060
|
47
|
+
description: Simple native pagination extension for will_paginate using mongoid skip
|
48
|
+
and limit methods
|
49
|
+
email:
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- Gemfile
|
57
|
+
- README
|
58
|
+
- Rakefile
|
59
|
+
- lib/mongoid_will_paginate.rb
|
60
|
+
- lib/mongoid_will_paginate/criteria.rb
|
61
|
+
- lib/mongoid_will_paginate/version.rb
|
62
|
+
- mongoid_will_paginate.gemspec
|
63
|
+
- spec/mongoid_will_paginate_spec.rb
|
64
|
+
- spec/rails_app.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: ''
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project: mongoid_will_paginate
|
86
|
+
rubygems_version: 1.8.10
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Simple native pagination extension for will_paginate
|
90
|
+
test_files: []
|