neography 0.0.31 → 1.0.0

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.
Files changed (85) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +1 -1
  3. data/CONTRIBUTORS +2 -1
  4. data/README.md +247 -0
  5. data/Rakefile +1 -2
  6. data/lib/neography/config.rb +48 -16
  7. data/lib/neography/connection.rb +151 -0
  8. data/lib/neography/errors.rb +42 -0
  9. data/lib/neography/node.rb +17 -14
  10. data/lib/neography/node_relationship.rb +3 -1
  11. data/lib/neography/node_traverser.rb +24 -20
  12. data/lib/neography/property.rb +31 -28
  13. data/lib/neography/property_container.rb +1 -1
  14. data/lib/neography/relationship.rb +16 -19
  15. data/lib/neography/rest/auto_indexes.rb +64 -0
  16. data/lib/neography/rest/batch.rb +262 -0
  17. data/lib/neography/rest/clean.rb +19 -0
  18. data/lib/neography/rest/cypher.rb +24 -0
  19. data/lib/neography/rest/gremlin.rb +24 -0
  20. data/lib/neography/rest/helpers.rb +26 -0
  21. data/lib/neography/rest/indexes.rb +97 -0
  22. data/lib/neography/rest/node_auto_indexes.rb +14 -0
  23. data/lib/neography/rest/node_indexes.rb +35 -0
  24. data/lib/neography/rest/node_paths.rb +57 -0
  25. data/lib/neography/rest/node_properties.rb +11 -0
  26. data/lib/neography/rest/node_relationships.rb +53 -0
  27. data/lib/neography/rest/node_traversal.rb +81 -0
  28. data/lib/neography/rest/nodes.rb +102 -0
  29. data/lib/neography/rest/paths.rb +36 -0
  30. data/lib/neography/rest/properties.rb +56 -0
  31. data/lib/neography/rest/relationship_auto_indexes.rb +14 -0
  32. data/lib/neography/rest/relationship_indexes.rb +35 -0
  33. data/lib/neography/rest/relationship_properties.rb +11 -0
  34. data/lib/neography/rest/relationships.rb +23 -0
  35. data/lib/neography/rest.rb +285 -615
  36. data/lib/neography/tasks.rb +1 -1
  37. data/lib/neography/version.rb +1 -1
  38. data/lib/neography.rb +13 -2
  39. data/neography.gemspec +8 -8
  40. data/spec/integration/authorization_spec.rb +2 -2
  41. data/spec/integration/index_spec.rb +4 -4
  42. data/spec/integration/neography_spec.rb +2 -2
  43. data/spec/integration/node_path_spec.rb +2 -2
  44. data/spec/integration/node_relationship_spec.rb +5 -3
  45. data/spec/integration/node_spec.rb +20 -19
  46. data/spec/integration/parsing_spec.rb +2 -2
  47. data/spec/integration/relationship_spec.rb +2 -2
  48. data/spec/integration/rest_batch_spec.rb +28 -28
  49. data/spec/integration/rest_bulk_spec.rb +2 -2
  50. data/spec/integration/rest_experimental_spec.rb +2 -2
  51. data/spec/integration/rest_gremlin_fail_spec.rb +2 -2
  52. data/spec/integration/rest_header_spec.rb +4 -9
  53. data/spec/integration/rest_index_spec.rb +21 -1
  54. data/spec/integration/rest_node_spec.rb +58 -44
  55. data/spec/integration/rest_path_spec.rb +5 -5
  56. data/spec/integration/rest_plugin_spec.rb +8 -2
  57. data/spec/integration/rest_relationship_spec.rb +35 -30
  58. data/spec/integration/rest_traverse_spec.rb +2 -2
  59. data/spec/matchers.rb +33 -0
  60. data/spec/neography_spec.rb +23 -0
  61. data/spec/spec_helper.rb +19 -1
  62. data/spec/unit/config_spec.rb +46 -0
  63. data/spec/unit/connection_spec.rb +205 -0
  64. data/spec/unit/node_spec.rb +100 -0
  65. data/spec/unit/properties_spec.rb +136 -0
  66. data/spec/unit/relationship_spec.rb +118 -0
  67. data/spec/unit/rest/batch_spec.rb +243 -0
  68. data/spec/unit/rest/clean_spec.rb +17 -0
  69. data/spec/unit/rest/cypher_spec.rb +21 -0
  70. data/spec/unit/rest/gremlin_spec.rb +26 -0
  71. data/spec/unit/rest/node_auto_indexes_spec.rb +67 -0
  72. data/spec/unit/rest/node_indexes_spec.rb +126 -0
  73. data/spec/unit/rest/node_paths_spec.rb +80 -0
  74. data/spec/unit/rest/node_properties_spec.rb +80 -0
  75. data/spec/unit/rest/node_relationships_spec.rb +78 -0
  76. data/spec/unit/rest/node_traversal_spec.rb +128 -0
  77. data/spec/unit/rest/nodes_spec.rb +188 -0
  78. data/spec/unit/rest/paths_spec.rb +69 -0
  79. data/spec/unit/rest/relationship_auto_indexes_spec.rb +67 -0
  80. data/spec/unit/rest/relationship_indexes_spec.rb +128 -0
  81. data/spec/unit/rest/relationship_properties_spec.rb +80 -0
  82. data/spec/unit/rest/relationships_spec.rb +22 -0
  83. metadata +86 -19
  84. data/Gemfile.lock +0 -44
  85. data/README.rdoc +0 -420
