neography-ajaycb 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.project +12 -0
- data/.travis.yml +1 -0
- data/CONTRIBUTORS +12 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +39 -0
- data/LICENSE +19 -0
- data/README.rdoc +350 -0
- data/Rakefile +15 -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 +46 -0
- data/lib/neography/config.rb +17 -0
- data/lib/neography/equal.rb +21 -0
- data/lib/neography/index.rb +13 -0
- data/lib/neography/neography.rb +10 -0
- data/lib/neography/node.rb +45 -0
- data/lib/neography/node_path.rb +29 -0
- data/lib/neography/node_relationship.rb +35 -0
- data/lib/neography/node_traverser.rb +142 -0
- data/lib/neography/path_traverser.rb +94 -0
- data/lib/neography/property.rb +53 -0
- data/lib/neography/property_container.rb +17 -0
- data/lib/neography/railtie.rb +8 -0
- data/lib/neography/relationship.rb +68 -0
- data/lib/neography/relationship_traverser.rb +80 -0
- data/lib/neography/rest.rb +534 -0
- data/lib/neography/tasks.rb +131 -0
- data/lib/neography/version.rb +3 -0
- data/neography.gemspec +29 -0
- data/spec/integration/authorization_spec.rb +48 -0
- data/spec/integration/index_spec.rb +32 -0
- data/spec/integration/neography_spec.rb +10 -0
- data/spec/integration/node_path_spec.rb +222 -0
- data/spec/integration/node_relationship_spec.rb +374 -0
- data/spec/integration/node_spec.rb +215 -0
- data/spec/integration/relationship_spec.rb +37 -0
- data/spec/integration/rest_batch_spec.rb +221 -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_index_spec.rb +297 -0
- data/spec/integration/rest_node_spec.rb +232 -0
- data/spec/integration/rest_path_spec.rb +209 -0
- data/spec/integration/rest_plugin_spec.rb +67 -0
- data/spec/integration/rest_relationship_spec.rb +327 -0
- data/spec/integration/rest_traverse_spec.rb +149 -0
- data/spec/spec_helper.rb +18 -0
- metadata +222 -0
@@ -0,0 +1,327 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Neography::Rest do
|
4
|
+
before(:each) do
|
5
|
+
@neo = Neography::Rest.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "create_relationship" do
|
9
|
+
it "can create an empty relationship" 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
|
+
new_relationship["start"].should_not be_nil
|
14
|
+
new_relationship["end"].should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can create a relationship with one property" do
|
18
|
+
new_node1 = @neo.create_node
|
19
|
+
new_node1[:id] = new_node1["self"].split('/').last
|
20
|
+
new_node2 = @neo.create_node
|
21
|
+
new_node2[:id] = new_node2["self"].split('/').last
|
22
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010'})
|
23
|
+
new_relationship["data"]["since"].should == '10-1-2010'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can create a relationship with more than one property" do
|
27
|
+
new_node1 = @neo.create_node
|
28
|
+
new_node2 = @neo.create_node
|
29
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
|
30
|
+
new_relationship["data"]["since"].should == '10-1-2010'
|
31
|
+
new_relationship["data"]["met"].should == "college"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "get_relationship" do
|
36
|
+
it "can get a relationship that exists" do
|
37
|
+
new_node1 = @neo.create_node
|
38
|
+
new_node2 = @neo.create_node
|
39
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
40
|
+
existing_relationship = @neo.get_relationship(new_relationship)
|
41
|
+
existing_relationship.should_not be_nil
|
42
|
+
existing_relationship.should have_key("self")
|
43
|
+
existing_relationship["self"].should == new_relationship["self"]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns nil if it tries to get a relationship that does not exist" do
|
47
|
+
new_node1 = @neo.create_node
|
48
|
+
new_node2 = @neo.create_node
|
49
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
50
|
+
fake_relationship = new_relationship["self"].split('/').last.to_i + 1000
|
51
|
+
existing_relationship = @neo.get_relationship(fake_relationship)
|
52
|
+
existing_relationship.should be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "set_relationship_properties" do
|
57
|
+
it "can set a relationship's properties" do
|
58
|
+
new_node1 = @neo.create_node
|
59
|
+
new_node2 = @neo.create_node
|
60
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
61
|
+
@neo.set_relationship_properties(new_relationship, {"since" => '10-1-2010', "met" => "college"})
|
62
|
+
@neo.set_relationship_properties(new_relationship, {"roommates" => "no"})
|
63
|
+
relationship_properties = @neo.get_relationship_properties(new_relationship)
|
64
|
+
relationship_properties["since"].should == '10-1-2010'
|
65
|
+
relationship_properties["met"].should == "college"
|
66
|
+
relationship_properties["roommates"].should == "no"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "it fails to set properties on a relationship that does not exist" do
|
70
|
+
new_node1 = @neo.create_node
|
71
|
+
new_node2 = @neo.create_node
|
72
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
73
|
+
fake_relationship = new_relationship["self"].split('/').last.to_i + 1000
|
74
|
+
@neo.set_relationship_properties(fake_relationship, {"since" => '10-1-2010', "met" => "college"})
|
75
|
+
relationship_properties = @neo.get_relationship_properties(fake_relationship)
|
76
|
+
relationship_properties.should be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "reset_relationship_properties" do
|
81
|
+
it "can reset a relationship's properties" do
|
82
|
+
new_node1 = @neo.create_node
|
83
|
+
new_node2 = @neo.create_node
|
84
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
85
|
+
@neo.set_relationship_properties(new_relationship, {"since" => '10-1-2010', "met" => "college"})
|
86
|
+
@neo.reset_relationship_properties(new_relationship, {"roommates" => "no"})
|
87
|
+
relationship_properties = @neo.get_relationship_properties(new_relationship)
|
88
|
+
relationship_properties["since"].should be_nil
|
89
|
+
relationship_properties["met"].should be_nil
|
90
|
+
relationship_properties["roommates"].should == "no"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "it fails to reset properties on a relationship that does not exist" do
|
94
|
+
new_node1 = @neo.create_node
|
95
|
+
new_node2 = @neo.create_node
|
96
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
97
|
+
fake_relationship = new_relationship["self"].split('/').last.to_i + 1000
|
98
|
+
@neo.reset_relationship_properties(fake_relationship, {"since" => '10-1-2010', "met" => "college"})
|
99
|
+
relationship_properties = @neo.get_relationship_properties(fake_relationship)
|
100
|
+
relationship_properties.should be_nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "get_relationship_properties" do
|
105
|
+
it "can get all of a relationship's properties" do
|
106
|
+
new_node1 = @neo.create_node
|
107
|
+
new_node2 = @neo.create_node
|
108
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
|
109
|
+
relationship_properties = @neo.get_relationship_properties(new_relationship)
|
110
|
+
relationship_properties["since"].should == '10-1-2010'
|
111
|
+
relationship_properties["met"].should == "college"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "can get some of a relationship's properties" do
|
115
|
+
new_node1 = @neo.create_node
|
116
|
+
new_node2 = @neo.create_node
|
117
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college", "roommates" => "no"})
|
118
|
+
relationship_properties = @neo.get_relationship_properties(new_relationship, ["since", "roommates"])
|
119
|
+
relationship_properties["since"].should == '10-1-2010'
|
120
|
+
relationship_properties["met"].should be_nil
|
121
|
+
relationship_properties["roommates"].should == "no"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "returns nil if it gets the properties on a relationship that does not have any" do
|
125
|
+
new_node1 = @neo.create_node
|
126
|
+
new_node2 = @neo.create_node
|
127
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
128
|
+
relationship_properties = @neo.get_relationship_properties(new_relationship)
|
129
|
+
relationship_properties.should be_nil
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns nil if it tries to get some of the properties on a relationship that does not have any" do
|
133
|
+
new_node1 = @neo.create_node
|
134
|
+
new_node2 = @neo.create_node
|
135
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
136
|
+
relationship_properties = @neo.get_relationship_properties(new_relationship, ["since", "roommates"])
|
137
|
+
relationship_properties.should be_nil
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns nil if it fails to get properties on a relationship that does not exist" do
|
141
|
+
new_node1 = @neo.create_node
|
142
|
+
new_node2 = @neo.create_node
|
143
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
|
144
|
+
fake_relationship = new_relationship["self"].split('/').last.to_i + 1000
|
145
|
+
relationship_properties = @neo.get_relationship_properties(fake_relationship)
|
146
|
+
relationship_properties.should be_nil
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "remove_relationship_properties" do
|
151
|
+
it "can remove a relationship's properties" do
|
152
|
+
new_node1 = @neo.create_node
|
153
|
+
new_node2 = @neo.create_node
|
154
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
|
155
|
+
@neo.remove_relationship_properties(new_relationship)
|
156
|
+
@neo.get_relationship_properties(new_relationship).should be_nil
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns nil if it fails to remove the properties of a relationship that does not exist" do
|
160
|
+
new_node1 = @neo.create_node
|
161
|
+
new_node2 = @neo.create_node
|
162
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
|
163
|
+
fake_relationship = new_relationship["self"].split('/').last.to_i + 1000
|
164
|
+
@neo.remove_relationship_properties(fake_relationship).should be_nil
|
165
|
+
@neo.get_relationship_properties(fake_relationship).should be_nil
|
166
|
+
end
|
167
|
+
|
168
|
+
it "can remove a specific relationship property" do
|
169
|
+
new_node1 = @neo.create_node
|
170
|
+
new_node2 = @neo.create_node
|
171
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
|
172
|
+
@neo.remove_relationship_properties(new_relationship, "met")
|
173
|
+
relationship_properties = @neo.get_relationship_properties(new_relationship, ["met", "since"])
|
174
|
+
relationship_properties["met"].should be_nil
|
175
|
+
relationship_properties["since"].should == '10-1-2010'
|
176
|
+
end
|
177
|
+
|
178
|
+
it "can remove more than one relationship property" do
|
179
|
+
new_node1 = @neo.create_node
|
180
|
+
new_node2 = @neo.create_node
|
181
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college", "roommates" => "no"})
|
182
|
+
@neo.remove_relationship_properties(new_relationship, ["met", "since"])
|
183
|
+
relationship_properties = @neo.get_relationship_properties(new_relationship, ["since", "met", "roommates"])
|
184
|
+
relationship_properties["met"].should be_nil
|
185
|
+
relationship_properties["since"].should be_nil
|
186
|
+
relationship_properties["roommates"].should == "no"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "delete_relationship" do
|
191
|
+
it "can delete an existing relationship" do
|
192
|
+
new_node1 = @neo.create_node
|
193
|
+
new_node2 = @neo.create_node
|
194
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
|
195
|
+
@neo.delete_relationship(new_relationship)
|
196
|
+
relationships = @neo.get_node_relationships(new_node1)
|
197
|
+
relationships.should be_nil
|
198
|
+
end
|
199
|
+
|
200
|
+
it "returns nil if it tries to delete a relationship that does not exist" do
|
201
|
+
new_node1 = @neo.create_node
|
202
|
+
new_node2 = @neo.create_node
|
203
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
|
204
|
+
fake_relationship = new_relationship["self"].split('/').last.to_i + 1000
|
205
|
+
existing_relationship = @neo.delete_relationship(fake_relationship)
|
206
|
+
existing_relationship.should be_nil
|
207
|
+
end
|
208
|
+
|
209
|
+
it "returns nil if it tries to delete a relationship that has already been deleted" do
|
210
|
+
new_node1 = @neo.create_node
|
211
|
+
new_node2 = @neo.create_node
|
212
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
|
213
|
+
existing_relationship = @neo.delete_relationship(new_relationship)
|
214
|
+
existing_relationship.should be_nil
|
215
|
+
existing_relationship = @neo.delete_relationship(new_relationship)
|
216
|
+
existing_relationship.should be_nil
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "get_node_relationships" do
|
221
|
+
it "can get a node's relationship" do
|
222
|
+
new_node1 = @neo.create_node
|
223
|
+
new_node2 = @neo.create_node
|
224
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
|
225
|
+
relationships = @neo.get_node_relationships(new_node1)
|
226
|
+
relationships.should_not be_nil
|
227
|
+
relationships[0]["start"].should == new_node1["self"]
|
228
|
+
relationships[0]["end"].should == new_node2["self"]
|
229
|
+
relationships[0]["type"].should == "friends"
|
230
|
+
relationships[0]["data"]["met"].should == "college"
|
231
|
+
relationships[0]["data"]["since"].should == '10-1-2005'
|
232
|
+
end
|
233
|
+
|
234
|
+
it "can get a node's multiple relationships" do
|
235
|
+
new_node1 = @neo.create_node
|
236
|
+
new_node2 = @neo.create_node
|
237
|
+
new_node3 = @neo.create_node
|
238
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
|
239
|
+
new_relationship = @neo.create_relationship("enemies", new_node1, new_node3, {"since" => '10-2-2010', "met" => "work"})
|
240
|
+
relationships = @neo.get_node_relationships(new_node1)
|
241
|
+
relationships.should_not be_nil
|
242
|
+
relationships[0]["start"].should == new_node1["self"]
|
243
|
+
relationships[0]["end"].should == new_node2["self"]
|
244
|
+
relationships[0]["type"].should == "friends"
|
245
|
+
relationships[0]["data"]["met"].should == "college"
|
246
|
+
relationships[0]["data"]["since"].should == '10-1-2005'
|
247
|
+
relationships[1]["start"].should == new_node1["self"]
|
248
|
+
relationships[1]["end"].should == new_node3["self"]
|
249
|
+
relationships[1]["type"].should == "enemies"
|
250
|
+
relationships[1]["data"]["met"].should == "work"
|
251
|
+
relationships[1]["data"]["since"].should == '10-2-2010'
|
252
|
+
end
|
253
|
+
|
254
|
+
it "can get a node's outgoing relationship" do
|
255
|
+
new_node1 = @neo.create_node
|
256
|
+
new_node2 = @neo.create_node
|
257
|
+
new_node3 = @neo.create_node
|
258
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
|
259
|
+
new_relationship = @neo.create_relationship("enemies", new_node3, new_node1, {"since" => '10-2-2010', "met" => "work"})
|
260
|
+
relationships = @neo.get_node_relationships(new_node1, "out")
|
261
|
+
relationships.should_not be_nil
|
262
|
+
relationships[0]["start"].should == new_node1["self"]
|
263
|
+
relationships[0]["end"].should == new_node2["self"]
|
264
|
+
relationships[0]["type"].should == "friends"
|
265
|
+
relationships[0]["data"]["met"].should == "college"
|
266
|
+
relationships[0]["data"]["since"].should == '10-1-2005'
|
267
|
+
relationships[1].should be_nil
|
268
|
+
end
|
269
|
+
|
270
|
+
it "can get a node's incoming relationship" do
|
271
|
+
new_node1 = @neo.create_node
|
272
|
+
new_node2 = @neo.create_node
|
273
|
+
new_node3 = @neo.create_node
|
274
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
|
275
|
+
new_relationship = @neo.create_relationship("enemies", new_node3, new_node1, {"since" => '10-2-2010', "met" => "work"})
|
276
|
+
relationships = @neo.get_node_relationships(new_node1, "in")
|
277
|
+
relationships.should_not be_nil
|
278
|
+
relationships[0]["start"].should == new_node3["self"]
|
279
|
+
relationships[0]["end"].should == new_node1["self"]
|
280
|
+
relationships[0]["type"].should == "enemies"
|
281
|
+
relationships[0]["data"]["met"].should == "work"
|
282
|
+
relationships[0]["data"]["since"].should == '10-2-2010'
|
283
|
+
relationships[1].should be_nil
|
284
|
+
end
|
285
|
+
|
286
|
+
it "can get a specific type of node relationships" do
|
287
|
+
new_node1 = @neo.create_node
|
288
|
+
new_node2 = @neo.create_node
|
289
|
+
new_node3 = @neo.create_node
|
290
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
|
291
|
+
new_relationship = @neo.create_relationship("enemies", new_node1, new_node3, {"since" => '10-2-2010', "met" => "work"})
|
292
|
+
relationships = @neo.get_node_relationships(new_node1, "all", "friends")
|
293
|
+
relationships.should_not be_nil
|
294
|
+
relationships[0]["start"].should == new_node1["self"]
|
295
|
+
relationships[0]["end"].should == new_node2["self"]
|
296
|
+
relationships[0]["type"].should == "friends"
|
297
|
+
relationships[0]["data"]["met"].should == "college"
|
298
|
+
relationships[0]["data"]["since"].should == '10-1-2005'
|
299
|
+
relationships[1].should be_nil
|
300
|
+
end
|
301
|
+
|
302
|
+
it "can get a specific type and direction of a node relationships" do
|
303
|
+
new_node1 = @neo.create_node
|
304
|
+
new_node2 = @neo.create_node
|
305
|
+
new_node3 = @neo.create_node
|
306
|
+
new_node4 = @neo.create_node
|
307
|
+
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
|
308
|
+
new_relationship = @neo.create_relationship("enemies", new_node1, new_node3, {"since" => '10-2-2010', "met" => "work"})
|
309
|
+
new_relationship = @neo.create_relationship("enemies", new_node4, new_node1, {"since" => '10-3-2010', "met" => "gym"})
|
310
|
+
relationships = @neo.get_node_relationships(new_node1, "in", "enemies")
|
311
|
+
relationships.should_not be_nil
|
312
|
+
relationships[0]["start"].should == new_node4["self"]
|
313
|
+
relationships[0]["end"].should == new_node1["self"]
|
314
|
+
relationships[0]["type"].should == "enemies"
|
315
|
+
relationships[0]["data"]["met"].should == "gym"
|
316
|
+
relationships[0]["data"]["since"].should == '10-3-2010'
|
317
|
+
relationships[1].should be_nil
|
318
|
+
end
|
319
|
+
|
320
|
+
it "returns nil if there are no relationships" do
|
321
|
+
new_node1 = @neo.create_node
|
322
|
+
relationships = @neo.get_node_relationships(new_node1)
|
323
|
+
relationships.should be_nil
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '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
|