From ea658b014c74535e9f0b577a3a188deb5d1c3676 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Fri, 14 Jun 2013 19:46:54 -0500 Subject: [PATCH] adding schema indexes --- .travis.yml | 2 +- lib/neography/rest.rb | 14 +++++++++ lib/neography/rest/schema_indexes.rb | 34 ++++++++++++++++++++++ spec/integration/rest_schema_index_spec.rb | 32 ++++++++++++++++++++ spec/unit/rest/schema_index_spec.rb | 31 ++++++++++++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 lib/neography/rest/schema_indexes.rb create mode 100644 spec/integration/rest_schema_index_spec.rb create mode 100644 spec/unit/rest/schema_index_spec.rb diff --git a/.travis.yml b/.travis.yml index c073fc8..fb0202c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -script: "bundle exec rake neo4j:install['enterprise','1.9'] neo4j:start spec --trace" +script: "bundle exec rake neo4j:install['enterprise','2.0.0-M03'] neo4j:start spec --trace" language: ruby rvm: - 1.9.3 diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index dba6afb..9824b27 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -6,6 +6,7 @@ require 'neography/rest/properties' require 'neography/rest/indexes' require 'neography/rest/auto_indexes' +require 'neography/rest/schema_indexes' require 'neography/rest/nodes' require 'neography/rest/node_properties' @@ -49,6 +50,7 @@ def initialize(options = ENV['NEO4J_URL'] || {}) @other_node_relationships = OtherNodeRelationships.new(@connection) @node_indexes = NodeIndexes.new(@connection) @node_auto_indexes = NodeAutoIndexes.new(@connection) + @schema_indexes = SchemaIndexes.new(@connection) @node_traversal = NodeTraversal.new(@connection) @node_paths = NodePaths.new(@connection) @@ -70,6 +72,18 @@ def initialize(options = ENV['NEO4J_URL'] || {}) def list_relationship_types @relationship_types.list end + + def get_schema_index(label) + @schema_indexes.list(label) + end + + def create_schema_index(label, properties) + @schema_indexes.create(label, properties) + end + + def delete_schema_index(label, property) + @schema_indexes.drop(label, property) + end # nodes diff --git a/lib/neography/rest/schema_indexes.rb b/lib/neography/rest/schema_indexes.rb new file mode 100644 index 0000000..5b5d385 --- /dev/null +++ b/lib/neography/rest/schema_indexes.rb @@ -0,0 +1,34 @@ +module Neography + class Rest + class SchemaIndexes + extend Neography::Rest::Paths + include Neography::Rest::Helpers + + add_path :base, "/schema/index/:label" + add_path :drop, "/schema/index/:label/:index" + + def initialize(connection) + @connection = connection + end + + def list(label) + @connection.get(base_path(:label => label)) + end + + def drop(label, index) + @connection.delete(drop_path(:label => label, :index => index)) + end + + def create(label, keys = []) + options = { + :body => ( + { :property_keys => keys + } + ).to_json, + :headers => json_content_type + } + @connection.post(base_path(:label => label), options) + end + end + end +end diff --git a/spec/integration/rest_schema_index_spec.rb b/spec/integration/rest_schema_index_spec.rb new file mode 100644 index 0000000..4ea9fdb --- /dev/null +++ b/spec/integration/rest_schema_index_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe Neography::Rest do + before(:each) do + @neo = Neography::Rest.new + end + + describe "create a schema index" do + it "can create a schema index" do + si = @neo.create_schema_index("person", ["name"]) + si.should_not be_nil + si["property-keys"].should include("name") + end + + end + + describe "list schema indexes" do + it "can get a listing of node indexes" do + si = @neo.get_schema_index("person") + si.should_not be_nil + si.first["label"].should include("person") + si.first["property-keys"].should include("name") + end + end + + describe "drop schema indexes" do + it "can drop an existing schema index" do + si = @neo.delete_schema_index("person", "name") + si.should be_nil + end + end +end \ No newline at end of file diff --git a/spec/unit/rest/schema_index_spec.rb b/spec/unit/rest/schema_index_spec.rb new file mode 100644 index 0000000..9a85980 --- /dev/null +++ b/spec/unit/rest/schema_index_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +module Neography + class Rest + describe SchemaIndexes do + + let(:connection) { stub(:configuration => "http://configuration") } + subject { SchemaIndexes.new(connection) } + + it "create schema indexes" do + options = { + :body => '{"property_keys":["name"]}', + :headers => json_content_type + } + connection.should_receive(:post).with("/schema/index/person", options) + subject.create("person", ["name"]) + end + + it "get schema indexes" do + connection.should_receive(:get).with("/schema/index/person") + subject.list("person") + end + + it "delete schema indexes" do + connection.should_receive(:delete).with("/schema/index/person/name") + subject.drop("person","name") + end + + end + end +end