mongoid_paging_token 0.0.2

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.
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'mongoid_paging_token/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'mongoid_paging_token'
7
+ s.version = MongoidPagingToken::VERSION
8
+ s.authors = ['Paul Walker']
9
+ s.email = ['github@paulwalker.tv']
10
+ s.homepage = ''
11
+ s.summary = 'An extension the generates a serialized Mongoid::Criteria for use as a paging token'
12
+ s.description = ''
13
+ s.license = 'MIT'
14
+
15
+ s.rubyforge_project = 'mongoid_paging_token'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
+
22
+ s.add_runtime_dependency 'mongoid', '~> 3.1.6'
23
+ end
data/spec/fake_app.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'action_controller/railtie'
2
+ require 'action_view/railtie'
3
+
4
+ app = Class.new(Rails::Application)
5
+ app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
6
+ app.config.session_store :cookie_store, :key => "_myapp_session"
7
+ app.config.eager_load = false
8
+ app.config.active_support.deprecation = :log
9
+ app.initialize!
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe MongoidPagingToken do
4
+
5
+ before :all do
6
+ class Foo
7
+ include ::Mongoid::Document
8
+
9
+ field :title, type: String
10
+ field :description, type: String
11
+ end
12
+ end
13
+
14
+ before :each do
15
+ @foos = 10.times.map do |i|
16
+ Foo.create! title: "title_#{i}"
17
+ end
18
+ end
19
+
20
+ describe :paging_token do
21
+ it 'generates a paging token for criteria when appropriate' do
22
+ expect(Foo.desc(:title).limit(5).paging_token).to_not be_nil
23
+ end
24
+
25
+ it 'does not generate a token when it cannot page further' do
26
+ expect(Foo.desc(:title).limit(15).paging_token).to be_nil
27
+ end
28
+
29
+ it 'does not generate a paging token when it does not have a sort' do
30
+ expect(Foo.limit(5).paging_token).to be_nil
31
+ end
32
+
33
+ it 'does not support sorting on more than two fields' do
34
+ expect { Foo.desc(:title, :description, :id).limit(5).paging_token }.to raise_error(NotImplementedError)
35
+ end
36
+ end
37
+
38
+ describe :page_by_token do
39
+ describe 'one field sort' do
40
+ it 'pages through items with the token' do
41
+ token = Foo.desc(:title).limit(4).paging_token
42
+
43
+ results = Foo.page_by_token(token)
44
+ expect(results.to_a.size).to eq(4)
45
+
46
+ token = results.paging_token
47
+ results = Foo.page_by_token(token)
48
+ expect(results.to_a.size).to eq(2)
49
+ expect(results.paging_token).to be_nil
50
+ end
51
+ end
52
+
53
+ describe 'two field sort' do
54
+ it 'pages through items with the token' do
55
+ token = Foo.desc(:title, :id).limit(4).paging_token
56
+
57
+ results = Foo.page_by_token(token)
58
+ expect(results.to_a.size).to eq(4)
59
+
60
+ token = results.paging_token
61
+ results = Foo.page_by_token(token)
62
+ expect(results.to_a.size).to eq(2)
63
+ expect(results.paging_token).to be_nil
64
+ end
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails'
2
+ require 'mongoid_paging_token'
3
+ require File.join(File.dirname(__FILE__), 'fake_app')
4
+ require 'rspec/rails'
5
+ require 'pry'
6
+
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ config.mock_with :rspec
11
+ config.before :each do
12
+ Mongoid.session(:default).collections.select do |collection|
13
+ collection.name !~ /system/
14
+ end.each(&:drop)
15
+ end
16
+ end
17
+
18
+ Mongoid.load_configuration(
19
+ sessions: {
20
+ 'default' => {
21
+ 'database' => 'mongoid_paging_token_test',
22
+ 'hosts' => ['localhost:27017'] } })
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_paging_token
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Paul Walker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mongoid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.6
27
+ description: ''
28
+ email:
29
+ - github@paulwalker.tv
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - .rspec
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - lib/mongoid_paging_token.rb
40
+ - lib/mongoid_paging_token/criteria.rb
41
+ - lib/mongoid_paging_token/document.rb
42
+ - lib/mongoid_paging_token/paging_token.rb
43
+ - lib/mongoid_paging_token/version.rb
44
+ - log/development.log
45
+ - mongoid_paging_token.gemspec
46
+ - spec/fake_app.rb
47
+ - spec/integration/mongoid_paging_token_spec.rb
48
+ - spec/spec_helper.rb
49
+ homepage: ''
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: mongoid_paging_token
69
+ rubygems_version: 2.1.11
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: An extension the generates a serialized Mongoid::Criteria for use as a paging
73
+ token
74
+ test_files:
75
+ - spec/fake_app.rb
76
+ - spec/integration/mongoid_paging_token_spec.rb
77
+ - spec/spec_helper.rb