neography 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ Maintainer:
2
+ Max De Marzi <maxdemarzi at gmail dot com>
3
+
4
+ Contributors:
5
+ * Peter Neubauer
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neography (0.0.1)
4
+ neography (0.0.2)
5
5
  httparty (~> 0.6.1)
6
6
  json
7
7
 
@@ -9,8 +9,13 @@ If you want to the full power of Neo4j, you will want to use JRuby and the excel
9
9
  === Installation
10
10
 
11
11
  gem install 'neography'
12
+
13
+ After that, in your ruby script, do
14
+
15
+ require 'rubygems'
12
16
  require 'neography'
13
17
 
18
+ in order to access the functionality.
14
19
  === Dependencies
15
20
 
16
21
  for use:
@@ -41,46 +46,46 @@ To Use:
41
46
 
42
47
  @neo = Neography::Rest.new
43
48
 
44
- @neo.get_root # Get the root node
45
- @neo.create_node # Create an empty node
46
- @neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
47
- @neo.get_node(id) # Get a node and its properties
48
- @neo.delete_node(id) # Delete an unrelated node
49
- @neo.delete_node!(id) # Delete a node and all its relationships
50
-
51
- @neo.reset_node_properties(id, {"age" => 31}) # Reset a node's properties
52
- @neo.set_node_properties(id, {"weight" => 200}) # Set a node's properties
53
- @neo.get_node_properties(id) # Get just the node properties
54
- @neo.get_node_properties(id, ["weight","age"]) # Get some of the node properties
55
- @neo.remove_node_properties(id) # Remove all properties of a node
56
- @neo.remove_node_properties(id, "weight") # Remove one property of a node
57
- @neo.remove_node_properties(id, ["weight","age"]) # Remove multiple properties of a node
58
-
59
- @neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
60
- @neo.get_node_relationships(id) # Get all relationships
61
- @neo.get_node_relationships(id, "in") # Get only incoming relationships
62
- @neo.get_node_relationships(id, "all", "enemies") # Get all relationships of type enemies
63
- @neo.get_node_relationships(id, "in", "enemies") # Get only incoming relationships of type enemies
64
- @neo.delete_relationship(id) # Delete a relationship
65
-
66
- @neo.reset_relationship_properties(id, {"age" => 31}) # Reset a relationship's properties
67
- @neo.set_relationship_properties(id, {"weight" => 200}) # Set a relationship's properties
68
- @neo.get_relationship_properties(id) # Get just the relationship properties
69
- @neo.get_relationship_properties(id, ["since","met"]) # Get some of the relationship properties
70
- @neo.remove_relationship_properties(id) # Remove all properties of a relationship
71
- @neo.remove_relationship_properties(id, "since") # Remove one property of a relationship
72
- @neo.remove_relationship_properties(id, ["since","met"]) # Remove multiple properties of a relationship
73
-
74
- @neo.list_indexes # doesn't really seam to do what the api says it does
75
- @neo.add_to_index(key, value, id) # adds a node to an index with the given key/value pair
76
- @neo.remove_from_index(key, value, id) # removes a node to an index with the given key/value pair
77
- @neo.get_index(key, value) # gets an index with the given key/value pair
78
-
79
- @neo.get_path(from, to, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
80
- @neo.get_paths(from, to, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
81
-
82
- nodes = @neo.traverse(id, # the id of the node where the traversal starts
83
- "nodes", # return_type (can be "nodes", "relationships" or "paths"
49
+ @neo.get_root # Get the root node
50
+ node1 = @neo.create_node # Create an empty node
51
+ node2 = @neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
52
+ @neo.get_node(node2) # Get a node and its properties
53
+ @neo.delete_node(node2) # Delete an unrelated node
54
+ @neo.delete_node!(node2) # Delete a node and all its relationships
55
+
56
+ @neo.reset_node_properties(node1, {"age" => 31}) # Reset a node's properties
57
+ @neo.set_node_properties(node1, {"weight" => 200}) # Set a node's properties
58
+ @neo.get_node_properties(node1) # Get just the node properties
59
+ @neo.get_node_properties(node1, ["weight","age"]) # Get some of the node properties
60
+ @neo.remove_node_properties(node1) # Remove all properties of a node
61
+ @neo.remove_node_properties(node1, "weight") # Remove one property of a node
62
+ @neo.remove_node_properties(node1, ["weight","age"]) # Remove multiple properties of a node
63
+
64
+ rel1 = @neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
65
+ @neo.get_node_relationships(node1) # Get all relationships
66
+ @neo.get_node_relationships(node1, "in") # Get only incoming relationships
67
+ @neo.get_node_relationships(node1, "all", "enemies") # Get all relationships of type enemies
68
+ @neo.get_node_relationships(node1, "in", "enemies") # Get only incoming relationships of type enemies
69
+ @neo.delete_relationship(rel1) # Delete a relationship
70
+
71
+ @neo.reset_relationship_properties(rel1, {"age" => 31}) # Reset a relationship's properties
72
+ @neo.set_relationship_properties(rel1, {"weight" => 200}) # Set a relationship's properties
73
+ @neo.get_relationship_properties(rel1) # Get just the relationship properties
74
+ @neo.get_relationship_properties(rel1, ["since","met"]) # Get some of the relationship properties
75
+ @neo.remove_relationship_properties(rel1) # Remove all properties of a relationship
76
+ @neo.remove_relationship_properties(rel1, "since") # Remove one property of a relationship
77
+ @neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship
78
+
79
+ @neo.list_indexes # doesn't really seam to do what the api says it does
80
+ @neo.add_to_index(key, value, node1) # adds a node to an index with the given key/value pair
81
+ @neo.remove_from_index(key, value, node1) # removes a node to an index with the given key/value pair
82
+ @neo.get_index(key, value) # gets an index with the given key/value pair
83
+
84
+ @neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
85
+ @neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
86
+
87
+ nodes = @neo.traverse(node1, # the node where the traversal starts
88
+ "nodes", # return_type "nodes", "relationships" or "paths"
84
89
  {"order" => "breadth first", # "breadth first" or "depth first" traversal order
85
90
  "uniqueness" => "node global", # See Uniqueness in API documentation for options.
86
91
  "relationships" => [{"type"=> "roommates", # A hash containg a description of the traversal
@@ -88,7 +93,7 @@ To Use:
88
93
  {"type"=> "friends", #
89
94
  "direction" => "out"}], #
90
95
  "prune evaluator" => {"language" => "javascript", # A prune evaluator (when to stop traversing)
91
- "body" => "position.endNode().getProperty('age') < 21;"
96
+ "body" => "position.endNode().getProperty('age') < 21;"},
92
97
  "return filter" => {"language" => "builtin", # "all" or "all but start node"
93
98
  "name" => "all"},
94
99
  "depth" => 4})
@@ -36,21 +36,21 @@ module Neography
36
36
  end
37
37
 
38
38
  def get_node(id)
39
- get("/node/#{id}")
39
+ get("/node/#{get_id(id)}")
40
40
  end
41
41
 
42
42
  def reset_node_properties(id, properties)
43
43
  options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} }
44
- put("/node/#{id}/properties", options)
44
+ put("/node/#{get_id(id)}/properties", options)
45
45
  end
46
46
 
47
47
  def get_node_properties(id, properties = nil)
48
48
  if properties.nil?
49
- get("/node/#{id}/properties")
49
+ get("/node/#{get_id(id)}/properties")
50
50
  else
51
51
  node_properties = Hash.new
52
52
  properties.to_a.each do |property|
53
- value = get("/node/#{id}/properties/#{property}")
53
+ value = get("/node/#{get_id(id)}/properties/#{property}")
54
54
  node_properties[property] = value unless value.nil?
55
55
  end
56
56
  return nil if node_properties.empty?
@@ -60,10 +60,10 @@ module Neography
60
60
 
61
61
  def remove_node_properties(id, properties = nil)
62
62
  if properties.nil?
63
- delete("/node/#{id}/properties")
63
+ delete("/node/#{get_id(id)}/properties")
64
64
  else
65
65
  properties.to_a.each do |property|
66
- delete("/node/#{id}/properties/#{property}")
66
+ delete("/node/#{get_id(id)}/properties/#{property}")
67
67
  end
68
68
  end
69
69
  end
@@ -71,31 +71,31 @@ module Neography
71
71
  def set_node_properties(id, properties)
72
72
  properties.each do |key, value|
73
73
  options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} }
