diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 33397e1..6240cc9 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -46,6 +46,7 @@ class Rest include Transactions include Nodes include NodeProperties + include Relationships extend Forwardable attr_reader :connection @@ -62,7 +63,6 @@ def initialize(options = ENV['NEO4J_URL'] || {}) @node_traversal ||= NodeTraversal.new(@connection) @node_paths ||= NodePaths.new(@connection) - @relationships ||= Relationships.new(@connection) @relationship_properties ||= RelationshipProperties.new(@connection) @relationship_indexes ||= RelationshipIndexes.new(@connection) @relationship_auto_indexes ||= RelationshipAutoIndexes.new(@connection) @@ -91,17 +91,8 @@ def delete_node!(id) # get("/nodes/") # end - # relationships - def get_relationship(id) - @relationships.get(id) - end - - def delete_relationship(id) - @relationships.delete(id) - end - def get_relationship_start_node(rel) get_node(rel["start"]) end @@ -109,6 +100,7 @@ def get_relationship_start_node(rel) def get_relationship_end_node(rel) get_node(rel["end"]) end + # relationship properties diff --git a/lib/neography/rest/batch.rb b/lib/neography/rest/batch.rb index e9b933f..bd52cb8 100644 --- a/lib/neography/rest/batch.rb +++ b/lib/neography/rest/batch.rb @@ -139,11 +139,11 @@ def get_node_relationships(id, direction = nil, types = nil) # Relationships def get_relationship(id) - get Relationships.base_path(:id => get_id(id)) + get "/relationship/%{id}" % {:id => get_id(id)} end def delete_relationship(id) - delete Relationships.base_path(:id => get_id(id)) + delete "/relationship/%{id}" % {:id => get_id(id)} end def create_relationship(type, from, to, data = nil) diff --git a/lib/neography/rest/relationships.rb b/lib/neography/rest/relationships.rb index 4191df3..3627386 100644 --- a/lib/neography/rest/relationships.rb +++ b/lib/neography/rest/relationships.rb @@ -1,21 +1,14 @@ module Neography class Rest - class Relationships - extend Neography::Rest::Paths + module Relationships include Neography::Rest::Helpers - - add_path :base, "/relationship/:id" - - def initialize(connection) - @connection ||= connection - end - - def get(id) - @connection.get(base_path(:id => get_id(id))) + + def get_relationship(id) + @connection.get("/relationship/%{id}" % {:id => get_id(id)}) end - def delete(id) - @connection.delete(base_path(:id => get_id(id))) + def delete_relationship(id) + @connection.delete("/relationship/%{id}" % {:id => get_id(id)}) end end diff --git a/spec/unit/rest/relationships_spec.rb b/spec/unit/rest/relationships_spec.rb index d6373ec..2f01bea 100644 --- a/spec/unit/rest/relationships_spec.rb +++ b/spec/unit/rest/relationships_spec.rb @@ -4,17 +4,16 @@ module Neography class Rest describe Relationships do - let(:connection) { double } - subject { Relationships.new(connection) } + subject { Neography::Rest.new } it "gets a relationship" do - connection.should_receive(:get).with("/relationship/42") - subject.get("42") + subject.connection.should_receive(:get).with("/relationship/42") + subject.get_relationship("42") end it "deletes a relationship" do - connection.should_receive(:delete).with("/relationship/42") - subject.delete("42") + subject.connection.should_receive(:delete).with("/relationship/42") + subject.delete_relationship("42") end end