neography 0.0.1

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.
@@ -0,0 +1,3 @@
1
+ module Neography
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "neography/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "neography"
7
+ s.version = Neography::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = "Max De Marzi"
10
+ s.email = "maxdemarzi@gmail.com"
11
+ s.homepage = "http://rubygems.org/gems/neography"
12
+ s.summary = "ruby wrapper to Neo4j Rest API"
13
+ s.description = "A Ruby wrapper to the Neo4j Rest API see http://components.neo4j.org/neo4j-rest/ for more details."
14
+
15
+ s.rubyforge_project = "neography"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "rspec", "~> 2.0.0.beta.22"
23
+ s.add_development_dependency "net-http-spy", "~> 0.2.1"
24
+ s.add_development_dependency "fakeweb", "~> 1.3.0"
25
+ s.add_dependency "httparty", "~> 0.6.1"
26
+ s.add_dependency "json"
27
+ end
@@ -0,0 +1,55 @@
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 indexes" do
10
+ @neo.list_indexes.should_not be_nil
11
+ end
12
+ end
13
+
14
+ describe "add to index" do
15
+ it "can add a node to an index" do
16
+ new_node = @neo.create_node
17
+ new_node[:id] = new_node["self"].split('/').last
18
+ key = generate_text(6)
19
+ value = generate_text
20
+ @neo.add_to_index(key, value, new_node[:id])
21
+ new_index = @neo.get_index(key, value)
22
+ new_index.should_not be_nil
23
+ @neo.remove_from_index(key, value, new_node[:id])
24
+ end
25
+ end
26
+
27
+ describe "remove from index" do
28
+ it "can remove a node from an index" do
29
+ new_node = @neo.create_node
30
+ new_node[:id] = new_node["self"].split('/').last
31
+ key = generate_text(6)
32
+ value = generate_text
33
+ @neo.add_to_index(key, value, new_node[:id])
34
+ new_index = @neo.get_index(key, value)
35
+ new_index.should_not be_nil
36
+ @neo.remove_from_index(key, value, new_node[:id])
37
+ new_index = @neo.get_index(key, value)
38
+ new_index.should be_nil
39
+ end
40
+ end
41
+
42
+ describe "get index" do
43
+ it "can get an index" do
44
+ new_node = @neo.create_node
45
+ new_node[:id] = new_node["self"].split('/').last
46
+ key = generate_text(6)
47
+ value = generate_text
48
+ @neo.add_to_index(key, value, new_node[:id])
49
+ new_index = @neo.get_index(key, value)
50
+ new_index.should_not be_nil
51
+ @neo.remove_from_index(key, value, new_node[:id])
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,241 @@
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 "get_root" do
9
+ it "can get the root node" do
10
+ root_node = @neo.get_root
11
+ root_node.should have_key("reference_node")
12
+ end
13
+ end
14
+
15
+ describe "create_node" do
16
+ it "can create an empty node" do
17
+ new_node = @neo.create_node
18
+ new_node.should_not be_nil
19
+ end
20
+
21
+ it "can create a node with one property" do
22
+ new_node = @neo.create_node("name" => "Max")
23
+ new_node["data"]["name"].should == "Max"
24
+ end
25
+
26
+ it "can create a node with more than one property" do
27
+ new_node = @neo.create_node("age" => 31, "name" => "Max")
28
+ new_node["data"]["name"].should == "Max"
29
+ new_node["data"]["age"].should == 31
30
+ end
31
+ end
32
+
33
+ describe "get_node" do
34
+ it "can get a node that exists" do
35
+ new_node = @neo.create_node
36
+ new_node[:id] = new_node["self"].split('/').last
37
+ existing_node = @neo.get_node(new_node[:id])
38
+ existing_node.should_not be_nil
39
+ existing_node.should have_key("self")
40
+ existing_node["self"].split('/').last.should == new_node[:id]
41
+ end
42
+
43
+ it "returns nil if it tries to get a node that does not exist" do
44
+ new_node = @neo.create_node
45
+ new_node[:id] = new_node["self"].split('/').last
46
+ existing_node = @neo.get_node(new_node[:id].to_i + 1000)
47
+ existing_node.should be_nil
48
+ end
49
+ end
50
+
51
+ describe "set_node_properties" do
52
+ it "can set a node's properties" do
53
+ new_node = @neo.create_node
54
+ new_node[:id] = new_node["self"].split('/').last
55
+ @neo.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown"})
56
+ existing_node = @neo.get_node(new_node[:id])
57
+ existing_node["data"]["weight"].should == 200
58
+ existing_node["data"]["eyes"].should == "brown"
59
+ end
60
+
61
+ it "it fails to set properties on a node that does not exist" do
62
+ new_node = @neo.create_node
63
+ new_node[:id] = new_node["self"].split('/').last
64
+ @neo.set_node_properties(new_node[:id].to_i + 1000, {"weight" => 150, "hair" => "blonde"})
65
+ node_properties = @neo.get_node_properties(new_node[:id].to_i + 1000)
66
+ node_properties.should be_nil
67
+ end
68
+ end
69
+
70
+ describe "reset_node_properties" do
71
+ it "can reset a node's properties" do
72
+ new_node = @neo.create_node
73
+ new_node[:id] = new_node["self"].split('/').last
74
+ @neo.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown", "hair" => "black"})
75
+ @neo.reset_node_properties(new_node[:id], {"weight" => 190, "eyes" => "blue"})
76
+ existing_node = @neo.get_node(new_node[:id])
77
+ existing_node["data"]["weight"].should == 190
78
+ existing_node["data"]["eyes"].should == "blue"
79
+ existing_node["data"]["hair"].should be_nil
80
+ end
81
+
82
+ it "it fails to reset properties on a node that does not exist" do
83
+ new_node = @neo.create_node
84
+ new_node[:id] = new_node["self"].split('/').last
85
+ @neo.reset_node_properties(new_node[:id].to_i + 1000, {"weight" => 170, "eyes" => "green"})
86
+ node_properties = @neo.get_node_properties(new_node[:id].to_i + 1000)
87
+ node_properties.should be_nil
88
+ end
89
+ end
90
+
91
+ describe "get_node_properties" do
92
+ it "can get all of a node's properties" do
93
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown")
94
+ new_node[:id] = new_node["self"].split('/').last
95
+ node_properties = @neo.get_node_properties(new_node[:id])
96
+ node_properties["weight"].should == 200
97
+ node_properties["eyes"].should == "brown"
98
+ end
99
+
100
+ it "can get some of a node's properties" do
101
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown", "height" => "2m")
102
+ new_node[:id] = new_node["self"].split('/').last
103
+ node_properties = @neo.get_node_properties(new_node[:id], ["weight", "height"])
104
+ node_properties["weight"].should == 200
105
+ node_properties["height"].should == "2m"
106
+ node_properties["eyes"].should be_nil
107
+ end
108
+
109
+ it "returns nil if it gets the properties on a node that does not have any" do
110
+ new_node = @neo.create_node
111
+ new_node[:id] = new_node["self"].split('/').last
112
+ @neo.get_node_properties(new_node[:id]).should be_nil
113
+ end
114
+
115
+ it "returns nil if it tries to get some of the properties on a node that does not have any" do
116
+ new_node = @neo.create_node
117
+ new_node[:id] = new_node["self"].split('/').last
118
+ @neo.get_node_properties(new_node[:id], ["weight", "height"]).should be_nil
119
+ end
120
+
121
+ it "returns nil if it fails to get properties on a node that does not exist" do
122
+ new_node = @neo.create_node
123
+ new_node[:id] = new_node["self"].split('/').last
124
+ @neo.get_node_properties(new_node[:id].to_i + 10000).should be_nil
125
+ end
126
+ end
127
+
128
+ describe "remove_node_properties" do
129
+ it "can remove a node's properties" do
130
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown")
131
+ new_node[:id] = new_node["self"].split('/').last
132
+ @neo.remove_node_properties(new_node[:id])
133
+ @neo.get_node_properties(new_node[:id]).should be_nil
134
+ end
135
+
136
+ it "returns nil if it fails to remove the properties of a node that does not exist" do
137
+ new_node = @neo.create_node
138
+ new_node[:id] = new_node["self"].split('/').last
139
+ @neo.remove_node_properties(new_node[:id].to_i + 10000).should be_nil
140
+ end
141
+
142
+ it "can remove a specific node property" do
143
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown")
144
+ new_node[:id] = new_node["self"].split('/').last
145
+ @neo.remove_node_properties(new_node[:id], "weight")
146
+ node_properties = @neo.get_node_properties(new_node[:id])
147
+ node_properties["weight"].should be_nil
148
+ node_properties["eyes"].should == "brown"
149
+ end
150
+
151
+ it "can remove more than one property" do
152
+ new_node = @neo.create_node("weight" => 200, "eyes" => "brown", "height" => "2m")
153
+ new_node[:id] = new_node["self"].split('/').last
154
+ @neo.remove_node_properties(new_node[:id], ["weight", "eyes"])
155
+ node_properties = @neo.get_node_properties(new_node[:id])
156
+ node_properties["weight"].should be_nil
157
+ node_properties["eyes"].should be_nil
158
+ end
159
+ end
160
+
161
+ describe "delete_node" do
162
+ it "can delete an unrelated node" do
163
+ new_node = @neo.create_node
164
+ new_node[:id] = new_node["self"].split('/').last
165
+ @neo.delete_node(new_node[:id]).should be_nil
166
+ existing_node = @neo.get_node(new_node[:id])
167
+ existing_node.should be_nil
168
+ end
169
+
170
+ it "cannot delete a node that has relationships" do
171
+ new_node1 = @neo.create_node
172
+ new_node1[:id] = new_node1["self"].split('/').last
173
+ new_node2 = @neo.create_node
174
+ new_node2[:id] = new_node2["self"].split('/').last
175
+ @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
176
+ @neo.delete_node(new_node1[:id]).should be_nil
177
+ existing_node = @neo.get_node(new_node1[:id])
178
+ existing_node.should_not be_nil
179
+ end
180
+
181
+ it "returns nil if it tries to delete a node that does not exist" do
182
+ new_node = @neo.create_node
183
+ new_node[:id] = new_node["self"].split('/').last
184
+ @neo.delete_node(new_node[:id].to_i + 1000).should be_nil
185
+ existing_node = @neo.get_node(new_node[:id].to_i + 1000)
186
+ existing_node.should be_nil
187
+ end
188
+
189
+ it "returns nil if it tries to delete a node that has already been deleted" do
190
+ new_node = @neo.create_node
191
+ new_node[:id] = new_node["self"].split('/').last
192
+ @neo.delete_node(new_node[:id]).should be_nil
193
+ existing_node = @neo.get_node(new_node[:id])
194
+ existing_node.should be_nil
195
+ @neo.delete_node(new_node[:id]).should be_nil
196
+ existing_node = @neo.get_node(new_node[:id])
197
+ existing_node.should be_nil
198
+ end
199
+ end
200
+
201
+ describe "delete_node!" do
202
+ it "can delete an unrelated node" do
203
+ new_node = @neo.create_node
204
+ new_node[:id] = new_node["self"].split('/').last
205
+ @neo.delete_node!(new_node[:id]).should be_nil
206
+ existing_node = @neo.get_node(new_node[:id])
207
+ existing_node.should be_nil
208
+ end
209
+
210
+ it "can delete a node that has relationships" do
211
+ new_node1 = @neo.create_node
212
+ new_node1[:id] = new_node1["self"].split('/').last
213
+ new_node2 = @neo.create_node
214
+ new_node2[:id] = new_node2["self"].split('/').last
215
+ @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
216
+ @neo.delete_node!(new_node1[:id]).should be_nil
217
+ existing_node = @neo.get_node(new_node1[:id])
218
+ existing_node.should be_nil
219
+ end
220
+
221
+ it "returns nil if it tries to delete a node that does not exist" do
222
+ new_node = @neo.create_node
223
+ new_node[:id] = new_node["self"].split('/').last
224
+ @neo.delete_node!(new_node[:id].to_i + 1000).should be_nil
225
+ existing_node = @neo.get_node(new_node[:id].to_i + 1000)
226
+ existing_node.should be_nil
227
+ end
228
+
229
+ it "returns nil if it tries to delete a node that has already been deleted" do
230
+ new_node = @neo.create_node
231
+ new_node[:id] = new_node["self"].split('/').last
232
+ @neo.delete_node!(new_node[:id]).should be_nil
233
+ existing_node = @neo.get_node(new_node[:id])
234
+ existing_node.should be_nil
235
+ @neo.delete_node!(new_node[:id]).should be_nil
236
+ existing_node = @neo.get_node(new_node[:id])
237
+ existing_node.should be_nil
238
+ end
239
+ end
240
+
241
+ end
@@ -0,0 +1,62 @@
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 "get path" do
9
+ it "can get a path between two nodes" do
10
+ new_node1 = @neo.create_node
11
+ new_node1[:id] = new_node1["self"].split('/').last
12
+ new_node2 = @neo.create_node
13
+ new_node2[:id] = new_node2["self"].split('/').last
14
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"})
15
+ path = @neo.get_path(new_node1[:id], new_node2[:id], {"type"=> "friends", "direction" => "out"})
16
+ path["start"].should == new_node1["self"]
17
+ path["end"].should == new_node2["self"]
18
+ path["nodes"].should == [new_node1["self"], new_node2["self"]]
19
+ end
20
+
21
+ it "can get the shortest path between two nodes" do
22
+ pending
23
+ end
24
+
25
+ it "can get a simple path between two nodes" do
26
+ pending
27
+ end
28
+
29
+ it "can get a path between two nodes of max depth 3" do
30
+ pending
31
+ end
32
+
33
+ it "can get a path between two nodes of a specific relationship" do
34
+ pending
35
+ end
36
+ end
37
+
38
+ describe "get paths" do
39
+ it "can get the shortest paths between two nodes" do
40
+ pending
41
+ end
42
+
43
+ it "can get all paths between two nodes" do
44
+ pending
45
+ end
46
+
47
+ it "can get all simple paths between two nodes" do
48
+ pending
49
+ end
50
+
51
+ it "can get paths between two nodes of max depth 3" do
52
+ pending
53
+ end
54
+
55
+ it "can get paths between two nodes of a specific relationship" do
56
+ pending
57
+ end
58
+
59
+ end
60
+
61
+
62
+ end
@@ -0,0 +1,372 @@
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 "create_relationship" do
9
+ it "can create an empty relationship" do
10
+ new_node1 = @neo.create_node
11
+ new_node1[:id] = new_node1["self"].split('/').last
12
+ new_node2 = @neo.create_node
13
+ new_node2[:id] = new_node2["self"].split('/').last
14
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
15
+ new_relationship["start"].should_not be_nil
16
+ new_relationship["end"].should_not be_nil
17
+ end
18
+
19
+ it "can create a relationship with one property" do
20
+ new_node1 = @neo.create_node
21
+ new_node1[:id] = new_node1["self"].split('/').last
22
+ new_node2 = @neo.create_node
23
+ new_node2[:id] = new_node2["self"].split('/').last
24
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010'})
25
+ new_relationship["data"]["since"].should == '10-1-2010'
26
+ end
27
+
28
+ it "can create a relationship with more than one property" do
29
+ new_node1 = @neo.create_node
30
+ new_node1[:id] = new_node1["self"].split('/').last
31
+ new_node2 = @neo.create_node
32
+ new_node2[:id] = new_node2["self"].split('/').last
33
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"})
34
+ new_relationship["data"]["since"].should == '10-1-2010'
35
+ new_relationship["data"]["met"].should == "college"
36
+ end
37
+ end
38
+
39
+ describe "set_relationship_properties" do
40
+ it "can set a relationship's properties" do
41
+ new_node1 = @neo.create_node
42
+ new_node1[:id] = new_node1["self"].split('/').last
43
+ new_node2 = @neo.create_node
44
+ new_node2[:id] = new_node2["self"].split('/').last
45
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
46
+ new_relationship[:id] = new_relationship["self"].split('/').last
47
+ @neo.set_relationship_properties(new_relationship[:id], {"since" => '10-1-2010', "met" => "college"})
48
+ @neo.set_relationship_properties(new_relationship[:id], {"roommates" => "no"})
49
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id])
50
+ relationship_properties["since"].should == '10-1-2010'
51
+ relationship_properties["met"].should == "college"
52
+ relationship_properties["roommates"].should == "no"
53
+ end
54
+
55
+ it "it fails to set properties on a relationship that does not exist" do
56
+ new_node1 = @neo.create_node
57
+ new_node1[:id] = new_node1["self"].split('/').last
58
+ new_node2 = @neo.create_node
59
+ new_node2[:id] = new_node2["self"].split('/').last
60
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
61
+ new_relationship[:id] = new_relationship["self"].split('/').last
62
+ @neo.set_relationship_properties(new_relationship[:id].to_i + 10000, {"since" => '10-1-2010', "met" => "college"})
63
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id].to_i + 10000)
64
+ relationship_properties.should be_nil
65
+ end
66
+ end
67
+
68
+ describe "reset_relationship_properties" do
69
+ it "can reset a relationship's properties" do
70
+ new_node1 = @neo.create_node
71
+ new_node1[:id] = new_node1["self"].split('/').last
72
+ new_node2 = @neo.create_node
73
+ new_node2[:id] = new_node2["self"].split('/').last
74
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
75
+ new_relationship[:id] = new_relationship["self"].split('/').last
76
+ @neo.set_relationship_properties(new_relationship[:id], {"since" => '10-1-2010', "met" => "college"})
77
+ @neo.reset_relationship_properties(new_relationship[:id], {"roommates" => "no"})
78
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id])
79
+ relationship_properties["since"].should be_nil
80
+ relationship_properties["met"].should be_nil
81
+ relationship_properties["roommates"].should == "no"
82
+ end
83
+
84
+ it "it fails to reset properties on a relationship that does not exist" do
85
+ new_node1 = @neo.create_node
86
+ new_node1[:id] = new_node1["self"].split('/').last
87
+ new_node2 = @neo.create_node
88
+ new_node2[:id] = new_node2["self"].split('/').last
89
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
90
+ new_relationship[:id] = new_relationship["self"].split('/').last
91
+ @neo.reset_relationship_properties(new_relationship[:id].to_i + 10000, {"since" => '10-1-2010', "met" => "college"})
92
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id].to_i + 10000)
93
+ relationship_properties.should be_nil
94
+ end
95
+ end
96
+
97
+ describe "get_relationship_properties" do
98
+ it "can get all of a relationship's properties" do
99
+ new_node1 = @neo.create_node
100
+ new_node1[:id] = new_node1["self"].split('/').last
101
+ new_node2 = @neo.create_node
102
+ new_node2[:id] = new_node2["self"].split('/').last
103
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"})
104
+ new_relationship[:id] = new_relationship["self"].split('/').last
105
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id])
106
+ relationship_properties["since"].should == '10-1-2010'
107
+ relationship_properties["met"].should == "college"
108
+ end
109
+
110
+ it "can get some of a relationship's properties" do
111
+ new_node1 = @neo.create_node
112
+ new_node1[:id] = new_node1["self"].split('/').last
113
+ new_node2 = @neo.create_node
114
+ new_node2[:id] = new_node2["self"].split('/').last
115
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college", "roommates" => "no"})
116
+ new_relationship[:id] = new_relationship["self"].split('/').last
117
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id], ["since", "roommates"])
118
+ relationship_properties["since"].should == '10-1-2010'
119
+ relationship_properties["met"].should be_nil
120
+ relationship_properties["roommates"].should == "no"
121
+ end
122
+
123
+ it "returns nil if it gets the properties on a relationship that does not have any" do
124
+ new_node1 = @neo.create_node
125
+ new_node1[:id] = new_node1["self"].split('/').last
126
+ new_node2 = @neo.create_node
127
+ new_node2[:id] = new_node2["self"].split('/').last
128
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
129
+ new_relationship[:id] = new_relationship["self"].split('/').last
130
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id])
131
+ relationship_properties.should be_nil
132
+ end
133
+
134
+ it "returns nil if it tries to get some of the properties on a relationship that does not have any" do
135
+ new_node1 = @neo.create_node
136
+ new_node1[:id] = new_node1["self"].split('/').last
137
+ new_node2 = @neo.create_node
138
+ new_node2[:id] = new_node2["self"].split('/').last
139
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
140
+ new_relationship[:id] = new_relationship["self"].split('/').last
141
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id], ["since", "roommates"])
142
+ relationship_properties.should be_nil
143
+ end
144
+
145
+ it "returns nil if it fails to get properties on a relationship that does not exist" do
146
+ new_node1 = @neo.create_node
147
+ new_node1[:id] = new_node1["self"].split('/').last
148
+ new_node2 = @neo.create_node
149
+ new_node2[:id] = new_node2["self"].split('/').last
150
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id])
151
+ new_relationship[:id] = new_relationship["self"].split('/').last
152
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id].to_i + 10000)
153
+ relationship_properties.should be_nil
154
+ end
155
+ end
156
+
157
+ describe "remove_relationship_properties" do
158
+ it "can remove a relationship's properties" do
159
+ new_node1 = @neo.create_node
160
+ new_node1[:id] = new_node1["self"].split('/').last
161
+ new_node2 = @neo.create_node
162
+ new_node2[:id] = new_node2["self"].split('/').last
163
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"})
164
+ new_relationship[:id] = new_relationship["self"].split('/').last
165
+ @neo.remove_relationship_properties(new_relationship[:id])
166
+ @neo.get_relationship_properties(new_relationship[:id]).should be_nil
167
+ end
168
+
169
+ it "returns nil if it fails to remove the properties of a relationship that does not exist" do
170
+ new_node1 = @neo.create_node
171
+ new_node1[:id] = new_node1["self"].split('/').last
172
+ new_node2 = @neo.create_node
173
+ new_node2[:id] = new_node2["self"].split('/').last
174
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"})
175
+ new_relationship[:id] = new_relationship["self"].split('/').last
176
+ @neo.remove_relationship_properties(new_relationship[:id])
177
+ @neo.get_relationship_properties(new_relationship[:id].to_i + 10000).should be_nil
178
+ end
179
+
180
+ it "can remove a specific relationship property" do
181
+ new_node1 = @neo.create_node
182
+ new_node1[:id] = new_node1["self"].split('/').last
183
+ new_node2 = @neo.create_node
184
+ new_node2[:id] = new_node2["self"].split('/').last
185
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"})
186
+ new_relationship[:id] = new_relationship["self"].split('/').last
187
+ @neo.remove_relationship_properties(new_relationship[:id], "met")
188
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id], ["met", "since"])
189
+ relationship_properties["met"].should be_nil
190
+ relationship_properties["since"].should == '10-1-2010'
191
+ end
192
+
193
+ it "can remove more than one relationship property" do
194
+ new_node1 = @neo.create_node
195
+ new_node1[:id] = new_node1["self"].split('/').last
196
+ new_node2 = @neo.create_node
197
+ new_node2[:id] = new_node2["self"].split('/').last
198
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college", "roommates" => "no"})
199
+ new_relationship[:id] = new_relationship["self"].split('/').last
200
+ @neo.remove_relationship_properties(new_relationship[:id], ["met", "since"])
201
+ relationship_properties = @neo.get_relationship_properties(new_relationship[:id], ["since", "met", "roommates"])
202
+ relationship_properties["met"].should be_nil
203
+ relationship_properties["since"].should be_nil
204
+ relationship_properties["roommates"].should == "no"
205
+ end
206
+ end
207
+
208
+ describe "delete_relationship" do
209
+ it "can delete an existing relationship" do
210
+ new_node1 = @neo.create_node
211
+ new_node1[:id] = new_node1["self"].split('/').last
212
+ new_node2 = @neo.create_node
213
+ new_node2[:id] = new_node2["self"].split('/').last
214
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"})
215
+ new_relationship[:id] = new_relationship["self"].split('/').last
216
+ @neo.delete_relationship(new_relationship[:id])
217
+ relationships = @neo.get_node_relationships(new_node1[:id])
218
+ relationships.should be_nil
219
+ end
220
+
221
+ it "returns nil if it tries to delete a relationship that does not exist" do
222
+ new_node1 = @neo.create_node
223
+ new_node1[:id] = new_node1["self"].split('/').last
224
+ new_node2 = @neo.create_node
225
+ new_node2[:id] = new_node2["self"].split('/').last
226
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"})
227
+ new_relationship[:id] = new_relationship["self"].split('/').last
228
+ existing_relationship = @neo.delete_relationship(new_relationship[:id].to_i + 1000)
229
+ existing_relationship.should be_nil
230
+ end
231
+
232
+ it "returns nil if it tries to delete a relationship that has already been deleted" do
233
+ new_node1 = @neo.create_node
234
+ new_node1[:id] = new_node1["self"].split('/').last
235
+ new_node2 = @neo.create_node
236
+ new_node2[:id] = new_node2["self"].split('/').last
237
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"})
238
+ new_relationship[:id] = new_relationship["self"].split('/').last
239
+ existing_relationship = @neo.delete_relationship(new_relationship[:id])
240
+ existing_relationship.should be_nil
241
+ existing_relationship = @neo.delete_relationship(new_relationship[:id])
242
+ existing_relationship.should be_nil
243
+ end
244
+ end
245
+
246
+ describe "get_node_relationships" do
247
+ it "can get a node's relationship" do
248
+ new_node1 = @neo.create_node
249
+ new_node1[:id] = new_node1["self"].split('/').last
250
+ new_node2 = @neo.create_node
251
+ new_node2[:id] = new_node2["self"].split('/').last
252
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"})
253
+ relationships = @neo.get_node_relationships(new_node1[:id])
254
+ relationships.should_not be_nil
255
+ relationships[0]["start"].split('/').last.should == new_node1[:id]
256
+ relationships[0]["end"].split('/').last.should == new_node2[:id]
257
+ relationships[0]["type"].should == "friends"
258
+ relationships[0]["data"]["met"].should == "college"
259
+ relationships[0]["data"]["since"].should == '10-1-2005'
260
+ end
261
+
262
+ it "can get a node's multiple relationships" do
263
+ new_node1 = @neo.create_node
264
+ new_node1[:id] = new_node1["self"].split('/').last
265
+ new_node2 = @neo.create_node
266
+ new_node2[:id] = new_node2["self"].split('/').last
267
+ new_node3 = @neo.create_node
268
+ new_node3[:id] = new_node3["self"].split('/').last
269
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"})
270
+ new_relationship = @neo.create_relationship("enemies", new_node1[:id], new_node3[:id], {"since" => '10-2-2010', "met" => "work"})
271
+ relationships = @neo.get_node_relationships(new_node1[:id])
272
+ relationships.should_not be_nil
273
+ relationships[0]["start"].split('/').last.should == new_node1[:id]
274
+ relationships[0]["end"].split('/').last.should == new_node2[:id]
275
+ relationships[0]["type"].should == "friends"
276
+ relationships[0]["data"]["met"].should == "college"
277
+ relationships[0]["data"]["since"].should == '10-1-2005'
278
+ relationships[1]["start"].split('/').last.should == new_node1[:id]
279
+ relationships[1]["end"].split('/').last.should == new_node3[:id]
280
+ relationships[1]["type"].should == "enemies"
281
+ relationships[1]["data"]["met"].should == "work"
282
+ relationships[1]["data"]["since"].should == '10-2-2010'
283
+ end
284
+
285
+ it "can get a node's outgoing relationship" do
286
+ new_node1 = @neo.create_node
287
+ new_node1[:id] = new_node1["self"].split('/').last
288
+ new_node2 = @neo.create_node
289
+ new_node2[:id] = new_node2["self"].split('/').last
290
+ new_node3 = @neo.create_node
291
+ new_node3[:id] = new_node3["self"].split('/').last
292
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"})
293
+ new_relationship = @neo.create_relationship("enemies", new_node3[:id], new_node1[:id], {"since" => '10-2-2010', "met" => "work"})
294
+ relationships = @neo.get_node_relationships(new_node1[:id], "out")
295
+ relationships.should_not be_nil
296
+ relationships[0]["start"].split('/').last.should == new_node1[:id]
297
+ relationships[0]["end"].split('/').last.should == new_node2[:id]
298
+ relationships[0]["type"].should == "friends"
299
+ relationships[0]["data"]["met"].should == "college"
300
+ relationships[0]["data"]["since"].should == '10-1-2005'
301
+ relationships[1].should be_nil
302
+ end
303
+
304
+ it "can get a node's incoming relationship" do
305
+ new_node1 = @neo.create_node
306
+ new_node1[:id] = new_node1["self"].split('/').last
307
+ new_node2 = @neo.create_node
308
+ new_node2[:id] = new_node2["self"].split('/').last
309
+ new_node3 = @neo.create_node
310
+ new_node3[:id] = new_node3["self"].split('/').last
311
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"})
312
+ new_relationship = @neo.create_relationship("enemies", new_node3[:id], new_node1[:id], {"since" => '10-2-2010', "met" => "work"})
313
+ relationships = @neo.get_node_relationships(new_node1[:id], "in")
314
+ relationships.should_not be_nil
315
+ relationships[0]["start"].split('/').last.should == new_node3[:id]
316
+ relationships[0]["end"].split('/').last.should == new_node1[:id]
317
+ relationships[0]["type"].should == "enemies"
318
+ relationships[0]["data"]["met"].should == "work"
319
+ relationships[0]["data"]["since"].should == '10-2-2010'
320
+ relationships[1].should be_nil
321
+ end
322
+
323
+ it "can get a specific type of node relationships" do
324
+ new_node1 = @neo.create_node
325
+ new_node1[:id] = new_node1["self"].split('/').last
326
+ new_node2 = @neo.create_node
327
+ new_node2[:id] = new_node2["self"].split('/').last
328
+ new_node3 = @neo.create_node
329
+ new_node3[:id] = new_node3["self"].split('/').last
330
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"})
331
+ new_relationship = @neo.create_relationship("enemies", new_node1[:id], new_node3[:id], {"since" => '10-2-2010', "met" => "work"})
332
+ relationships = @neo.get_node_relationships(new_node1[:id], "all", "friends")
333
+ relationships.should_not be_nil
334
+ relationships[0]["start"].split('/').last.should == new_node1[:id]
335
+ relationships[0]["end"].split('/').last.should == new_node2[:id]
336
+ relationships[0]["type"].should == "friends"
337
+ relationships[0]["data"]["met"].should == "college"
338
+ relationships[0]["data"]["since"].should == '10-1-2005'
339
+ relationships[1].should be_nil
340
+ end
341
+
342
+ it "can get a specific type and direction of a node relationships" do
343
+ new_node1 = @neo.create_node
344
+ new_node1[:id] = new_node1["self"].split('/').last
345
+ new_node2 = @neo.create_node
346
+ new_node2[:id] = new_node2["self"].split('/').last
347
+ new_node3 = @neo.create_node
348
+ new_node3[:id] = new_node3["self"].split('/').last
349
+ new_node4 = @neo.create_node
350
+ new_node4[:id] = new_node4["self"].split('/').last
351
+ new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"})
352
+ new_relationship = @neo.create_relationship("enemies", new_node1[:id], new_node3[:id], {"since" => '10-2-2010', "met" => "work"})
353
+ new_relationship = @neo.create_relationship("enemies", new_node4[:id], new_node1[:id], {"since" => '10-3-2010', "met" => "gym"})
354
+ relationships = @neo.get_node_relationships(new_node1[:id], "in", "enemies")
355
+ relationships.should_not be_nil
356
+ relationships[0]["start"].split('/').last.should == new_node4[:id]
357
+ relationships[0]["end"].split('/').last.should == new_node1[:id]
358
+ relationships[0]["type"].should == "enemies"
359
+ relationships[0]["data"]["met"].should == "gym"
360
+ relationships[0]["data"]["since"].should == '10-3-2010'
361
+ relationships[1].should be_nil
362
+ end
363
+
364
+ it "returns nil if there are no relationships" do
365
+ new_node1 = @neo.create_node
366
+ new_node1[:id] = new_node1["self"].split('/').last
367
+ relationships = @neo.get_node_relationships(new_node1[:id])
368
+ relationships.should be_nil
369
+ end
370
+ end
371
+
372
+ end