74
- put("/node/#{id}/properties/#{key}", options)
74
+ put("/node/#{get_id(id)}/properties/#{key}", options)
75
75
  end
76
76
  end
77
77
 
78
78
  def delete_node(id)
79
- delete("/node/#{id}")
79
+ delete("/node/#{get_id(id)}")
80
80
  end
81
81
 
82
82
  def create_relationship(type, from, to, props = nil)
83
- options = { :body => {:to => self.configuration + "/node/#{to}", :data => props, :type => type }.to_json, :headers => {'Content-Type' => 'application/json'} }
84
- post("/node/#{from}/relationships", options)
83
+ options = { :body => {:to => self.configuration + "/node/#{get_id(to)}", :data => props, :type => type }.to_json, :headers => {'Content-Type' => 'application/json'} }
84
+ post("/node/#{get_id(from)}/relationships", options)
85
85
  end
86
86
 
87
87
  def reset_relationship_properties(id, properties)
88
88
  options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} }
89
- put("/relationship/#{id}/properties", options)
89
+ put("/relationship/#{get_id(id)}/properties", options)
90
90
  end
91
91
 
92
92
  def get_relationship_properties(id, properties = nil)
93
93
  if properties.nil?
94
- get("/relationship/#{id}/properties")
94
+ get("/relationship/#{get_id(id)}/properties")
95
95
  else
