neography-down 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.project +12 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +4 -0
  6. data/CHANGELOG.md +939 -0
  7. data/CONTRIBUTORS +18 -0
  8. data/Gemfile +4 -0
  9. data/Guardfile +14 -0
  10. data/LICENSE +19 -0
  11. data/README.md +281 -0
  12. data/Rakefile +14 -0
  13. data/examples/facebook.rb +40 -0
  14. data/examples/facebook_v2.rb +25 -0
  15. data/examples/greatest.rb +43 -0
  16. data/examples/linkedin.rb +39 -0
  17. data/examples/linkedin_v2.rb +22 -0
  18. data/examples/traversal_example1.rb +65 -0
  19. data/examples/traversal_example2.rb +54 -0
  20. data/lib/neography.rb +45 -0
  21. data/lib/neography/config.rb +64 -0
  22. data/lib/neography/connection.rb +263 -0
  23. data/lib/neography/equal.rb +21 -0
  24. data/lib/neography/errors.rb +60 -0
  25. data/lib/neography/index.rb +52 -0
  26. data/lib/neography/multi_json_parser.rb +28 -0
  27. data/lib/neography/neography.rb +10 -0
  28. data/lib/neography/node.rb +63 -0
  29. data/lib/neography/node_path.rb +29 -0
  30. data/lib/neography/node_relationship.rb +37 -0
  31. data/lib/neography/node_traverser.rb +146 -0
  32. data/lib/neography/path_traverser.rb +100 -0
  33. data/lib/neography/property.rb +110 -0
  34. data/lib/neography/property_container.rb +28 -0
  35. data/lib/neography/railtie.rb +19 -0
  36. data/lib/neography/relationship.rb +78 -0
  37. data/lib/neography/relationship_traverser.rb +80 -0
  38. data/lib/neography/rest.rb +99 -0
  39. data/lib/neography/rest/batch.rb +414 -0
  40. data/lib/neography/rest/clean.rb +17 -0
  41. data/lib/neography/rest/constraints.rb +38 -0
  42. data/lib/neography/rest/cypher.rb +29 -0
  43. data/lib/neography/rest/extensions.rb +21 -0
  44. data/lib/neography/rest/gremlin.rb +20 -0
  45. data/lib/neography/rest/helpers.rb +96 -0
  46. data/lib/neography/rest/node_auto_indexes.rb +60 -0
  47. data/lib/neography/rest/node_indexes.rb +139 -0
  48. data/lib/neography/rest/node_labels.rb +49 -0
  49. data/lib/neography/rest/node_paths.rb +49 -0
  50. data/lib/neography/rest/node_properties.rb +52 -0
  51. data/lib/neography/rest/node_relationships.rb +33 -0
  52. data/lib/neography/rest/node_traversal.rb +25 -0
  53. data/lib/neography/rest/nodes.rb +94 -0
  54. data/lib/neography/rest/other_node_relationships.rb +38 -0
  55. data/lib/neography/rest/relationship_auto_indexes.rb +60 -0
  56. data/lib/neography/rest/relationship_indexes.rb +142 -0
  57. data/lib/neography/rest/relationship_properties.rb +52 -0
  58. data/lib/neography/rest/relationship_types.rb +11 -0
  59. data/lib/neography/rest/relationships.rb +16 -0
  60. data/lib/neography/rest/schema_indexes.rb +26 -0
  61. data/lib/neography/rest/spatial.rb +137 -0
  62. data/lib/neography/rest/transactions.rb +101 -0
  63. data/lib/neography/tasks.rb +207 -0
  64. data/lib/neography/version.rb +3 -0
  65. data/neography.gemspec +39 -0
  66. data/spec/integration/authorization_spec.rb +40 -0
  67. data/spec/integration/broken_spatial_spec.rb +28 -0
  68. data/spec/integration/index_spec.rb +71 -0
  69. data/spec/integration/neography_spec.rb +10 -0
  70. data/spec/integration/node_encoding_spec.rb +71 -0
  71. data/spec/integration/node_path_spec.rb +222 -0
  72. data/spec/integration/node_relationship_spec.rb +381 -0
  73. data/spec/integration/node_spec.rb +260 -0
  74. data/spec/integration/parsing_spec.rb +13 -0
  75. data/spec/integration/performance_spec.rb +17 -0
  76. data/spec/integration/relationship_spec.rb +37 -0
  77. data/spec/integration/rest_batch_no_streaming_spec.rb +41 -0
  78. data/spec/integration/rest_batch_spec.rb +604 -0
  79. data/spec/integration/rest_batch_streaming_spec.rb +51 -0
  80. data/spec/integration/rest_bulk_spec.rb +106 -0
  81. data/spec/integration/rest_constraints_spec.rb +72 -0
  82. data/spec/integration/rest_experimental_spec.rb +22 -0
  83. data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
  84. data/spec/integration/rest_header_spec.rb +15 -0
  85. data/spec/integration/rest_index_spec.rb +481 -0
  86. data/spec/integration/rest_labels_spec.rb +128 -0
  87. data/spec/integration/rest_node_spec.rb +274 -0
  88. data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
  89. data/spec/integration/rest_path_spec.rb +231 -0
  90. data/spec/integration/rest_plugin_spec.rb +177 -0
  91. data/spec/integration/rest_relationship_spec.rb +354 -0
  92. data/spec/integration/rest_relationship_types_spec.rb +18 -0
  93. data/spec/integration/rest_schema_index_spec.rb +32 -0
  94. data/spec/integration/rest_spatial_spec.rb +166 -0
  95. data/spec/integration/rest_transaction_spec.rb +166 -0
  96. data/spec/integration/rest_traverse_spec.rb +149 -0
  97. data/spec/integration/unmanaged_spec.rb +27 -0
  98. data/spec/matchers.rb +33 -0
  99. data/spec/neography_spec.rb +23 -0
  100. data/spec/spec_helper.rb +44 -0
  101. data/spec/unit/config_spec.rb +135 -0
  102. data/spec/unit/connection_spec.rb +284 -0
  103. data/spec/unit/node_spec.rb +100 -0
  104. data/spec/unit/properties_spec.rb +285 -0
  105. data/spec/unit/relationship_spec.rb +118 -0
  106. data/spec/unit/rest/batch_spec.rb +262 -0
  107. data/spec/unit/rest/clean_spec.rb +16 -0
  108. data/spec/unit/rest/constraints_spec.rb +45 -0
  109. data/spec/unit/rest/cypher_spec.rb +20 -0
  110. data/spec/unit/rest/extensions_spec.rb +28 -0
  111. data/spec/unit/rest/gremlin_spec.rb +25 -0
  112. data/spec/unit/rest/helpers_spec.rb +124 -0
  113. data/spec/unit/rest/labels_spec.rb +77 -0
  114. data/spec/unit/rest/node_auto_indexes_spec.rb +70 -0
  115. data/spec/unit/rest/node_indexes_spec.rb +140 -0
  116. data/spec/unit/rest/node_paths_spec.rb +77 -0
  117. data/spec/unit/rest/node_properties_spec.rb +79 -0
  118. data/spec/unit/rest/node_relationships_spec.rb +57 -0
  119. data/spec/unit/rest/node_traversal_spec.rb +35 -0
  120. data/spec/unit/rest/nodes_spec.rb +187 -0
  121. data/spec/unit/rest/relationship_auto_indexes_spec.rb +66 -0
  122. data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
  123. data/spec/unit/rest/relationship_properties_spec.rb +79 -0
  124. data/spec/unit/rest/relationship_types_spec.rb +15 -0
  125. data/spec/unit/rest/relationships_spec.rb +21 -0
  126. data/spec/unit/rest/schema_index_spec.rb +30 -0
  127. data/spec/unit/rest/transactions_spec.rb +43 -0
  128. metadata +372 -0
