neography-ajaycb 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,374 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Neography::NodeRelationship do
|
4
|
+
|
5
|
+
def create_nodes
|
6
|
+
#
|
7
|
+
# f
|
8
|
+
# ^
|
9
|
+
# friends
|
10
|
+
# |
|
11
|
+
# a --friends-> b --friends--> c
|
12
|
+
# | ^
|
13
|
+
# | |
|
14
|
+
# +--- work -----+
|
15
|
+
# |
|
16
|
+
# +--- work ---> d --- work --> e
|
17
|
+
a = Neography::Node.create :name => 'a'
|
18
|
+
b = Neography::Node.create :name => 'b'
|
19
|
+
c = Neography::Node.create :name => 'c'
|
20
|
+
d = Neography::Node.create :name => 'd'
|
21
|
+
e = Neography::Node.create :name => 'e'
|
22
|
+
f = Neography::Node.create :name => 'f'
|
23
|
+
a.outgoing(:friends) << b
|
24
|
+
b.outgoing(:friends) << c
|
25
|
+
b.outgoing(:work) << c
|
26
|
+
b.outgoing(:work) << d
|
27
|
+
d.outgoing(:work) << e
|
28
|
+
b.outgoing(:friends) << f
|
29
|
+
[a,b,c,d,e,f]
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "outgoing" do
|
33
|
+
it "#outgoing(:friends) << other_node creates an outgoing relationship of type :friends" do
|
34
|
+
a = Neography::Node.create
|
35
|
+
other_node = Neography::Node.create
|
36
|
+
|
37
|
+
# when
|
38
|
+
a.outgoing(:friends) << other_node
|
39
|
+
|
40
|
+
# then
|
41
|
+
a.outgoing(:friends).first.should == other_node
|
42
|
+
end
|
43
|
+
|
44
|
+
it "#outgoing(:friends) << b << c creates an outgoing relationship of type :friends" do
|
45
|
+
a = Neography::Node.create
|
46
|
+
b = Neography::Node.create
|
47
|
+
c = Neography::Node.create
|
48
|
+
|
49
|
+
# when
|
50
|
+
a.outgoing(:friends) << b << c
|
51
|
+
|
52
|
+
# then
|
53
|
+
a.outgoing(:friends).should include(b,c)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "#outgoing returns all incoming nodes of any type" do
|
57
|
+
a,b,c,d,e,f = create_nodes
|
58
|
+
|
59
|
+
b.outgoing.should include(c,f,d)
|
60
|
+
[*b.outgoing].size.should == 4 #c is related by both work and friends
|
61
|
+
end
|
62
|
+
|
63
|
+
it "#outgoing(type) should only return outgoing nodes of the given type of depth one" do
|
64
|
+
a,b,c,d = create_nodes
|
65
|
+
b.outgoing(:work).should include(c,d)
|
66
|
+
[*b.outgoing(:work)].size.should == 2
|
67
|
+
end
|
68
|
+
|
69
|
+
it "#outgoing(type1).outgoing(type2) should return outgoing nodes of the given types" do
|
70
|
+
a,b,c,d,e,f = create_nodes
|
71
|
+
nodes = b.outgoing(:work).outgoing(:friends)
|
72
|
+
|
73
|
+
nodes.should include(c,d,f)
|
74
|
+
nodes.size.should == 4 #c is related by both work and friends
|
75
|
+
end
|
76
|
+
|
77
|
+
it "#outgoing(type).depth(4) should only return outgoing nodes of the given type and depth" do
|
78
|
+
a,b,c,d,e = create_nodes
|
79
|
+
[*b.outgoing(:work).depth(4)].size.should == 3
|
80
|
+
b.outgoing(:work).depth(4).should include(c,d,e)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "#outgoing(type).depth(4).include_start_node should also include the start node" do
|
84
|
+
a,b,c,d,e = create_nodes
|
85
|
+
[*b.outgoing(:work).depth(4).include_start_node].size.should == 4
|
86
|
+
b.outgoing(:work).depth(4).include_start_node.should include(b,c,d,e)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "#outgoing(type).depth(:all) should traverse at any depth" do
|
90
|
+
a,b,c,d,e = create_nodes
|
91
|
+
[*b.outgoing(:work).depth(:all)].size.should == 3
|
92
|
+
b.outgoing(:work).depth(:all).should include(c,d,e)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "incoming" do
|
97
|
+
it "#incoming(:friends) << other_node should add an incoming relationship" do
|
98
|
+
a = Neography::Node.create
|
99
|
+
other_node = Neography::Node.create
|
100
|
+
|
101
|
+
# when
|
102
|
+
a.incoming(:friends) << other_node
|
103
|
+
|
104
|
+
# then
|
105
|
+
a.incoming(:friends).first.should == other_node
|
106
|
+
end
|
107
|
+
|
108
|
+
it "#incoming(:friends) << b << c creates an incoming relationship of type :friends" do
|
109
|
+
a = Neography::Node.create
|
110
|
+
b = Neography::Node.create
|
111
|
+
c = Neography::Node.create
|
112
|
+
|
113
|
+
# when
|
114
|
+
a.incoming(:friends) << b << c
|
115
|
+
|
116
|
+
# then
|
117
|
+
a.incoming(:friends).should include(b,c)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "#incoming returns all incoming nodes of any type" do
|
121
|
+
a,b,c,d,e,f = create_nodes
|
122
|
+
|
123
|
+
b.incoming.should include(a)
|
124
|
+
[*b.incoming].size.should == 1
|
125
|
+
end
|
126
|
+
|
127
|
+
it "#incoming(type).depth(2) should only return outgoing nodes of the given type and depth" do
|
128
|
+
a,b,c,d,e = create_nodes
|
129
|
+
[*e.incoming(:work).depth(2)].size.should == 2
|
130
|
+
e.incoming(:work).depth(2).should include(b,d)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "#incoming(type) should only return incoming nodes of the given type of depth one" do
|
134
|
+
a,b,c,d = create_nodes
|
135
|
+
c.incoming(:work).should include(b)
|
136
|
+
[*c.incoming(:work)].size.should == 1
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "both" do
|
141
|
+
it "#both(:friends) << other_node should raise an exception" do
|
142
|
+
a = Neography::Node.create
|
143
|
+
other_node = Neography::Node.create
|
144
|
+
|
145
|
+
# when
|
146
|
+
a.both(:friends) << other_node
|
147
|
+
a.incoming(:friends).first.should == other_node
|
148
|
+
a.outgoing(:friends).first.should == other_node
|
149
|
+
end
|
150
|
+
|
151
|
+
it "#both returns all incoming and outgoing nodes of any type" do
|
152
|
+
a,b,c,d,e,f = create_nodes
|
153
|
+
|
154
|
+
b.both.should include(a,c,d,f)
|
155
|
+
[*b.both].size.should == 5 #c is related by both work and friends
|
156
|
+
b.incoming.should include(a)
|
157
|
+
b.outgoing.should include(c)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "#both(type) should return both incoming and outgoing nodes of the given type of depth one" do
|
161
|
+
a,b,c,d,e,f = create_nodes
|
162
|
+
|
163
|
+
b.both(:friends).should include(a,c,f)
|
164
|
+
[*b.both(:friends)].size.should == 3
|
165
|
+
end
|
166
|
+
|
167
|
+
it "#outgoing and #incoming can be combined to traverse several relationship types" do
|
168
|
+
a,b,c,d,e = create_nodes
|
169
|
+
nodes = [*b.incoming(:friends).outgoing(:work)]
|
170
|
+
|
171
|
+
nodes.should include(a,c,d)
|
172
|
+
nodes.should_not include(b,e)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
describe "prune" do
|
178
|
+
it "#prune, if it returns true the traversal will be stop for that path" do
|
179
|
+
a, b, c, d, e = create_nodes
|
180
|
+
[*b.outgoing(:work).depth(4)].size.should == 3
|
181
|
+
b.outgoing(:work).depth(4).should include(c,d,e)
|
182
|
+
|
183
|
+
[*b.outgoing(:work).prune("position.endNode().getProperty('name') == 'd';")].size.should == 2
|
184
|
+
b.outgoing(:work).prune("position.endNode().getProperty('name') == 'd';").should include(c,d)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "filter" do
|
189
|
+
it "#filter, if it returns true the node will be included in the return results" do
|
190
|
+
a, b, c, d, e = create_nodes
|
191
|
+
[*b.outgoing(:work).depth(4)].size.should == 3
|
192
|
+
b.outgoing(:work).depth(4).should include(c,d,e)
|
193
|
+
|
194
|
+
[*b.outgoing(:work).depth(4).filter("position.length() == 2;")].size.should == 1
|
195
|
+
b.outgoing(:work).depth(4).filter("position.length() == 2;").should include(e)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "rels" do
|
200
|
+
it "#rels returns a RelationshipTraverser which can filter which relationship it should return by specifying #to_other" do
|
201
|
+
a = Neography::Node.create
|
202
|
+
b = Neography::Node.create
|
203
|
+
c = Neography::Node.create
|
204
|
+
r1 = Neography::Relationship.create(:friend, a, b)
|
205
|
+
Neography::Relationship.create(:friend, a, c)
|
206
|
+
|
207
|
+
a.rels.to_other(b).size.should == 1
|
208
|
+
a.rels.to_other(b).should include(r1)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "#rels returns an RelationshipTraverser which provides a method for deleting all the relationships" do
|
212
|
+
a = Neography::Node.create
|
213
|
+
b = Neography::Node.create
|
214
|
+
c = Neography::Node.create
|
215
|
+
r1 = Neography::Relationship.create(:friend, a, b)
|
216
|
+
r2 = Neography::Relationship.create(:friend, a, c)
|
217
|
+
|
218
|
+
a.rel?(:friend).should be_true
|
219
|
+
a.rels.del
|
220
|
+
a.rel?(:friend).should be_false
|
221
|
+
r1.exist?.should be_false
|
222
|
+
r2.exist?.should be_false
|
223
|
+
end
|
224
|
+
|
225
|
+
it "#rels returns an RelationshipTraverser with methods #del and #to_other which can be combined to only delete a subset of the relationships" do
|
226
|
+
a = Neography::Node.create
|
227
|
+
b = Neography::Node.create
|
228
|
+
c = Neography::Node.create
|
229
|
+
r1 = Neography::Relationship.create(:friend, a, b)
|
230
|
+
r2 = Neography::Relationship.create(:friend, a, c)
|
231
|
+
r1.exist?.should be_true
|
232
|
+
r2.exist?.should be_true
|
233
|
+
a.rels.to_other(c).del
|
234
|
+
r1.exist?.should be_true
|
235
|
+
r2.exist?.should be_false
|
236
|
+
end
|
237
|
+
|
238
|
+
it "#rels should return both incoming and outgoing relationship of any type of depth one" do
|
239
|
+
a,b,c,d,e,f = create_nodes
|
240
|
+
b.rels.size.should == 5
|
241
|
+
nodes = b.rels.collect{|r| r.other_node(b)}
|
242
|
+
nodes.should include(a,c,d,f)
|
243
|
+
nodes.should_not include(e)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "#rels(:friends) should return both incoming and outgoing relationships of given type of depth one" do
|
247
|
+
# given
|
248
|
+
a,b,c,d,e,f = create_nodes
|
249
|
+
|
250
|
+
# when
|
251
|
+
rels = [*b.rels(:friends)]
|
252
|
+
|
253
|
+
# then
|
254
|
+
rels.size.should == 3
|
255
|
+
nodes = rels.collect{|r| r.end_node}
|
256
|
+
nodes.should include(b,c,f)
|
257
|
+
nodes.should_not include(a,d,e)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "#rels(:friends).outgoing should return only outgoing relationships of given type of depth one" do
|
261
|
+
# given
|
262
|
+
a,b,c,d,e,f = create_nodes
|
263
|
+
|
264
|
+
# when
|
265
|
+
rels = [*b.rels(:friends).outgoing]
|
266
|
+
|
267
|
+
# then
|
268
|
+
rels.size.should == 2
|
269
|
+
nodes = rels.collect{|r| r.end_node}
|
270
|
+
nodes.should include(c,f)
|
271
|
+
nodes.should_not include(a,b,d,e)
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
it "#rels(:friends).incoming should return only outgoing relationships of given type of depth one" do
|
276
|
+
# given
|
277
|
+
a,b,c,d,e = create_nodes
|
278
|
+
|
279
|
+
# when
|
280
|
+
rels = [*b.rels(:friends).incoming]
|
281
|
+
|
282
|
+
# then
|
283
|
+
rels.size.should == 1
|
284
|
+
nodes = rels.collect{|r| r.start_node}
|
285
|
+
nodes.should include(a)
|
286
|
+
nodes.should_not include(b,c,d,e)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "#rels(:friends,:work) should return both incoming and outgoing relationships of given types of depth one" do
|
290
|
+
# given
|
291
|
+
a,b,c,d,e,f = create_nodes
|
292
|
+
|
293
|
+
# when
|
294
|
+
rels = [*b.rels(:friends,:work)]
|
295
|
+
|
296
|
+
# then
|
297
|
+
rels.size.should == 5
|
298
|
+
nodes = rels.collect{|r| r.other_node(b)}
|
299
|
+
nodes.should include(a,c,d,f)
|
300
|
+
nodes.should_not include(b,e)
|
301
|
+
end
|
302
|
+
|
303
|
+
it "#rels(:friends,:work).outgoing should return outgoing relationships of given types of depth one" do
|
304
|
+
# given
|
305
|
+
a,b,c,d,e,f = create_nodes
|
306
|
+
|
307
|
+
# when
|
308
|
+
rels = [*b.rels(:friends,:work).outgoing]
|
309
|
+
|
310
|
+
# then
|
311
|
+
rels.size.should == 4
|
312
|
+
nodes = rels.collect{|r| r.other_node(b)}
|
313
|
+
nodes.should include(c,d,f)
|
314
|
+
nodes.should_not include(a,b,e)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
describe "rel" do
|
319
|
+
it "#rel returns a single relationship if there is only one relationship" do
|
320
|
+
a = Neography::Node.create
|
321
|
+
b = Neography::Node.create
|
322
|
+
rel = Neography::Relationship.create(:friend, a, b)
|
323
|
+
a.rel(:outgoing, :friend).should == rel
|
324
|
+
end
|
325
|
+
|
326
|
+
it "#rel returns nil if there is no relationship" do
|
327
|
+
a = Neography::Node.create
|
328
|
+
b = Neography::Node.create
|
329
|
+
a.rel(:outgoing, :friend).should be_nil
|
330
|
+
end
|
331
|
+
|
332
|
+
it "#rel should only return one relationship even if there are more" do
|
333
|
+
a = Neography::Node.create
|
334
|
+
b = Neography::Node.create
|
335
|
+
c = Neography::Node.create
|
336
|
+
Neography::Relationship.create(:friend, a, b)
|
337
|
+
Neography::Relationship.create(:friend, a, c)
|
338
|
+
[*a.rel(:outgoing, :friend)].size == 1
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe "rel?" do
|
343
|
+
it "#rel? returns true if there are any relationships" do
|
344
|
+
n1 = Neography::Node.create
|
345
|
+
n1.rel?.should be_false
|
346
|
+
n1.outgoing(:foo) << Neography::Node.create
|
347
|
+
|
348
|
+
n1.rel?.should be_true
|
349
|
+
n1.rel?(:bar).should be_false
|
350
|
+
n1.rel?(:foo).should be_true
|
351
|
+
n1.rel?(:incoming, :foo).should be_false
|
352
|
+
n1.rel?(:outgoing, :foo).should be_true
|
353
|
+
n1.rel?(:foo, :incoming).should be_false
|
354
|
+
n1.rel?(:foo, :outgoing).should be_true
|
355
|
+
n1.rel?(:incoming).should be_false
|
356
|
+
n1.rel?(:outgoing).should be_true
|
357
|
+
n1.rel?(:both).should be_true
|
358
|
+
n1.rel?(:all).should be_true
|
359
|
+
n1.rel?.should be_true
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
|
364
|
+
describe "delete relationship" do
|
365
|
+
it "can delete an existing relationship" do
|
366
|
+
p1 = Neography::Node.create
|
367
|
+
p2 = Neography::Node.create
|
368
|
+
new_rel = Neography::Relationship.create(:family, p1, p2)
|
369
|
+
new_rel.del
|
370
|
+
Neography::Relationship.load(new_rel).should be_nil
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Neography::Node do
|
4
|
+
|
5
|
+
describe "create and new" do
|
6
|
+
it "can create an empty node" do
|
7
|
+
new_node = Neography::Node.create
|
8
|
+
new_node.should_not be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can create a node with one property" do
|
12
|
+
new_node = Neography::Node.create("name" => "Max")
|
13
|
+
new_node.name.should == "Max"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can create a node with more than one property" do
|
17
|
+
new_node = Neography::Node.create("age" => 31, "name" => "Max")
|
18
|
+
new_node.name.should == "Max"
|
19
|
+
new_node.age.should == 31
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can create a node with more than one property not on the default rest server" do
|
23
|
+
@neo = Neography::Rest.new
|
24
|
+
new_node = Neography::Node.create({"age" => 31, "name" => "Max"}, @neo)
|
25
|
+
new_node.name.should == "Max"
|
26
|
+
new_node.age.should == 31
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can create a node with more than one property not on the default rest server the other way" do
|
30
|
+
@neo = Neography::Rest.new
|
31
|
+
new_node = Neography::Node.create(@neo, {"age" => 31, "name" => "Max"})
|
32
|
+
new_node.name.should == "Max"
|
33
|
+
new_node.age.should == 31
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
describe "load" do
|
39
|
+
it "can get a node that exists" do
|
40
|
+
new_node = Neography::Node.create
|
41
|
+
existing_node = Neography::Node.load(new_node)
|
42
|
+
existing_node.should_not be_nil
|
43
|
+
existing_node.neo_id.should_not be_nil
|
44
|
+
existing_node.neo_id.should == new_node.neo_id
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns nil if it tries to load a node that does not exist" do
|
48
|
+
new_node = Neography::Node.create
|
49
|
+
fake_node = new_node.neo_id.to_i + 1000
|
50
|
+
existing_node = Neography::Node.load(fake_node)
|
51
|
+
existing_node.should be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "can load a node that exists not on the default rest server" do
|
55
|
+
@neo = Neography::Rest.new
|
56
|
+
new_node = Neography::Node.create(@neo)
|
57
|
+
existing_node = Neography::Node.load(new_node, @neo)
|
58
|
+
existing_node.should_not be_nil
|
59
|
+
existing_node.neo_id.should_not be_nil
|
60
|
+
existing_node.neo_id.should == new_node.neo_id
|
61
|
+
end
|
62
|
+
|
63
|
+
it "can load a node that exists not on the default rest server the other way" do
|
64
|
+
@neo = Neography::Rest.new
|
65
|
+
new_node = Neography::Node.create(@neo)
|
66
|
+
existing_node = Neography::Node.load(@neo, new_node)
|
67
|
+
existing_node.should_not be_nil
|
68
|
+
existing_node.neo_id.should_not be_nil
|
69
|
+
existing_node.neo_id.should == new_node.neo_id
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "del" do
|
74
|
+
it "can delete itself" do
|
75
|
+
new_node = Neography::Node.create
|
76
|
+
node_id = new_node.neo_id
|
77
|
+
new_node.del
|
78
|
+
deleted_node = Neography::Node.load(node_id)
|
79
|
+
deleted_node.should be_nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "exists?" do
|
84
|
+
it "can tell if it exists" do
|
85
|
+
new_node = Neography::Node.create
|
86
|
+
new_node.exist?.should be_true
|
87
|
+
end
|
88
|
+
|
89
|
+
it "can tell if does not exists" do
|
90
|
+
new_node = Neography::Node.create
|
91
|
+
new_node.del
|
92
|
+
new_node.exist?.should be_false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "equality" do
|
97
|
+
it "can tell two nodes are the same with equal?" do
|
98
|
+
new_node = Neography::Node.create
|
99
|
+
another_node = Neography::Node.load(new_node)
|
100
|
+
new_node.equal?(another_node).should be_true
|
101
|
+
end
|
102
|
+
|
103
|
+
it "can tell two nodes are the same with eql?" do
|
104
|
+
new_node = Neography::Node.create
|
105
|
+
another_node = Neography::Node.load(new_node)
|
106
|
+
new_node.eql?(another_node).should be_true
|
107
|
+
end
|
108
|
+
|
109
|
+
it "can tell two nodes are the same with ==" do
|
110
|
+
new_node = Neography::Node.create
|
111
|
+
another_node = Neography::Node.load(new_node)
|
112
|
+
(new_node == another_node).should be_true
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "set properties" do
|
117
|
+
it "can change a node's properties that already exist using []=" do
|
118
|
+
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
|
119
|
+
|
120
|
+
new_node[:weight] = 200
|
121
|
+
new_node[:eyes] = "brown"
|
122
|
+
|
123
|
+
existing_node = Neography::Node.load(new_node)
|
124
|
+
existing_node.weight.should == 200
|
125
|
+
existing_node.eyes.should == "brown"
|
126
|
+
end
|
127
|
+
|
128
|
+
it "can change a node's properties that already exist" do
|
129
|
+
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
|
130
|
+
|
131
|
+
new_node.weight = 200
|
132
|
+
new_node.eyes = "brown"
|
133
|
+
|
134
|
+
existing_node = Neography::Node.load(new_node)
|
135
|
+
existing_node.weight.should == 200
|
136
|
+
existing_node.eyes.should == "brown"
|
137
|
+
end
|
138
|
+
|
139
|
+
it "can change a node's properties that does not already exist" do
|
140
|
+
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
|
141
|
+
|
142
|
+
new_node.weight = 200
|
143
|
+
new_node.eyes = "brown"
|
144
|
+
new_node[:hair] = "black"
|
145
|
+
|
146
|
+
existing_node = Neography::Node.load(new_node)
|
147
|
+
existing_node.weight.should == 200
|
148
|
+
existing_node.eyes.should == "brown"
|
149
|
+
existing_node.hair.should == "black"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "can pass issue 18" do
|
153
|
+
n = Neography::Node.create("name" => "Test")
|
154
|
+
n.prop = 1
|
155
|
+
n.prop.should == 1
|
156
|
+
n.prop = 1
|
157
|
+
n.prop.should == 1
|
158
|
+
n[:prop].should == 1
|
159
|
+
n[:prop2] = 2
|
160
|
+
n[:prop2].should == 2
|
161
|
+
n[:prop2] = 2
|
162
|
+
n[:prop2].should == 2
|
163
|
+
n.name
|
164
|
+
n.name = "New Name"
|
165
|
+
n.name.should == "New Name"
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "get node properties" do
|
171
|
+
it "can get node properties using []" do
|
172
|
+
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
|
173
|
+
new_node[:weight].should == 150
|
174
|
+
new_node[:eyes].should == "green"
|
175
|
+
end
|
176
|
+
|
177
|
+
it "can get node properties" do
|
178
|
+
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
|
179
|
+
new_node.weight.should == 150
|
180
|
+
new_node.eyes.should == "green"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "delete node properties" do
|
185
|
+
it "can delete node properties using []" do
|
186
|
+
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
|
187
|
+
|
188
|
+
new_node[:weight] = nil
|
189
|
+
new_node[:eyes] = nil
|
190
|
+
|
191
|
+
new_node[:weight].should be_nil
|
192
|
+
new_node[:eyes].should be_nil
|
193
|
+
|
194
|
+
existing_node = Neography::Node.load(new_node)
|
195
|
+
existing_node.weight.should be_nil
|
196
|
+
existing_node.eyes.should be_nil
|
197
|
+
end
|
198
|
+
|
199
|
+
it "can delete node properties" do
|
200
|
+
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
|
201
|
+
|
202
|
+
new_node.weight = nil
|
203
|
+
new_node.eyes = nil
|
204
|
+
|
205
|
+
new_node.weight.should be_nil
|
206
|
+
new_node.eyes.should be_nil
|
207
|
+
|
208
|
+
existing_node = Neography::Node.load(new_node)
|
209
|
+
existing_node.weight.should be_nil
|
210
|
+
existing_node.eyes.should be_nil
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
end
|