96
96
  relationship_properties = Hash.new
97
97
  properties.to_a.each do |property|
98
- value = get("/relationship/#{id}/properties/#{property}")
98
+ value = get("/relationship/#{get_id(id)}/properties/#{property}")
99
99
  relationship_properties[property] = value unless value.nil?
100
100
  end
101
101
  return nil if relationship_properties.empty?
@@ -105,10 +105,10 @@ module Neography
105
105
 
106
106
  def remove_relationship_properties(id, properties = nil)
107
107
  if properties.nil?
108
- delete("/relationship/#{id}/properties")
108
+ delete("/relationship/#{get_id(id)}/properties")
109
109
  else
110
110
  properties.to_a.each do |property|
111
- delete("/relationship/#{id}/properties/#{property}")
111
+ delete("/relationship/#{get_id(id)}/properties/#{property}")
112
112
  end
113
113
  end
114
114
  end
@@ -116,30 +116,30 @@ module Neography
116
116
  def set_relationship_properties(id, properties)
117
117
  properties.each do |key, value|
118
118
  options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} }
119
- put("/relationship/#{id}/properties/#{key}", options)
119
+ put("/relationship/#{get_id(id)}/properties/#{key}", options)
120
120
  end
121
121
  end
122
122
 
123
123
  def delete_relationship(id)
124
- delete("/relationship/#{id}")
124
+ delete("/relationship/#{get_id(id)}")
125
125
  end
126
126
 
127
127
  def get_node_relationships(id, dir=nil, types=nil)
128
128
  dir = get_dir(dir)
129
129
 
130
130
  if types.nil?
131
- node_relationships = get("/node/#{id}/relationships/#{dir}") || Array.new
131
+ node_relationships = get("/node/#{get_id(id)}/relationships/#{dir}") || Array.new
132
132
  else
133
- node_relationships = get("/node/#{id}/relationships/#{dir}/#{types.to_a.join('&')}") || Array.new
133
+ node_relationships = get("/node/#{get_id(id)}/relationships/#{dir}/#{types.to_a.join('&')}") || Array.new
134
134
  end
135
135
  return nil if node_relationships.empty?
136
136
  node_relationships
137
137
  end
138
138
 
139
139
  def delete_node!(id)
140
- relationships = get_node_relationships(id)
140
+ relationships = get_node_relationships(get_id(id))
141
141
  relationships.each { |r| delete_relationship(r["self"].split('/').last) } unless relationships.nil?
142
- delete("/node/#{id}")
142
+ delete("/node/#{get_id(id)}")
143
143
  end
144
144
 
145
145
  def list_indexes
@@ -147,12 +147,12 @@ module Neography
147
147
  end
148
148
 
149
149
  def add_to_index(key, value, id)
150
- options = { :body => (self.configuration + "/node/#{id}").to_json, :headers => {'Content-Type' => 'application/json'} }
150
+ options = { :body => (self.configuration + "/node/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} }
151
151
  post("/index/node/#{key}/#{value}", options)
152
152
  end
153
153
 
154
154
  def remove_from_index(key, value, id)
155
- delete("/index/node/#{key}/#{value}/#{id}")
155
+ delete("/index/node/#{key}/#{value}/#{get_id(id)}")
156
156
  end
157
157
 
158
158
  def get_index(key, value)
@@ -168,17 +168,17 @@ module Neography
168
168
  "prune evaluator" => description["prune evaluator"],
169
169
  "return filter" => description["return filter"],
170
170
  "max depth" => get_depth(description["depth"]), }.to_json, :headers => {'Content-Type' => 'application/json'} }
