neography-ajaycb 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +5 -0
  2. data/.project +12 -0
  3. data/.travis.yml +1 -0
  4. data/CONTRIBUTORS +12 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +39 -0
  7. data/LICENSE +19 -0
  8. data/README.rdoc +350 -0
  9. data/Rakefile +15 -0
  10. data/examples/facebook.rb +40 -0
  11. data/examples/facebook_v2.rb +25 -0
  12. data/examples/greatest.rb +43 -0
  13. data/examples/linkedin.rb +39 -0
  14. data/examples/linkedin_v2.rb +22 -0
  15. data/examples/traversal_example1.rb +65 -0
  16. data/examples/traversal_example2.rb +54 -0
  17. data/lib/neography.rb +46 -0
  18. data/lib/neography/config.rb +17 -0
  19. data/lib/neography/equal.rb +21 -0
  20. data/lib/neography/index.rb +13 -0
  21. data/lib/neography/neography.rb +10 -0
  22. data/lib/neography/node.rb +45 -0
  23. data/lib/neography/node_path.rb +29 -0
  24. data/lib/neography/node_relationship.rb +35 -0
  25. data/lib/neography/node_traverser.rb +142 -0
  26. data/lib/neography/path_traverser.rb +94 -0
  27. data/lib/neography/property.rb +53 -0
  28. data/lib/neography/property_container.rb +17 -0
  29. data/lib/neography/railtie.rb +8 -0
  30. data/lib/neography/relationship.rb +68 -0
  31. data/lib/neography/relationship_traverser.rb +80 -0
  32. data/lib/neography/rest.rb +534 -0
  33. data/lib/neography/tasks.rb +131 -0
  34. data/lib/neography/version.rb +3 -0
  35. data/neography.gemspec +29 -0
  36. data/spec/integration/authorization_spec.rb +48 -0
  37. data/spec/integration/index_spec.rb +32 -0
  38. data/spec/integration/neography_spec.rb +10 -0
  39. data/spec/integration/node_path_spec.rb +222 -0
  40. data/spec/integration/node_relationship_spec.rb +374 -0
  41. data/spec/integration/node_spec.rb +215 -0
  42. data/spec/integration/relationship_spec.rb +37 -0
  43. data/spec/integration/rest_batch_spec.rb +221 -0
  44. data/spec/integration/rest_bulk_spec.rb +106 -0
  45. data/spec/integration/rest_experimental_spec.rb +22 -0
  46. data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
  47. data/spec/integration/rest_index_spec.rb +297 -0
  48. data/spec/integration/rest_node_spec.rb +232 -0
  49. data/spec/integration/rest_path_spec.rb +209 -0
  50. data/spec/integration/rest_plugin_spec.rb +67 -0
  51. data/spec/integration/rest_relationship_spec.rb +327 -0
  52. data/spec/integration/rest_traverse_spec.rb +149 -0
  53. data/spec/spec_helper.rb +18 -0
  54. metadata +222 -0
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Relationship do
4
+ describe "create relationship" do
5
+ it "#new(:family, p1, p2) creates a new relationship between to nodes of given type" do
6
+ p1 = Neography::Node.create
7
+ p2 = Neography::Node.create
8
+
9
+ Neography::Relationship.create(:family, p1, p2)
10
+ p1.outgoing(:family).should include(p2)
11
+ p2.incoming(:family).should include(p1)
12
+ end
13
+
14
+ it "#new(:family, p1, p2, :since => '1998', :colour => 'blue') creates relationship and sets its properties" do
15
+ p1 = Neography::Node.create
16
+ p2 = Neography::Node.create
17
+ rel = Neography::Relationship.create(:family, p1, p2, :since => 1998, :colour => 'blue')
18
+
19
+ rel[:since].should == 1998
20
+ rel[:colour].should == 'blue'
21
+ rel.since.should == 1998
22
+ rel.colour.should == 'blue'
23
+ end
24
+
25
+ it "#outgoing(:friends).create(other) creates a new relationship between self and other node" do
26
+ p1 = Neography::Node.create
27
+ p2 = Neography::Node.create
28
+ rel = p1.outgoing(:foo).create(p2)
29
+
30
+ rel.should be_kind_of(Neography::Relationship)
31
+ p1.outgoing(:foo).first.should == p2
32
+ p1.outgoing(:foo).should include(p2)
33
+ p2.incoming(:foo).should include(p1)
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,221 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ describe "simple batch" do
9
+ it "can get a single node" do
10
+ new_node = @neo.create_node
11
+ new_node[:id] = new_node["self"].split('/').last
12
+ batch_result = @neo.batch [:get_node, new_node]
13
+ batch_result.first.should_not be_nil
14
+ batch_result.first.should have_key("id")
15
+ batch_result.first.should have_key("body")
16
+ batch_result.first.should have_key("from")
17
+ batch_result.first["body"]["self"].split('/').last.should == new_node[:id]
18
+ end
19
+
20
+ it "can get multiple nodes" do
21
+ node1 = @neo.create_node
22
+ node1[:id] = node1["self"].split('/').last
23
+ node2 = @neo.create_node
24
+ node2[:id] = node2["self"].split('/').last
25
+
26
+ batch_result = @neo.batch [:get_node, node1], [:get_node, node2]
27
+ batch_result.first.should_not be_nil
28
+ batch_result.first.should have_key("id")
29
+ batch_result.first.should have_key("body")
30
+ batch_result.first.should have_key("from")
31
+ batch_result.first["body"]["self"].split('/').last.should == node1[:id]
32
+ batch_result.last.should have_key("id")
33
+ batch_result.last.should have_key("body")
34
+ batch_result.last.should have_key("from")
35
+ batch_result.last["body"]["self"].split('/').last.should == node2[:id]
36
+
37
+ end
38
+
39
+ it "can create a single node" do
40
+ batch_result = @neo.batch [:create_node, {"name" => "Max"}]
41
+ batch_result.first["body"]["data"]["name"].should == "Max"
42
+ end
43
+
44
+ it "can create multiple nodes" do
45
+ batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}]
46
+ batch_result.first["body"]["data"]["name"].should == "Max"
47
+ batch_result.last["body"]["data"]["name"].should == "Marc"
48
+ end
49
+
50
+ it "can create multiple nodes given an *array" do
51
+ batch_result = @neo.batch *[[:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}]]
52
+ batch_result.first["body"]["data"]["name"].should == "Max"
53
+ batch_result.last["body"]["data"]["name"].should == "Marc"
54
+ end
55
+
56
+
57
+ it "can update a property of a node" do
58
+ new_node = @neo.create_node("name" => "Max")
59
+ batch_result = @neo.batch [:set_node_property, new_node, {"name" => "Marc"}]
60
+ batch_result.first.should have_key("id")
61
+ batch_result.first.should have_key("from")
62
+ existing_node = @neo.get_node(new_node)
63
+ existing_node["data"]["name"].should == "Marc"
64
+ end
65
+
66
+ it "can update a property of multiple nodes" do
67
+ node1 = @neo.create_node("name" => "Max")
68
+ node2 = @neo.create_node("name" => "Marc")
69
+ batch_result = @neo.batch [:set_node_property, node1, {"name" => "Tom"}], [:set_node_property, node2, {"name" => "Jerry"}]
70
+ batch_result.first.should have_key("id")
71
+ batch_result.first.should have_key("from")
72
+ batch_result.last.should have_key("id")
73
+ batch_result.last.should have_key("from")
74
+ existing_node = @neo.get_node(node1)
75
+ existing_node["data"]["name"].should == "Tom"
76
+ existing_node = @neo.get_node(node2)
77
+ existing_node["data"]["name"].should == "Jerry"
78
+ end
79
+
80
+ it "can reset the properties of a node" do
81
+ new_node = @neo.create_node("name" => "Max", "weight" => 200)
82
+ batch_result = @neo.batch [:reset_node_properties, new_node, {"name" => "Marc"}]
83
+ batch_result.first.should have_key("id")
84
+ batch_result.first.should have_key("from")
85
+ existing_node = @neo.get_node(new_node)
86
+ existing_node["data"]["name"].should == "Marc"
87
+ existing_node["data"]["weight"].should be_nil
88
+ end
89
+
90
+ it "can reset the properties of multiple nodes" do
91
+ node1 = @neo.create_node("name" => "Max", "weight" => 200)
92
+ node2 = @neo.create_node("name" => "Marc", "weight" => 180)
93
+ batch_result = @neo.batch [:reset_node_properties, node1, {"name" => "Tom"}], [:reset_node_properties, node2, {"name" => "Jerry"}]
94
+ batch_result.first.should have_key("id")
95
+ batch_result.first.should have_key("from")
96
+ batch_result.last.should have_key("id")
97
+ batch_result.last.should have_key("from")
98
+ existing_node = @neo.get_node(node1)
99
+ existing_node["data"]["name"].should == "Tom"
100
+ existing_node["data"]["weight"].should be_nil
101
+ existing_node = @neo.get_node(node2)
102
+ existing_node["data"]["name"].should == "Jerry"
103
+ existing_node["data"]["weight"].should be_nil
104
+ end
105
+
106
+ it "can get a single relationship" do
107
+ node1 = @neo.create_node
108
+ node2 = @neo.create_node
109
+ new_relationship = @neo.create_relationship("friends", node1, node2)
110
+ batch_result = @neo.batch [:get_relationship, new_relationship]
111
+ batch_result.first["body"]["type"].should == "friends"
112
+ batch_result.first["body"]["start"].split('/').last.should == node1["self"].split('/').last
113
+ batch_result.first["body"]["end"].split('/').last.should == node2["self"].split('/').last
114
+ batch_result.first["body"]["self"].should == new_relationship["self"]
115
+ end
116
+
117
+ it "can create a single relationship" do
118
+ node1 = @neo.create_node
119
+ node2 = @neo.create_node
120
+ batch_result = @neo.batch [:create_relationship, "friends", node1, node2, {:since => "high school"}]
121
+ batch_result.first["body"]["type"].should == "friends"
122
+ batch_result.first["body"]["data"]["since"].should == "high school"
123
+ batch_result.first["body"]["start"].split('/').last.should == node1["self"].split('/').last
124
+ batch_result.first["body"]["end"].split('/').last.should == node2["self"].split('/').last
125
+ end
126
+
127
+ it "can update a single relationship" do
128
+ node1 = @neo.create_node
129
+ node2 = @neo.create_node
130
+ new_relationship = @neo.create_relationship("friends", node1, node2, {:since => "high school"})
131
+ batch_result = @neo.batch [:set_relationship_property, new_relationship, {:since => "college"}]
132
+ batch_result.first.should have_key("id")
133
+ batch_result.first.should have_key("from")
134
+ existing_relationship = @neo.get_relationship(new_relationship)
135
+ existing_relationship["type"].should == "friends"
136
+ existing_relationship["data"]["since"].should == "college"
137
+ existing_relationship["start"].split('/').last.should == node1["self"].split('/').last
138
+ existing_relationship["end"].split('/').last.should == node2["self"].split('/').last
139
+ existing_relationship["self"].should == new_relationship["self"]
140
+ end
141
+
142
+ it "can add a node to an index" do
143
+ new_node = @neo.create_node
144
+ key = generate_text(6)
145
+ value = generate_text
146
+ new_index = @neo.get_node_index("test_node_index", key, value)
147
+ batch_result = @neo.batch [:add_node_to_index, "test_node_index", key, value, new_node]
148
+ batch_result.first.should have_key("id")
149
+ batch_result.first.should have_key("from")
150
+ existing_index = @neo.find_node_index("test_node_index", key, value)
151
+ existing_index.should_not be_nil
152
+ existing_index.first["self"].should == new_node["self"]
153
+ @neo.remove_node_from_index("test_node_index", key, value, new_node)
154
+ end
155
+ end
156
+
157
+ describe "referenced batch" do
158
+ it "can create a relationship from two newly created nodes" do
159
+ batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}], [:create_relationship, "friends", "{0}", "{1}", {:since => "high school"}]
160
+ batch_result.first["body"]["data"]["name"].should == "Max"
161
+ batch_result[1]["body"]["data"]["name"].should == "Marc"
162
+ batch_result.last["body"]["type"].should == "friends"
163
+ batch_result.last["body"]["data"]["since"].should == "high school"
164
+ batch_result.last["body"]["start"].split('/').last.should == batch_result.first["body"]["self"].split('/').last
165
+ batch_result.last["body"]["end"].split('/').last.should == batch_result[1]["body"]["self"].split('/').last
166
+ end
167
+
168
+ it "can create a relationship from an existing node and a newly created node" do
169
+ node1 = @neo.create_node("name" => "Max", "weight" => 200)
170
+ batch_result = @neo.batch [:create_node, {"name" => "Marc"}], [:create_relationship, "friends", "{0}", node1, {:since => "high school"}]
171
+ batch_result.first["body"]["data"]["name"].should == "Marc"
172
+ batch_result.last["body"]["type"].should == "friends"
173
+ batch_result.last["body"]["data"]["since"].should == "high school"
174
+ batch_result.last["body"]["start"].split('/').last.should == batch_result.first["body"]["self"].split('/').last
175
+ batch_result.last["body"]["end"].split('/').last.should == node1["self"].split('/').last
176
+ end
177
+
178
+ it "can add a newly created node to an index" do
179
+ key = generate_text(6)
180
+ value = generate_text
181
+ new_index = @neo.get_node_index("test_node_index", key, value)
182
+ batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:add_node_to_index, "test_node_index", key, value, "{0}"]
183
+ batch_result.first.should have_key("id")
184
+ batch_result.first.should have_key("from")
185
+ existing_index = @neo.find_node_index("test_node_index", key, value)
186
+ existing_index.should_not be_nil
187
+ existing_index.first["self"].should == batch_result.first["body"]["self"]
188
+ @neo.remove_node_from_index("test_node_index", key, value, batch_result.first["body"]["self"].split('/').last)
189
+ end
190
+
191
+ it "can add a newly created relationship to an index" do
192
+ key = generate_text(6)
193
+ value = generate_text
194
+ node1 = @neo.create_node
195
+ node2 = @neo.create_node
196
+ batch_result = @neo.batch [:create_relationship, "friends", node1, node2, {:since => "high school"}], [:add_relationship_to_index, "test_relationship_index", key, value, "{0}"]
197
+ batch_result.first["body"]["type"].should == "friends"
198
+ batch_result.first["body"]["data"]["since"].should == "high school"
199
+ batch_result.first["body"]["start"].split('/').last.should == node1["self"].split('/').last
200
+ batch_result.first["body"]["end"].split('/').last.should == node2["self"].split('/').last
201
+ existing_index = @neo.find_relationship_index("test_relationship_index", key, value)
202
+ existing_index.should_not be_nil
203
+ existing_index.first["self"].should == batch_result.first["body"]["self"]
204
+
205
+ end
206
+
207
+ it "can kitchen sink" do
208
+ key = generate_text(6)
209
+ value = generate_text
210
+
211
+ batch_result = @neo.batch [:create_node, {"name" => "Max"}],
212
+ [:create_node, {"name" => "Marc"}],
213
+ [:add_node_to_index, "test_node_index", key, value, "{0}"]
214
+ [:add_node_to_index, "test_node_index", key, value, "{1}"]
215
+ [:create_relationship, "friends", "{0}", "{1}", {:since => "college"}]
216
+ [:add_relationship_to_index, "test_relationship_index", key, value, "{4}"]
217
+ batch_result.should_not be_nil
218
+ end
219
+ end
220
+
221
+ end
@@ -0,0 +1,106 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ describe "can create many nodes threaded" do
9
+ it "can create empty nodes threaded" do
10
+ new_nodes = @neo.create_nodes_threaded(2)
11
+ new_nodes.should_not be_nil
12
+ new_nodes.size.should == 2
13
+ end
14
+
15
+ it "is faster than non-threaded?" , :slow => true do
16
+ Benchmark.bm do |x|
17
+ x.report("create 500 nodes ") { @not_threaded = @neo.create_nodes(500) }
18
+ x.report("create 500 nodes threaded") { @threaded = @neo.create_nodes_threaded(500) }
19
+ x.report("create 1000 nodes threaded") { @threaded2c = @neo.create_nodes_threaded(1000) }
20
+ end
21
+
22
+ @not_threaded[99].should_not be_nil
23
+ @threaded[99].should_not be_nil
24
+ @threaded2c[199].should_not be_nil
25
+ end
26
+
27
+ end
28
+
29
+ describe "can create many nodes" do
30
+ it "can create empty nodes" do
31
+ new_nodes = @neo.create_nodes(2)
32
+ new_nodes.should_not be_nil
33
+ new_nodes.size.should == 2
34
+ end
35
+
36
+ it "can create nodes with one property" do
37
+ new_nodes = @neo.create_nodes([{"name" => "Max"}, {"name" => "Alex"}])
38
+ new_nodes[0]["data"]["name"].should == "Max"
39
+ new_nodes[1]["data"]["name"].should == "Alex"
40
+ end
41
+
42
+ it "can create nodes with one property that are different" do
43
+ new_nodes = @neo.create_nodes([{"name" => "Max"}, {"age" => 24}])
44
+ new_nodes[0]["data"]["name"].should == "Max"
45
+ new_nodes[1]["data"]["age"].should == 24
46
+ end
47
+
48
+ it "can create nodes with more than one property" do
49
+ new_nodes = @neo.create_nodes([{"age" => 31, "name" => "Max"}, {"age" => 24, "name" => "Alex"}])
50
+ new_nodes[0]["data"]["name"].should == "Max"
51
+ new_nodes[0]["data"]["age"].should == 31
52
+ new_nodes[1]["data"]["name"].should == "Alex"
53
+ new_nodes[1]["data"]["age"].should == 24
54
+ end
55
+
56
+ it "can create nodes with more than one property that are different" do
57
+ new_nodes = @neo.create_nodes([{"age" => 31, "name" => "Max"}, {"height" => "5-11", "weight" => 215}])
58
+ new_nodes[0]["data"]["name"].should == "Max"
59
+ new_nodes[0]["data"]["age"].should == 31
60
+ new_nodes[1]["data"]["height"].should == "5-11"
61
+ new_nodes[1]["data"]["weight"].should == 215
62
+ end
63
+
64
+ it "is not super slow?" , :slow => true do
65
+ Benchmark.bm do |x|
66
+ x.report( "create 1 node" ) { @neo.create_nodes( 1) }
67
+ x.report( "create 10 nodes") { @neo.create_nodes( 10) }
68
+ x.report("create 100 nodes") { @neo.create_nodes(100) }
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "can get many nodes" do
74
+ it "can get 2 nodes passed in as an array" do
75
+ new_nodes = @neo.create_nodes(2)
76
+ existing_nodes = @neo.get_nodes(new_nodes)
77
+ existing_nodes.should_not be_nil
78
+ existing_nodes.size.should == 2
79
+ end
80
+
81
+ it "can get 2 nodes passed in by commas" do
82
+ new_nodes = @neo.create_nodes(2)
83
+ new_node1 = new_nodes[0]["self"].split('/').last
84
+ new_node2 = new_nodes[1]["self"].split('/').last
85
+ existing_nodes = @neo.get_nodes(new_node1, new_node2)
86
+ existing_nodes.should_not be_nil
87
+ existing_nodes.size.should == 2
88
+ existing_nodes[0]["self"] == new_node1["self"]
89
+ existing_nodes[1]["self"] == new_node2["self"]
90
+ end
91
+
92
+ it "is not super slow?" , :slow => true do
93
+ one_node = @neo.create_nodes( 1)
94
+ ten_nodes = @neo.create_nodes( 10)
95
+ one_hundred_nodes = @neo.create_nodes(100)
96
+
97
+ Benchmark.bm do |x|
98
+ x.report( "get 1 node ") { @neo.get_nodes(one_node) }
99
+ x.report( "get 10 nodes") { @neo.get_nodes(ten_nodes) }
100
+ x.report("get 100 nodes") { @neo.get_nodes(one_hundred_nodes) }
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+
9
+ describe "get_nodes", :slow => true do
10
+ it "can get nodes that exists" do
11
+ existing_nodes = @neo.get_nodes
12
+ existing_nodes.should_not be_nil
13
+ end
14
+
15
+ it "can get all nodes that exists the ugly way" do
16
+ new_node = @neo.create_node
17
+ last_node_id = new_node["self"].split('/').last.to_i
18
+ existing_nodes = @neo.get_nodes((1..last_node_id).to_a)
19
+ existing_nodes.should_not be_nil
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ describe "don't break gremlin" do
9
+ it "can handle node and relationship indexes" 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
+ key = generate_text(6)
14
+ value = generate_text
15
+ @neo.add_node_to_index("test_index", key, value, new_node1)
16
+ @neo.add_relationship_to_index("test_index2", key, value, new_relationship)
17
+ end
18
+
19
+ it "gremlin works" do
20
+ root_node = @neo.execute_script("g.v(0)")
21
+ root_node.should have_key("self")
22
+ root_node["self"].split('/').last.should == "0"
23
+ end
24
+ end
25
+
26
+
27
+ describe "break gremlin" do
28
+ it "can can't handle node and relationship indexes with the same name", :break_gremlin => true do
29
+ new_node1 = @neo.create_node
30
+ new_node2 = @neo.create_node
31
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
32
+ key = generate_text(6)
33
+ value = generate_text
34
+ @neo.add_node_to_index("test_index3", key, value, new_node1)
35
+ @neo.add_relationship_to_index("test_index3", key, value, new_relationship)
36
+ end
37
+
38
+ it "gremlin works" do
39
+ root_node = @neo.execute_script("g.v(0)")
40
+ root_node.should have_key("self")
41
+ root_node["self"].split('/').last.should == "0"
42
+ end
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,297 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ describe "list indexes" do
9
+ it "can get a listing of node indexes" do
10
+ new_node = @neo.create_node
11
+ key = generate_text(6)
12
+ value = generate_text
13
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
14
+ @neo.list_indexes.should_not be_nil
15
+ end
16
+
17
+ it "can get a listing of relationship indexes" do
18
+ new_node1 = @neo.create_node
19
+ new_node2 = @neo.create_node
20
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
21
+ key = generate_text(6)
22
+ value = generate_text
23
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
24
+ @neo.list_relationship_indexes.should_not be_nil
25
+ end
26
+ end
27
+
28
+ describe "create an index" do
29
+ it "can create a node index" do
30
+ name = generate_text(6)
31
+ new_index = @neo.create_node_index(name)
32
+ new_index.should_not be_nil
33
+ new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
34
+ new_index["provider"].should == "lucene"
35
+ new_index["type"].should == "exact"
36
+ end
37
+
38
+ it "can create a node index with options" do
39
+ name = generate_text(6)
40
+ new_index = @neo.create_node_index(name, "fulltext","lucene")
41
+ new_index.should_not be_nil
42
+ new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
43
+ new_index["provider"].should == "lucene"
44
+ new_index["type"].should == "fulltext"
45
+ end
46
+
47
+ it "can create a relationship index" do
48
+ name = generate_text(6)
49
+ new_index = @neo.create_relationship_index(name)
50
+ new_index.should_not be_nil
51
+ new_index["template"].should == "#{@neo.configuration}/index/relationship/#{name}/{key}/{value}"
52
+ new_index["provider"].should == "lucene"
53
+ new_index["type"].should == "exact"
54
+ end
55
+
56
+ it "can create a relationship index with options" do
57
+ name = generate_text(6)
58
+ new_index = @neo.create_relationship_index(name, "fulltext","lucene")
59
+ new_index.should_not be_nil
60
+ new_index["template"].should == "#{@neo.configuration}/index/relationship/#{name}/{key}/{value}"
61
+ new_index["provider"].should == "lucene"
62
+ new_index["type"].should == "fulltext"
63
+ end
64
+
65
+
66
+ end
67
+
68
+ describe "add to index" do
69
+ it "can add a node to an index" do
70
+ new_node = @neo.create_node
71
+ key = generate_text(6)
72
+ value = generate_text
73
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
74
+ new_index = @neo.get_node_index("test_node_index", key, value)
75
+ new_index.should_not be_nil
76
+ @neo.remove_node_from_index("test_node_index", key, value, new_node)
77
+ end
78
+
79
+ it "can add a relationship to an index" do
80
+ new_node1 = @neo.create_node
81
+ new_node2 = @neo.create_node
82
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
83
+ key = generate_text(6)
84
+ value = generate_text
85
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
86
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
87
+ new_index.should_not be_nil
88
+ @neo.remove_relationship_from_index("test_relationship_index", key, value, new_relationship)
89
+ end
90
+ end
91
+
92
+ describe "remove from index" do
93
+ it "can remove a node from an index" do
94
+ new_node = @neo.create_node
95
+ key = generate_text(6)
96
+ value = generate_text
97
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
98
+ new_index = @neo.get_node_index("test_node_index", key, value)
99
+ new_index.should_not be_nil
100
+ @neo.remove_node_from_index("test_node_index", key, value, new_node)
101
+ new_index = @neo.get_node_index("test_node_index", key, value)
102
+ new_index.should be_nil
103
+ end
104
+
105
+ it "can remove a node from an index without supplying value" do
106
+ new_node = @neo.create_node
107
+ key = generate_text(6)
108
+ value = generate_text
109
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
110
+ new_index = @neo.get_node_index("test_node_index", key, value)
111
+ new_index.should_not be_nil
112
+ @neo.remove_node_from_index("test_node_index", key, new_node)
113
+ new_index = @neo.get_node_index("test_node_index", key, value)
114
+ new_index.should be_nil
115
+ end
116
+
117
+ it "can remove a node from an index without supplying key nor value" do
118
+ new_node = @neo.create_node
119
+ key = generate_text(6)
120
+ value = generate_text
121
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
122
+ new_index = @neo.get_node_index("test_node_index", key, value)
123
+ new_index.should_not be_nil
124
+ @neo.remove_node_from_index("test_node_index", new_node)
125
+ new_index = @neo.get_node_index("test_node_index", key, value)
126
+ new_index.should be_nil
127
+ end
128
+
129
+ it "can remove a relationship from an index" do
130
+ new_node1 = @neo.create_node
131
+ new_node2 = @neo.create_node
132
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
133
+ key = generate_text(6)
134
+ value = generate_text
135
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
136
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
137
+ new_index.should_not be_nil
138
+ @neo.remove_relationship_from_index("test_relationship_index", key, value, new_relationship)
139
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
140
+ new_index.should be_nil
141
+ end
142
+
143
+ it "can remove a relationship from an index without supplying value" do
144
+ new_node1 = @neo.create_node
145
+ new_node2 = @neo.create_node
146
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
147
+ key = generate_text(6)
148
+ value = generate_text
149
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
150
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
151
+ new_index.should_not be_nil
152
+ @neo.remove_relationship_from_index("test_relationship_index", key, new_relationship)
153
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
154
+ new_index.should be_nil
155
+ end
156
+
157
+ it "can remove a relationship from an index without supplying key nor value" do
158
+ new_node1 = @neo.create_node
159
+ new_node2 = @neo.create_node
160
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
161
+ key = generate_text(6)
162
+ value = generate_text
163
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
164
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
165
+ new_index.should_not be_nil
166
+ @neo.remove_relationship_from_index("test_relationship_index", new_relationship)
167
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
168
+ new_index.should be_nil
169
+ end
170
+ end
171
+
172
+ describe "get index" do
173
+ it "can get a node index" do
174
+ new_node = @neo.create_node
175
+ key = generate_text(6)
176
+ value = generate_text
177
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
178
+ new_index = @neo.get_node_index("test_node_index", key, value)
179
+ new_index.should_not be_nil
180
+ @neo.remove_node_from_index("test_node_index", key, value, new_node)
181
+ end
182
+
183
+ it "can get a relationship index" do
184
+ new_node1 = @neo.create_node
185
+ new_node2 = @neo.create_node
186
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
187
+ key = generate_text(6)
188
+ value = generate_text
189
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
190
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
191
+ new_index.should_not be_nil
192
+ @neo.remove_relationship_from_index("test_relationship_index", key, value, new_relationship)
193
+ end
194
+ end
195
+
196
+ describe "query index" do
197
+ it "can query a node index" do
198
+ new_node = @neo.create_node
199
+ key = generate_text(6)
200
+ value = generate_text
201
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
202
+ new_index = @neo.get_node_index("test_node_index", key, value)
203
+ new_index.first["self"].should == new_node["self"]
204
+ @neo.remove_node_from_index("test_node_index", key, value, new_node)
205
+ end
206
+
207
+ it "can find a node index" do
208
+ new_node = @neo.create_node
209
+ key = generate_text(6)
210
+ value = generate_text
211
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
212
+ new_index = @neo.find_node_index("test_node_index", key, value)
213
+ new_index.first["self"].should == new_node["self"]
214
+ @neo.remove_node_from_index("test_node_index", key, value, new_node)
215
+ end
216
+
217
+ it "can find a node index using generic query" do
218
+ new_node = @neo.create_node
219
+ key = generate_text(6)
220
+ value = generate_text
221
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
222
+ new_index = @neo.find_node_index("test_node_index", "#{key}: #{value}")
223
+ new_index.first["self"].should == new_node["self"]
224
+ @neo.remove_node_from_index("test_node_index", key, value, new_node)
225
+ end
226
+
227
+ it "can get a relationship index" do
228
+ new_node1 = @neo.create_node
229
+ new_node2 = @neo.create_node
230
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
231
+ key = generate_text(6)
232
+ value = generate_text
233
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
234
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
235
+ new_index.first["self"].should == new_relationship["self"]
236
+ @neo.remove_relationship_from_index("test_relationship_index", key, value, new_relationship)
237
+ end
238
+
239
+ it "can get a relationship index with empty spaces" do
240
+ new_node1 = @neo.create_node
241
+ new_node2 = @neo.create_node
242
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
243
+ key = generate_text(6)
244
+ value = generate_text + " " + generate_text
245
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
246
+ new_index = @neo.get_relationship_index("test_relationship_index", key, value)
247
+ new_index.first["self"].should == new_relationship["self"]
248
+ @neo.remove_relationship_from_index("test_relationship_index", key, value, new_relationship)
249
+ end
250
+
251
+ it "can find a relationship index" do
252
+ new_node1 = @neo.create_node
253
+ new_node2 = @neo.create_node
254
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
255
+ key = generate_text(6)
256
+ value = generate_text
257
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
258
+ new_index = @neo.find_relationship_index("test_relationship_index", key, value)
259
+ new_index.first["self"].should == new_relationship["self"]
260
+ @neo.remove_relationship_from_index("test_relationship_index", key, value, new_relationship)
261
+ end
262
+
263
+ it "can find a relationship index using generic query" do
264
+ new_node1 = @neo.create_node
265
+ new_node2 = @neo.create_node
266
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
267
+ key = generate_text(6)
268
+ value = generate_text
269
+ @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship)
270
+ new_index = @neo.find_relationship_index("test_relationship_index", "#{key}: #{value}")
271
+ new_index.first["self"].should == new_relationship["self"]
272
+ @neo.remove_relationship_from_index("test_relationship_index", key, value, new_relationship)
273
+ end
274
+
275
+ it "can find use the results of a node index" do
276
+ new_node1 = @neo.create_node
277
+ new_node2 = @neo.create_node
278
+ key = generate_text(6)
279
+ value1 = generate_text
280
+ value2 = generate_text
281
+ @neo.add_node_to_index("test_node_index", key, value1, new_node1)
282
+ @neo.add_node_to_index("test_node_index", key, value2, new_node2)
283
+ existing_node1 = @neo.get_node_index("test_node_index", key, value1)
284
+ existing_node2 = @neo.get_node_index("test_node_index", key, value2)
285
+ new_relationship = @neo.create_relationship("friends", existing_node1, existing_node2)
286
+ new_relationship["start"].should_not be_nil
287
+ new_relationship["start"].should == new_node1["self"]
288
+ new_relationship["end"].should_not be_nil
289
+ new_relationship["end"].should == new_node2["self"]
290
+ @neo.remove_node_from_index("test_node_index", new_node1)
291
+ @neo.remove_node_from_index("test_node_index", new_node2)
292
+ end
293
+
294
+ end
295
+
296
+
297
+ end