From fea872764f4b2d2486dba562631a919acd2e62b2 Mon Sep 17 00:00:00 2001 From: Roel van Dijk Date: Wed, 26 Sep 2012 16:41:10 +0200 Subject: [PATCH] Deprecated syntax with Neography::Rest server as the first argument to Node and Relationship. --- README.rdoc | 6 ++---- lib/neography/node.rb | 8 ++++---- lib/neography/relationship.rb | 12 ++++++------ spec/integration/node_spec.rb | 23 +++++++++++------------ spec/unit/node_spec.rb | 19 +++++++++++-------- spec/unit/relationship_spec.rb | 8 +++++--- 6 files changed, 39 insertions(+), 37 deletions(-) diff --git a/README.rdoc b/README.rdoc index 8947d00..31f9775 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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 diff --git a/lib/neography/node.rb b/lib/neography/node.rb index a074148..609f6b3 100644 --- a/lib/neography/node.rb +++ b/lib/neography/node.rb @@ -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 diff --git a/lib/neography/relationship.rb b/lib/neography/relationship.rb index 889cb4f..0bf5b0e 100644 --- a/lib/neography/relationship.rb +++ b/lib/neography/relationship.rb @@ -8,7 +8,7 @@ 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 @@ -16,14 +16,14 @@ def create(type, from_node, to_node, props=nil) 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 diff --git a/spec/integration/node_spec.rb b/spec/integration/node_spec.rb index e7ea393..647b174 100644 --- a/spec/integration/node_spec.rb +++ b/spec/integration/node_spec.rb @@ -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 @@ -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 @@ -221,4 +220,4 @@ end -end \ No newline at end of file +end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index ead1081..e52e575 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/unit/relationship_spec.rb b/spec/unit/relationship_spec.rb index 5612171..5af1f52 100644 --- a/spec/unit/relationship_spec.rb +++ b/spec/unit/relationship_spec.rb @@ -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