diff --git a/lib/neography/rest/node_labels.rb b/lib/neography/rest/node_labels.rb index b48ab16..27968eb 100644 --- a/lib/neography/rest/node_labels.rb +++ b/lib/neography/rest/node_labels.rb @@ -17,11 +17,11 @@ def initialize(connection) def list @connection.get(base_path) end - + def get(id) - @connection.get(node_path(:id => id)) + @connection.get(node_path(:id => get_id(id))) end - + def get_nodes(label) @connection.get(nodes_path(:label => label)) end @@ -37,9 +37,9 @@ def add(id, label) ).to_json, :headers => json_content_type } - @connection.post(node_path(:id => id), options) + @connection.post(node_path(:id => get_id(id)), options) end - + def set(id, label) options = { :body => ( @@ -47,11 +47,11 @@ def set(id, label) ).to_json, :headers => json_content_type } - @connection.put(node_path(:id => id), options) - end + @connection.put(node_path(:id => get_id(id)), options) + end def delete(id, label) - @connection.delete(delete_path(:id => id, :label => label)) + @connection.delete(delete_path(:id => get_id(id), :label => label)) end diff --git a/spec/integration/rest_labels_spec.rb b/spec/integration/rest_labels_spec.rb index 68dc28e..26a2d7d 100644 --- a/spec/integration/rest_labels_spec.rb +++ b/spec/integration/rest_labels_spec.rb @@ -16,9 +16,8 @@ describe "add_label" do it "can add a label to a node" do new_node = @neo.create_node - new_node_id = new_node["self"].split('/').last - @neo.add_label(new_node_id, "Person") - labels = @neo.get_node_labels(new_node_id) + @neo.add_label(new_node, "Person") + labels = @neo.get_node_labels(new_node) labels.should == ["Person"] end @@ -39,7 +38,7 @@ labels.should == ["Actor", "Director"] end end - + describe "set_label" do it "can set a label to a node" do new_node = @neo.create_node @@ -47,17 +46,16 @@ @neo.set_label(new_node_id, "Person") labels = @neo.get_node_labels(new_node_id) labels.should == ["Person"] - end + end it "can set a label to a node that already had a label" do new_node = @neo.create_node - new_node_id = new_node["self"].split('/').last - @neo.add_label(new_node_id, "Actor") - @neo.set_label(new_node_id, "Director") - labels = @neo.get_node_labels(new_node_id) + @neo.add_label(new_node, "Actor") + @neo.set_label(new_node, "Director") + labels = @neo.get_node_labels(new_node) labels.should == ["Director"] - end - + end + it "can set multiple labels to a node" do new_node = @neo.create_node new_node_id = new_node["self"].split('/').last @@ -70,12 +68,11 @@ describe "delete_label" do it "can delete a label from a node" do new_node = @neo.create_node - new_node_id = new_node["self"].split('/').last - @neo.set_label(new_node_id, ["Actor", "Director"]) - @neo.delete_label(new_node_id, "Actor") - labels = @neo.get_node_labels(new_node_id) + @neo.set_label(new_node, ["Actor", "Director"]) + @neo.delete_label(new_node, "Actor") + labels = @neo.get_node_labels(new_node) labels.should == ["Director"] - end + end it "can delete a label from a node that doesn't have one" do new_node = @neo.create_node @@ -83,15 +80,15 @@ @neo.delete_label(new_node_id, "Actor") labels = @neo.get_node_labels(new_node_id) labels.should == [] - end + end it "cannot delete a label from a node that doesn't exist" do new_node = @neo.create_node new_node_id = new_node["self"].split('/').last - expect { + expect { @neo.delete_label(new_node_id.to_i + 1, "Actor") }.to raise_error Neography::NodeNotFoundException - end + end end describe "get_nodes_labeled" do @@ -101,14 +98,14 @@ @neo.set_label(new_node_id, ["Actor", "Director"]) nodes = @neo.get_nodes_labeled("Actor") nodes.last["self"].split('/').last.should == new_node_id - end + end it "returns an empty array on non-existing label" do nodes = @neo.get_nodes_labeled("do_not_exist") nodes.should == [] - end + end end - + describe "find_nodes_labeled" do it "can find a node with a label and a property" do new_node = @neo.create_node(:name => "max") @@ -116,7 +113,7 @@ @neo.set_label(new_node_id, "clown") nodes = @neo.find_nodes_labeled("clown", { :name => "max" }) nodes.last["self"].split('/').last.should == new_node_id - end + end it "returns an empty array on non-existing label property" do new_node = @neo.create_node(:name => "max") @@ -124,8 +121,8 @@ @neo.set_label(new_node_id, "clown") nodes = @neo.find_nodes_labeled("clown", { :name => "does_not_exist" }) nodes.should == [] - end + end + + end - end - -end \ No newline at end of file +end