neo_rest 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/GemFile +11 -0
- data/Gemfile.lock +27 -0
- data/LICENCE +20 -0
- data/RakeFile.rb +44 -0
- data/VERSION +1 -0
- data/lib/NeoRest/config.rb +13 -0
- data/lib/NeoRest/index.rb +41 -0
- data/lib/NeoRest/node.rb +91 -0
- data/lib/NeoRest/relationship.rb +67 -0
- data/lib/NeoRest/test_helper.rb +15 -0
- data/lib/neo_rest.rb +6 -0
- data/spec/NeoRest/index_spec.rb +68 -0
- data/spec/NeoRest/node_spec.rb +192 -0
- data/spec/NeoRest/relationship_spec.rb +75 -0
- data/spec/NeoRest/test_helper_spec.rb +17 -0
- data/spec/spec_helper.rb +13 -0
- data/specs.watchr +61 -0
- metadata +20 -2
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@neorest
|
data/GemFile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
json (1.5.1)
|
6
|
+
mime-types (1.16)
|
7
|
+
rest-client (1.6.1)
|
8
|
+
mime-types (>= 1.16)
|
9
|
+
rspec (2.6.0)
|
10
|
+
rspec-core (~> 2.6.0)
|
11
|
+
rspec-expectations (~> 2.6.0)
|
12
|
+
rspec-mocks (~> 2.6.0)
|
13
|
+
rspec-core (2.6.3)
|
14
|
+
rspec-expectations (2.6.0)
|
15
|
+
diff-lcs (~> 1.1.2)
|
16
|
+
rspec-mocks (2.6.0)
|
17
|
+
watchr (0.7)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
bundler
|
24
|
+
json (= 1.5.1)
|
25
|
+
rest-client (= 1.6.1)
|
26
|
+
rspec
|
27
|
+
watchr
|
data/LICENCE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Cre8iveThough.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/RakeFile.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "neo_rest"
|
8
|
+
gem.summary = %Q{a rest wrapper for the Neo4j rest API}
|
9
|
+
gem.description = %Q{a rest wrapper for the Neo4j rest API}
|
10
|
+
gem.email = "mark.nijhof@cre8ivethought.com"
|
11
|
+
gem.homepage = "http://github.com/MarkNijhof/NeoRest"
|
12
|
+
gem.authors = ["Mark Nijhof"]
|
13
|
+
gem.add_development_dependency "rspec", '2.6.0'
|
14
|
+
gem.add_dependency "json", '1.5.1'
|
15
|
+
gem.add_dependency "rest-client", '1.6.1'
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :test => [:set_test_environment] do
|
23
|
+
sh "bundle exec watchr"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :neo_stop do
|
27
|
+
sh "~/neo4j-server-dev/bin/neo4j stop"
|
28
|
+
sh "~/neo4j-server/bin/neo4j stop"
|
29
|
+
end
|
30
|
+
|
31
|
+
task :neo_start do
|
32
|
+
sh "~/neo4j-server-dev/bin/neo4j start"
|
33
|
+
sh "~/neo4j-server/bin/neo4j start"
|
34
|
+
end
|
35
|
+
|
36
|
+
task :set_test_environment do
|
37
|
+
ENV['AUTOFEATURE'] = "true"
|
38
|
+
ENV['RSPEC'] = "true"
|
39
|
+
|
40
|
+
ENV['NEO4J_HOST'] = 'localhost'
|
41
|
+
ENV['NEO4J_PORT'] = '7474'
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module NeoRest
|
7
|
+
|
8
|
+
class Index < OpenStruct
|
9
|
+
|
10
|
+
attr_reader :index_name, :key, :value
|
11
|
+
|
12
|
+
def initialize( index_name, key, value )
|
13
|
+
@index_name = index_name
|
14
|
+
@key = key
|
15
|
+
@value = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def remove node
|
19
|
+
node = node.neo_id if node.respond_to?('neo_id')
|
20
|
+
RestClient.delete( "#{$neo_base_url}/index/node/#{index_name}/#{key}/#{URI.escape(value)}/#{node}" )
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_nodes
|
24
|
+
NeoRest::Index.get_nodes index_name, key, value
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
|
29
|
+
def get_nodes index_name, key, value
|
30
|
+
nodes_json = JSON.parse( RestClient.get( "#{$neo_base_url}/index/node/#{index_name}/#{key}/#{URI.escape(value)}", :accept => :json ) )
|
31
|
+
nodes = []
|
32
|
+
nodes_json.each { | node | nodes << NeoRest::Node.new( node ) }
|
33
|
+
return nodes unless block_given?
|
34
|
+
nodes.each { | node | yield node }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/NeoRest/node.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module NeoRest
|
7
|
+
|
8
|
+
class Node < OpenStruct
|
9
|
+
|
10
|
+
attr_reader :neo_id, :neo_url
|
11
|
+
|
12
|
+
def initialize( hash = nil )
|
13
|
+
@table = {}
|
14
|
+
if hash
|
15
|
+
@neo_id = hash["self"].split('/').last
|
16
|
+
@neo_url = hash["self"]
|
17
|
+
|
18
|
+
for key, value in hash["data"]
|
19
|
+
@table[key.to_sym] = value
|
20
|
+
new_ostruct_member(key)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update properties = {}
|
26
|
+
if not properties.empty?
|
27
|
+
@table.each { | key, value | delete_field( key ) }
|
28
|
+
@table.clear
|
29
|
+
|
30
|
+
for key, value in properties
|
31
|
+
@table[key.to_sym] = value
|
32
|
+
new_ostruct_member(key)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
RestClient.put( "#{$neo_base_url}/node/#{neo_id}/properties", @table.to_json, :content_type => :json, :accept => :json )
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete
|
40
|
+
NeoRest::Node.delete neo_id
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_relationships direction = :all
|
44
|
+
relationsships_json = JSON.parse( RestClient.get( "#{$neo_base_url}/node/#{neo_id}/relationships/#{direction}", :accept => :json ) )
|
45
|
+
relationsships = []
|
46
|
+
relationsships_json.each { | relationship | relationsships << NeoRest::Relationship.new( relationship ) }
|
47
|
+
return relationsships unless block_given?
|
48
|
+
relationsships.each { | relationship | yield relationship }
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_relationship_to node, type, meta_data = {}
|
52
|
+
NeoRest::Relationship.new( JSON.parse( RestClient.post( "#{$neo_base_url}/node/#{neo_id}/relationships", { :to => "#{$base}/node/#{node.neo_id}", :type => type, :data => meta_data }.to_json, :content_type => :json, :accept => :json ) ) )
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_relationship_from node, type, meta_data = {}
|
56
|
+
NeoRest::Relationship.new( JSON.parse( RestClient.post( "#{$neo_base_url}/node/#{node.neo_id}/relationships", { :to => "#{$base}/node/#{neo_id}", :type => type, :data => meta_data }.to_json, :content_type => :json, :accept => :json ) ) )
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_to_index index_name, key, value
|
60
|
+
RestClient.post( "#{$neo_base_url}/index/node/#{index_name}/#{key}/#{URI.escape(value)}", ("#{$base}/node/#{neo_id}").to_json, :content_type => :json, :accept => :json )
|
61
|
+
NeoRest::Index.new index_name, key, value
|
62
|
+
end
|
63
|
+
|
64
|
+
class << self
|
65
|
+
|
66
|
+
def create_new node_data
|
67
|
+
NeoRest::Node.new( JSON.parse( RestClient.post( "#{$neo_base_url}/node", node_data.to_json, :content_type => :json, :accept => :json ) ) )
|
68
|
+
end
|
69
|
+
|
70
|
+
def load node_id
|
71
|
+
RestClient.get( "#{$neo_base_url}/node/#{node_id}", :accept => :json ){ |response, request, result, &block|
|
72
|
+
case response.code
|
73
|
+
when 200
|
74
|
+
NeoRest::Node.new( JSON.parse( response ) )
|
75
|
+
when 404
|
76
|
+
return nil
|
77
|
+
else
|
78
|
+
response.return!(request, result, &block)
|
79
|
+
end
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def delete node
|
84
|
+
node = node.neo_id if node.respond_to?('neo_id')
|
85
|
+
RestClient.delete( "#{$neo_base_url}/node/#{node}" )
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module NeoRest
|
6
|
+
|
7
|
+
class Relationship < OpenStruct
|
8
|
+
|
9
|
+
attr_reader :neo_id, :neo_url, :start_id, :end_id, :type
|
10
|
+
|
11
|
+
def initialize( hash = nil )
|
12
|
+
@table = {}
|
13
|
+
if hash
|
14
|
+
@neo_id = hash["self"].split('/').last
|
15
|
+
@neo_url = hash["self"]
|
16
|
+
@start_id = hash["start"].split('/').last
|
17
|
+
@end_id = hash["end"].split('/').last
|
18
|
+
@type = hash["type"]
|
19
|
+
|
20
|
+
for key, value in hash["data"]
|
21
|
+
@table[key.to_sym] = value
|
22
|
+
new_ostruct_member(key)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def update properties = {}
|
28
|
+
if not properties.empty?
|
29
|
+
@table.each { | key, value | delete_field( key ) }
|
30
|
+
@table.clear
|
31
|
+
|
32
|
+
for key, value in properties
|
33
|
+
@table[key.to_sym] = value
|
34
|
+
new_ostruct_member(key)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
RestClient.put( "#{$neo_base_url}/relationship/#{neo_id}/properties", @table.to_json, :content_type => :json, :accept => :json )
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete
|
42
|
+
NeoRest::Relationship.delete neo_id
|
43
|
+
end
|
44
|
+
|
45
|
+
class << self
|
46
|
+
|
47
|
+
def load relationship_id
|
48
|
+
RestClient.get( "#{$neo_base_url}/relationship/#{relationship_id}", :accept => :json ){ |response, request, result, &block|
|
49
|
+
case response.code
|
50
|
+
when 200
|
51
|
+
NeoRest::Node.new( JSON.parse( response ) )
|
52
|
+
when 404
|
53
|
+
return nil
|
54
|
+
else
|
55
|
+
response.return!(request, result, &block)
|
56
|
+
end
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def delete relationship_id
|
61
|
+
RestClient.delete( "#{$neo_base_url}/relationship/#{relationship_id}" )
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module NeoRest
|
3
|
+
|
4
|
+
class TestHelper
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def clean_the_whole_database delete_key
|
9
|
+
# this needs the following plugin installed in the Neo server: https://github.com/jexp/neo4j-clean-remote-db-addon
|
10
|
+
RestClient.delete( "http://#{$neo_host}:#{$neo_port}/cleandb/#{delete_key}" )
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/neo_rest.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "NeoRest::Index" do
|
5
|
+
|
6
|
+
describe "get_nodes", :neo4j => true do
|
7
|
+
|
8
|
+
it "will get all the nodes from an index" do
|
9
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
10
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
11
|
+
|
12
|
+
new_node_1.add_to_index :friends, :name, 'node name 1'
|
13
|
+
new_node_2.add_to_index :friends, :name, 'node name 1'
|
14
|
+
|
15
|
+
nodes = NeoRest::Index.get_nodes :friends, :name, 'node name 1'
|
16
|
+
nodes.count.should == 2
|
17
|
+
nodes[0].neo_id.should == new_node_1.neo_id
|
18
|
+
nodes[1].neo_id.should == new_node_2.neo_id
|
19
|
+
end
|
20
|
+
|
21
|
+
it "will get all the nodes from an index" do
|
22
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
23
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
24
|
+
|
25
|
+
index = new_node_1.add_to_index :friends, :name, 'node name 1'
|
26
|
+
new_node_2.add_to_index :friends, :name, 'node name 1'
|
27
|
+
|
28
|
+
nodes = index.get_nodes
|
29
|
+
nodes.count.should == 2
|
30
|
+
nodes[0].neo_id.should == new_node_1.neo_id
|
31
|
+
nodes[1].neo_id.should == new_node_2.neo_id
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "delete", :neo4j => true do
|
37
|
+
|
38
|
+
it "will remove a node from the index using neo_id" do
|
39
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
40
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
41
|
+
|
42
|
+
index = new_node_1.add_to_index :friends, :name, 'node name 1'
|
43
|
+
new_node_2.add_to_index :friends, :name, 'node name 1'
|
44
|
+
|
45
|
+
index.remove new_node_1.neo_id
|
46
|
+
|
47
|
+
nodes = NeoRest::Index.get_nodes :friends, :name, 'node name 1'
|
48
|
+
nodes.count.should == 1
|
49
|
+
nodes[0].neo_id.should == new_node_2.neo_id
|
50
|
+
end
|
51
|
+
|
52
|
+
it "will remove a node from the index using node" do
|
53
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
54
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
55
|
+
|
56
|
+
index = new_node_1.add_to_index :friends, :name, 'node name 1'
|
57
|
+
new_node_2.add_to_index :friends, :name, 'node name 1'
|
58
|
+
|
59
|
+
index.remove new_node_1
|
60
|
+
|
61
|
+
nodes = NeoRest::Index.get_nodes :friends, :name, 'node name 1'
|
62
|
+
nodes.count.should == 1
|
63
|
+
nodes[0].neo_id.should == new_node_2.neo_id
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "NeoRest::Node" do
|
5
|
+
|
6
|
+
describe "create_new", :neo4j => true do
|
7
|
+
|
8
|
+
it "will create a new node" do
|
9
|
+
new_node = NeoRest::Node.create_new( {:name => 'node name', :other_property => 'property value'} )
|
10
|
+
new_node.name.should == 'node name'
|
11
|
+
new_node.other_property.should == 'property value'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "load", :neo4j => true do
|
17
|
+
|
18
|
+
it "will load an existing node" do
|
19
|
+
new_node = NeoRest::Node.create_new( {:name => 'node name', :other_property => 'property value'} )
|
20
|
+
|
21
|
+
existing_node = NeoRest::Node.load( new_node.neo_id )
|
22
|
+
existing_node.name.should == 'node name'
|
23
|
+
existing_node.other_property.should == 'property value'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "add_to_index", :neo4j => true do
|
29
|
+
|
30
|
+
it "will add the node to an index" do
|
31
|
+
new_node = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
32
|
+
|
33
|
+
new_node.add_to_index :friends, :name, 'node name 1'
|
34
|
+
|
35
|
+
nodes = NeoRest::Index.get_nodes :friends, :name, 'node name 1'
|
36
|
+
nodes.count.should == 1
|
37
|
+
nodes[0].neo_id.should == new_node.neo_id
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "add_relationship_to", :neo4j => true do
|
43
|
+
|
44
|
+
it "will add a relationships to a node" do
|
45
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
46
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
47
|
+
|
48
|
+
relationship = new_node_1.add_relationship_to new_node_2, :knows
|
49
|
+
relationship.start_id.should == new_node_1.neo_id
|
50
|
+
relationship.end_id.should == new_node_2.neo_id
|
51
|
+
relationship.type.should == "knows"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "will add a relationships with meta data to a node" do
|
55
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
56
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
57
|
+
|
58
|
+
relationship = new_node_1.add_relationship_to new_node_2, :knows, {:name => 'relation one', :description => 'description one'}
|
59
|
+
relationship.name.should == "relation one"
|
60
|
+
relationship.description.should == "description one"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "add_relationship_from", :neo4j => true do
|
66
|
+
|
67
|
+
it "will add a relationships from a node" do
|
68
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
69
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
70
|
+
|
71
|
+
relationship = new_node_1.add_relationship_from new_node_2, :knows
|
72
|
+
relationship.start_id.should == new_node_2.neo_id
|
73
|
+
relationship.end_id.should == new_node_1.neo_id
|
74
|
+
relationship.type.should == "knows"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "will add a relationships with meta data from a node" do
|
78
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
79
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
80
|
+
|
81
|
+
relationship = new_node_1.add_relationship_from new_node_2, :knows, {:name => 'relation one', :description => 'description one'}
|
82
|
+
relationship.name.should == "relation one"
|
83
|
+
relationship.description.should == "description one"
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "get_relationships", :neo4j => true do
|
89
|
+
|
90
|
+
it "will load all existing relations of a node" do
|
91
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
92
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
93
|
+
|
94
|
+
new_node_1.add_relationship_to new_node_2, :knows
|
95
|
+
new_node_1.add_relationship_to new_node_2, :knows, {:name => 'relation one', :description => 'description one'}
|
96
|
+
|
97
|
+
relationships = new_node_1.get_relationships
|
98
|
+
relationships.count.should == 2
|
99
|
+
relationships[1].name.should == 'relation one'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "will load all existing relations going out the node" do
|
103
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
104
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
105
|
+
|
106
|
+
new_node_1.add_relationship_to new_node_2, :knows
|
107
|
+
new_node_1.add_relationship_to new_node_2, :knows, {:name => 'relation one', :description => 'description one'}
|
108
|
+
new_node_1.add_relationship_from new_node_2, :knows, {:name => 'relation two', :description => 'description two'}
|
109
|
+
|
110
|
+
relationships = new_node_1.get_relationships :out
|
111
|
+
relationships.count.should == 2
|
112
|
+
relationships[1].name.should == 'relation one'
|
113
|
+
end
|
114
|
+
|
115
|
+
it "will load all existing relations going out the node" do
|
116
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
117
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
118
|
+
|
119
|
+
new_node_1.add_relationship_to new_node_2, :knows
|
120
|
+
new_node_1.add_relationship_to new_node_2, :knows, {:name => 'relation one', :description => 'description one'}
|
121
|
+
new_node_1.add_relationship_from new_node_2, :knows, {:name => 'relation two', :description => 'description two'}
|
122
|
+
|
123
|
+
relationships = new_node_1.get_relationships :in
|
124
|
+
relationships.count.should == 1
|
125
|
+
relationships[0].name.should == 'relation two'
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "update", :neo4j => true do
|
131
|
+
|
132
|
+
it "will update an existing node" do
|
133
|
+
new_node = NeoRest::Node.create_new( {:name => 'node name', :other_property => 'property value'} )
|
134
|
+
|
135
|
+
new_node.name = 'new node name'
|
136
|
+
new_node.other_property = 'new property value'
|
137
|
+
new_node.update
|
138
|
+
|
139
|
+
existing_node = NeoRest::Node.load( new_node.neo_id )
|
140
|
+
existing_node.name.should == 'new node name'
|
141
|
+
existing_node.other_property.should == 'new property value'
|
142
|
+
end
|
143
|
+
|
144
|
+
it "will update an existing node with a hash" do
|
145
|
+
new_node = NeoRest::Node.create_new( {:name => 'node name', :other_property => 'property value'} )
|
146
|
+
|
147
|
+
new_node.update( {:name => 'new node name', :other_property => 'new property value', :new_property => 'value'} )
|
148
|
+
|
149
|
+
new_node.name.should == 'new node name'
|
150
|
+
new_node.other_property.should == 'new property value'
|
151
|
+
new_node.new_property.should == 'value'
|
152
|
+
|
153
|
+
existing_node = NeoRest::Node.load( new_node.neo_id )
|
154
|
+
existing_node.name.should == 'new node name'
|
155
|
+
existing_node.other_property.should == 'new property value'
|
156
|
+
existing_node.new_property.should == 'value'
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "delete", :neo4j => true do
|
162
|
+
|
163
|
+
it "will delete an existing node that is loaded" do
|
164
|
+
new_node = NeoRest::Node.create_new( {:name => 'node name', :other_property => 'property value'} )
|
165
|
+
|
166
|
+
new_node.delete
|
167
|
+
|
168
|
+
existing_node = NeoRest::Node.load( new_node.neo_id )
|
169
|
+
existing_node.nil?.should == true
|
170
|
+
end
|
171
|
+
|
172
|
+
it "will delete an existing node using neo_id" do
|
173
|
+
new_node = NeoRest::Node.create_new( {:name => 'node name', :other_property => 'property value'} )
|
174
|
+
|
175
|
+
NeoRest::Node.delete new_node.neo_id
|
176
|
+
|
177
|
+
existing_node = NeoRest::Node.load( new_node.neo_id )
|
178
|
+
existing_node.nil?.should == true
|
179
|
+
end
|
180
|
+
|
181
|
+
it "will delete an existing node using node" do
|
182
|
+
new_node = NeoRest::Node.create_new( {:name => 'node name', :other_property => 'property value'} )
|
183
|
+
|
184
|
+
NeoRest::Node.delete new_node
|
185
|
+
|
186
|
+
existing_node = NeoRest::Node.load( new_node.neo_id )
|
187
|
+
existing_node.nil?.should == true
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "NeoRest::Relationship" do
|
5
|
+
|
6
|
+
describe "load", :neo4j => true do
|
7
|
+
|
8
|
+
it "will load an existing relationship" do
|
9
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
10
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
11
|
+
|
12
|
+
new_relationship = new_node_1.add_relationship_to new_node_2, :knows
|
13
|
+
new_relationship.name = 'relation one'
|
14
|
+
new_relationship.description = 'description one'
|
15
|
+
new_relationship.update
|
16
|
+
|
17
|
+
existing_relationship = NeoRest::Relationship.load new_relationship.neo_id
|
18
|
+
existing_relationship.neo_id.should == new_relationship.neo_id
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "update", :neo4j => true do
|
24
|
+
|
25
|
+
it "will update an existing relationship" do
|
26
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
27
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
28
|
+
|
29
|
+
new_relationship = new_node_1.add_relationship_to new_node_2, :knows
|
30
|
+
new_relationship.name = 'relation one'
|
31
|
+
new_relationship.description = 'description one'
|
32
|
+
new_relationship.update
|
33
|
+
|
34
|
+
existing_relationship = NeoRest::Relationship.load new_relationship.neo_id
|
35
|
+
existing_relationship.name.should == 'relation one'
|
36
|
+
existing_relationship.description.should == 'description one'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "will update an existing relationship with a hash" do
|
40
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
41
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
42
|
+
|
43
|
+
new_relationship = new_node_1.add_relationship_to new_node_2, :knows
|
44
|
+
new_relationship.update( {:name => 'relation one', :description => 'description one', :new_property => 'value'} )
|
45
|
+
|
46
|
+
existing_relationship = NeoRest::Relationship.load new_relationship.neo_id
|
47
|
+
existing_relationship.name.should == 'relation one'
|
48
|
+
existing_relationship.description.should == 'description one'
|
49
|
+
existing_relationship.new_property.should == 'value'
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "delete", :neo4j => true do
|
55
|
+
|
56
|
+
it "will delete an existing relationship that is loaded" do
|
57
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
58
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
59
|
+
|
60
|
+
relationship_1 = new_node_1.add_relationship_to new_node_2, :knows
|
61
|
+
relationship_1.delete
|
62
|
+
end
|
63
|
+
|
64
|
+
it "will delete an existing relationship" do
|
65
|
+
new_node_1 = NeoRest::Node.create_new( {:name => 'node name 1', :other_property => 'property value'} )
|
66
|
+
new_node_2 = NeoRest::Node.create_new( {:name => 'node name 2', :other_property => 'property value'} )
|
67
|
+
|
68
|
+
relationship_1 = new_node_1.add_relationship_to new_node_2, :knows
|
69
|
+
|
70
|
+
NeoRest::Relationship.delete relationship_1.neo_id
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "NeoRest::TestHelper" do
|
5
|
+
|
6
|
+
describe "clean_the_whole_database", :neo4j => true do
|
7
|
+
# new_node = NeoRest::Node.create_new( {:name => 'node name', :other_property => 'property value'} )
|
8
|
+
|
9
|
+
# NeoRest::TestHelper.clean_the_whole_database 'yeah_delete_it_all'
|
10
|
+
|
11
|
+
# new_node.name.should == 'node name'
|
12
|
+
|
13
|
+
# lambda{ NeoRest::Node.load( new_node.neo_id ) }.should raise_error
|
14
|
+
# lambda{ raise('test') }.should raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/specs.watchr
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# adapted from http://github.com/rspec/rspec-rails/blob/master/specs.watchr
|
2
|
+
|
3
|
+
# Run me with:
|
4
|
+
#
|
5
|
+
# $ watchr specs.watchr
|
6
|
+
|
7
|
+
# --------------------------------------------------
|
8
|
+
# Convenience Methods
|
9
|
+
# --------------------------------------------------
|
10
|
+
def all_spec_files
|
11
|
+
Dir['spec/**/*_spec.rb']
|
12
|
+
end
|
13
|
+
|
14
|
+
def run_spec_matching(thing_to_match)
|
15
|
+
matches = all_spec_files.grep(/#{thing_to_match}/i)
|
16
|
+
if matches.empty?
|
17
|
+
puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"
|
18
|
+
else
|
19
|
+
run matches.join(' ')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run(files_to_run)
|
24
|
+
puts("Running: #{files_to_run}")
|
25
|
+
system("rspec -c #{files_to_run}")
|
26
|
+
no_int_for_you
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_all_specs
|
30
|
+
run(all_spec_files.join(' '))
|
31
|
+
end
|
32
|
+
|
33
|
+
# --------------------------------------------------
|
34
|
+
# Watchr Rules
|
35
|
+
# --------------------------------------------------
|
36
|
+
watch('^spec/(.*)_spec\.rb') { |m| run_spec_matching(m[1]) }
|
37
|
+
watch('^app/(.*)\.rb') { |m| run_spec_matching(m[1]) }
|
38
|
+
watch('^app/(.*)\.haml') { |m| run_spec_matching(m[1]) }
|
39
|
+
watch('^lib/(.*)\.rb') { |m| run_spec_matching(m[1]) }
|
40
|
+
watch('^spec/spec_helper\.rb') { run_all_specs }
|
41
|
+
watch('^spec/support/.*\.rb') { run_all_specs }
|
42
|
+
|
43
|
+
# --------------------------------------------------
|
44
|
+
# Signal Handling
|
45
|
+
# --------------------------------------------------
|
46
|
+
|
47
|
+
def no_int_for_you
|
48
|
+
@sent_an_int = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
Signal.trap 'INT' do
|
52
|
+
if @sent_an_int then
|
53
|
+
puts " A second INT? Ok, I get the message. Shutting down now."
|
54
|
+
exit
|
55
|
+
else
|
56
|
+
puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
|
57
|
+
@sent_an_int = true
|
58
|
+
Kernel.sleep 1.5
|
59
|
+
run_all_specs
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mark Nijhof
|
@@ -140,7 +140,25 @@ extensions: []
|
|
140
140
|
extra_rdoc_files:
|
141
141
|
- README
|
142
142
|
files:
|
143
|
+
- .rvmrc
|
144
|
+
- GemFile
|
145
|
+
- Gemfile.lock
|
146
|
+
- LICENCE
|
143
147
|
- README
|
148
|
+
- RakeFile.rb
|
149
|
+
- VERSION
|
150
|
+
- lib/NeoRest/config.rb
|
151
|
+
- lib/NeoRest/index.rb
|
152
|
+
- lib/NeoRest/node.rb
|
153
|
+
- lib/NeoRest/relationship.rb
|
154
|
+
- lib/NeoRest/test_helper.rb
|
155
|
+
- lib/neo_rest.rb
|
156
|
+
- spec/NeoRest/index_spec.rb
|
157
|
+
- spec/NeoRest/node_spec.rb
|
158
|
+
- spec/NeoRest/relationship_spec.rb
|
159
|
+
- spec/NeoRest/test_helper_spec.rb
|
160
|
+
- spec/spec_helper.rb
|
161
|
+
- specs.watchr
|
144
162
|
has_rdoc: true
|
145
163
|
homepage: http://github.com/MarkNijhof/NeoRest
|
146
164
|
licenses: []
|