Skip to content

Commit

Permalink
Merge pull request #105 from sosiouxme/label-node-hashes
Browse files Browse the repository at this point in the history
Accept node hashes in label methods
  • Loading branch information
maxdemarzi committed Aug 14, 2013
2 parents 62a16ed + 02295aa commit 40c1a0c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
16 changes: 8 additions & 8 deletions lib/neography/rest/node_labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,21 +37,21 @@ 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 => (
Array(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


Expand Down
51 changes: 24 additions & 27 deletions spec/integration/rest_labels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -39,25 +38,24 @@
labels.should == ["Actor", "Director"]
end
end

describe "set_label" do
it "can set a label to a node" do
new_node = @neo.create_node
new_node_id = new_node["self"].split('/').last
@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
Expand All @@ -70,28 +68,27 @@
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
new_node_id = new_node["self"].split('/').last
@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
Expand All @@ -101,31 +98,31 @@
@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")
new_node_id = new_node["self"].split('/').last
@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")
new_node_id = new_node["self"].split('/').last
@neo.set_label(new_node_id, "clown")
nodes = @neo.find_nodes_labeled("clown", { :name => "does_not_exist" })
nodes.should == []
end
end

end

end

end
end

0 comments on commit 40c1a0c

Please sign in to comment.