From da919e851bdbda4d4dead054b5a25f662258727d Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Mon, 17 Jun 2013 19:57:26 -0500 Subject: [PATCH] adding unit tests for labels --- spec/integration/rest_labels_spec.rb | 2 - spec/unit/rest/rest_labels_spec.rb | 73 ++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 spec/unit/rest/rest_labels_spec.rb diff --git a/spec/integration/rest_labels_spec.rb b/spec/integration/rest_labels_spec.rb index 3d72e2a..68dc28e 100644 --- a/spec/integration/rest_labels_spec.rb +++ b/spec/integration/rest_labels_spec.rb @@ -113,7 +113,6 @@ it "can find a node with a label and a property" do new_node = @neo.create_node(:name => "max") new_node_id = new_node["self"].split('/').last - puts new_node_id @neo.set_label(new_node_id, "clown") nodes = @neo.find_nodes_labeled("clown", { :name => "max" }) nodes.last["self"].split('/').last.should == new_node_id @@ -122,7 +121,6 @@ it "returns an empty array on non-existing label property" do new_node = @neo.create_node(:name => "max") new_node_id = new_node["self"].split('/').last - puts new_node_id @neo.set_label(new_node_id, "clown") nodes = @neo.find_nodes_labeled("clown", { :name => "does_not_exist" }) nodes.should == [] diff --git a/spec/unit/rest/rest_labels_spec.rb b/spec/unit/rest/rest_labels_spec.rb new file mode 100644 index 0000000..b0ede40 --- /dev/null +++ b/spec/unit/rest/rest_labels_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +module Neography + class Rest + describe NodeLabels do + + let(:connection) { stub } + subject { NodeLabels.new(connection) } + + it "list node labels" do + connection.should_receive(:get).with("/labels") + subject.list + end + + it "get labels for node" do + connection.should_receive(:get).with("/node/0/labels") + subject.get(0) + end + + it "get nodes for labels" do + connection.should_receive(:get).with("/label/person/nodes") + subject.get_nodes("person") + end + + it "find nodes for labels and property" do + connection.should_receive(:get).with("/label/person/nodes?name=\"max\"") + subject.find_nodes("person", {:name => "max"}) + end + + it "can add a label to a node" do + options = { + :body => '["Actor"]', + :headers => json_content_type + } + connection.should_receive(:post).with("/node/0/labels", options) + subject.add(0, ["Actor"]) + end + + it "can add labels to a node" do + options = { + :body => '["Actor","Director"]', + :headers => json_content_type + } + connection.should_receive(:post).with("/node/0/labels", options) + subject.add(0, ["Actor", "Director"]) + end + + it "can set a label to a node" do + options = { + :body => '["Actor"]', + :headers => json_content_type + } + connection.should_receive(:put).with("/node/0/labels", options) + subject.set(0, ["Actor"]) + end + + it "can add labels to a node" do + options = { + :body => '["Actor","Director"]', + :headers => json_content_type + } + connection.should_receive(:put).with("/node/0/labels", options) + subject.set(0, ["Actor", "Director"]) + end + + it "can delete a label from a node" do + connection.should_receive(:delete).with("/node/0/labels/Actor") + subject.delete(0,"Actor") + end + + end + end +end