neography-down 1.6.4

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 (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,18 @@
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 relationship types" do
9
+ it "can get a listing of relationship types" 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
+ rel_types = @neo.list_relationship_types
14
+ expect(rel_types).not_to be_nil
15
+ expect(rel_types).to include("friends")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ describe "create a schema index" do
9
+ it "can create a schema index" do
10
+ si = @neo.create_schema_index("person", ["name"])
11
+ expect(si).not_to be_nil
12
+ expect(si["property_keys"]).to include("name")
13
+ end
14
+
15
+ end
16
+
17
+ describe "list schema indexes" do
18
+ it "can get a listing of node indexes" do
19
+ si = @neo.get_schema_index("person")
20
+ expect(si).not_to be_nil
21
+ expect(si.first["label"]).to include("person")
22
+ expect(si.first["property_keys"]).to include("name")
23
+ end
24
+ end
25
+
26
+ describe "drop schema indexes" do
27
+ it "can drop an existing schema index" do
28
+ si = @neo.delete_schema_index("person", "name")
29
+ expect(si).to be_nil
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,166 @@
1
+ require 'spec_helper'
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ describe "find the spatial plugin" do
9
+ it "can get a description of the spatial plugin" do
10
+ si = @neo.get_spatial
11
+ expect(si).not_to be_nil
12
+ expect(si["graphdb"]["addEditableLayer"]).not_to be_nil
13
+ end
14
+ end
15
+
16
+ describe "add a point layer" do
17
+ it "can add a simple point layer" do
18
+ pl = @neo.add_point_layer("restaurants")
19
+ expect(pl).not_to be_nil
20
+ expect(pl.first["data"]["layer"]).to eq("restaurants")
21
+ expect(pl.first["data"]["geomencoder_config"]).to eq("lon:lat")
22
+ end
23
+
24
+ it "can add a simple point layer with lat and long" do
25
+ pl = @neo.add_point_layer("coffee_shops", "latitude", "longitude")
26
+ expect(pl).not_to be_nil
27
+ expect(pl.first["data"]["layer"]).to eq("coffee_shops")
28
+ expect(pl.first["data"]["geomencoder_config"]).to eq("longitude:latitude")
29
+ end
30
+ end
31
+
32
+ describe "add an editable layer" do
33
+ it "can add an editable layer" do
34
+ el = @neo.add_editable_layer("zipcodes", "WKT", "wkt")
35
+ expect(el).not_to be_nil
36
+ expect(el.first["data"]["layer"]).to eq("zipcodes")
37
+ expect(el.first["data"]["geomencoder_config"]).to eq("wkt")
38
+ end
39
+ end
40
+
41
+ describe "get a spatial layer" do
42
+ it "can get a layer" do
43
+ sl = @neo.get_layer("restaurants")
44
+ expect(sl).not_to be_nil
45
+ expect(sl.first["data"]["layer"]).to eq("restaurants")
46
+ end
47
+ end
48
+
49
+ describe "create a spatial index" do
50
+ it "can create a spatial index" do
51
+ index = @neo.create_spatial_index("restaurants")
52
+ expect(index["provider"]).to eq("spatial")
53
+ expect(index["geometry_type"]).to eq("point")
54
+ expect(index["lat"]).to eq("lat")
55
+ expect(index["lon"]).to eq("lon")
56
+ end
57
+ end
58
+
59
+ describe "add geometry to spatial layer" do
60
+ it "can add a geometry" do
61
+ geometry = "LINESTRING (15.2 60.1, 15.3 60.1)"
62
+ geo = @neo.add_geometry_to_layer("zipcodes", geometry)
63
+ expect(geo).not_to be_nil
64
+ expect(geo.first["data"]["wkt"]).to eq(geometry)
65
+ end
66
+ end
67
+
68
+ describe "update geometry from spatial layer" do
69
+ it "can update a geometry" do
70
+ geometry = "LINESTRING (15.2 60.1, 15.3 60.1)"
71
+ geo = @neo.add_geometry_to_layer("zipcodes", geometry)
72
+ expect(geo).not_to be_nil
73
+ expect(geo.first["data"]["wkt"]).to eq(geometry)
74
+ geometry = "LINESTRING (14.7 60.1, 15.3 60.1)"
75
+ existing_geo = @neo.edit_geometry_from_layer("zipcodes", geometry, geo)
76
+ expect(existing_geo.first["data"]["wkt"]).to eq(geometry)
77
+ expect(existing_geo.first["self"].split('/').last.to_i).to eq(geo.first["self"].split('/').last.to_i)
78
+ end
79
+ end
80
+
81
+ describe "add a node to a layer" do
82
+ it "can add a node to a simple point layer" do
83
+ properties = {:name => "Max's Restaurant", :lat => 41.8819, :lon => 87.6278}
84
+ node = @neo.create_node(properties)
85
+ expect(node).not_to be_nil
86
+ added = @neo.add_node_to_layer("restaurants", node)
87
+ expect(added.first["data"]["lat"]).to eq(properties[:lat])
88
+ expect(added.first["data"]["lon"]).to eq(properties[:lon])
89
+
90
+ added = @neo.add_node_to_index("restaurants", "dummy", "dummy", node)
91
+ expect(added["data"]["lat"]).to eq(properties[:lat])
92
+ expect(added["data"]["lon"]).to eq(properties[:lon])
93
+ end
94
+ end
95
+
96
+ describe "find geometries in a bounding box" do
97
+ it "can find a geometry in a bounding box" do
98
+ properties = {:name => "Max's Restaurant", :lat => 41.8819, :lon => 87.6278}
99
+ node = @neo.find_geometries_in_bbox("restaurants", 87.5, 87.7, 41.7, 41.9)
100
+ expect(node).not_to be_empty
101
+ expect(node.first["data"]["lat"]).to eq(properties[:lat])
102
+ expect(node.first["data"]["lon"]).to eq(properties[:lon])
103
+ expect(node.first["data"]["name"]).to eq("Max's Restaurant")
104
+ end
105
+
106
+ it "can find a geometry in a bounding box using cypher" do
107
+ properties = {:lat => 60.1, :lon => 15.2}
108
+ @neo.create_spatial_index("geombbcypher", "point", "lat", "lon")
109
+ node = @neo.create_node(properties)
110
+ added = @neo.add_node_to_index("geombbcypher", "dummy", "dummy", node)
111
+ existing_node = @neo.execute_query("start node = node:geombbcypher('bbox:[15.0,15.3,60.0,60.2]') return node")
112
+ expect(existing_node).not_to be_empty
113
+ expect(existing_node["data"][0][0]["data"]["lat"]).to eq(properties[:lat])
114
+ expect(existing_node["data"][0][0]["data"]["lon"]).to eq(properties[:lon])
115
+ end
116
+
117
+ it "can find a geometry in a bounding box using cypher two" do
118
+ properties = {:lat => 60.1, :lon => 15.2}
119
+ @neo.create_spatial_index("geombbcypher2", "point", "lat", "lon")
120
+ node = @neo.create_node(properties)
121
+ added = @neo.add_node_to_spatial_index("geombbcypher2", node)
122
+ existing_node = @neo.execute_query("start node = node:geombbcypher2('bbox:[15.0,15.3,60.0,60.2]') return node")
123
+ expect(existing_node).not_to be_empty
124
+ expect(existing_node["data"][0][0]["data"]["lat"]).to eq(properties[:lat])
125
+ expect(existing_node["data"][0][0]["data"]["lon"]).to eq(properties[:lon])
126
+ end
127
+
128
+ end
129
+
130
+ describe "find geometries within distance" do
131
+ it "can find a geometry within distance" do
132
+ properties = {:name => "Max's Restaurant", :lat => 41.8819, :lon => 87.6278}
133
+ node = @neo.find_geometries_within_distance("restaurants", 87.627, 41.881, 10)
134
+ expect(node).not_to be_empty
135
+ expect(node.first["data"]["lat"]).to eq(properties[:lat])
136
+ expect(node.first["data"]["lon"]).to eq(properties[:lon])
137
+ expect(node.first["data"]["name"]).to eq("Max's Restaurant")
138
+ end
139
+
140
+ it "can find a geometry within distance using cypher" do
141
+ properties = {:lat => 60.1, :lon => 15.2}
142
+ @neo.create_spatial_index("geowdcypher", "point", "lat", "lon")
143
+ node = @neo.create_node(properties)
144
+ added = @neo.add_node_to_index("geowdcypher", "dummy", "dummy", node)
145
+ existing_node = @neo.execute_query("start n = node:geowdcypher({bbox}) return n", {:bbox => "withinDistance:[60.0,15.0,100.0]"})
146
+ expect(existing_node).not_to be_empty
147
+ expect(existing_node).not_to be_empty
148
+ expect(existing_node["data"][0][0]["data"]["lat"]).to eq(properties[:lat])
149
+ expect(existing_node["data"][0][0]["data"]["lon"]).to eq(properties[:lon])
150
+ end
151
+
152
+ it "can find a geometry within distance using cypher 2" do
153
+ properties = {:lat => 60.1, :lon => 15.2}
154
+ @neo.create_spatial_index("geowdcypher2", "point", "lat", "lon")
155
+ node = @neo.create_node(properties)
156
+ added = @neo.add_node_to_spatial_index("geowdcypher2", node)
157
+ existing_node = @neo.execute_query("start n = node:geowdcypher2({bbox}) return n", {:bbox => "withinDistance:[60.0,15.0,100.0]"})
158
+ expect(existing_node).not_to be_empty
159
+ expect(existing_node).not_to be_empty
160
+ expect(existing_node["data"][0][0]["data"]["lat"]).to eq(properties[:lat])
161
+ expect(existing_node["data"][0][0]["data"]["lon"]).to eq(properties[:lon])
162
+ end
163
+
164
+ end
165
+
166
+ end
@@ -0,0 +1,166 @@
1
+ require 'spec_helper'
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ describe "start a transaction" do
9
+ it "can start a transaction" do
10
+ tx = @neo.begin_transaction
11
+ expect(tx).to have_key("transaction")
12
+ expect(tx["results"]).to be_empty
13
+ end
14
+
15
+ it "can start a transaction with statements" do
16
+ tx = @neo.begin_transaction("start n=node(0) return n")
17
+ expect(tx).to have_key("transaction")
18
+ expect(tx).to have_key("results")
19
+ expect(tx["results"]).not_to be_empty
20
+ end
21
+
22
+ it "can start a transaction with statements and represent them as a graph" do
23
+ tx = @neo.begin_transaction(["CREATE ( bike:Bike { weight: 10 } ) CREATE ( frontWheel:Wheel { spokes: 3 } ) CREATE ( backWheel:Wheel { spokes: 32 } ) CREATE p1 = bike -[:HAS { position: 1 } ]-> frontWheel CREATE p2 = bike -[:HAS { position: 2 } ]-> backWheel RETURN bike, p1, p2",
24
+ ["row", "graph", "rest"]])
25
+ expect(tx).to have_key("transaction")
26
+ expect(tx).to have_key("results")
27
+ expect(tx["results"]).not_to be_empty
28
+ expect(tx["results"].first["data"].first["row"]).not_to be_empty
29
+ expect(tx["results"].first["data"].first["graph"]).not_to be_empty
30
+ expect(tx["results"].first["data"].first["rest"]).not_to be_empty
31
+ end
32
+
33
+
34
+ end
35
+
36
+ describe "keep a transaction" do
37
+ it "can keep a transaction" do
38
+ tx = @neo.begin_transaction
39
+ expect(tx).to have_key("transaction")
40
+ expect(tx["results"]).to be_empty
41
+ sleep(1)
42
+ existing_tx = @neo.keep_transaction(tx)
43
+ expect(existing_tx).to have_key("transaction")
44
+ expect(existing_tx["transaction"]["expires"]).to be > tx["transaction"]["expires"]
45
+ end
46
+ end
47
+
48
+
49
+ describe "add to a transaction" do
50
+ it "can add to a transaction" do
51
+ tx = @neo.begin_transaction
52
+ expect(tx).to have_key("transaction")
53
+ expect(tx["results"]).to be_empty
54
+ existing_tx = @neo.in_transaction(tx, "start n=node(0) return n")
55
+ expect(existing_tx).to have_key("transaction")
56
+ expect(existing_tx).to have_key("results")
57
+ expect(existing_tx["results"]).not_to be_empty
58
+ end
59
+
60
+ it "can add to a transaction with parameters" do
61
+ tx = @neo.begin_transaction
62
+ expect(tx).to have_key("transaction")
63
+ expect(tx["results"]).to be_empty
64
+ existing_tx = @neo.in_transaction(tx, ["start n=node({id}) return n", {:id => 0}])
65
+ expect(existing_tx).to have_key("transaction")
66
+ expect(existing_tx).to have_key("results")
67
+ expect(existing_tx["results"]).not_to be_empty
68
+ end
69
+
70
+ it "can add to a transaction with representation" do
71
+ tx = @neo.begin_transaction
72
+ expect(tx).to have_key("transaction")
73
+ expect(tx["results"]).to be_empty
74
+ existing_tx = @neo.in_transaction(tx, ["start n=node(0) return n", [:row,:rest]])
75
+ expect(existing_tx).to have_key("transaction")
76
+ expect(existing_tx).to have_key("results")
77
+ expect(existing_tx["results"]).not_to be_empty
78
+ end
79
+
80
+ it "can add to a transaction with parameters and representation" do
81
+ tx = @neo.begin_transaction
82
+ expect(tx).to have_key("transaction")
83
+ expect(tx["results"]).to be_empty
84
+ existing_tx = @neo.in_transaction(tx, ["start n=node({id}) return n", {:id => 0}, [:row,:rest]])
85
+ expect(existing_tx).to have_key("transaction")
86
+ expect(existing_tx).to have_key("results")
87
+ expect(existing_tx["results"]).not_to be_empty
88
+ end
89
+
90
+ end
91
+
92
+ describe "commit a transaction" do
93
+ it "can commit an opened empty transaction" do
94
+ tx = @neo.begin_transaction
95
+ expect(tx).to have_key("transaction")
96
+ expect(tx["results"]).to be_empty
97
+ existing_tx = @neo.commit_transaction(tx)
98
+ expect(existing_tx).to have_key("results")
99
+ expect(existing_tx["results"]).to be_empty
100
+ end
101
+
102
+ it "can commit an opened transaction" do
103
+ tx = @neo.begin_transaction("start n=node(0) return n")
104
+ expect(tx).to have_key("transaction")
105
+ expect(tx["results"]).not_to be_empty
106
+ existing_tx = @neo.commit_transaction(tx)
107
+ expect(existing_tx).not_to have_key("transaction")
108
+ expect(existing_tx).to have_key("results")
109
+ expect(existing_tx["results"]).to be_empty
110
+ end
111
+
112
+ it "can commit an opened transaction with new statements" do
113
+ tx = @neo.begin_transaction
114
+ expect(tx).to have_key("transaction")
115
+ expect(tx["results"]).to be_empty
116
+ existing_tx = @neo.commit_transaction(tx, "start n=node(0) return n")
117
+ expect(existing_tx).not_to have_key("transaction")
118
+ expect(existing_tx).to have_key("results")
119
+ expect(existing_tx["results"]).not_to be_empty
120
+ end
121
+
122
+ it "can commit an new transaction right away" do
123
+ tx = @neo.commit_transaction(["start n=node(0) return n"])
124
+ expect(tx).not_to have_key("transaction")
125
+ expect(tx).to have_key("results")
126
+ expect(tx["results"]).not_to be_empty
127
+ end
128
+
129
+ it "can commit an new transaction right away with parameters" do
130
+ tx = @neo.commit_transaction(["start n=node({id}) return n", {:id => 0}])
131
+ expect(tx).not_to have_key("transaction")
132
+ expect(tx).to have_key("results")
133
+ expect(tx["results"]).not_to be_empty
134
+ end
135
+
136
+ it "can commit an new transaction right away without parameters" do
137
+ tx = @neo.commit_transaction("start n=node(0) return n")
138
+ expect(tx).not_to have_key("transaction")
139
+ expect(tx).to have_key("results")
140
+ expect(tx["results"]).not_to be_empty
141
+ end
142
+
143
+ end
144
+
145
+ describe "rollback a transaction" do
146
+ it "can rollback an opened empty transaction" do
147
+ tx = @neo.begin_transaction
148
+ expect(tx).to have_key("transaction")
149
+ expect(tx["results"]).to be_empty
150
+ existing_tx = @neo.rollback_transaction(tx)
151
+ expect(existing_tx).to have_key("results")
152
+ expect(existing_tx["results"]).to be_empty
153
+ end
154
+
155
+ it "can rollback an opened transaction" do
156
+ tx = @neo.begin_transaction("start n=node(0) return n")
157
+ expect(tx).to have_key("transaction")
158
+ expect(tx["results"]).not_to be_empty
159
+ existing_tx = @neo.rollback_transaction(tx)
160
+ expect(existing_tx).not_to have_key("transaction")
161
+ expect(existing_tx).to have_key("results")
162
+ expect(existing_tx["results"]).to be_empty
163
+ end
164
+ end
165
+
166
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ @new_node1 = @neo.create_node("age" => 31, "name" => "Max")
7
+ @new_node2 = @neo.create_node("age" => 30, "name" => "Helene")
8
+ @new_node3 = @neo.create_node("age" => 17, "name" => "Alex")
9
+ @new_node4 = @neo.create_node("age" => 24, "name" => "Eric")
10
+ @new_node5 = @neo.create_node("age" => 32, "name" => "Leslie")
11
+ end
12
+
13
+ describe "traverse" do
14
+ it "can traverse the graph and return nodes" do
15
+ @neo.create_relationship("friends", @new_node1, @new_node2)
16
+ @neo.create_relationship("friends", @new_node2, @new_node3)
17
+ @neo.create_relationship("friends", @new_node3, @new_node4)
18
+ @neo.create_relationship("friends", @new_node4, @new_node5)
19
+ @neo.create_relationship("friends", @new_node3, @new_node5)
20
+ nodes = @neo.traverse(@new_node1, "nodes", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} )
21
+ expect(nodes).not_to be_nil
22
+ expect(nodes[0]["self"]).to eq(@new_node2["self"])
23
+ expect(nodes[1]["self"]).to eq(@new_node3["self"])
24
+ expect(nodes[2]["self"]).to eq(@new_node4["self"])
25
+ expect(nodes[3]["self"]).to eq(@new_node5["self"])
26
+ end
27
+ it "can traverse the graph and return relationships" do
28
+ new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
29
+ new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
30
+ new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
31
+ new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
32
+ new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
33
+
34
+ relationships = @neo.traverse(@new_node1, "relationships", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} )
35
+ expect(relationships).not_to be_nil
36
+
37
+ expect(relationships[0]["self"]).to eq(new_relationship1["self"])
38
+ expect(relationships[1]["self"]).to eq(new_relationship2["self"])
39
+ expect(relationships[2]["self"]).to eq(new_relationship3["self"])
40
+ expect(relationships[3]["self"]).to eq(new_relationship4["self"])
41
+ end
42
+
43
+ it "can traverse the graph and return paths" do
44
+ new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
45
+ new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
46
+ new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
47
+ new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
48
+ new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
49
+
50
+ paths = @neo.traverse(@new_node1, "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} )
51
+ expect(paths).not_to be_nil
52
+
53
+ expect(paths[0]["nodes"]).to eq([@new_node1["self"], @new_node2["self"]])
54
+ expect(paths[1]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"]])
55
+ expect(paths[2]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]])
56
+ expect(paths[3]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"], @new_node5["self"]])
57
+ end
58
+
59
+ it "can traverse the graph up to a certain depth" do
60
+ new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
61
+ new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
62
+ new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
63
+ new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
64
+ new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
65
+
66
+ paths = @neo.traverse(@new_node1, "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 3} )
67
+ expect(paths).not_to be_nil
68
+
69
+ expect(paths[0]["nodes"]).to eq([@new_node1["self"], @new_node2["self"]])
70
+ expect(paths[1]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"]])
71
+ expect(paths[2]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]])
72
+ expect(paths[3]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node5["self"]])
73
+ end
74
+
75
+ it "can traverse the graph in a certain order" do
76
+ new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
77
+ new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
78
+ new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
79
+ new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
80
+ new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
81
+
82
+ paths = @neo.traverse(@new_node1, "paths", {"order" => "breadth first", "relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} )
83
+ expect(paths).not_to be_nil
84
+
85
+ expect(paths[0]["nodes"]).to eq([@new_node1["self"], @new_node2["self"]])
86
+ expect(paths[1]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"]])
87
+ expect(paths[2]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]])
88
+ expect(paths[3]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node5["self"]])
89
+ end
90
+
91
+ it "can traverse the graph with a specific uniqueness" do
92
+ new_relationship1= @neo.create_relationship("roommates", @new_node1, @new_node2)
93
+ new_relationship2= @neo.create_relationship("roommates", @new_node2, @new_node3)
94
+ new_relationship1= @neo.create_relationship("friends", @new_node3, @new_node2)
95
+ new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node5)
96
+ new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
97
+ new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
98
+ new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
99
+
100
+ paths = @neo.traverse(@new_node1, "paths", {"order" => "breadth first", "uniqueness" => "node global", "relationships" => [{"type"=> "roommates", "direction" => "all"},{"type"=> "friends", "direction" => "out"}], "depth" => 4} )
101
+ expect(paths).not_to be_nil
102
+
103
+ expect(paths[0]["nodes"]).to eq([@new_node1["self"], @new_node2["self"]])
104
+ expect(paths[1]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node5["self"]])
105
+ expect(paths[2]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"]])
106
+ expect(paths[3]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]])
107
+ end
108
+
109
+ it "can traverse the graph with a prune evaluator" do
110
+ new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2)
111
+ new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3)
112
+ new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4)
113
+ new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5)
114
+ new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5)
115
+
116
+ paths = @neo.traverse(@new_node1,
117
+ "paths",
118
+ {"relationships" => {"type"=> "friends", "direction" => "out"},
119
+ "depth" => 3,
120
+ "prune evaluator" => {"language" => "javascript", "body" => "position.endNode().getProperty('age') < 21;"
121
+ }} )
122
+ expect(paths).not_to be_nil
123
+ expect(paths[0]["nodes"]).to eq([@new_node1["self"], @new_node2["self"]])
124
+ expect(paths[1]["nodes"]).to eq([@new_node1["self"], @new_node2["self"], @new_node3["self"]])
125
+ expect(paths[2]).to be_nil
126
+ end
127
+
128
+ it "can traverse the graph with a return filter" do
129
+ @neo.create_relationship("friends", @new_node1, @new_node2)
130
+ @neo.create_relationship("friends", @new_node2, @new_node3)
131
+ @neo.create_relationship("friends", @new_node3, @new_node4)
132
+ @neo.create_relationship("friends", @new_node4, @new_node5)
133
+ @neo.create_relationship("friends", @new_node3, @new_node5)
134
+ nodes = @neo.traverse(@new_node1, "node", {"relationships" => {"type"=> "friends", "direction" => "out"},
135
+ "return filter" => {"language" => "builtin", "name" => "all"},
136
+ "depth" => 4} )
137
+ expect(nodes).not_to be_nil
138
+ expect(nodes[0]["self"]).to eq(@new_node1["self"])
139
+ expect(nodes[1]["self"]).to eq(@new_node2["self"])
140
+ expect(nodes[2]["self"]).to eq(@new_node3["self"])
141
+ expect(nodes[3]["self"]).to eq(@new_node4["self"])
142
+ expect(nodes[4]["self"]).to eq(@new_node5["self"])
143
+ end
144
+
145
+
146
+
147
+ end
148
+
149
+ end