Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added specs, can paginate traversals and indexes

  • Loading branch information...
commit 81a013db06439422a7789ba03511899160528860 1 parent 70bd7a0
@dnagir authored
View
3  .gitignore
@@ -1,4 +1,7 @@
*.gem
+*.swp
+db/
+bin/
.bundle
Gemfile.lock
pkg/*
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
2  Gemfile
@@ -2,3 +2,5 @@ source "http://rubygems.org"
# Specify your gem's dependencies in neo4j-will_paginate.gemspec
gemspec
+
+gem 'neo4j', :path => '../neo4j'
View
29 lib/neo4j-will_paginate.rb
@@ -1,7 +1,34 @@
require "neo4j-will_paginate/version"
+require 'will_paginate/collection'
+require 'neo4j'
+
module Neo4j
module WillPaginate
- # Your code goes here...
+
+ module Pagination
+ include ::WillPaginate::CollectionMethods
+
+
+ def paginate(options={})
+ page = options[:page] || 1
+ per_page = options[:per] || options[:per_page] || options[:limit] || WillPaginate.per_page
+ ::WillPaginate::Collection.create(page, per_page) do |pager|
+ res = ::Neo4j::Paginated.create_from(self, page, per_page)
+ pager.replace res.to_a
+ pager.total_entries = res.total unless pager.total_entries
+ end
+ end
+
+ end
+
end
+
+end
+
+[
+ Neo4j::Traversal::Traverser,
+ Neo4j::Index::LuceneQuery
+].each do |m|
+ m.send :include, Neo4j::WillPaginate::Pagination
end
View
7 neo4j-will_paginate.gemspec
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- # specify any dependencies here; for example:
- # s.add_development_dependency "rspec"
- # s.add_runtime_dependency "rest-client"
+ s.add_development_dependency "rspec"
+ s.add_runtime_dependency "activesupport", "~> 3.0"
+ s.add_runtime_dependency "will_paginate", "~> 3.0"
+ s.add_runtime_dependency "neo4j", ">= 2.0.0.alpha"
end
View
51 spec/neo4j-will_paginate_spec.rb
@@ -0,0 +1,51 @@
+require 'spec_helper'
+
+module Specs
+
+ class Person < ::Neo4j::Model
+ property :name, :default => 'x'
+ index :name
+ has_n :friends
+ end
+
+ describe Neo4j::WillPaginate::Pagination do
+ subject { source.paginate(:page => 2, :per_page => 3) }
+
+ context ::Neo4j::Traversal::Traverser do
+ let(:source) { Person.all }
+ before { 10.times { Person.create } }
+
+ its(:size) { should == 3 }
+ its(:current_page) { should == 2 }
+ its(:per_page) { should == 3 }
+ its(:total_entries) { should == 10 }
+ its(:offset) { should == 3 }
+ end
+
+ context ::Neo4j::Index::LuceneQuery do
+ let(:source) { Person.all(:conditions => 'name: *') }
+ before { 10.times { Person.create(:name => 'x') } }
+
+ its(:size) { should == 3 }
+ its(:current_page) { should == 2 }
+ its(:per_page) { should == 3 }
+ its(:total_entries) { should == 10 }
+ its(:offset) { should == 3 }
+ end
+
+ context ::Neo4j::HasN::Mapping do
+ end
+
+ context ::Neo4j::HasList::Mapping do
+ end
+
+ context ::Neo4j::Rails::Relationships::NodesDSL do
+ # class
+ end
+
+ context ::Neo4j::Rails::Relationships::RelsDSL do
+ # class
+ end
+ end
+
+end
View
42 spec/spec_helper.rb
@@ -0,0 +1,42 @@
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper.rb"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+end
+
+
+require 'neo4j-will_paginate'
+
+
+# neo4j Specs clean-up
+require 'fileutils'
+
+def rm_db_storage!
+ FileUtils.rm_rf Neo4j::Config[:storage_path]
+ raise "Can't delete db" if File.exist?(Neo4j::Config[:storage_path])
+end
+
+RSpec.configure do |config|
+ $spec_counter = 0
+
+ config.before(:all) do
+ rm_db_storage! unless Neo4j.running?
+ end
+
+ config.after(:each) do
+ Neo4j::Rails::Model.close_lucene_connections
+ Neo4j::Transaction.run do
+ Neo4j::Index::IndexerRegistry.delete_all_indexes
+ end
+ Neo4j::Transaction.run do
+ Neo4j.threadlocal_ref_node = Neo4j::Node.new :name => "ref_#{$spec_counter}"
+ $spec_counter += 1
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.