-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up the Node and Relationship classes, add some basic specs.
- Loading branch information
Roel van Dijk
committed
Sep 23, 2012
1 parent
b4834e5
commit 6536a7e
Showing
5 changed files
with
208 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
describe Node do | ||
|
||
describe "::create" do | ||
context "no explicit server" do | ||
|
||
before do | ||
# stub out actual connections | ||
@db = stub(Rest).as_null_object | ||
Rest.stub(:new) { @db } | ||
end | ||
|
||
it "assigns a new Rest db by default" do | ||
node = Node.create | ||
node.neo_server.should == @db | ||
end | ||
|
||
it "creates without arguments" do | ||
@db.should_receive(:create_node).with(nil) | ||
Node.create | ||
end | ||
|
||
it "creates with only a hash argument" do | ||
properties = { :foo => "bar" } | ||
@db.should_receive(:create_node).with(properties) | ||
Node.create(properties) | ||
end | ||
|
||
end | ||
|
||
context "explicit server" do | ||
|
||
it "can pass a server as the first arugment, properties as the second" do | ||
@other_server = Neography::Rest.new | ||
properties = { :foo => "bar" } | ||
@other_server.should_receive(:create_node).with(properties) | ||
Node.create(@other_server, properties) | ||
end | ||
|
||
it "can pass properties as the first argument, a server as the second" do | ||
@other_server = Neography::Rest.new | ||
properties = { :foo => "bar" } | ||
@other_server.should_receive(:create_node).with(properties) | ||
Node.create(properties, @other_server) | ||
end | ||
|
||
end | ||
end | ||
|
||
describe "::load" do | ||
context "no explicit server" do | ||
|
||
before do | ||
# stub out actual connections | ||
@db = stub(Rest).as_null_object | ||
Rest.stub(:new) { @db } | ||
end | ||
|
||
it "load by id" do | ||
@db.should_receive(:get_node).with(5) | ||
Node.load(5) | ||
end | ||
|
||
it "loads by node" do | ||
node = Node.new | ||
@db.should_receive(:get_node).with(node) | ||
Node.load(node) | ||
end | ||
|
||
it "loads by full server string" do | ||
@db.should_receive(:get_node).with("http://localhost:7474/db/data/node/2") | ||
Node.load("http://localhost:7474/db/data/node/2") | ||
end | ||
|
||
end | ||
|
||
context "explicit server" do | ||
|
||
it "can pass a server as the first argument, node as the second" do | ||
@other_server = Neography::Rest.new | ||
@other_server.should_receive(:get_node).with(42) | ||
node = Node.load(@other_server, 42) | ||
end | ||
|
||
it "can pass a node as the first argument, server as the second" do | ||
@other_server = Neography::Rest.new | ||
@other_server.should_receive(:get_node).with(42) | ||
node = Node.load(42, @other_server) | ||
end | ||
|
||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
describe Relationship do | ||
|
||
let(:db) { stub(Rest).as_null_object } | ||
let(:relationship_hash) do | ||
{ | ||
"self" => "0", | ||
"start" => "1", | ||
"end" => "2", | ||
"data" => {} | ||
} | ||
end | ||
|
||
describe "::create" do | ||
let(:from) { stub(:neo_server => db) } | ||
let(:to) { stub(:neo_server => db) } | ||
let(:props) { { :foo => "bar" } } | ||
|
||
it "creates a new node through Rest" do | ||
db.should_receive(:create_relationship).with("type", from, to, props) | ||
|
||
Relationship.create("type", from, to, props) | ||
end | ||
|
||
it "assigns fields" do | ||
db.stub(:create_relationship).and_return(relationship_hash) | ||
|
||
rel = Relationship.create("type", from, to, props) | ||
|
||
rel.start_node.should == from | ||
rel.end_node.should == to | ||
rel.rel_type.should == "type" | ||
end | ||
end | ||
|
||
describe "::load" do | ||
context "no explicit server" do | ||
|
||
before do | ||
# stub out actual connections | ||
@db = stub(Rest).as_null_object | ||
Rest.stub(:new) { @db } | ||
end | ||
|
||
it "load by id" do | ||
@db.should_receive(:get_relationship).with(5) | ||
Relationship.load(5) | ||
end | ||
|
||
it "loads by relationship" do | ||
relationship = Relationship.new(relationship_hash) | ||
@db.should_receive(:get_relationship).with(relationship) | ||
Relationship.load(relationship) | ||
end | ||
|
||
it "loads by full server string" do | ||
@db.should_receive(:get_relationship).with("http://localhost:7474/db/data/relationship/2") | ||
Relationship.load("http://localhost:7474/db/data/relationship/2") | ||
end | ||
|
||
end | ||
|
||
context "explicit server" do | ||
|
||
it "can 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) | ||
end | ||
|
||
it "can pass a relationship as the first argument, server as the second" do | ||
@other_server = Neography::Rest.new | ||
@other_server.should_receive(:get_relationship).with(42) | ||
relationship = Relationship.load(42, @other_server) | ||
end | ||
|
||
end | ||
end | ||
|
||
end | ||
end |