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,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neography::Rest do
|
4
|
+
before(:each) do
|
5
|
+
@neo = Neography::Rest.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "list relationship types" do
|
9
|
+
it "can get a listing of relationship types" do
|
10
|
+
new_node1 = @neo.create_node
|
11
|
+
new_node2 = @neo.create_node
|
12
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
13
|
+
rel_types = @neo.list_relationship_types
|
14
|
+
rel_types.should_not be_nil
|
15
|
+
rel_types.should include("friends")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neography::Rest do
|
4
|
+
before(:each) do
|
5
|
+
@neo = Neography::Rest.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "create a schema index" do
|
9
|
+
it "can create a schema index" do
|
10
|
+
si = @neo.create_schema_index("person", ["name"])
|
11
|
+
si.should_not be_nil
|
12
|
+
si["property-keys"].should include("name")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "list schema indexes" do
|
18
|
+
it "can get a listing of node indexes" do
|
19
|
+
si = @neo.get_schema_index("person")
|
20
|
+
si.should_not be_nil
|
21
|
+
si.first["label"].should include("person")
|
22
|
+
si.first["property-keys"].should include("name")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "drop schema indexes" do
|
27
|
+
it "can drop an existing schema index" do
|
28
|
+
si = @neo.delete_schema_index("person", "name")
|
29
|
+
si.should be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neography::Rest do
|
4
|
+
before(:each) do
|
5
|
+
@neo = Neography::Rest.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "start a transaction" do
|
9
|
+
it "can start a transaction" do
|
10
|
+
tx = @neo.begin_transaction
|
11
|
+
tx.should have_key("transaction")
|
12
|
+
tx["results"].should be_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can start a transaction with statements" do
|
16
|
+
tx = @neo.begin_transaction("start n=node(0) return n")
|
17
|
+
tx.should have_key("transaction")
|
18
|
+
tx.should have_key("results")
|
19
|
+
tx["results"].should_not be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can start a transaction with statements and represent them as a graph" do
|
23
|
+
tx = @neo.begin_transaction(["CREATE ( bike:Bike { weight: 10 } ) CREATE ( frontWheel:Wheel { spokes: 3 } ) CREATE ( backWheel:Wheel { spokes: 32 } ) CREATE p1 = bike -[:HAS { position: 1 } ]-> frontWheel CREATE p2 = bike -[:HAS { position: 2 } ]-> backWheel RETURN bike, p1, p2",
|
24
|
+
["row", "graph", "rest"]])
|
25
|
+
tx.should have_key("transaction")
|
26
|
+
tx.should have_key("results")
|
27
|
+
tx["results"].should_not be_empty
|
28
|
+
tx["results"].first["data"].first["row"].should_not be_empty
|
29
|
+
tx["results"].first["data"].first["graph"].should_not be_empty
|
30
|
+
tx["results"].first["data"].first["rest"].should_not be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "keep a transaction" do
|
37
|
+
it "can keep a transaction" do
|
38
|
+
tx = @neo.begin_transaction
|
39
|
+
tx.should have_key("transaction")
|
40
|
+
tx["results"].should be_empty
|
41
|
+
sleep(1)
|
42
|
+
existing_tx = @neo.keep_transaction(tx)
|
43
|
+
existing_tx.should have_key("transaction")
|
44
|
+
existing_tx["transaction"]["expires"].should > tx["transaction"]["expires"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
describe "add to a transaction" do
|
50
|
+
it "can add to a transaction" do
|
51
|
+
tx = @neo.begin_transaction
|
52
|
+
tx.should have_key("transaction")
|
53
|
+
tx["results"].should be_empty
|
54
|
+
existing_tx = @neo.in_transaction(tx, "start n=node(0) return n")
|
55
|
+
existing_tx.should have_key("transaction")
|
56
|
+
existing_tx.should have_key("results")
|
57
|
+
existing_tx["results"].should_not be_empty
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can add to a transaction with parameters" do
|
61
|
+
tx = @neo.begin_transaction
|
62
|
+
tx.should have_key("transaction")
|
63
|
+
tx["results"].should be_empty
|
64
|
+
existing_tx = @neo.in_transaction(tx, ["start n=node({id}) return n", {:id => 0}])
|
65
|
+
existing_tx.should have_key("transaction")
|
66
|
+
existing_tx.should have_key("results")
|
67
|
+
existing_tx["results"].should_not be_empty
|
68
|
+
end
|
69
|
+
|
70
|
+
it "can add to a transaction with representation" do
|
71
|
+
tx = @neo.begin_transaction
|
72
|
+
tx.should have_key("transaction")
|
73
|
+
tx["results"].should be_empty
|
74
|
+
existing_tx = @neo.in_transaction(tx, ["start n=node(0) return n", [:row,:rest]])
|
75
|
+
existing_tx.should have_key("transaction")
|
76
|
+
existing_tx.should have_key("results")
|
77
|
+
existing_tx["results"].should_not be_empty
|
78
|
+
end
|
79
|
+
|
80
|
+
it "can add to a transaction with parameters and representation" do
|
81
|
+
tx = @neo.begin_transaction
|
82
|
+
tx.should have_key("transaction")
|
83
|
+
tx["results"].should be_empty
|
84
|
+
existing_tx = @neo.in_transaction(tx, ["start n=node({id}) return n", {:id => 0}, [:row,:rest]])
|
85
|
+
existing_tx.should have_key("transaction")
|
86
|
+
existing_tx.should have_key("results")
|
87
|
+
existing_tx["results"].should_not be_empty
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "commit a transaction" do
|
93
|
+
it "can commit an opened empty transaction" do
|
94
|
+
tx = @neo.begin_transaction
|
95
|
+
tx.should have_key("transaction")
|
96
|
+
tx["results"].should be_empty
|
97
|
+
existing_tx = @neo.commit_transaction(tx)
|
98
|
+
existing_tx.should have_key("results")
|
99
|
+
existing_tx["results"].should be_empty
|
100
|
+
end
|
101
|
+
|
102
|
+
it "can commit an opened transaction" do
|
103
|
+
tx = @neo.begin_transaction("start n=node(0) return n")
|
104
|
+
tx.should have_key("transaction")
|
105
|
+
tx["results"].should_not be_empty
|
106
|
+
existing_tx = @neo.commit_transaction(tx)
|
107
|
+
existing_tx.should_not have_key("transaction")
|
108
|
+
existing_tx.should have_key("results")
|
109
|
+
existing_tx["results"].should be_empty
|
110
|
+
end
|
111
|
+
|
112
|
+
it "can commit an opened transaction with new statements" do
|
113
|
+
tx = @neo.begin_transaction
|
114
|
+
tx.should have_key("transaction")
|
115
|
+
tx["results"].should be_empty
|
116
|
+
existing_tx = @neo.commit_transaction(tx, "start n=node(0) return n")
|
117
|
+
existing_tx.should_not have_key("transaction")
|
118
|
+
existing_tx.should have_key("results")
|
119
|
+
existing_tx["results"].should_not be_empty
|
120
|
+
end
|
121
|
+
|
122
|
+
it "can commit an new transaction right away" do
|
123
|
+
tx = @neo.commit_transaction(["start n=node(0) return n"])
|
124
|
+
tx.should_not have_key("transaction")
|
125
|
+
tx.should have_key("results")
|
126
|
+
tx["results"].should_not be_empty
|
127
|
+
end
|
128
|
+
|
129
|
+
it "can commit an new transaction right away with parameters" do
|
130
|
+
tx = @neo.commit_transaction(["start n=node({id}) return n", {:id => 0}])
|
131
|
+
tx.should_not have_key("transaction")
|
132
|
+
tx.should have_key("results")
|
133
|
+
tx["results"].should_not be_empty
|
134
|
+
end
|
135
|
+
|
136
|
+
it "can commit an new transaction right away without parameters" do
|
137
|
+
tx = @neo.commit_transaction("start n=node(0) return n")
|
138
|
+
tx.should_not have_key("transaction")
|
139
|
+
tx.should have_key("results")
|
140
|
+
tx["results"].should_not be_empty
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "rollback a transaction" do
|
146
|
+
it "can rollback an opened empty transaction" do
|
147
|
+
tx = @neo.begin_transaction
|
148
|
+
tx.should have_key("transaction")
|
149
|
+
tx["results"].should be_empty
|
150
|
+
existing_tx = @neo.rollback_transaction(tx)
|
151
|
+
existing_tx.should have_key("results")
|
152
|
+
existing_tx["results"].should be_empty
|
153
|
+
end
|
154
|
+
|
155
|
+
it "can rollback an opened transaction" do
|
156
|
+
tx = @neo.begin_transaction("start n=node(0) return n")
|
157
|
+
tx.should have_key("transaction")
|
158
|
+
tx["results"].should_not be_empty
|
159
|
+
existing_tx = @neo.rollback_transaction(tx)
|
160
|
+
existing_tx.should have_key("transaction")
|
161
|
+
existing_tx.should have_key("results")
|
162
|
+
existing_tx["results"].should be_empty
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neography::Rest do
|
4
|
+
before(:each) do
|
5
|
+
@neo = Neography::Rest.new
|
6
|
+
@new_node1 = @neo.create_node("age" => 31, "name" => "Max")
|
7
|
+
@new_node2 = @neo.create_node("age" => 30, "name" => "Helene")
|
8
|
+
@new_node3 = @neo.create_node("age" => 17, "name" => "Alex")
|
9
|
+
@new_node4 = @neo.create_node("age" => 24, "name" => "Eric")
|
10
|
+
@new_node5 = @neo.create_node("age" => 32, "name" => "Leslie")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "traverse" do
|
14
|
+
it "can traverse the graph and return nodes" do
|
15
|
+
@neo.create_relationship("friends", @new_node1, @new_node2)
|
16
|
+
@neo.create_relationship("friends", @new_node2, @new_node3)
|
17
|
+
@neo.create_relationship("friends", @new_node3, @new_node4)
|
18
|
+
@neo.create_relationship("friends", @new_node4, @new_node5)
|
19
|
+
@neo.create_relationship("friends", @new_node3, @new_node5)
|
20
|
+
nodes = @neo.traverse(@new_node1, "nodes", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} )
|
21
|
+
nodes.should_not be_nil
|
22
|
+
nodes[0]["self"].should == @new_node2["self"]
|
23
|
+
nodes[1]["self"].should == @new_node3["self"]
|
24
|
+
nodes[2]["self"].should == @new_node4["self"]
|
25
|
+
nodes[3]["self"].should == @new_node5["self"]
|
26
|
+
end
|
27
|
+
it "can traverse the graph and return relationships" do
|
28
|
+
new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
|
29
|
+
new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
|
30
|
+
new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
|
31
|
+
new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
|
32
|
+
new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
|
33
|
+
|
34
|
+
relationships = @neo.traverse(@new_node1, "relationships", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} )
|
35
|
+
relationships.should_not be_nil
|
36
|
+
|
37
|
+
relationships[0]["self"].should == new_relationship1["self"]
|
38
|
+
relationships[1]["self"].should == new_relationship2["self"]
|
39
|
+
relationships[2]["self"].should == new_relationship3["self"]
|
40
|
+
relationships[3]["self"].should == new_relationship4["self"]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can traverse the graph and return paths" do
|
44
|
+
new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
|
45
|
+
new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
|
46
|
+
new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
|
47
|
+
new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
|
48
|
+
new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
|
49
|
+
|
50
|
+
paths = @neo.traverse(@new_node1, "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} )
|
51
|
+
paths.should_not be_nil
|
52
|
+
|
53
|
+
paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]]
|
54
|
+
paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]]
|
55
|
+
paths[2]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]]
|
56
|
+
paths[3]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"], @new_node5["self"]]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can traverse the graph up to a certain depth" do
|
60
|
+
new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
|
61
|
+
new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
|
62
|
+
new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
|
63
|
+
new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
|
64
|
+
new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
|
65
|
+
|
66
|
+
paths = @neo.traverse(@new_node1, "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 3} )
|
67
|
+
paths.should_not be_nil
|
68
|
+
|
69
|
+
paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]]
|
70
|
+
paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]]
|
71
|
+
paths[2]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]]
|
72
|
+
paths[3]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node5["self"]]
|
73
|
+
end
|
74
|
+
|
75
|
+
it "can traverse the graph in a certain order" do
|
76
|
+
new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
|
77
|
+
new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
|
78
|
+
new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
|
79
|
+
new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
|
80
|
+
new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
|
81
|
+
|
82
|
+
paths = @neo.traverse(@new_node1, "paths", {"order" => "breadth first", "relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} )
|
83
|
+
paths.should_not be_nil
|
84
|
+
|
85
|
+
paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]]
|
86
|
+
paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]]
|
87
|
+
paths[2]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]]
|
88
|
+
paths[3]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node5["self"]]
|
89
|
+
end
|
90
|
+
|
91
|
+
it "can traverse the graph with a specific uniqueness" do
|
92
|
+
new_relationship1= @neo.create_relationship("roommates", @new_node1, @new_node2)
|
93
|
+
new_relationship2= @neo.create_relationship("roommates", @new_node2, @new_node3)
|
94
|
+
new_relationship1= @neo.create_relationship("friends", @new_node3, @new_node2)
|
95
|
+
new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node5)
|
96
|
+
new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
|
97
|
+
new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
|
98
|
+
new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
|
99
|
+
|
100
|
+
paths = @neo.traverse(@new_node1, "paths", {"order" => "breadth first", "uniqueness" => "node global", "relationships" => [{"type"=> "roommates", "direction" => "all"},{"type"=> "friends", "direction" => "out"}], "depth" => 4} )
|
101
|
+
paths.should_not be_nil
|
102
|
+
|
103
|
+
paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]]
|
104
|
+
paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node5["self"]]
|
105
|
+
paths[2]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]]
|
106
|
+
paths[3]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]]
|
107
|
+
end
|
108
|
+
|
109
|
+
it "can traverse the graph with a prune evaluator" do
|
110
|
+
new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
|
111
|
+
new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
|
112
|
+
new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
|
113
|
+
new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
|
114
|
+
new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
|
115
|
+
|
116
|
+
paths = @neo.traverse(@new_node1,
|
117
|
+
"paths",
|
118
|
+
{"relationships" => {"type"=> "friends", "direction" => "out"},
|
119
|
+
"depth" => 3,
|
120
|
+
"prune evaluator" => {"language" => "javascript", "body" => "position.endNode().getProperty('age') < 21;"
|
121
|
+
}} )
|
122
|
+
paths.should_not be_nil
|
123
|
+
paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]]
|
124
|
+
paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]]
|
125
|
+
paths[2].should be_nil
|
126
|
+
end
|
127
|
+
|
128
|
+
it "can traverse the graph with a return filter" do
|
129
|
+
@neo.create_relationship("friends", @new_node1, @new_node2)
|
130
|
+
@neo.create_relationship("friends", @new_node2, @new_node3)
|
131
|
+
@neo.create_relationship("friends", @new_node3, @new_node4)
|
132
|
+
@neo.create_relationship("friends", @new_node4, @new_node5)
|
133
|
+
@neo.create_relationship("friends", @new_node3, @new_node5)
|
134
|
+
nodes = @neo.traverse(@new_node1, "node", {"relationships" => {"type"=> "friends", "direction" => "out"},
|
135
|
+
"return filter" => {"language" => "builtin", "name" => "all"},
|
136
|
+
"depth" => 4} )
|
137
|
+
nodes.should_not be_nil
|
138
|
+
nodes[0]["self"].should == @new_node1["self"]
|
139
|
+
nodes[1]["self"].should == @new_node2["self"]
|
140
|
+
nodes[2]["self"].should == @new_node3["self"]
|
141
|
+
nodes[3]["self"].should == @new_node4["self"]
|
142
|
+
nodes[4]["self"].should == @new_node5["self"]
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
data/spec/matchers.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Convenience matcher for matching JSON fields with a hash
|
2
|
+
RSpec::Matchers.define :json_match do |field, expected|
|
3
|
+
|
4
|
+
match do |actual|
|
5
|
+
expected == JSON.parse(actual[field])
|
6
|
+
end
|
7
|
+
|
8
|
+
failure_message_for_should do
|
9
|
+
"expected JSON in field '#{field}' to match '#{expected}'"
|
10
|
+
end
|
11
|
+
|
12
|
+
description do
|
13
|
+
"JSON in field '#{field}' should match '#{expected.inspect}'"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
# Convenience matcher for matching fields in a hash
|
19
|
+
RSpec::Matchers.define :hash_match do |field, expected|
|
20
|
+
|
21
|
+
match do |actual|
|
22
|
+
expected == actual[field]
|
23
|
+
end
|
24
|
+
|
25
|
+
failure_message_for_should do
|
26
|
+
"expected field '#{field}' to match '#{expected}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
description do
|
30
|
+
"field '#{field}' should match '#{expected.inspect}'"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neography do
|
4
|
+
|
5
|
+
describe "::configure" do
|
6
|
+
|
7
|
+
it "returns the same configuration" do
|
8
|
+
Neography.configuration.should == Neography.configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the Config" do
|
12
|
+
Neography.configuration.should be_a Neography::Config
|
13
|
+
end
|
14
|
+
|
15
|
+
it "yields the configuration" do
|
16
|
+
Neography.configure do |config|
|
17
|
+
config.should == Neography.configuration
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'neography'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'matchers'
|
4
|
+
require 'coveralls'
|
5
|
+
Coveralls.wear!
|
6
|
+
|
7
|
+
# If you want to see more, uncomment the next few lines
|
8
|
+
# require 'net-http-spy'
|
9
|
+
# Net::HTTP.http_logger_options = {:body => true} # just the body
|
10
|
+
# Net::HTTP.http_logger_options = {:verbose => true} # see everything
|
11
|
+
|
12
|
+
def generate_text(length=8)
|
13
|
+
chars = 'abcdefghjkmnpqrstuvwxyz'
|
14
|
+
key = ''
|
15
|
+
length.times { |i| key << chars[rand(chars.length)] }
|
16
|
+
key
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |c|
|
20
|
+
c.filter_run_excluding :slow => true, :gremlin => true
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def json_content_type
|
25
|
+
{"Content-Type"=>"application/json"}
|
26
|
+
end
|
27
|
+
|
28
|
+
def error_response(attributes)
|
29
|
+
request_uri = double()
|
30
|
+
request_uri.stub(:request_uri).and_return("")
|
31
|
+
|
32
|
+
http_header = double()
|
33
|
+
http_header.stub(:request_uri).and_return(request_uri)
|
34
|
+
|
35
|
+
double(
|
36
|
+
http_header: http_header,
|
37
|
+
code: attributes[:code],
|
38
|
+
body: {
|
39
|
+
message: attributes[:message],
|
40
|
+
exception: attributes[:exception],
|
41
|
+
stacktrace: attributes[:stacktrace]
|
42
|
+
}.reject { |k,v| v.nil? }.to_json
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|