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,128 @@
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_labels" do
9
+ it "can get the labels of the database" do
10
+ @neo.set_label(0, "Person")
11
+ labels = @neo.list_labels
12
+ expect(labels).to include("Person")
13
+ end
14
+ end
15
+
16
+ describe "add_label" do
17
+ it "can add a label to a node" do
18
+ new_node = @neo.create_node
19
+ @neo.add_label(new_node, "Person")
20
+ labels = @neo.get_node_labels(new_node)
21
+ expect(labels).to eq(["Person"])
22
+ end
23
+
24
+ it "can add another label to a node" do
25
+ new_node = @neo.create_node
26
+ new_node_id = new_node["self"].split('/').last
27
+ @neo.add_label(new_node_id, "Actor")
28
+ @neo.add_label(new_node_id, "Director")
29
+ labels = @neo.get_node_labels(new_node_id)
30
+ expect(labels).to eq(["Actor", "Director"])
31
+ end
32
+
33
+ it "can add multiple labels to a node" do
34
+ new_node = @neo.create_node
35
+ new_node_id = new_node["self"].split('/').last
36
+ @neo.add_label(new_node_id, ["Actor", "Director"])
37
+ labels = @neo.get_node_labels(new_node_id)
38
+ expect(labels).to eq(["Actor", "Director"])
39
+ end
40
+ end
41
+
42
+ describe "set_label" do
43
+ it "can set a label to a node" do
44
+ new_node = @neo.create_node
45
+ new_node_id = new_node["self"].split('/').last
46
+ @neo.set_label(new_node_id, "Person")
47
+ labels = @neo.get_node_labels(new_node_id)
48
+ expect(labels).to eq(["Person"])
49
+ end
50
+
51
+ it "can set a label to a node that already had a label" do
52
+ new_node = @neo.create_node
53
+ @neo.add_label(new_node, "Actor")
54
+ @neo.set_label(new_node, "Director")
55
+ labels = @neo.get_node_labels(new_node)
56
+ expect(labels).to eq(["Director"])
57
+ end
58
+
59
+ it "can set multiple labels to a node" do
60
+ new_node = @neo.create_node
61
+ new_node_id = new_node["self"].split('/').last
62
+ @neo.set_label(new_node_id, ["Actor", "Director"])
63
+ labels = @neo.get_node_labels(new_node_id)
64
+ expect(labels).to eq(["Actor", "Director"])
65
+ end
66
+ end
67
+
68
+ describe "delete_label" do
69
+ it "can delete a label from a node" do
70
+ new_node = @neo.create_node
71
+ @neo.set_label(new_node, ["Actor", "Director"])
72
+ @neo.delete_label(new_node, "Actor")
73
+ labels = @neo.get_node_labels(new_node)
74
+ expect(labels).to eq(["Director"])
75
+ end
76
+
77
+ it "can delete a label from a node that doesn't have one" do
78
+ new_node = @neo.create_node
79
+ new_node_id = new_node["self"].split('/').last
80
+ @neo.delete_label(new_node_id, "Actor")
81
+ labels = @neo.get_node_labels(new_node_id)
82
+ expect(labels).to eq([])
83
+ end
84
+
85
+ it "cannot delete a label from a node that doesn't exist" do
86
+ new_node = @neo.create_node
87
+ new_node_id = new_node["self"].split('/').last
88
+ expect {
89
+ @neo.delete_label(new_node_id.to_i + 1, "Actor")
90
+ }.to raise_error Neography::NodeNotFoundException
91
+ end
92
+ end
93
+
94
+ describe "get_nodes_labeled" do
95
+ it "can get a node with a label" do
96
+ new_node = @neo.create_node
97
+ new_node_id = new_node["self"].split('/').last
98
+ @neo.set_label(new_node_id, ["Actor", "Director"])
99
+ nodes = @neo.get_nodes_labeled("Actor")
100
+ expect(nodes.last["self"].split('/').last).to eq(new_node_id)
101
+ end
102
+
103
+ it "returns an empty array on non-existing label" do
104
+ nodes = @neo.get_nodes_labeled("do_not_exist")
105
+ expect(nodes).to eq([])
106
+ end
107
+ end
108
+
109
+ describe "find_nodes_labeled" do
110
+ it "can find a node with a label and a property" do
111
+ new_node = @neo.create_node(:name => "max")
112
+ new_node_id = new_node["self"].split('/').last
113
+ @neo.set_label(new_node_id, "clown")
114
+ nodes = @neo.find_nodes_labeled("clown", { :name => "max" })
115
+ expect(nodes.last["self"].split('/').last).to eq(new_node_id)
116
+ end
117
+
118
+ it "returns an empty array on non-existing label property" do
119
+ new_node = @neo.create_node(:name => "max")
120
+ new_node_id = new_node["self"].split('/').last
121
+ @neo.set_label(new_node_id, "clown")
122
+ nodes = @neo.find_nodes_labeled("clown", { :name => "does_not_exist" })
123
+ expect(nodes).to eq([])
124
+ end
125
+
126
+ end
127
+
128
+ end
@@ -0,0 +1,274 @@
1
+ # Encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Neography::Rest do
6
+ before(:each) do
7
+ @neo = Neography::Rest.new
8
+ end
9
+
10
+ describe "get_root" do
11
+ it "can get the root node", :reference => true do
12
+ root_node = @neo.get_root
13
+ expect(root_node).to have_key("self")
14
+ expect(root_node["self"].split('/').last).to eq("0")
15
+ end
16
+ end
17
+
18
+ describe "create_node" do
19
+ it "can create an empty node" do
20
+ new_node = @neo.create_node
21
+ expect(new_node).not_to be_nil
22
+ end
23
+
24
+ it "can create a node with one property" do
25
+ new_node = @neo.create_node("name" => "Max")
26
+ expect(new_node["data"]["name"]).to eq("Max")
27
+ end
28
+
29
+ it "can create a node with nil properties" do
30
+ new_node = @neo.create_node("name" => "Max", "age" => nil )
31
+ expect(new_node["data"]["name"]).to eq("Max")
32
+ expect(new_node["data"]["age"]).to be_nil
33
+ end
34
+
35
+
36
+ it "can create a node with more than one property" do
37
+ new_node = @neo.create_node("age" => 31, "name" => "Max")
38
+ expect(new_node["data"]["name"]).to eq("Max")
39
+ expect(new_node["data"]["age"]).to eq(31)
40
+ end
41
+
42
+ it "can create a unique node with more than one property" do
43
+ index_name = generate_text(6)
44
+ key = generate_text(6)
45
+ value = generate_text
46
+ @neo.create_node_index(index_name)
47
+ new_node = @neo.create_unique_node(index_name, key, value, {"age" => 31, "name" => "Max"})
48
+ expect(new_node["data"]["name"]).to eq("Max")
49
+ expect(new_node["data"]["age"]).to eq(31)
50
+ new_node_id = new_node["self"].split('/').last
51
+ existing_node = @neo.create_unique_node(index_name, key, value, {"age" => 39, "name" => "Thomas"})
52
+ expect(existing_node["self"].split('/').last).to eq(new_node_id)
53
+ expect(existing_node["data"]["name"]).to eq("Max")
54
+ expect(existing_node["data"]["age"]).to eq(31)
55
+ end
56
+
57
+ end
58
+
59
+ describe "get_node" do
60
+ it "can get a node that exists" do
61
+ new_node = @neo.create_node
62
+ new_node[:id] = new_node["self"].split('/').last
63
+ existing_node = @neo.get_node(new_node)
64
+ expect(existing_node).not_to be_nil
65
+ expect(existing_node).to have_key("self")
66
+ expect(existing_node["self"].split('/').last).to eq(new_node[:id])
67
+ end
68
+
69
+ it "raises an error if it tries to get a node that does not exist" do
70
+ new_node = @neo.create_node
71
+ fake_node = new_node["self"].split('/').last.to_i + 1000
72
+ expect {
73
+ @neo.get_node(fake_node)
74
+ }.to raise_error Neography::NodeNotFoundException
75
+ end
76
+
77
+ it "can get a node with a tilde" do
78
+ new_node = @neo.create_node("name" => "Ateísmo Sureño")
79
+ new_node[:id] = new_node["self"].split('/').last
80
+ existing_node = @neo.get_node(new_node)
81
+ expect(existing_node).not_to be_nil
82
+ expect(existing_node).to have_key("self")
83
+ expect(existing_node["self"].split('/').last).to eq(new_node[:id])
84
+ expect(existing_node["data"]["name"]).to eq("Ateísmo Sureño")
85
+ end
86
+ end
87
+
88
+ describe "set_node_properties" do
89
+ it "can set a node's properties" do
90
+ new_node = @neo.create_node
91
+ @neo.set_node_properties(new_node, {"weight" => 200, "eyes" => "brown"})
92
+ existing_node = @neo.get_node(new_node)
93
+ expect(existing_node["data"]["weight"]).to eq(200)
94
+ expect(existing_node["data"]["eyes"]).to eq("brown")
95
+ end
96
+
97
+ it "it fails to set properties on a node that does not exist" do
98
+ new_node = @neo.create_node
99
+ fake_node = new_node["self"].split('/').last.to_i + 1000
100
+ expect {
101
+ @neo.set_node_properties(fake_node, {"weight" => 150, "hair" => "blonde"})
102
+ }.to raise_error Neography::NodeNotFoundException
103
+ end
104
+ end
105
+
106
+ describe "reset_node_properties" do
107
+ it "can reset a node's properties" do
108
+ new_node = @neo.create_node
109
+ @neo.set_node_properties(new_node, {"weight" => 200, "eyes" => "brown", "hair" => "black"})
110
+ @neo.reset_node_properties(new_node, {"weight" => 190, "eyes" => "blue"})
111
+ existing_node = @neo.get_node(new_node)
112
+ expect(existing_node["data"]["weight"]).to eq(190)
113
+ expect(existing_node["data"]["eyes"]).to eq("blue")
114
+ expect(existing_node["data"]["hair"]).to be_nil
115
+ end
116
+
117
+ it "it fails to reset properties on a node that does not exist" do
118
+ new_node = @neo.create_node
119
+ fake_node = new_node["self"].split('/').last.to_i + 1000
120
+ expect {
121
+ @neo.reset_node_properties(fake_node, {"weight" => 170, "eyes" => "green"})
122
+ }.to raise_error Neography::NodeNotFoundException
123
+ end
124
+ end
125
+
126
+ describe "get_node_properties" do
127
+ it "can get all of a node's properties" do
128
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown")
129
+ node_properties = @neo.get_node_properties(new_node)
130
+ expect(node_properties["weight"]).to eq(200)
131
+ expect(node_properties["eyes"]).to eq("brown")
132
+ end
133
+
134
+ it "can get some of a node's properties" do
135
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown", "height" => "2m")
136
+ node_properties = @neo.get_node_properties(new_node, ["weight", "height"])
137
+ expect(node_properties["weight"]).to eq(200)
138
+ expect(node_properties["height"]).to eq("2m")
139
+ expect(node_properties["eyes"]).to be_nil
140
+ end
141
+
142
+ it "returns nil if it gets the properties on a node that does not have any" do
143
+ new_node = @neo.create_node
144
+ expect(@neo.get_node_properties(new_node)).to be_nil
145
+ end
146
+
147
+ it "raises error if it tries to get some of the properties on a node that does not have any" do
148
+ new_node = @neo.create_node
149
+ expect {
150
+ expect(@neo.get_node_properties(new_node, ["weight", "height"])).to be_nil
151
+ }.to raise_error Neography::NoSuchPropertyException
152
+ end
153
+
154
+ it "raises error if it fails to get properties on a node that does not exist" do
155
+ new_node = @neo.create_node
156
+ fake_node = new_node["self"].split('/').last.to_i + 1000
157
+ expect {
158
+ expect(@neo.get_node_properties(fake_node)).to be_nil
159
+ }.to raise_error Neography::NodeNotFoundException
160
+ end
161
+ end
162
+
163
+ describe "remove_node_properties" do
164
+ it "can remove a node's properties" do
165
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown")
166
+ @neo.remove_node_properties(new_node)
167
+ expect(@neo.get_node_properties(new_node)).to be_nil
168
+ end
169
+
170
+ it "raises error if it fails to remove the properties of a node that does not exist" do
171
+ new_node = @neo.create_node
172
+ fake_node = new_node["self"].split('/').last.to_i + 1000
173
+ expect {
174
+ expect(@neo.remove_node_properties(fake_node)).to be_nil
175
+ }.to raise_error Neography::NodeNotFoundException
176
+ end
177
+
178
+ it "can remove a specific node property" do
179
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown")
180
+ @neo.remove_node_properties(new_node, "weight")
181
+ node_properties = @neo.get_node_properties(new_node)
182
+ expect(node_properties["weight"]).to be_nil
183
+ expect(node_properties["eyes"]).to eq("brown")
184
+ end
185
+
186
+ it "can remove more than one property" do
187
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown", "height" => "2m")
188
+ @neo.remove_node_properties(new_node, ["weight", "eyes"])
189
+ node_properties = @neo.get_node_properties(new_node)
190
+ expect(node_properties["weight"]).to be_nil
191
+ expect(node_properties["eyes"]).to be_nil
192
+ end
193
+ end
194
+
195
+ describe "delete_node" do
196
+ it "can delete an unrelated node" do
197
+ new_node = @neo.create_node
198
+ expect(@neo.delete_node(new_node)).to be_nil
199
+ expect {
200
+ @neo.get_node(new_node)
201
+ }.to raise_error Neography::NodeNotFoundException
202
+ end
203
+
204
+ it "cannot delete a node that has relationships" do
205
+ new_node1 = @neo.create_node
206
+ new_node2 = @neo.create_node
207
+ @neo.create_relationship("friends", new_node1, new_node2)
208
+ expect {
209
+ expect(@neo.delete_node(new_node1)).to be_nil
210
+ }.to raise_error Neography::OperationFailureException
211
+ existing_node = @neo.get_node(new_node1)
212
+ expect(existing_node).not_to be_nil
213
+ end
214
+
215
+ it "raises error if it tries to delete a node that does not exist" do
216
+ new_node = @neo.create_node
217
+ fake_node = new_node["self"].split('/').last.to_i + 1000
218
+ expect {
219
+ expect(@neo.delete_node(fake_node)).to be_nil
220
+ }.to raise_error Neography::NodeNotFoundException
221
+ end
222
+
223
+ it "raises error if it tries to delete a node that has already been deleted" do
224
+ new_node = @neo.create_node
225
+ expect(@neo.delete_node(new_node)).to be_nil
226
+ expect {
227
+ existing_node = @neo.get_node(new_node)
228
+ }.to raise_error Neography::NodeNotFoundException
229
+ expect {
230
+ expect(@neo.delete_node(new_node)).to be_nil
231
+ }.to raise_error Neography::NodeNotFoundException
232
+ end
233
+ end
234
+
235
+ describe "delete_node!" do
236
+ it "can delete an unrelated node" do
237
+ new_node = @neo.create_node
238
+ expect(@neo.delete_node!(new_node)).to be_nil
239
+ expect {
240
+ existing_node = @neo.get_node(new_node)
241
+ }.to raise_error Neography::NodeNotFoundException
242
+ end
243
+
244
+ it "can delete a node that has relationships" do
245
+ new_node1 = @neo.create_node
246
+ new_node2 = @neo.create_node
247
+ @neo.create_relationship("friends", new_node1, new_node2)
248
+ expect(@neo.delete_node!(new_node1)).to be_nil
249
+ expect {
250
+ existing_node = @neo.get_node(new_node1)
251
+ }.to raise_error Neography::NodeNotFoundException
252
+ end
253
+
254
+ it "raises error if it tries to delete a node that does not exist" do
255
+ new_node = @neo.create_node
256
+ fake_node = new_node["self"].split('/').last.to_i + 1000
257
+ expect {
258
+ expect(@neo.delete_node!(fake_node)).to be_nil
259
+ }.to raise_error Neography::NodeNotFoundException
260
+ end
261
+
262
+ it "raises error if it tries to delete a node that has already been deleted" do
263
+ new_node = @neo.create_node
264
+ expect(@neo.delete_node!(new_node)).to be_nil
265
+ expect {
266
+ existing_node = @neo.get_node(new_node)
267
+ }.to raise_error Neography::NodeNotFoundException
268
+ expect {
269
+ expect(@neo.delete_node!(new_node)).to be_nil
270
+ }.to raise_error Neography::NodeNotFoundException
271
+ end
272
+ end
273
+
274
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ describe "get_relationship" do
9
+ it "can get a relationship that exists" 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
+ existing_relationships = @neo.get_node_relationships_to(new_node1, new_node2)
14
+ expect(existing_relationships[0]).not_to be_nil
15
+ expect(existing_relationships[0]).to have_key("self")
16
+ expect(existing_relationships[0]["self"]).to eq(new_relationship["self"])
17
+ end
18
+
19
+ it "returns empty array if it tries to get a relationship that does not exist" do
20
+ new_node1 = @neo.create_node
21
+ new_node2 = @neo.create_node
22
+ new_node3 = @neo.create_node
23
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
24
+ existing_relationship = @neo.get_node_relationships_to(new_node1, new_node3)
25
+ expect(existing_relationship).to be_empty
26
+ end
27
+ end
28
+
29
+ describe "get_node_relationships" do
30
+ it "can get a node's relationship" do
31
+ new_node1 = @neo.create_node
32
+ new_node2 = @neo.create_node
33
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
34
+ relationships = @neo.get_node_relationships_to(new_node1, new_node2)
35
+ expect(relationships).not_to be_nil
36
+ expect(relationships[0]["start"]).to eq(new_node1["self"])
37
+ expect(relationships[0]["end"]).to eq(new_node2["self"])
38
+ expect(relationships[0]["type"]).to eq("friends")
39
+ expect(relationships[0]["data"]["met"]).to eq("college")
40
+ expect(relationships[0]["data"]["since"]).to eq('10-1-2005')
41
+ end
42
+
43
+ it "can get a node's multiple relationships" do
44
+ new_node1 = @neo.create_node
45
+ new_node2 = @neo.create_node
46
+ new_node3 = @neo.create_node
47
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
48
+ new_relationship = @neo.create_relationship("enemies", new_node1, new_node2, {"since" => '10-2-2010', "met" => "work"})
49
+ relationships = @neo.get_node_relationships_to(new_node1, new_node2)
50
+ expect(relationships).not_to be_nil
51
+ expect(relationships[0]["start"]).to eq(new_node1["self"])
52
+ expect(relationships[0]["end"]).to eq(new_node2["self"])
53
+ expect(relationships[0]["type"]).to eq("friends")
54
+ expect(relationships[0]["data"]["met"]).to eq("college")
55
+ expect(relationships[0]["data"]["since"]).to eq('10-1-2005')
56
+ expect(relationships[1]["start"]).to eq(new_node1["self"])
57
+ expect(relationships[1]["end"]).to eq(new_node2["self"])
58
+ expect(relationships[1]["type"]).to eq("enemies")
59
+ expect(relationships[1]["data"]["met"]).to eq("work")
60
+ expect(relationships[1]["data"]["since"]).to eq('10-2-2010')
61
+ end
62
+
63
+ it "can get all of a node's outgoing relationship" do
64
+ new_node1 = @neo.create_node
65
+ new_node2 = @neo.create_node
66
+ new_node3 = @neo.create_node
67
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
68
+ new_relationship = @neo.create_relationship("enemies", new_node2, new_node1, {"since" => '10-2-2010', "met" => "work"})
69
+ relationships = @neo.get_node_relationships_to(new_node1, new_node2, "out")
70
+ expect(relationships).not_to be_nil
71
+ expect(relationships[0]["start"]).to eq(new_node1["self"])
72
+ expect(relationships[0]["end"]).to eq(new_node2["self"])
73
+ expect(relationships[0]["type"]).to eq("friends")
74
+ expect(relationships[0]["data"]["met"]).to eq("college")
75
+ expect(relationships[0]["data"]["since"]).to eq('10-1-2005')
76
+ expect(relationships[1]).to be_nil
77
+ end
78
+
79
+ it "can get all of a node's incoming relationship" do
80
+ new_node1 = @neo.create_node
81
+ new_node2 = @neo.create_node
82
+ new_node3 = @neo.create_node
83
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
84
+ new_relationship = @neo.create_relationship("enemies", new_node3, new_node1, {"since" => '10-2-2010', "met" => "work"})
85
+ relationships = @neo.get_node_relationships_to(new_node1, new_node3, "in")
86
+ expect(relationships).not_to be_nil
87
+ expect(relationships[0]["start"]).to eq(new_node3["self"])
88
+ expect(relationships[0]["end"]).to eq(new_node1["self"])
89
+ expect(relationships[0]["type"]).to eq("enemies")
90
+ expect(relationships[0]["data"]["met"]).to eq("work")
91
+ expect(relationships[0]["data"]["since"]).to eq('10-2-2010')
92
+ expect(relationships[1]).to be_nil
93
+ end
94
+
95
+ it "can get a specific type of node relationships" do
96
+ new_node1 = @neo.create_node
97
+ new_node2 = @neo.create_node
98
+ new_node3 = @neo.create_node
99
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
100
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node3, {"since" => '10-2-2010', "met" => "work"})
101
+ relationships = @neo.get_node_relationships_to(new_node1, new_node2, "all", "friends")
102
+ expect(relationships).not_to be_nil
103
+ expect(relationships[0]["start"]).to eq(new_node1["self"])
104
+ expect(relationships[0]["end"]).to eq(new_node2["self"])
105
+ expect(relationships[0]["type"]).to eq("friends")
106
+ expect(relationships[0]["data"]["met"]).to eq("college")
107
+ expect(relationships[0]["data"]["since"]).to eq('10-1-2005')
108
+ expect(relationships[1]).to be_nil
109
+ end
110
+
111
+ it "can get a specific type and direction of a node relationships" do
112
+ new_node1 = @neo.create_node
113
+ new_node2 = @neo.create_node
114
+ new_node3 = @neo.create_node
115
+ new_node4 = @neo.create_node
116
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"})
117
+ new_relationship = @neo.create_relationship("enemies", new_node1, new_node3, {"since" => '10-2-2010', "met" => "work"})
118
+ new_relationship = @neo.create_relationship("enemies", new_node4, new_node1, {"since" => '10-3-2010', "met" => "gym"})
119
+ relationships = @neo.get_node_relationships_to(new_node1, new_node4, "in", "enemies")
120
+ expect(relationships).not_to be_nil
121
+ expect(relationships[0]["start"]).to eq(new_node4["self"])
122
+ expect(relationships[0]["end"]).to eq(new_node1["self"])
123
+ expect(relationships[0]["type"]).to eq("enemies")
124
+ expect(relationships[0]["data"]["met"]).to eq("gym")
125
+ expect(relationships[0]["data"]["since"]).to eq('10-3-2010')
126
+ expect(relationships[1]).to be_nil
127
+ end
128
+
129
+ it "returns nil if there are no relationships" do
130
+ new_node1 = @neo.create_node
131
+ new_node2 = @neo.create_node
132
+ relationships = @neo.get_node_relationships_to(new_node1, new_node2)
133
+ expect(relationships).to be_empty
134
+ end
135
+ end
136
+
137
+ end