171
- traversal = post("/node/#{id}/traverse/#{get_type(return_type)}", options) || Array.new
171
+ traversal = post("/node/#{get_id(id)}/traverse/#{get_type(return_type)}", options) || Array.new
172
172
  end
173
173
 
174
174
  def get_path(from, to, relationships, depth=1, algorithm="shortestPath")
175
- options = { :body => {"to" => self.configuration + "/node/#{to}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
176
- path = post("/node/#{from}/path", options) || Hash.new
175
+ options = { :body => {"to" => self.configuration + "/node/#{get_id(to)}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
176
+ path = post("/node/#{get_id(from)}/path", options) || Hash.new
177
177
  end
178
178
 
179
179
  def get_paths(from, to, relationships, depth=1, algorithm="allPaths")
180
- options = { :body => {"to" => self.configuration + "/node/#{to}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
181
- paths = post("/node/#{from}/paths", options) || Array.new
180
+ options = { :body => {"to" => self.configuration + "/node/#{get_id(to)}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
181
+ paths = post("/node/#{get_id(from)}/paths", options) || Array.new
182
182
  end
183
183
 
184
184
  private
@@ -190,10 +190,10 @@ module Neography
190
190
  case code
191
191
  when 200
192
192
  @logger.debug "OK" if @log_enabled
193
- response
193
+ response.parsed_response
194
194
  when 201
195
195
  @logger.debug "OK, created #{body}" if @log_enabled
196
- response
196
+ response.parsed_response
197
197
  when 204
198
198
  @logger.debug "OK, no content returned" if @log_enabled
199
199
  nil
@@ -225,6 +225,17 @@ module Neography
225
225
  evaluate_response(HTTParty.delete(configuration + path, options))
226
226
  end
227
227
 
228
+ def get_id(id)
229
+ case id
230
+ when Hash
231
+ id["self"].split('/').last
232
+ when String
233
+ id.split('/').last
234
+ else
235
+ id
236
+ end
237
+ end
238
+
228
239
  def get_dir(dir)
229
240
  case dir
230
241
  when :incoming, "incoming", :in, "in"
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -14,26 +14,24 @@ describe Neography::Rest do
14
14
  describe "add to index" do
15
15
  it "can add a node to an index" do
16
16
  new_node = @neo.create_node
17
- new_node[:id] = new_node["self"].split('/').last
18
17
  key = generate_text(6)
19
18
  value = generate_text
20
- @neo.add_to_index(key, value, new_node[:id])
19
+ @neo.add_to_index(key, value, new_node)
21
20
  new_index = @neo.get_index(key, value)
22
21
  new_index.should_not be_nil
23
- @neo.remove_from_index(key, value, new_node[:id])
22
+ @neo.remove_from_index(key, value, new_node)
24
23
  end
25
24
  end
26
25
 
27
26
  describe "remove from index" do
28
27
  it "can remove a node from an index" do
29
28
  new_node = @neo.create_node
30
- new_node[:id] = new_node["self"].split('/').last
31
29
  key = generate_text(6)
32
30
  value = generate_text
33
- @neo.add_to_index(key, value, new_node[:id])
31
+ @neo.add_to_index(key, value, new_node)
34
32
  new_index = @neo.get_index(key, value)
35
33
  new_index.should_not be_nil
36
- @neo.remove_from_index(key, value, new_node[:id])
34
+ @neo.remove_from_index(key, value, new_node)
37
35
  new_index = @neo.get_index(key, value)
38
36
  new_index.should be_nil
39
37
  end
@@ -42,13 +40,12 @@ describe Neography::Rest do
42
40
  describe "get index" do
43
41
  it "can get an index" do
44
42
  new_node = @neo.create_node
45
- new_node[:id] = new_node["self"].split('/').last
46
43
  key = generate_text(6)
47
44
  value = generate_text
48
- @neo.add_to_index(key, value, new_node[:id])
45
+ @neo.add_to_index(key, value, new_node)
49
46
  new_index = @neo.get_index(key, value)
50
47
  new_index.should_not be_nil
51
- @neo.remove_from_index(key, value, new_node[:id])
48
+ @neo.remove_from_index(key, value, new_node)
52
49
  end
53
50
  end
54
51
 
@@ -34,7 +34,7 @@ describe Neography::Rest do
34
34
  it "can get a node that exists" do
35
35
  new_node = @neo.create_node
36
36
  new_node[:id] = new_node["self"].split('/').last
37
- existing_node = @neo.get_node(new_node[:id])
37
+ existing_node = @neo.get_node(new_node)
38
38
  existing_node.should_not be_nil
39
39
  existing_node.should have_key("self")
40
40
  existing_node["self"].split('/').last.should == new_node[:id]
@@ -42,8 +42,8 @@ describe Neography::Rest do
42
42
 
43
43
  it "returns nil if it tries to get a node that does not exist" do
44
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)
45
+ fake_node = new_node["self"].split('/').last.to_i + 1000
46
+ existing_node = @neo.get_node(fake_node)
47
47
  existing_node.should be_nil
48
48
  end
49
49
  end
@@ -51,18 +51,17 @@ describe Neography::Rest do
51
51
  describe "set_node_properties" do
52
52
  it "can set a node's properties" do
53
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])
54
+ @neo.set_node_properties(new_node, {"weight" => 200, "eyes" => "brown"})
55
+ existing_node = @neo.get_node(new_node)
57
56
  existing_node["data"]["weight"].should == 200
58
57
  existing_node["data"]["eyes"].should == "brown"
59
58
  end
60
59
 
61
60
  it "it fails to set properties on a node that does not exist" do
62
61
  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)
62
+ fake_node = new_node["self"].split('/').last.to_i + 1000
63
+ @neo.set_node_properties(fake_node, {"weight" => 150, "hair" => "blonde"})
64
+ node_properties = @neo.get_node_properties(fake_node)
66
65
  node_properties.should be_nil
67
66
  end
68
67
  end
@@ -70,10 +69,9 @@ describe Neography::Rest do
70
69
  describe "reset_node_properties" do
71
70
  it "can reset a node's properties" do
72
71
  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])
72
+ @neo.set_node_properties(new_node, {"weight" => 200, "eyes" => "brown", "hair" => "black"})
73
+ @neo.reset_node_properties(new_node, {"weight" => 190, "eyes" => "blue"})
74
+ existing_node = @neo.get_node(new_node)
77
75
  existing_node["data"]["weight"].should == 190
78
76
  existing_node["data"]["eyes"].should == "blue"
79
77
  existing_node["data"]["hair"].should be_nil
@@ -81,9 +79,9 @@ describe Neography::Rest do
81
79
 
82
80
  it "it fails to reset properties on a node that does not exist" do
83
81
  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)
82
+ fake_node = new_node["self"].split('/').last.to_i + 1000
83
+ @neo.reset_node_properties(fake_node, {"weight" => 170, "eyes" => "green"})
84
+ node_properties = @neo.get_node_properties(fake_node)
87
85
  node_properties.should be_nil
88
86
  end
89
87
  end
@@ -91,16 +89,14 @@ describe Neography::Rest do
91
89
  describe "get_node_properties" do
92
90
  it "can get all of a node's properties" do
93
91
  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])
