Skip to content

Commit

Permalink
adding unit tests for labels
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jun 18, 2013
1 parent 735ebc2 commit da919e8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
2 changes: 0 additions & 2 deletions spec/integration/rest_labels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 == []
Expand Down
73 changes: 73 additions & 0 deletions spec/unit/rest/rest_labels_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit da919e8

Please sign in to comment.