neography-calamitates 1.2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/.project +12 -0
- data/.travis.yml +4 -0
- data/CONTRIBUTORS +18 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.md +261 -0
- data/Rakefile +14 -0
- data/examples/facebook.rb +40 -0
- data/examples/facebook_v2.rb +25 -0
- data/examples/greatest.rb +43 -0
- data/examples/linkedin.rb +39 -0
- data/examples/linkedin_v2.rb +22 -0
- data/examples/traversal_example1.rb +65 -0
- data/examples/traversal_example2.rb +54 -0
- data/lib/neography.rb +45 -0
- data/lib/neography/config.rb +52 -0
- data/lib/neography/connection.rb +203 -0
- data/lib/neography/equal.rb +21 -0
- data/lib/neography/errors.rb +45 -0
- data/lib/neography/index.rb +52 -0
- data/lib/neography/multi_json_parser.rb +28 -0
- data/lib/neography/neography.rb +10 -0
- data/lib/neography/node.rb +53 -0
- data/lib/neography/node_path.rb +29 -0
- data/lib/neography/node_relationship.rb +37 -0
- data/lib/neography/node_traverser.rb +146 -0
- data/lib/neography/path_traverser.rb +100 -0
- data/lib/neography/property.rb +61 -0
- data/lib/neography/property_container.rb +29 -0
- data/lib/neography/railtie.rb +19 -0
- data/lib/neography/relationship.rb +70 -0
- data/lib/neography/relationship_traverser.rb +80 -0
- data/lib/neography/rest.rb +470 -0
- data/lib/neography/rest/auto_indexes.rb +64 -0
- data/lib/neography/rest/batch.rb +277 -0
- data/lib/neography/rest/clean.rb +19 -0
- data/lib/neography/rest/cypher.rb +33 -0
- data/lib/neography/rest/extensions.rb +25 -0
- data/lib/neography/rest/gremlin.rb +24 -0
- data/lib/neography/rest/helpers.rb +38 -0
- data/lib/neography/rest/indexes.rb +100 -0
- data/lib/neography/rest/node_auto_indexes.rb +14 -0
- data/lib/neography/rest/node_indexes.rb +50 -0
- data/lib/neography/rest/node_labels.rb +60 -0
- data/lib/neography/rest/node_paths.rb +57 -0
- data/lib/neography/rest/node_properties.rb +11 -0
- data/lib/neography/rest/node_relationships.rb +42 -0
- data/lib/neography/rest/node_traversal.rb +81 -0
- data/lib/neography/rest/nodes.rb +102 -0
- data/lib/neography/rest/other_node_relationships.rb +48 -0
- data/lib/neography/rest/paths.rb +36 -0
- data/lib/neography/rest/properties.rb +56 -0
- data/lib/neography/rest/relationship_auto_indexes.rb +14 -0
- data/lib/neography/rest/relationship_indexes.rb +35 -0
- data/lib/neography/rest/relationship_properties.rb +11 -0
- data/lib/neography/rest/relationship_types.rb +18 -0
- data/lib/neography/rest/relationships.rb +23 -0
- data/lib/neography/rest/schema_indexes.rb +34 -0
- data/lib/neography/rest/transactions.rb +102 -0
- data/lib/neography/tasks.rb +158 -0
- data/lib/neography/version.rb +3 -0
- data/neography.gemspec +32 -0
- data/spec/integration/authorization_spec.rb +48 -0
- data/spec/integration/index_spec.rb +70 -0
- data/spec/integration/neography_spec.rb +10 -0
- data/spec/integration/node_encoding_spec.rb +71 -0
- data/spec/integration/node_path_spec.rb +222 -0
- data/spec/integration/node_relationship_spec.rb +381 -0
- data/spec/integration/node_spec.rb +251 -0
- data/spec/integration/parsing_spec.rb +13 -0
- data/spec/integration/performance_spec.rb +17 -0
- data/spec/integration/relationship_spec.rb +37 -0
- data/spec/integration/rest_batch_spec.rb +512 -0
- data/spec/integration/rest_batch_streaming_spec.rb +32 -0
- data/spec/integration/rest_bulk_spec.rb +106 -0
- data/spec/integration/rest_experimental_spec.rb +22 -0
- data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
- data/spec/integration/rest_header_spec.rb +14 -0
- data/spec/integration/rest_index_spec.rb +468 -0
- data/spec/integration/rest_labels_spec.rb +128 -0
- data/spec/integration/rest_node_spec.rb +274 -0
- data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
- data/spec/integration/rest_path_spec.rb +231 -0
- data/spec/integration/rest_plugin_spec.rb +177 -0
- data/spec/integration/rest_relationship_spec.rb +354 -0
- data/spec/integration/rest_relationship_types_spec.rb +18 -0
- data/spec/integration/rest_schema_index_spec.rb +32 -0
- data/spec/integration/rest_transaction_spec.rb +166 -0
- data/spec/integration/rest_traverse_spec.rb +149 -0
- data/spec/matchers.rb +33 -0
- data/spec/neography_spec.rb +23 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/unit/config_spec.rb +46 -0
- data/spec/unit/connection_spec.rb +211 -0
- data/spec/unit/node_spec.rb +100 -0
- data/spec/unit/properties_spec.rb +140 -0
- data/spec/unit/relationship_spec.rb +118 -0
- data/spec/unit/rest/batch_spec.rb +243 -0
- data/spec/unit/rest/clean_spec.rb +17 -0
- data/spec/unit/rest/cypher_spec.rb +21 -0
- data/spec/unit/rest/extensions_spec.rb +29 -0
- data/spec/unit/rest/gremlin_spec.rb +26 -0
- data/spec/unit/rest/labels_spec.rb +73 -0
- data/spec/unit/rest/node_auto_indexes_spec.rb +67 -0
- data/spec/unit/rest/node_indexes_spec.rb +141 -0
- data/spec/unit/rest/node_paths_spec.rb +80 -0
- data/spec/unit/rest/node_properties_spec.rb +80 -0
- data/spec/unit/rest/node_relationships_spec.rb +78 -0
- data/spec/unit/rest/node_traversal_spec.rb +128 -0
- data/spec/unit/rest/nodes_spec.rb +188 -0
- data/spec/unit/rest/paths_spec.rb +69 -0
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +67 -0
- data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
- data/spec/unit/rest/relationship_properties_spec.rb +80 -0
- data/spec/unit/rest/relationship_types_spec.rb +16 -0
- data/spec/unit/rest/relationships_spec.rb +22 -0
- data/spec/unit/rest/schema_index_spec.rb +31 -0
- data/spec/unit/rest/transactions_spec.rb +44 -0
- metadata +372 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
# borrowed from architect4r
|
2
|
+
require 'os'
|
3
|
+
require 'httpclient'
|
4
|
+
require 'zip'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
namespace :neo4j do
|
8
|
+
desc "Install Neo4j"
|
9
|
+
task :install, :edition, :version do |t, args|
|
10
|
+
args.with_defaults(:edition => "community", :version => "1.9.4")
|
11
|
+
puts "Installing Neo4j-#{args[:edition]}-#{args[:version]}"
|
12
|
+
|
13
|
+
if OS::Underlying.windows?
|
14
|
+
# Download Neo4j
|
15
|
+
unless File.exist?('neo4j.zip')
|
16
|
+
df = File.open('neo4j.zip', 'wb')
|
17
|
+
begin
|
18
|
+
Net::HTTP.start("dist.neo4j.org") do |http|
|
19
|
+
http.request_get("/neo4j-#{args[:edition]}-#{args[:version]}-windows.zip") do |resp|
|
20
|
+
resp.read_body do |segment|
|
21
|
+
df.write(segment)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
ensure
|
26
|
+
df.close()
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Extract and move to neo4j directory
|
31
|
+
unless File.exist?('neo4j')
|
32
|
+
Zip::File.open('neo4j.zip') do |zip_file|
|
33
|
+
zip_file.each do |f|
|
34
|
+
f_path=File.join(".", f.name)
|
35
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
36
|
+
begin
|
37
|
+
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
38
|
+
rescue
|
39
|
+
puts f.name + " failed to extract."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
FileUtils.mv "neo4j-#{args[:edition]}-#{args[:version]}", "neo4j"
|
44
|
+
end
|
45
|
+
|
46
|
+
# Install if running with Admin Privileges
|
47
|
+
if %x[reg query "HKU\\S-1-5-19"].size > 0
|
48
|
+
%x[neo4j/bin/neo4j install]
|
49
|
+
puts "Neo4j Installed as a service."
|
50
|
+
end
|
51
|
+
|
52
|
+
else
|
53
|
+
%x[curl -O http://dist.neo4j.org/neo4j-#{args[:edition]}-#{args[:version]}-unix.tar.gz]
|
54
|
+
%x[tar -xvzf neo4j-#{args[:edition]}-#{args[:version]}-unix.tar.gz]
|
55
|
+
%x[mv neo4j-#{args[:edition]}-#{args[:version]} neo4j]
|
56
|
+
%x[rm neo4j-#{args[:edition]}-#{args[:version]}-unix.tar.gz]
|
57
|
+
puts "Neo4j Installed in to neo4j directory."
|
58
|
+
end
|
59
|
+
puts "Type 'rake neo4j:start' to start it"
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "Start the Neo4j Server"
|
63
|
+
task :start do
|
64
|
+
puts "Starting Neo4j..."
|
65
|
+
if OS::Underlying.windows?
|
66
|
+
if %x[reg query "HKU\\S-1-5-19"].size > 0
|
67
|
+
value = %x[neo4j/bin/Neo4j.bat start] #start service
|
68
|
+
else
|
69
|
+
puts "Starting Neo4j directly, not as a service."
|
70
|
+
value = %x[neo4j/bin/Neo4j.bat]
|
71
|
+
end
|
72
|
+
else
|
73
|
+
value = %x[neo4j/bin/neo4j start]
|
74
|
+
end
|
75
|
+
puts value
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Start the Neo4j Server in the background"
|
79
|
+
task :start_no_wait do
|
80
|
+
puts "Starting Neo4j in the background..."
|
81
|
+
if OS::Underlying.windows?
|
82
|
+
if %x[reg query "HKU\\S-1-5-19"].size > 0
|
83
|
+
value = %x[neo4j/bin/Neo4j.bat start-no-wait] #start service
|
84
|
+
else
|
85
|
+
puts "Starting Neo4j directly, not as a service."
|
86
|
+
value = %x[neo4j/bin/Neo4j.bat start-no-wait]
|
87
|
+
end
|
88
|
+
else
|
89
|
+
value = %x[neo4j/bin/neo4j start-no-wait]
|
90
|
+
end
|
91
|
+
puts value
|
92
|
+
end
|
93
|
+
|
94
|
+
desc "Stop the Neo4j Server"
|
95
|
+
task :stop do
|
96
|
+
puts "Stopping Neo4j..."
|
97
|
+
if OS::Underlying.windows?
|
98
|
+
if %x[reg query "HKU\\S-1-5-19"].size > 0
|
99
|
+
value = %x[neo4j/bin/Neo4j.bat stop] #stop service
|
100
|
+
else
|
101
|
+
puts "You do not have administrative rights to stop the Neo4j Service"
|
102
|
+
end
|
103
|
+
else
|
104
|
+
value = %x[neo4j/bin/neo4j stop]
|
105
|
+
end
|
106
|
+
puts value
|
107
|
+
end
|
108
|
+
|
109
|
+
desc "Restart the Neo4j Server"
|
110
|
+
task :restart do
|
111
|
+
puts "Restarting Neo4j..."
|
112
|
+
if OS::Underlying.windows?
|
113
|
+
if %x[reg query "HKU\\S-1-5-19"].size > 0
|
114
|
+
%x[neo4j/bin/Neo4j.bat restart]
|
115
|
+
else
|
116
|
+
puts "You do not have administrative rights to restart the Neo4j Service"
|
117
|
+
end
|
118
|
+
else
|
119
|
+
%x[neo4j/bin/neo4j restart]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
desc "Reset the Neo4j Server"
|
124
|
+
task :reset_yes_i_am_sure do
|
125
|
+
# Stop the server
|
126
|
+
if OS::Underlying.windows?
|
127
|
+
if %x[reg query "HKU\\S-1-5-19"].size > 0
|
128
|
+
%x[neo4j/bin/Neo4j.bat stop]
|
129
|
+
|
130
|
+
# Reset the database
|
131
|
+
FileUtils.rm_rf("neo4j/data/graph.db")
|
132
|
+
FileUtils.mkdir("neo4j/data/graph.db")
|
133
|
+
|
134
|
+
# Remove log files
|
135
|
+
FileUtils.rm_rf("neo4j/data/log")
|
136
|
+
FileUtils.mkdir("neo4j/data/log")
|
137
|
+
|
138
|
+
%x[neo4j/bin/Neo4j.bat start]
|
139
|
+
else
|
140
|
+
puts "You do not have administrative rights to reset the Neo4j Service"
|
141
|
+
end
|
142
|
+
else
|
143
|
+
%x[neo4j/bin/neo4j stop]
|
144
|
+
|
145
|
+
# Reset the database
|
146
|
+
FileUtils.rm_rf("neo4j/data/graph.db")
|
147
|
+
FileUtils.mkdir("neo4j/data/graph.db")
|
148
|
+
|
149
|
+
# Remove log files
|
150
|
+
FileUtils.rm_rf("neo4j/data/log")
|
151
|
+
FileUtils.mkdir("neo4j/data/log")
|
152
|
+
|
153
|
+
# Start the server
|
154
|
+
%x[neo4j/bin/neo4j start]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
data/neography.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "neography/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "neography-calamitates"
|
7
|
+
s.version = Neography::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = "Max De Marzi"
|
10
|
+
s.email = "maxdemarzi@gmail.com"
|
11
|
+
s.homepage = "http://rubygems.org/gems/neography"
|
12
|
+
s.summary = "ruby wrapper to Neo4j Rest API"
|
13
|
+
s.description = "A Ruby wrapper to the Neo4j Rest API see http://docs.neo4j.org/chunked/stable/rest-api.html for more details."
|
14
|
+
|
15
|
+
s.rubyforge_project = "neography"
|
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_development_dependency "rspec", ">= 2.11"
|
23
|
+
s.add_development_dependency "net-http-spy", "0.2.1"
|
24
|
+
s.add_development_dependency "rake", ">= 0.8.7"
|
25
|
+
s.add_development_dependency "coveralls"
|
26
|
+
s.add_dependency "httpclient", ">= 2.3.3"
|
27
|
+
s.add_dependency "rake", ">= 0.8.7"
|
28
|
+
s.add_dependency "json", ">= 1.7.7"
|
29
|
+
s.add_dependency "os", ">= 0.9.6"
|
30
|
+
s.add_dependency "rubyzip", "~> 1.0.0"
|
31
|
+
s.add_dependency "multi_json", ">= 1.3.2"
|
32
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neography::Rest, :slow => true do
|
4
|
+
describe "basic authentication" do
|
5
|
+
describe "get_root" do
|
6
|
+
it "can get the root node"do
|
7
|
+
@neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"})
|
8
|
+
root_node = @neo.get_root
|
9
|
+
root_node.should have_key("reference_node")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "create_node" do
|
14
|
+
it "can create an empty node" do
|
15
|
+
@neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"})
|
16
|
+
new_node = @neo.create_node
|
17
|
+
new_node.should_not be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "quick initializer" do
|
22
|
+
it "can get the root node" do
|
23
|
+
@neo = Neography::Rest.new("http://abbe3c012:34d7b22eb@4c36b641.neo4j.atns.de:7474/9dc1fda5be8b5cde29621e21cae5adece3de0f37")
|
24
|
+
root_node = @neo.get_root
|
25
|
+
root_node.should have_key("reference_node")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "digest authentication" do
|
31
|
+
describe "get_root" do
|
32
|
+
it "can get the root node" do
|
33
|
+
@neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"})
|
34
|
+
root_node = @neo.get_root
|
35
|
+
root_node.should have_key("reference_node")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "create_node" do
|
40
|
+
it "can create an empty node" do
|
41
|
+
@neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"})
|
42
|
+
new_node = @neo.create_node
|
43
|
+
new_node.should_not be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neography::Index do
|
4
|
+
|
5
|
+
it "can add a node to an index" do
|
6
|
+
new_node = Neography::Node.create
|
7
|
+
key = generate_text(6)
|
8
|
+
value = generate_text
|
9
|
+
new_node.add_to_index("node_test_index", key, value)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can add a node to an index uniquely" do
|
13
|
+
new_node = Neography::Node.create
|
14
|
+
key = generate_text(6)
|
15
|
+
value = generate_text
|
16
|
+
new_node.add_to_index("node_test_index", key, value, true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can add a relationship to an index" do
|
20
|
+
node1 = Neography::Node.create
|
21
|
+
node2 = Neography::Node.create
|
22
|
+
r = Neography::Relationship.create(:friends, node1, node2)
|
23
|
+
key = generate_text(6)
|
24
|
+
value = generate_text
|
25
|
+
r.add_to_index("relationship_test_index", key, value)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can find a node in an index" do
|
29
|
+
value = generate_text
|
30
|
+
new_node = Neography::Node.create("name" => value)
|
31
|
+
new_node.add_to_index("node_test_index", "name", value)
|
32
|
+
existing_node = Neography::Node.find("node_test_index", "name", value)
|
33
|
+
existing_node.name.should == value
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can find a node in an index with brackets" do
|
37
|
+
value = "Sen. Roy Blunt [R-MO]"
|
38
|
+
new_node = Neography::Node.create("name" => value)
|
39
|
+
new_node.add_to_index("node_test_index", "name", value)
|
40
|
+
existing_node = Neography::Node.find("node_test_index", "name", value)
|
41
|
+
existing_node.name.should == value
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can find a relationship in an index" do
|
45
|
+
value = generate_text
|
46
|
+
node1 = Neography::Node.create
|
47
|
+
node2 = Neography::Node.create
|
48
|
+
r = Neography::Relationship.create(:friends, node1, node2, {"name" => value})
|
49
|
+
r.add_to_index("relationship_test_index", "name", value)
|
50
|
+
existing_r = Neography::Relationship.find("relationship_test_index", "name", value)
|
51
|
+
existing_r.name.should == value
|
52
|
+
end
|
53
|
+
|
54
|
+
it "can find multiple nodes in an index" do
|
55
|
+
value1 = generate_text
|
56
|
+
value2 = generate_text
|
57
|
+
value3 = generate_text
|
58
|
+
node1 = Neography::Node.create("first_name" => value1, "last_name" => value2)
|
59
|
+
node1.add_to_index("node_test_index", "first_name", value1)
|
60
|
+
node2 = Neography::Node.create("first_name" => value1, "last_name" => value3)
|
61
|
+
node2.add_to_index("node_test_index", "first_name", value1)
|
62
|
+
|
63
|
+
existing_nodes = Neography::Node.find("node_test_index", "first_name", value1)
|
64
|
+
existing_nodes.size.should == 2
|
65
|
+
existing_nodes.first.last_name.should == value2
|
66
|
+
existing_nodes.last.last_name.should == value3
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Neography::Node do
|
5
|
+
|
6
|
+
describe "create and new" do
|
7
|
+
|
8
|
+
it "can create a node with UTF-8 encoded properties" do
|
9
|
+
new_node = Neography::Node.create("name" => "美都池水")
|
10
|
+
new_node.name.should == "美都池水"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can create a node with more than one UTF-8 encoded properties" do
|
14
|
+
new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
|
15
|
+
new_node.first_name.should == "美都"
|
16
|
+
new_node.last_name.should == "池水"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "load" do
|
22
|
+
it "can get a node with UTF-8 encoded properties that exists" do
|
23
|
+
new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
|
24
|
+
existing_node = Neography::Node.load(new_node)
|
25
|
+
existing_node.should_not be_nil
|
26
|
+
existing_node.neo_id.should_not be_nil
|
27
|
+
existing_node.neo_id.should == new_node.neo_id
|
28
|
+
existing_node.first_name.should == "美都"
|
29
|
+
existing_node.last_name.should == "池水"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can get a node with UTF-8 encoded properties from an index" do
|
33
|
+
@neo = Neography::Rest.new
|
34
|
+
new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
|
35
|
+
key = generate_text(6)
|
36
|
+
value = generate_text
|
37
|
+
@neo.add_node_to_index("test_node_index", key, value, new_node)
|
38
|
+
node_from_index = @neo.get_node_index("test_node_index", key, value)
|
39
|
+
existing_node = Neography::Node.load(node_from_index)
|
40
|
+
existing_node.should_not be_nil
|
41
|
+
existing_node.neo_id.should_not be_nil
|
42
|
+
existing_node.neo_id.should == new_node.neo_id
|
43
|
+
existing_node.first_name.should == "美都"
|
44
|
+
existing_node.last_name.should == "池水"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can get a node with UTF-8 encoded properties that exists via cypher" do
|
48
|
+
new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
|
49
|
+
cypher = "START n = node({id}) return n"
|
50
|
+
@neo = Neography::Rest.new
|
51
|
+
results = @neo.execute_query(cypher, {:id => new_node.neo_id.to_i})
|
52
|
+
existing_node = Neography::Node.load(results)
|
53
|
+
existing_node.should_not be_nil
|
54
|
+
existing_node.neo_id.should_not be_nil
|
55
|
+
existing_node.neo_id.should == new_node.neo_id
|
56
|
+
existing_node.first_name.should == "美都"
|
57
|
+
existing_node.last_name.should == "池水"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can get columns of data from a node with UTF-8 encoded properties that exists via cypher" do
|
61
|
+
new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
|
62
|
+
cypher = "START me = node({id})
|
63
|
+
RETURN me.first_name, me.last_name"
|
64
|
+
@neo = Neography::Rest.new
|
65
|
+
results = @neo.execute_query(cypher, {:id => new_node.neo_id.to_i})
|
66
|
+
results['data'][0].should == ["美都","池水"]
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neography::NodePath do
|
4
|
+
|
5
|
+
def create_nodes
|
6
|
+
johnathan = Neography::Node.create("name" =>'Johnathan')
|
7
|
+
mark = Neography::Node.create("name" =>'Mark')
|
8
|
+
phill = Neography::Node.create("name" =>'Phill')
|
9
|
+
mary = Neography::Node.create("name" =>'Mary')
|
10
|
+
|
11
|
+
johnathan.both(:friends) << mark
|
12
|
+
mark.both(:friends) << mary
|
13
|
+
mark.both(:friends) << phill
|
14
|
+
phill.both(:friends) << mary
|
15
|
+
|
16
|
+
[johnathan, mark, phill, mary]
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "all_paths" do
|
20
|
+
it "can return nodes" do
|
21
|
+
johnathan, mark, phill, mary = create_nodes
|
22
|
+
|
23
|
+
johnathan.all_paths_to(mary).incoming(:friends).depth(4).nodes.each do |path|
|
24
|
+
path.map{|n| n.is_a?(Neography::Node).should be_true}
|
25
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_false}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can return relationships" do
|
30
|
+
johnathan, mark, phill, mary = create_nodes
|
31
|
+
|
32
|
+
johnathan.all_paths_to(mary).incoming(:friends).depth(4).rels.each do |path|
|
33
|
+
path.map{|n| n.is_a?(Neography::Node).should be_false}
|
34
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_true}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can return both" do
|
39
|
+
johnathan, mark, phill, mary = create_nodes
|
40
|
+
|
41
|
+
johnathan.all_paths_to(mary).incoming(:friends).depth(4).each do |path|
|
42
|
+
path.each_with_index do |n,i|
|
43
|
+
if i.even?
|
44
|
+
n.is_a?(Neography::Node).should be_true
|
45
|
+
else
|
46
|
+
n.is_a?(Neography::Relationship).should be_true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "all_simple_paths" do
|
54
|
+
it "can return nodes" do
|
55
|
+
johnathan, mark, phill, mary = create_nodes
|
56
|
+
|
57
|
+
johnathan.all_simple_paths_to(mary).incoming(:friends).depth(4).nodes.each do |path|
|
58
|
+
path.map{|n| n.is_a?(Neography::Node).should be_true}
|
59
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_false}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "can return relationships" do
|
64
|
+
johnathan, mark, phill, mary = create_nodes
|
65
|
+
|
66
|
+
johnathan.all_simple_paths_to(mary).incoming(:friends).depth(4).rels.each do |path|
|
67
|
+
path.map{|n| n.is_a?(Neography::Node).should be_false}
|
68
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_true}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "can return both" do
|
73
|
+
johnathan, mark, phill, mary = create_nodes
|
74
|
+
|
75
|
+
johnathan.all_simple_paths_to(mary).incoming(:friends).depth(4).each do |path|
|
76
|
+
path.each_with_index do |n,i|
|
77
|
+
if i.even?
|
78
|
+
n.is_a?(Neography::Node).should be_true
|
79
|
+
else
|
80
|
+
n.is_a?(Neography::Relationship).should be_true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "all_shortest_paths_to" do
|
88
|
+
it "can return nodes" do
|
89
|
+
johnathan, mark, phill, mary = create_nodes
|
90
|
+
|
91
|
+
johnathan.all_shortest_paths_to(mary).incoming(:friends).depth(4).nodes.each do |path|
|
92
|
+
path.map{|n| n.is_a?(Neography::Node).should be_true}
|
93
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_false}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "can return relationships" do
|
98
|
+
johnathan, mark, phill, mary = create_nodes
|
99
|
+
|
100
|
+
johnathan.all_shortest_paths_to(mary).incoming(:friends).depth(4).rels.each do |path|
|
101
|
+
path.map{|n| n.is_a?(Neography::Node).should be_false}
|
102
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_true}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it "can return both" do
|
107
|
+
johnathan, mark, phill, mary = create_nodes
|
108
|
+
|
109
|
+
johnathan.all_shortest_paths_to(mary).incoming(:friends).depth(4).each do |path|
|
110
|
+
path.each_with_index do |n,i|
|
111
|
+
if i.even?
|
112
|
+
n.is_a?(Neography::Node).should be_true
|
113
|
+
else
|
114
|
+
n.is_a?(Neography::Relationship).should be_true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "path_to" do
|
122
|
+
it "can return nodes" do
|
123
|
+
johnathan, mark, phill, mary = create_nodes
|
124
|
+
|
125
|
+
johnathan.path_to(mary).incoming(:friends).depth(4).nodes.each do |path|
|
126
|
+
path.map{|n| n.is_a?(Neography::Node).should be_true}
|
127
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_false}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it "can return relationships" do
|
132
|
+
johnathan, mark, phill, mary = create_nodes
|
133
|
+
|
134
|
+
johnathan.path_to(mary).incoming(:friends).depth(4).rels.each do |path|
|
135
|
+
path.map{|n| n.is_a?(Neography::Node).should be_false}
|
136
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_true}
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "can return both" do
|
141
|
+
johnathan, mark, phill, mary = create_nodes
|
142
|
+
|
143
|
+
johnathan.path_to(mary).incoming(:friends).depth(4).each do |path|
|
144
|
+
path.each_with_index do |n,i|
|
145
|
+
if i.even?
|
146
|
+
n.is_a?(Neography::Node).should be_true
|
147
|
+
else
|
148
|
+
n.is_a?(Neography::Relationship).should be_true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "simple_path_to" do
|
156
|
+
it "can return nodes" do
|
157
|
+
johnathan, mark, phill, mary = create_nodes
|
158
|
+
|
159
|
+
johnathan.simple_path_to(mary).incoming(:friends).depth(4).nodes.each do |path|
|
160
|
+
path.map{|n| n.is_a?(Neography::Node).should be_true}
|
161
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_false}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it "can return relationships" do
|
166
|
+
johnathan, mark, phill, mary = create_nodes
|
167
|
+
|
168
|
+
johnathan.simple_path_to(mary).incoming(:friends).depth(4).rels.each do |path|
|
169
|
+
path.map{|n| n.is_a?(Neography::Node).should be_false}
|
170
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_true}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
it "can return both" do
|
175
|
+
johnathan, mark, phill, mary = create_nodes
|
176
|
+
|
177
|
+
johnathan.simple_path_to(mary).incoming(:friends).depth(4).each do |path|
|
178
|
+
path.each_with_index do |n,i|
|
179
|
+
if i.even?
|
180
|
+
n.is_a?(Neography::Node).should be_true
|
181
|
+
else
|
182
|
+
n.is_a?(Neography::Relationship).should be_true
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "shortest_path_to" do
|
190
|
+
it "can return nodes" do
|
191
|
+
johnathan, mark, phill, mary = create_nodes
|
192
|
+
|
193
|
+
johnathan.shortest_path_to(mary).incoming(:friends).depth(4).nodes.each do |path|
|
194
|
+
path.map{|n| n.is_a?(Neography::Node).should be_true}
|
195
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_false}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
it "can return relationships" do
|
200
|
+
johnathan, mark, phill, mary = create_nodes
|
201
|
+
|
202
|
+
johnathan.shortest_path_to(mary).incoming(:friends).depth(4).rels.each do |path|
|
203
|
+
path.map{|n| n.is_a?(Neography::Node).should be_false}
|
204
|
+
path.map{|n| n.is_a?(Neography::Relationship).should be_true}
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
it "can return both" do
|
209
|
+
johnathan, mark, phill, mary = create_nodes
|
210
|
+
|
211
|
+
johnathan.shortest_path_to(mary).incoming(:friends).depth(4).each do |path|
|
212
|
+
path.each_with_index do |n,i|
|
213
|
+
if i.even?
|
214
|
+
n.is_a?(Neography::Node).should be_true
|
215
|
+
else
|
216
|
+
n.is_a?(Neography::Relationship).should be_true
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|