92
+ node_properties = @neo.get_node_properties(new_node)
96
93
  node_properties["weight"].should == 200
97
94
  node_properties["eyes"].should == "brown"
98
95
  end
99
96
 
100
97
  it "can get some of a node's properties" do
101
98
  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"])
99
+ node_properties = @neo.get_node_properties(new_node, ["weight", "height"])
104
100
  node_properties["weight"].should == 200
105
101
  node_properties["height"].should == "2m"
106
102
  node_properties["eyes"].should be_nil
@@ -108,51 +104,46 @@ describe Neography::Rest do
108
104
 
109
105
  it "returns nil if it gets the properties on a node that does not have any" do
110
106
  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
107
+ @neo.get_node_properties(new_node).should be_nil
113
108
  end
114
109
 
115
110
  it "returns nil if it tries to get some of the properties on a node that does not have any" do
116
111
  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
112
+ @neo.get_node_properties(new_node, ["weight", "height"]).should be_nil
119
113
  end
120
114
 
121
115
  it "returns nil if it fails to get properties on a node that does not exist" do
122
116
  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
117
+ fake_node = new_node["self"].split('/').last.to_i + 1000
118
+ @neo.get_node_properties(fake_node).should be_nil
125
119
  end
126
120
  end
127
121
 
128
122
  describe "remove_node_properties" do
129
123
  it "can remove a node's properties" do
130
124
  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
125
+ @neo.remove_node_properties(new_node)
126
+ @neo.get_node_properties(new_node).should be_nil
134
127
  end