@@ -0,0 +1,243 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe Batch do
6
+
7
+ let(:connection) { stub(:gremlin_path => "/gremlin", :cypher_path => "/cypher") }
8
+ subject { Batch.new(connection) }
9
+
10
+ it "gets nodes" do
11
+ expected_body = [
12
+ { "id" => 0, "method" => "GET", "to" => "/node/foo" },
13
+ { "id" => 1, "method" => "GET", "to" => "/node/bar" }
14
+ ]
15
+
16
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
17
+ subject.execute [:get_node, "foo"], [:get_node, "bar"]
18
+ end
19
+
20
+ it "creates nodes" do
21
+ expected_body = [
22
+ { "id" => 0, "method" => "POST", "to" => "/node", "body" => { "foo" => "bar" } },
23
+ { "id" => 1, "method" => "POST", "to" => "/node", "body" => { "baz" => "qux" } }
24
+ ]
25
+
26
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
27
+ subject.execute [:create_node, { "foo" => "bar" }], [:create_node, { "baz" => "qux" }]
28
+ end
29
+
30
+ it "deletes nodes" do
31
+ expected_body = [
32
+ { "id" => 0, "method" => "DELETE", "to" => "/node/foo" },
33
+ { "id" => 1, "method" => "DELETE", "to" => "/node/bar" }
34
+ ]
35
+
36
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
37
+ subject.execute [:delete_node, "foo"], [:delete_node, "bar"]
38
+ end
39
+
40
+ it "creates unique nodes" do
41
+ expected_body = [
42
+ { "id" => 0, "method" => "POST", "to" => "/index/node/foo?unique", "body" => { "key" => "bar", "value" => "baz", "properties" => "qux" } },
43
+ { "id" => 1, "method" => "POST", "to" => "/index/node/quux?unique", "body" => { "key" => "corge", "value" => "grault", "properties" => "garply" } }
44
+ ]
45
+
46
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
47
+ subject.execute [:create_unique_node, "foo", "bar", "baz", "qux" ],
48
+ [:create_unique_node, "quux", "corge", "grault", "garply"]
49
+ end
50
+
51
+ it "adds nodes to an index" do
52
+ expected_body = [
53
+ { "id" => 0, "method" => "POST", "to" => "/index/node/foo", "body" => { "uri" => "/node/qux", "key" => "bar", "value" => "baz" } },
54
+ { "id" => 1, "method" => "POST", "to" => "/index/node/quux", "body" => { "uri" => "{0}", "key" => "corge", "value" => "grault" } }
55
+ ]
56
+
57
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
58
+ subject.execute [:add_node_to_index, "foo", "bar", "baz", "qux" ],
59
+ [:add_node_to_index, "quux", "corge", "grault", "{0}"]
60
+ end
61
+
62
+ it "gets nodes from an index" do
63
+ expected_body = [
64
+ { "id" => 0, "method" => "GET", "to" => "/index/node/foo/bar/baz" },
65
+ { "id" => 1, "method" => "GET", "to" => "/index/node/qux/quux/corge" }
66
+ ]
67
+
68
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
69
+ subject.execute [:get_node_index, "foo", "bar", "baz" ],
70
+ [:get_node_index, "qux", "quux", "corge" ]
71
+ end
72
+
73
+ it "deletes nodes from an index" do
74
+ expected_body = [
75
+ { "id" => 0, "method" => "DELETE", "to" => "/index/node/index1/id1" },
76
+ { "id" => 1, "method" => "DELETE", "to" => "/index/node/index2/key2/id2" },
77
+ { "id" => 2, "method" => "DELETE", "to" => "/index/node/index3/key3/value3/id3" }
78
+ ]
79
+
80
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
81
+ subject.execute [:remove_node_from_index, "index1", "id1", ],
82
+ [:remove_node_from_index, "index2", "key2", "id2" ],
83
+ [:remove_node_from_index, "index3", "key3", "value3", "id3" ]
84
+ end
85
+
86
+ it "sets node properties" do
87
+ expected_body = [
88
+ { "id" => 0, "method" => "PUT", "to" => "/node/index1/properties/key1", "body" => "value1" },
89
+ { "id" => 1, "method" => "PUT", "to" => "/node/index2/properties/key2", "body" => "value2" }
90
+ ]
91
+
92
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
93
+ subject.execute [:set_node_property, "index1", { "key1" => "value1" } ],
94
+ [:set_node_property, "index2", { "key2" => "value2" } ]
95
+ end
96
+
97
+ it "resets node properties" do
98
+ expected_body = [
99
+ { "id" => 0, "method" => "PUT", "to" => "/node/index1/properties", "body" => { "key1" => "value1" } },
100
+ { "id" => 1, "method" => "PUT", "to" => "/node/index2/properties", "body" => { "key2" => "value2" } }
101
+ ]
102
+
103
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
104
+ subject.execute [:reset_node_properties, "index1", { "key1" => "value1" } ],
105
+ [:reset_node_properties, "index2", { "key2" => "value2" } ]
106
+ end
107
+
108
+ it "gets node relationships" do
109
+ expected_body = [
110
+ { "id" => 0, "method" => "GET", "to" => "/node/id1/relationships/direction1" },
111
+ { "id" => 1, "method" => "GET", "to" => "/node/id2/relationships/all" }
112
+ ]
113
+
114
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
115
+ subject.execute [:get_node_relationships, "id1", "direction1" ],
116
+ [:get_node_relationships, "id2" ]
117
+ end
118
+
119
+ it "gets relationships" do
120
+ expected_body = [
121
+ { "id" => 0, "method" => "GET", "to" => "/relationship/foo" },
122
+ { "id" => 1, "method" => "GET", "to" => "/relationship/bar" }
123
+ ]
124
+
125
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
126
+ subject.execute [:get_relationship, "foo"], [:get_relationship, "bar"]
127
+ end
128
+
129
+ it "creates relationships" do
130
+ expected_body = [
131
+ { "id" => 0, "method" => "POST", "to" => "/node/from1/relationships", "body" => { "to" => "/node/to1", "type" => "type1", "data" => "data1" } },
132
+ { "id" => 1, "method" => "POST", "to" => "{0}/relationships", "body" => { "to" => "{1}", "type" => "type2", "data" => "data2" } }
133
+ ]
134
+
135
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
136
+ subject.execute [:create_relationship, "type1", "from1", "to1", "data1" ],
137
+ [:create_relationship, "type2", "{0}", "{1}", "data2" ]
138
+ end
139
+
140
+ it "deletes relationships" do
141
+ expected_body = [
142
+ { "id" => 0, "method" => "DELETE", "to" => "/relationship/foo" },
143
+ { "id" => 1, "method" => "DELETE", "to" => "/relationship/bar" }
144
+ ]
145
+
146
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
147
+ subject.execute [:delete_relationship, "foo"], [:delete_relationship, "bar"]
148
+ end
149
+
150
+ it "creates unique nodes" do
151
+ expected_body = [
152
+ { "id" => 0, "method" => "POST", "to" => "/index/relationship/index1?unique", "body" => { "key" => "key1", "value" => "value1", "type" => "type1", "start" => "/node/node1", "end" => "/node/node2" } },
153
+ { "id" => 1, "method" => "POST", "to" => "/index/relationship/index2?unique", "body" => { "key" => "key2", "value" => "value2", "type" => "type2", "start" => "{0}", "end" => "{1}" } }
154
+ ]
155
+
156
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
157
+ subject.execute [:create_unique_relationship, "index1", "key1", "value1", "type1", "node1", "node2" ],
158
+ [:create_unique_relationship, "index2", "key2", "value2", "type2", "{0}", "{1}" ]
159
+ end
160
+
161
+ it "adds relationships to an index" do
162
+ expected_body = [
163
+ { "id" => 0, "method" => "POST", "to" => "/index/relationship/index1", "body" => { "uri" => "/relationship/rel1", "key" => "key1", "value" => "value1" } },
164
+ { "id" => 1, "method" => "POST", "to" => "/index/relationship/index2", "body" => { "uri" => "{0}", "key" => "key2", "value" => "value2" } }
165
+ ]
166
+
167
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
168
+ subject.execute [:add_relationship_to_index, "index1", "key1", "value1", "rel1" ],
169
+ [:add_relationship_to_index, "index2", "key2", "value2", "{0}"]
170
+ end
171
+
172
+ it "gets relationships from an index" do
173
+ expected_body = [
174
+ { "id" => 0, "method" => "GET", "to" => "/index/relationship/foo/bar/baz" },
175
+ { "id" => 1, "method" => "GET", "to" => "/index/relationship/qux/quux/corge" }
176
+ ]
177
+
178
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
179
+ subject.execute [:get_relationship_index, "foo", "bar", "baz" ],
180
+ [:get_relationship_index, "qux", "quux", "corge" ]
181
+ end
182
+
183
+ it "deletes relationships from an index" do
184
+ expected_body = [
185
+ { "id" => 0, "method" => "DELETE", "to" => "/index/relationship/index1/id1" },
186
+ { "id" => 1, "method" => "DELETE", "to" => "/index/relationship/index2/key2/id2" },
187
+ { "id" => 2, "method" => "DELETE", "to" => "/index/relationship/index3/key3/value3/id3" }
188
+ ]
189
+
190
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
191
+ subject.execute [:remove_relationship_from_index, "index1", "id1", ],
192
+ [:remove_relationship_from_index, "index2", "key2", "id2" ],
193
+ [:remove_relationship_from_index, "index3", "key3", "value3", "id3" ]
194
+ end
195
+
196
+ it "sets relationship properties" do
197
+ expected_body = [
198
+ { "id" => 0, "method" => "PUT", "to" => "/relationship/index1/properties/key1", "body" => "value1" },
199
+ { "id" => 1, "method" => "PUT", "to" => "/relationship/index2/properties/key2", "body" => "value2" }
200
+ ]
201
+
202
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
203
+ subject.execute [:set_relationship_property, "index1", { "key1" => "value1" } ],
204
+ [:set_relationship_property, "index2", { "key2" => "value2" } ]
205
+ end
206
+
207
+ it "resets relationship properties" do
208
+ expected_body = [
209
+ { "id" => 0, "method" => "PUT", "to" => "/relationship/index1/properties", "body" => { "key1" => "value1" } },
210
+ { "id" => 1, "method" => "PUT", "to" => "{0}/properties", "body" => { "key2" => "value2" } }
211
+ ]
212
+
213
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
214
+ subject.execute [:reset_relationship_properties, "index1", { "key1" => "value1" } ],
215
+ [:reset_relationship_properties, "{0}", { "key2" => "value2" } ]
216
+ end
217
+
218
+ it "executes scripts" do
219
+ expected_body = [
220
+ { "id" => 0, "method" => "POST", "to" => "/gremlin", "body" => { "script" => "script1", "params" => "params1" } },
221
+ { "id" => 1, "method" => "POST", "to" => "/gremlin", "body" => { "script" => "script2", "params" => "params2" } }
222
+ ]
223
+
224
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
225
+ subject.execute [:execute_script, "script1", "params1"],
226
+ [:execute_script, "script2", "params2"]
227
+ end
228
+
229
+ it "executes queries" do
230
+ expected_body = [
231
+ { "id" => 0, "method" => "POST", "to" => "/cypher", "body" => { "query" => "query1", "params" => "params1" } },
232
+ { "id" => 1, "method" => "POST", "to" => "/cypher", "body" => { "query" => "query2" } }
233
+ ]
234
+
235
+ connection.should_receive(:post).with("/batch", json_match(:body, expected_body))
236
+ subject.execute [:execute_query, "query1", "params1"],
237
+ [:execute_query, "query2" ]
238
+ end
239
+
240
+ end
241
+ end
242
+ end
243
+
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe Clean do
6
+
7
+ let(:connection) { stub }
8
+ subject { Clean.new(connection) }
9
+
10
+ it "cleans the database" do
11
+ connection.should_receive(:delete).with("/cleandb/secret-key")
12
+ subject.execute
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe Cypher do
6
+
7
+ let(:connection) { stub(:cypher_path => "/cypher") }
8
+ subject { Cypher.new(connection) }
9
+
10
+ it "executes a cypher query" do
11
+ options = {
12
+ :body=>"{\"query\":\"SOME QUERY\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}",
13
+ :headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true"}
14
+ }
15
+ connection.should_receive(:post).with("/cypher", options)
16
+ subject.query("SOME QUERY", { :foo => "bar", :baz => "qux" })
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe Gremlin do
6
+
7
+ let(:connection) { stub(:gremlin_path => "/gremlin") }
8
+ subject { Gremlin.new(connection) }
9
+
10
+ it "executes a gremlin script" do
11
+ options = {
12
+ :body=>"{\"script\":\"SOME SCRIPT\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}",
13
+ :headers=>{"Content-Type"=>"application/json"}
14
+ }
15
+ connection.should_receive(:post).with("/gremlin", options)
16
+ subject.execute("SOME SCRIPT", { :foo => "bar", :baz => "qux" })
17
+ end
18
+
19
+ it "returns nil if script result is null" do
20
+ connection.stub(:post).and_return("null")
21
+ subject.execute("", {}).should be_nil
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe NodeAutoIndexes do
6
+
7
+ let(:connection) { stub }
8
+ subject { NodeAutoIndexes.new(connection) }
9
+
10
+ it "gets a node from an auto index" do
11
+ connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
12
+ subject.get("some_key", "some_value")
13
+ end
14
+
15
+ it "returns nil if nothing was found in the auto index" do
16
+ connection.stub(:get).and_return(nil)
17
+ subject.get("some_key", "some_value").should be_nil
18
+ end
19
+
20
+ it "finds by key and value if value passed to #find_or_query" do
21
+ connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
22
+ subject.find_or_query("some_key", "some_value")
23
+ end
24
+
25
+ it "finds by query if no value passed to #find_or_query" do
26
+ connection.should_receive(:get).with("/index/auto/node/?query=some_query")
27
+ subject.find_or_query("some_query")
28
+ end
29
+
30
+ it "finds by key and value" do
31
+ connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
32
+ subject.find("some_key", "some_value")
33
+ end
34
+
35
+ it "finds by query" do
36
+ connection.should_receive(:get).with("/index/auto/node/?query=some_query")
37
+ subject.query("some_query")
38
+ end
39
+
40
+ it "gets the status" do
41
+ connection.should_receive(:get).with("/index/auto/node/status")
42
+ subject.status
43
+ end
44
+
45
+ it "sets the status" do
46
+ connection.should_receive(:put).with("/index/auto/node/status", hash_match(:body, '"foo"'))
47
+ subject.status = "foo"
48
+ end
49
+
50
+ it "gets auto index properties" do
51
+ connection.should_receive(:get).with("/index/auto/node/properties")
52
+ subject.properties
53
+ end
54
+
55
+ it "adds a property to an auto index" do
56
+ connection.should_receive(:post).with("/index/auto/node/properties", hash_match(:body, "foo"))
57
+ subject.add_property("foo")
58
+ end
59
+
60
+ it "removes a property from an auto index" do
61
+ connection.should_receive(:delete).with("/index/auto/node/properties/foo")
62
+ subject.remove_property("foo")
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe NodeIndexes do
6
+
7
+ let(:connection) { stub(:configuration => "http://configuration") }
8
+ subject { NodeIndexes.new(connection) }
9
+
10
+ it "lists all indexes" do
11
+ connection.should_receive(:get).with("/index/node")
12
+ subject.list
13
+ end
14
+
15
+ it "creates a node index" do
16
+ expected_body = {
17
+ "config" => {
18
+ "type" => "some_type",
19
+ "provider" => "some_provider"
20
+ },
21
+ "name" => "some_index"
22
+ }
23
+ connection.should_receive(:post).with("/index/node", json_match(:body, expected_body))
24
+ subject.create("some_index", "some_type", "some_provider")
25
+ end
26
+
27
+ it "returns the post result after creation" do
28
+ connection.stub(:post).and_return("foo")
29
+ subject.create("some_index", "some_type", "some_provider").should == "foo"
30
+ end
31
+
32
+ it "creates an auto-index" do
33
+ expected_body = {
34
+ "config" => {
35
+ "type" => "some_type",
36
+ "provider" => "some_provider"
37
+ },
38
+ "name" => "node_auto_index"
39
+ }
40
+ connection.should_receive(:post).with("/index/node", json_match(:body, expected_body))
41
+ subject.create_auto("some_type", "some_provider")
42
+ end
43
+
44
+ it "creates a unique node in an index" do
45
+ expected_body = {
46
+ "properties" => "properties",
47
+ "key" => "key",
48
+ "value" => "value"
49
+ }
50
+ connection.should_receive(:post).with("/index/node/some_index?unique", json_match(:body, expected_body))
51
+ subject.create_unique("some_index", "key", "value", "properties")
52
+ end
53
+
54
+ it "adds a node to an index" do
55
+ expected_body = {
56
+ "uri" => "http://configuration/node/42",
57
+ "key" => "key",
58
+ "value" => "value"
59
+ }
60
+ connection.should_receive(:post).with("/index/node/some_index", json_match(:body, expected_body))
61
+ subject.add("some_index", "key", "value", "42")
62
+ end
63
+
64
+ it "gets a node from an index" do
65
+ connection.should_receive(:get).with("/index/node/some_index/some_key/some_value")
66
+ subject.get("some_index", "some_key", "some_value")
67
+ end
68
+
69
+ it "returns nil if nothing was found in the index" do
70
+ connection.stub(:get).and_return(nil)
71
+ subject.get("some_index", "some_key", "some_value").should be_nil
72
+ end
73
+
74
+ it "finds by key and value if both passed to #find" do
75
+ connection.should_receive(:get).with("/index/node/some_index/some_key/some_value")
76
+ subject.find("some_index", "some_key", "some_value")
77
+ end
78
+
79
+ it "finds by query if no value passed to #find" do
80
+ connection.should_receive(:get).with("/index/node/some_index?query=some_query")
81
+ subject.find("some_index", "some_query")
82
+ end
83
+
84
+ it "finds by key and value" do
85
+ connection.should_receive(:get).with("/index/node/some_index/some_key/some_value")
86
+ subject.find_by_key_value("some_index", "some_key", "some_value")
87
+ end
88
+
89
+ it "finds by query" do
90
+ connection.should_receive(:get).with("/index/node/some_index?query=some_query")
91
+ subject.find_by_query("some_index", "some_query")
92
+ end
93
+
94
+ it "removes a node from an index by id for #remove with two arguments" do
95
+ connection.should_receive(:delete).with("/index/node/some_index/42")
96
+ subject.remove("some_index", "42")
97
+ end
98
+
99
+ it "removes a node from an index by key for #remove with three arguments" do
100
+ connection.should_receive(:delete).with("/index/node/some_index/some_key/42")
101
+ subject.remove("some_index", "some_key", "42")
102
+ end
103
+
104
+ it "removes a node from an index by key and value for #remove with four arguments" do
105
+ connection.should_receive(:delete).with("/index/node/some_index/some_key/some_value/42")
106
+ subject.remove("some_index", "some_key", "some_value", "42")
107
+ end
108
+
109
+ it "removes a node from an index" do
110
+ connection.should_receive(:delete).with("/index/node/some_index/42")
111
+ subject.remove_by_id("some_index", "42")
112
+ end
113
+
114
+ it "removes a node from an index by key" do
115
+ connection.should_receive(:delete).with("/index/node/some_index/some_key/42")
116
+ subject.remove_by_key("some_index", "42", "some_key")
117
+ end
118
+
119
+ it "removes a node from an index by key and value" do
120
+ connection.should_receive(:delete).with("/index/node/some_index/some_key/some_value/42")
121
+ subject.remove_by_value("some_index", "42", "some_key", "some_value")
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe NodePaths do
6
+
7
+ let(:connection) { stub(:configuration => "http://configuration") }
8
+ subject { NodePaths.new(connection) }
9
+
10
+ it "gets a shortest path between two nodes" do
11
+ expected_body = {
12
+ "to" => "http://configuration/node/43",
13
+ "relationships" => "relationships",
14
+ "max_depth" => 3,
15
+ "algorithm" => "shortestPath"
16
+ }
17
+
18
+ connection.should_receive(:post).with("/node/42/path", json_match(:body, expected_body))
19
+
20
+ subject.get("42", "43", "relationships", 3, "shortestPath")
21
+ end
22
+
23
+ it "gets all shortest paths between two nodes" do
24
+ expected_body = {
25
+ "to" => "http://configuration/node/43",
26
+ "relationships" => "relationships",
27
+ "max_depth" => 3,
28
+ "algorithm" => "shortestPath"
29
+ }
30
+
31
+ connection.should_receive(:post).with("/node/42/paths", json_match(:body, expected_body))
32
+
33
+ subject.get_all("42", "43", "relationships", 3, "shortestPath")
34
+ end
35
+
36
+ it "gets all shortest weighted paths between two nodes" do
37
+ expected_body = {
38
+ "to" => "http://configuration/node/43",
39
+ "relationships" => "relationships",
40
+ "cost_property" => "cost",
41
+ "max_depth" => 3,
42
+ "algorithm" => "shortestPath"
43
+ }
44
+
45
+ connection.should_receive(:post).with("/node/42/paths", json_match(:body, expected_body))
46
+
47
+ subject.shortest_weighted("42", "43", "relationships", "cost", 3, "shortestPath")
48
+ end
49
+
50
+ context "algorithm" do
51
+
52
+ subject { NodePaths.new(nil) }
53
+
54
+ [ :shortest, "shortest", :shortestPath, "shortestPath", :short, "short" ].each do |algorithm|
55
+ it "parses shortestPath" do
56
+ subject.send(:get_algorithm, algorithm).should == "shortestPath"
57
+ end
58
+ end
59
+
60
+ [ :allSimplePaths, "allSimplePaths", :simple, "simple" ].each do |algorithm|
61
+ it "parses allSimplePaths" do
62
+ subject.send(:get_algorithm, algorithm).should == "allSimplePaths"
63
+ end
64
+ end
65
+
66
+ [ :dijkstra, "dijkstra" ].each do |algorithm|
67
+ it "parses dijkstra" do
68
+ subject.send(:get_algorithm, algorithm).should == "dijkstra"
69
+ end
70
+ end
71
+
72
+ it "parses allPaths by default" do
73
+ subject.send(:get_algorithm, "foo").should == "allPaths"
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe NodeProperties do
6
+
7
+ let(:connection) { stub }
8
+ subject { NodeProperties.new(connection) }
9
+
10
+ it "sets properties" do
11
+ options1 = {
12
+ :body => '"bar"',
13
+ :headers => json_content_type
14
+ }
15
+ options2 = {
16
+ :body => '"qux"',
17
+ :headers => json_content_type
18
+ }
19
+ connection.should_receive(:put).with("/node/42/properties/foo", options1)
20
+ connection.should_receive(:put).with("/node/42/properties/baz", options2)
21
+ subject.set("42", {:foo => "bar", :baz => "qux"})
22
+ end
23
+
24
+ it "resets properties" do
25
+ options = {
26
+ :body => '{"foo":"bar"}',
27
+ :headers => json_content_type
28
+ }
29
+ connection.should_receive(:put).with("/node/42/properties", options)
30
+ subject.reset("42", {:foo => "bar"})
31
+ end
32
+
33
+ context "getting properties" do
34
+
35
+ it "gets all properties" do
36
+ connection.should_receive(:get).with("/node/42/properties")
37
+ subject.get("42")
38
+ end
39
+
40
+ it "gets multiple properties" do
41
+ connection.should_receive(:get).with("/node/42/properties/foo")
42
+ connection.should_receive(:get).with("/node/42/properties/bar")
43
+ subject.get("42", "foo", "bar")
44
+ end
45
+
46
+ it "returns multiple properties as a hash" do
47
+ connection.stub(:get).and_return("baz", "qux")
48
+ subject.get("42", "foo", "bar").should == { "foo" => "baz", "bar" => "qux" }
49
+ end
50
+
51
+ it "returns nil if no properties were found" do
52
+ connection.stub(:get).and_return(nil, nil)
53
+ subject.get("42", "foo", "bar").should be_nil
54
+ end
55
+
56
+ it "returns hash without nil return values" do
57
+ connection.stub(:get).and_return("baz", nil)
58
+ subject.get("42", "foo", "bar").should == { "foo" => "baz" }
59
+ end
60
+
61
+ end
62
+
63
+ context "removing properties" do
64
+
65
+ it "removes all properties" do
66
+ connection.should_receive(:delete).with("/node/42/properties")
67
+ subject.remove("42")
68
+ end
69
+
70
+ it "removes multiple properties" do
71
+ connection.should_receive(:delete).with("/node/42/properties/foo")
72
+ connection.should_receive(:delete).with("/node/42/properties/bar")
73
+ subject.remove("42", "foo", "bar")
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+ end
80
+ end