@@ -0,0 +1,381 @@
1
+ require '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
+ expect(a.outgoing(:friends).first).to eq(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
+ expect(a.outgoing(:friends)).to 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
+ expect(b.outgoing).to include(c,f,d)
60
+ expect([*b.outgoing].size).to eq(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
+ expect(b.outgoing(:work)).to include(c,d)
66
+ expect([*b.outgoing(:work)].size).to eq(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
+ expect(nodes).to include(c,d,f)
74
+ expect(nodes.size).to eq(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
+ expect([*b.outgoing(:work).depth(4)].size).to eq(3)
80
+ expect(b.outgoing(:work).depth(4)).to 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
+ expect([*b.outgoing(:work).depth(4).include_start_node].size).to eq(4)
86
+ expect(b.outgoing(:work).depth(4).include_start_node).to 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
+ expect([*b.outgoing(:work).depth(:all)].size).to eq(3)
92
+ expect(b.outgoing(:work).depth(:all)).to 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
+ expect(a.incoming(:friends).first).to eq(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
+ expect(a.incoming(:friends)).to 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
+ expect(b.incoming).to include(a)
124
+ expect([*b.incoming].size).to eq(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
+ expect([*e.incoming(:work).depth(2)].size).to eq(2)
130
+ expect(e.incoming(:work).depth(2)).to 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
+ expect(c.incoming(:work)).to include(b)
136
+ expect([*c.incoming(:work)].size).to eq(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
+ expect(a.incoming(:friends).first).to eq(other_node)
148
+ expect(a.outgoing(:friends).first).to eq(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
+ expect(b.both).to include(a,c,d,f)
155
+ expect([*b.both].size).to eq(5) #c is related by both work and friends
156
+ expect(b.incoming).to include(a)
157
+ expect(b.outgoing).to include(c)
158
+ end
159
+
160
+ it "#both returns an empty array for unconnected nodes" do
161
+ a = Neography::Node.create
162
+ expect(a.both.size).to eq(0)
163
+ end
164
+
165
+ it "#both(type) should return both incoming and outgoing nodes of the given type of depth one" do
166
+ a,b,c,d,e,f = create_nodes
167
+
168
+ expect(b.both(:friends)).to include(a,c,f)
169
+ expect([*b.both(:friends)].size).to eq(3)
170
+ end
171
+
172
+ it "#outgoing and #incoming can be combined to traverse several relationship types" do
173
+ a,b,c,d,e = create_nodes
174
+ nodes = [*b.incoming(:friends).outgoing(:work)]
175
+
176
+ expect(nodes).to include(a,c,d)
177
+ expect(nodes).not_to include(b,e)
178
+ end
179
+ end
180
+
181
+
182
+ describe "prune" do
183
+ it "#prune, if it returns true the traversal will be stop for that path" do
184
+ a, b, c, d, e = create_nodes
185
+ expect([*b.outgoing(:work).depth(4)].size).to eq(3)
186
+ expect(b.outgoing(:work).depth(4)).to include(c,d,e)
187
+
188
+ expect([*b.outgoing(:work).prune("position.endNode().getProperty('name') == 'd';")].size).to eq(2)
189
+ expect(b.outgoing(:work).prune("position.endNode().getProperty('name') == 'd';")).to include(c,d)
190
+ end
191
+ end
192
+
193
+ describe "filter" do
194
+ it "#filter, if it returns true the node will be included in the return results" do
195
+ a, b, c, d, e = create_nodes
196
+ expect([*b.outgoing(:work).depth(4)].size).to eq(3)
197
+ expect(b.outgoing(:work).depth(4)).to include(c,d,e)
198
+
199
+ expect([*b.outgoing(:work).depth(4).filter("position.length() == 2;")].size).to eq(1)
200
+ expect(b.outgoing(:work).depth(4).filter("position.length() == 2;")).to include(e)
201
+ end
202
+ end
203
+
204
+ describe "rels" do
205
+ it "#rels returns a RelationshipTraverser which can filter which relationship it should return by specifying #to_other" do
206
+ a = Neography::Node.create
207
+ b = Neography::Node.create
208
+ c = Neography::Node.create
209
+ r1 = Neography::Relationship.create(:friend, a, b)
210
+ Neography::Relationship.create(:friend, a, c)
211
+
212
+ expect(a.rels.to_other(b).size).to eq(1)
213
+ expect(a.rels.to_other(b)).to include(r1)
214
+ end
215
+
216
+ it "#rels returns an RelationshipTraverser which provides a method for deleting all the relationships" do
217
+ a = Neography::Node.create
218
+ b = Neography::Node.create
219
+ c = Neography::Node.create
220
+ r1 = Neography::Relationship.create(:friend, a, b)
221
+ r2 = Neography::Relationship.create(:friend, a, c)
222
+
223
+ expect(a.rel?(:friend)).to be true
224
+ a.rels.del
225
+ expect(a.rel?(:friend)).to be false
226
+ expect(r1.exist?).to be false
227
+ expect(r2.exist?).to be false
228
+ end
229
+
230
+ it "#rels returns an RelationshipTraverser with methods #del and #to_other which can be combined to only delete a subset of the relationships" do
231
+ a = Neography::Node.create
232
+ b = Neography::Node.create
233
+ c = Neography::Node.create
234
+ r1 = Neography::Relationship.create(:friend, a, b)
235
+ r2 = Neography::Relationship.create(:friend, a, c)
236
+ expect(r1.exist?).to be true
237
+ expect(r2.exist?).to be true
238
+ a.rels.to_other(c).del
239
+ expect(r1.exist?).to be true
240
+ expect(r2.exist?).to be false
241
+ end
242
+
243
+ it "#rels should return both incoming and outgoing relationship of any type of depth one" do
244
+ a,b,c,d,e,f = create_nodes
245
+ expect(b.rels.size).to eq(5)
246
+ nodes = b.rels.collect{|r| r.other_node(b)}
247
+ expect(nodes).to include(a,c,d,f)
248
+ expect(nodes).not_to include(e)
249
+ end
250
+
251
+ it "#rels(:friends) should return both incoming and outgoing relationships of given type of depth one" do
252
+ # given
253
+ a,b,c,d,e,f = create_nodes
254
+
255
+ # when
256
+ rels = [*b.rels(:friends)]
257
+
258
+ # then
259
+ expect(rels.size).to eq(3)
260
+ nodes = rels.collect{|r| r.end_node}
261
+ expect(nodes).to include(b,c,f)
262
+ expect(nodes).not_to include(a,d,e)
263
+ end
264
+
265
+ it "#rels(:friends).outgoing should return only outgoing relationships of given type of depth one" do
266
+ # given
267
+ a,b,c,d,e,f = create_nodes
268
+
269
+ # when
270
+ rels = [*b.rels(:friends).outgoing]
271
+
272
+ # then
273
+ expect(rels.size).to eq(2)
274
+ nodes = rels.collect{|r| r.end_node}
275
+ expect(nodes).to include(c,f)
276
+ expect(nodes).not_to include(a,b,d,e)
277
+ end
278
+
279
+
280
+ it "#rels(:friends).incoming should return only outgoing relationships of given type of depth one" do
281
+ # given
282
+ a,b,c,d,e = create_nodes
283
+
284
+ # when
285
+ rels = [*b.rels(:friends).incoming]
286
+
287
+ # then
288
+ expect(rels.size).to eq(1)
289
+ nodes = rels.collect{|r| r.start_node}
290
+ expect(nodes).to include(a)
291
+ expect(nodes).not_to include(b,c,d,e)
292
+ end
293
+
294
+ it "#rels(:friends,:work) should return both incoming and outgoing relationships of given types of depth one" do
295
+ # given
296
+ a,b,c,d,e,f = create_nodes
297
+
298
+ # when
299
+ rels = [*b.rels(:friends,:work)]
300
+
301
+ # then
302
+ expect(rels.size).to eq(5)
303
+ nodes = rels.collect{|r| r.other_node(b)}
304
+ expect(nodes).to include(a,c,d,f)
305
+ expect(nodes).not_to include(b,e)
306
+ end
307
+
308
+ it "#rels(:friends,:work).outgoing should return outgoing relationships of given types of depth one" do
309
+ # given
310
+ a,b,c,d,e,f = create_nodes
311
+
312
+ # when
313
+ rels = [*b.rels(:friends,:work).outgoing]
314
+
315
+ # then
316
+ expect(rels.size).to eq(4)
317
+ nodes = rels.collect{|r| r.other_node(b)}
318
+ expect(nodes).to include(c,d,f)
319
+ expect(nodes).not_to include(a,b,e)
320
+ end
321
+ end
322
+
323
+ describe "rel" do
324
+ it "#rel returns a single relationship if there is only one relationship" do
325
+ a = Neography::Node.create
326
+ b = Neography::Node.create
327
+ rel = Neography::Relationship.create(:friend, a, b)
328
+ expect(a.rel(:outgoing, :friend)).to eq(rel)
329
+ end
330
+
331
+ it "#rel returns nil if there is no relationship" do
332
+ a = Neography::Node.create
333
+ b = Neography::Node.create
334
+ expect(a.rel(:outgoing, :friend)).to be_empty
335
+ end
336
+
337
+ it "#rel should only return one relationship even if there are more" do
338
+ a = Neography::Node.create
339
+ b = Neography::Node.create
340
+ c = Neography::Node.create
341
+ Neography::Relationship.create(:friend, a, b)
342
+ Neography::Relationship.create(:friend, a, c)
343
+ [*a.rel(:outgoing, :friend)].size == 1
344
+ end
345
+ end
346
+
347
+ describe "rel?" do
348
+ it "#rel? returns true if there are any relationships" do
349
+ n1 = Neography::Node.create
350
+ expect(n1.rel?).to be false
351
+ n1.outgoing(:foo) << Neography::Node.create
352
+
353
+ expect(n1.rel?).to be true
354
+ expect(n1.rel?(:bar)).to be false
355
+ expect(n1.rel?(:foo)).to be true
356
+ expect(n1.rel?(:incoming, :foo)).to be false
357
+ expect(n1.rel?(:outgoing, :foo)).to be true
358
+ expect(n1.rel?(:foo, :incoming)).to be false
359
+ expect(n1.rel?(:foo, :outgoing)).to be true
360
+ expect(n1.rel?(:incoming)).to be false
361
+ expect(n1.rel?(:outgoing)).to be true
362
+ expect(n1.rel?(:both)).to be true
363
+ expect(n1.rel?(:all)).to be true
364
+ expect(n1.rel?).to be true
365
+ end
366
+ end
367
+
368
+
369
+ describe "delete relationship" do
370
+ it "can delete an existing relationship" do
371
+ p1 = Neography::Node.create
372
+ p2 = Neography::Node.create
373
+ new_rel = Neography::Relationship.create(:family, p1, p2)
374
+ new_rel.del
375
+ expect {
376
+ Neography::Relationship.load(new_rel)
377
+ }.to raise_error Neography::RelationshipNotFoundException
378
+ end
379
+ end
380
+
381
+ end
@@ -0,0 +1,260 @@
1
+ require '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
+ expect(new_node).not_to be_nil
9
+ end
10
+
11
+ it "can create a node with one property" do
12
+ new_node = Neography::Node.create("name" => "Max")
13
+ expect(new_node.name).to eq("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
+ expect(new_node.name).to eq("Max")
19
+ expect(new_node.age).to eq(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
+ expect(new_node.name).to eq("Max")
26
+ expect(new_node.age).to eq(31)
27
+ end
28
+
29
+ it "cannot create a node with more than one property not on the default rest server the other way" do
30
+ @neo = Neography::Rest.new
31
+ expect {
32
+ new_node = Neography::Node.create(@neo, {"age" => 31, "name" => "Max"})
33
+ }.to raise_error(ArgumentError)
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
+ expect(existing_node).not_to be_nil
43
+ expect(existing_node.neo_id).not_to be_nil
44
+ expect(existing_node.neo_id).to eq(new_node.neo_id)
45
+ end
46
+
47
+ it "raises an error 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
+ expect {
51
+ existing_node = Neography::Node.load(fake_node)
52
+ }.to raise_error Neography::NodeNotFoundException
53
+ end
54
+
55
+ it "can load a node that exists not on the default rest server" do
56
+ @neo = Neography::Rest.new
57
+ new_node = Neography::Node.create({}, @neo)
58
+ existing_node = Neography::Node.load(new_node, @neo)
59
+ expect(existing_node).not_to be_nil
60
+ expect(existing_node.neo_id).not_to be_nil
61
+ expect(existing_node.neo_id).to eq(new_node.neo_id)
62
+ end
63
+
64
+ it "cannot load a node that exists not on the default rest server the other way" do
65
+ @neo = Neography::Rest.new
66
+ new_node = Neography::Node.create({}, @neo)
67
+ expect {
68
+ existing_node = Neography::Node.load(@neo, new_node)
69
+ }.to raise_error(ArgumentError)
70
+ end
71
+
72
+ it "can get a node from an index" do
73
+ @neo = Neography::Rest.new
74
+ new_node = Neography::Node.create("age" => 31, "name" => "Max")
75
+ key = generate_text(6)
76
+ value = generate_text
77
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
78
+ node_from_index = @neo.get_node_index("test_node_index", key, value)
79
+ existing_node = Neography::Node.load(node_from_index)
80
+ expect(existing_node).not_to be_nil
81
+ expect(existing_node.neo_id).not_to be_nil
82
+ expect(existing_node.neo_id).to eq(new_node.neo_id)
83
+ end
84
+
85
+ it "can get a node that exists via cypher" do
86
+ new_node = Neography::Node.create("age" => 31, "name" => "Max")
87
+ cypher = "START n = node({id}) return n"
88
+ @neo = Neography::Rest.new
89
+ results = @neo.execute_query(cypher, {:id => new_node.neo_id.to_i})
90
+ existing_node = Neography::Node.load(results)
91
+ expect(existing_node).not_to be_nil
92
+ expect(existing_node.neo_id).not_to be_nil
93
+ expect(existing_node.neo_id).to eq(new_node.neo_id)
94
+ end
95
+
96
+
97
+ end
98
+
99
+ describe "del" do
100
+ it "can delete itself" do
101
+ new_node = Neography::Node.create
102
+ node_id = new_node.neo_id
103
+ new_node.del
104
+ expect {
105
+ Neography::Node.load(node_id)
106
+ }.to raise_error Neography::NodeNotFoundException
107
+ end
108
+ end
109
+
110
+ describe "exists?" do
111
+ it "can tell if it exists" do
112
+ new_node = Neography::Node.create
113
+ expect(new_node.exist?).to be true
114
+ end
115
+
116
+ it "can tell if does not exists" do
117
+ new_node = Neography::Node.create
118
+ new_node.del
119
+ expect(new_node.exist?).to be false
120
+ end
121
+ end
122
+
123
+ describe "equality" do
124
+ it "can tell two nodes are the same with equal?" do
125
+ new_node = Neography::Node.create
126
+ another_node = Neography::Node.load(new_node)
127
+ expect(new_node.equal?(another_node)).to be true
128
+ end
129
+
130
+ it "can tell two nodes are the same with eql?" do
131
+ new_node = Neography::Node.create
132
+ another_node = Neography::Node.load(new_node)
133
+ expect(new_node.eql?(another_node)).to be true
134
+ end
135
+
136
+ it "can tell two nodes are the same with ==" do
137
+ new_node = Neography::Node.create
138
+ another_node = Neography::Node.load(new_node)
139
+ expect(new_node == another_node).to be true
140
+ end
141
+ end
142
+
143
+ describe "set properties" do
144
+ it "can change a node's properties that already exist using []=" do
145
+ new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
146
+
147
+ new_node[:weight] = 200
148
+ new_node[:eyes] = "brown"
149
+
150
+ existing_node = Neography::Node.load(new_node)
151
+ expect(existing_node.weight).to eq(200)
152
+ expect(existing_node.eyes).to eq("brown")
153
+ end
154
+
155
+ it "can change a node's properties that already exist" do
156
+ new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
157
+
158
+ new_node.weight = 200
159
+ new_node.eyes = "brown"
160
+
161
+ existing_node = Neography::Node.load(new_node)
162
+ expect(existing_node.weight).to eq(200)
163
+ expect(existing_node.eyes).to eq("brown")
164
+ end
165
+
166
+ it "can change a node's properties that does not already exist using []=" do
167
+ new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
168
+
169
+ new_node.weight = 200
170
+ new_node.eyes = "brown"
171
+ new_node[:hair] = "black"
172
+
173
+ existing_node = Neography::Node.load(new_node)
174
+ expect(existing_node.weight).to eq(200)
175
+ expect(existing_node.eyes).to eq("brown")
176
+ expect(existing_node.hair).to eq("black")
177
+ end
178
+
179
+ it "can change a node's properties that does not already exist" do
180
+ new_node = Neography::Node.create
181
+
182
+ new_node.hair = "black"
183
+
184
+ existing_node = Neography::Node.load(new_node)
185
+ expect(existing_node.hair).to eq("black")
186
+ end
187
+
188
+ it "can pass issue 18" do
189
+ n = Neography::Node.create("name" => "Test")
190
+ n.prop = 1
191
+ expect(n.prop).to eq(1)
192
+ n.prop = 1
193
+ expect(n.prop).to eq(1)
194
+ expect(n[:prop]).to eq(1)
195
+ n[:prop2] = 2
196
+ expect(n[:prop2]).to eq(2)
197
+ n[:prop2] = 2
198
+ expect(n[:prop2]).to eq(2)
199
+ n.name
200
+ n.name = "New Name"
201
+ expect(n.name).to eq("New Name")
202
+ end
203
+
204
+ end
205
+
206
+ describe "get node properties" do
207
+ it "can get node properties using []" do
208
+ new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
209
+ expect(new_node[:weight]).to eq(150)
210
+ expect(new_node[:eyes]).to eq("green")
211
+ end
212
+
213
+ it "can get node properties" do
214
+ new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
215
+ expect(new_node.weight).to eq(150)
216
+ expect(new_node.eyes).to eq("green")
217
+ end
218
+ end
219
+
220
+ describe "delete node properties" do
221
+ it "can delete node properties using []" do
222
+ new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
223
+
224
+ new_node[:weight] = nil
225
+ new_node[:eyes] = nil
226
+
227
+ expect(new_node[:weight]).to be_nil
228
+ expect(new_node[:eyes]).to be_nil
229
+
230
+ existing_node = Neography::Node.load(new_node)
231
+ expect(existing_node.weight).to be_nil
232
+ expect(existing_node.eyes).to be_nil
233
+ end
234
+
235
+ it "can delete node properties" do
236
+ new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
237
+
238
+ new_node.weight = nil
239
+ new_node.eyes = nil
240
+
241
+ expect(new_node.weight).to be_nil
242
+ expect(new_node.eyes).to be_nil
243
+
244
+ existing_node = Neography::Node.load(new_node)
245
+ expect(existing_node.weight).to be_nil
246
+ expect(existing_node.eyes).to be_nil
247
+ end
248
+ end
249
+
250
+ describe 'gets labels' do
251
+ let(:subject) {
252
+ node = Neography::Node.create
253
+ node.neo_server.add_label(node, 'Label')
254
+ node.neo_server.add_label(node, 'Label2')
255
+ node
256
+ }
257
+
258
+ it { expect(subject.labels).to eq(%w(Label Label2)) }
259
+ end
260
+ end