Skip to content

Commit

Permalink
Deprecated syntax with Neography::Rest server as the first argument t…
Browse files Browse the repository at this point in the history
…o Node and Relationship.
  • Loading branch information
Roel van Dijk committed Sep 26, 2012
1 parent bee8025 commit fea8727
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 37 deletions.
6 changes: 2 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,13 @@ The Neo4j ID is available by using node.neo_id .

Neography::Node.create # Create an empty node
Neography::Node.create("age" => 31, "name" => "Max") # Create a node with some properties
Neography::Node.create(@neo2, {"age" => 31, "name" => "Max"}) # Create a node on the server defined in @neo2
Neography::Node.create({"age" => 31, "name" => "Max"}, @neo2) # Same as above, but different order
Neography::Node.create({"age" => 31, "name" => "Max"}, @neo2) # Create a node on the server defined in @neo2

Neography::Node.load(5) # Get a node and its properties by id
Neography::Node.load(existing_node) # Get a node and its properties by Node
Neography::Node.load("http://localhost:7474/db/data/node/2") # Get a node and its properties by String

Neography::Node.load(@neo2, 5) # Get a node on the server defined in @neo2
Neography::Node.load(5, @neo2) # Same as above, but different order
Neography::Node.load(5, @neo2) # Get a node on the server defined in @neo2

n1 = Node.create
n1.del # Deletes the node
Expand Down
8 changes: 4 additions & 4 deletions lib/neography/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class Node < PropertyContainer
attr_accessor :neo_server

class << self
def create(*args)
db, props = split_args(*args)
def create(props = nil, db = Neography::Rest.new)
raise ArgumentError.new("syntax deprecated") if props.is_a?(Neography::Rest)

node = self.new(db.create_node(props))
node.neo_server = db
node
end

def load(*args)
db, node = split_args(*args)
def load(node, db = Neography::Rest.new)
raise ArgumentError.new("syntax deprecated") if node.is_a?(Neography::Rest)

node = db.get_node(node)
if node
Expand Down
12 changes: 6 additions & 6 deletions lib/neography/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ class Relationship < PropertyContainer

class << self

def create(type, from_node, to_node, props=nil)
def create(type, from_node, to_node, props = nil)
rel = Neography::Relationship.new(from_node.neo_server.create_relationship(type, from_node, to_node, props))
rel.start_node = from_node
rel.end_node = to_node
rel.rel_type = type
rel
end

def load(*args)
db, rel = split_args(*args)
def load(rel, db = Neography::Rest.new)
raise ArgumentError.new("syntax deprecated") if rel.is_a?(Neography::Rest)

rel = db.get_relationship(rel)
if rel
rel = Neography::Relationship.new(rel)
rel.start_node = Neography::Node.load(rel.start_node, db)
rel.end_node = Neography::Node.load(rel.end_node, db)
rel = Neography::Relationship.new(rel)
rel.start_node = Neography::Node.load(rel.start_node, db)
rel.end_node = Neography::Node.load(rel.end_node, db)
end
rel
end
Expand Down
23 changes: 11 additions & 12 deletions spec/integration/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
new_node.age.should == 31
end

it "can create a node with more than one property not on the default rest server the other way" do
it "cannot create a node with more than one property not on the default rest server the other way" do
@neo = Neography::Rest.new
new_node = Neography::Node.create(@neo, {"age" => 31, "name" => "Max"})
new_node.name.should == "Max"
new_node.age.should == 31
expect {
new_node = Neography::Node.create(@neo, {"age" => 31, "name" => "Max"})
}.to raise_error(ArgumentError)
end
end

Expand All @@ -53,20 +53,19 @@

it "can load a node that exists not on the default rest server" do
@neo = Neography::Rest.new
new_node = Neography::Node.create(@neo)
new_node = Neography::Node.create({}, @neo)
existing_node = Neography::Node.load(new_node, @neo)
existing_node.should_not be_nil
existing_node.neo_id.should_not be_nil
existing_node.neo_id.should == new_node.neo_id
end

it "can load a node that exists not on the default rest server the other way" do
it "cannot load a node that exists not on the default rest server the other way" do
@neo = Neography::Rest.new
new_node = Neography::Node.create(@neo)
existing_node = Neography::Node.load(@neo, new_node)
existing_node.should_not be_nil
existing_node.neo_id.should_not be_nil
existing_node.neo_id.should == new_node.neo_id
new_node = Neography::Node.create({}, @neo)
expect {
existing_node = Neography::Node.load(@neo, new_node)
}.to raise_error(ArgumentError)
end
end

Expand Down Expand Up @@ -221,4 +220,4 @@
end


end
end
19 changes: 11 additions & 8 deletions spec/unit/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module Neography
context "no explicit server" do

before do
# stub out actual connections
@db = stub(Rest).as_null_object
@db = mock(Neography::Rest, :is_a? => true).as_null_object
Rest.stub(:new) { @db }
end

Expand All @@ -32,11 +31,13 @@ module Neography

context "explicit server" do

it "can pass a server as the first arugment, properties as the second" do
it "cannot pass a server as the first argument, properties as the second (deprecated)" do
@other_server = Neography::Rest.new
properties = { :foo => "bar" }
@other_server.should_receive(:create_node).with(properties)
Node.create(@other_server, properties)
@other_server.should_not_receive(:create_node).with(properties)
expect {
Node.create(@other_server, properties)
}.to raise_error(ArgumentError)
end

it "can pass properties as the first argument, a server as the second" do
Expand Down Expand Up @@ -78,10 +79,12 @@ module Neography

context "explicit server" do

it "can pass a server as the first argument, node as the second" do
it "cannot pass a server as the first argument, node as the second (depracted)" do
@other_server = Neography::Rest.new
@other_server.should_receive(:get_node).with(42)
node = Node.load(@other_server, 42)
@other_server.should_not_receive(:get_node).with(42)
expect {
node = Node.load(@other_server, 42)
}.to raise_error(ArgumentError)
end

it "can pass a node as the first argument, server as the second" do
Expand Down
8 changes: 5 additions & 3 deletions spec/unit/relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ module Neography

context "explicit server" do

it "can pass a server as the first argument, relationship as the second" do
it "cannot pass a server as the first argument, relationship as the second" do
@other_server = Neography::Rest.new
@other_server.should_receive(:get_relationship).with(42)
relationship = Relationship.load(@other_server, 42)
@other_server.should_not_receive(:get_relationship).with(42)
expect {
relationship = Relationship.load(@other_server, 42)
}.to raise_error(ArgumentError)
end

it "can pass a relationship as the first argument, server as the second" do
Expand Down

0 comments on commit fea8727

Please sign in to comment.