135
128
 
136
129
  it "returns nil if it fails to remove the properties of a node that does not exist" do
137
130
  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
131
+ fake_node = new_node["self"].split('/').last.to_i + 1000
132
+ @neo.remove_node_properties(fake_node).should be_nil
140
133
  end
141
134
 
142
135
  it "can remove a specific node property" do
143
136
  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])
137
+ @neo.remove_node_properties(new_node, "weight")
138
+ node_properties = @neo.get_node_properties(new_node)
147
139
  node_properties["weight"].should be_nil
148
140
  node_properties["eyes"].should == "brown"
149
141
  end
150
142
 
151
143
  it "can remove more than one property" do
152
144
  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])
145
+ @neo.remove_node_properties(new_node, ["weight", "eyes"])
146
+ node_properties = @neo.get_node_properties(new_node)
156
147
  node_properties["weight"].should be_nil
157
148
  node_properties["eyes"].should be_nil
158
149
  end
@@ -161,39 +152,35 @@ describe Neography::Rest do
161
152
  describe "delete_node" do
162
153
  it "can delete an unrelated node" do
163
154
  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])
155
+ @neo.delete_node(new_node).should be_nil
156
+ existing_node = @neo.get_node(new_node)
167
157
  existing_node.should be_nil
168
158
  end
169
159
 
170
160
  it "cannot delete a node that has relationships" do
171
161
  new_node1 = @neo.create_node
172
- new_node1[:id] = new_node1["self"].split('/').last
173
162
  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])
163
+ @neo.create_relationship("friends", new_node1, new_node2)
164
+ @neo.delete_node(new_node1).should be_nil
165
+ existing_node = @neo.get_node(new_node1)
178
166
  existing_node.should_not be_nil
179
167
  end
180
168
 
181
169
  it "returns nil if it tries to delete a node that does not exist" do
182
170
  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)
171
+ fake_node = new_node["self"].split('/').last.to_i + 1000
172
+ @neo.delete_node(fake_node).should be_nil
173
+ existing_node = @neo.get_node(fake_node)
186
174
  existing_node.should be_nil
187
175
  end
188
176
 
189
177
  it "returns nil if it tries to delete a node that has already been deleted" do
190
178
  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])
179
+ @neo.delete_node(new_node).should be_nil
180
+ existing_node = @neo.get_node(new_node)
194
181
  existing_node.should be_nil
195
- @neo.delete_node(new_node[:id]).should be_nil
196
- existing_node = @neo.get_node(new_node[:id])
182
+ @neo.delete_node(new_node).should be_nil
183
+ existing_node = @neo.get_node(new_node)
197
184
  existing_node.should be_nil
198
185
  end
199
186
  end
@@ -201,39 +188,35 @@ describe Neography::Rest do
201
188
  describe "delete_node!" do
202
189
  it "can delete an unrelated node" do
203
190
  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])
191
+ @neo.delete_node!(new_node).should be_nil
192
+ existing_node = @neo.get_node(new_node)
207
193
  existing_node.should be_nil
208
194
  end
209
195
 
210
196
  it "can delete a node that has relationships" do
211
197
  new_node1 = @neo.create_node
212
- new_node1[:id] = new_node1["self"].split('/').last
213
198
  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])
199
+ @neo.create_relationship("friends", new_node1, new_node2)
200
+ @neo.delete_node!(new_node1).should be_nil
201
+ existing_node = @neo.get_node(new_node1)
218
202
  existing_node.should be_nil
219
203
  end
220
204
 
221
205
  it "returns nil if it tries to delete a node that does not exist" do
222
206
  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)
207
+ fake_node = new_node["self"].split('/').last.to_i + 1000
208
+ @neo.delete_node!(fake_node).should be_nil
209
+ existing_node = @neo.get_node(fake_node)
226
210
  existing_node.should be_nil
227
211
  end
228
212
 
229
213
  it "returns nil if it tries to delete a node that has already been deleted" do
230
214
  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])
215
+ @neo.delete_node!(new_node).should be_nil
216
+ existing_node = @neo.get_node(new_node)
234
217
  existing_node.should be_nil
235
- @neo.delete_node!(new_node[:id]).should be_nil
236
- existing_node = @neo.get_node(new_node[:id])
218
+ @neo.delete_node!(new_node).should be_nil
219
+ existing_node = @neo.get_node(new_node)
237
220
  existing_node.should be_nil
238
221
  end
239
222
  end