-
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.
Add some basic unit tests for REST classes.
- Loading branch information
Showing
6 changed files
with
262 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
class Rest | ||
describe Clean do | ||
|
||
let(:connection) { stub } | ||
subject { Clean.new(connection) } | ||
|
||
it "cleans the database" do | ||
connection.should_receive(:delete).with("/cleandb/secret-key") | ||
subject.execute | ||
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,21 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
class Rest | ||
describe Cypher do | ||
|
||
let(:connection) { stub(:cypher_path => "/cypher") } | ||
subject { Cypher.new(connection) } | ||
|
||
it "executes a cypher query" do | ||
options = { | ||
:body=>"{\"query\":\"SOME QUERY\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}", | ||
:headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true"} | ||
} | ||
connection.should_receive(:post).with("/cypher", options) | ||
subject.query("SOME QUERY", { :foo => "bar", :baz => "qux" }) | ||
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,26 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
class Rest | ||
describe Gremlin do | ||
|
||
let(:connection) { stub(:gremlin_path => "/gremlin") } | ||
subject { Gremlin.new(connection) } | ||
|
||
it "executes a gremlin script" do | ||
options = { | ||
:body=>"{\"script\":\"SOME SCRIPT\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}", | ||
:headers=>{"Content-Type"=>"application/json"} | ||
} | ||
connection.should_receive(:post).with("/gremlin", options) | ||
subject.execute("SOME SCRIPT", { :foo => "bar", :baz => "qux" }) | ||
end | ||
|
||
it "returns nil if script result is null" do | ||
connection.stub(:post).and_return("null") | ||
subject.execute("", {}).should be_nil | ||
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,194 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
class Rest | ||
describe Nodes do | ||
|
||
let(:connection) { stub } | ||
subject { Nodes.new(connection) } | ||
|
||
context "get nodes" do | ||
it "gets single nodes" do | ||
connection.should_receive(:get).with("/node/42") | ||
subject.get("42") | ||
end | ||
|
||
it "gets multiple nodes" do | ||
connection.should_receive(:get).with("/node/42") | ||
connection.should_receive(:get).with("/node/43") | ||
subject.get_each("42", "43") | ||
end | ||
|
||
it "returns multiple nodes in an array" do | ||
connection.stub(:get).and_return("foo", "bar") | ||
subject.get_each("42", "43").should == [ "foo", "bar" ] | ||
end | ||
|
||
it "gets the root node" do | ||
connection.stub(:get).with("/").and_return({ "reference_node" => "42" }) | ||
connection.should_receive(:get).with("/node/42") | ||
subject.root | ||
end | ||
|
||
it "returns the root node" do | ||
connection.stub(:get).and_return({ "reference_node" => "42" }, "foo") | ||
subject.root.should == "foo" | ||
end | ||
end | ||
|
||
context "create nodes" do | ||
|
||
it "creates with attributes" do | ||
options = { | ||
:body => '{"foo":"bar","baz":"qux"}', | ||
:headers => json_content_type | ||
} | ||
connection.should_receive(:post).with("/node", options) | ||
subject.create_with_attributes({:foo => "bar", :baz => "qux"}) | ||
end | ||
|
||
it "returns the created node" do | ||
connection.stub(:post).and_return("foo") | ||
subject.create_with_attributes({}).should == "foo" | ||
end | ||
|
||
it "creates with attributes using #create method" do | ||
options = { | ||
:body => '{"foo":"bar","baz":"qux"}', | ||
:headers => json_content_type | ||
} | ||
connection.should_receive(:post).with("/node", options) | ||
subject.create({:foo => "bar", :baz => "qux"}) | ||
end | ||
|
||
it "creates empty nodes" do | ||
connection.should_receive(:post).with("/node") | ||
subject.create_empty | ||
end | ||
|
||
it "returns an empty node" do | ||
connection.stub(:post).and_return("foo") | ||
subject.create_empty.should == "foo" | ||
end | ||
|
||
it "creates empty nodes using #create method" do | ||
connection.should_receive(:post).with("/node") | ||
subject.create | ||
end | ||
|
||
end | ||
|
||
context "delete nodes" do | ||
|
||
it "deletes a node" do | ||
connection.should_receive(:delete).with("/node/42") | ||
subject.delete("42") | ||
end | ||
|
||
end | ||
|
||
context "#create_multiple" do | ||
|
||
it "creates multiple with attributes" do | ||
options1 = { | ||
:body => '{"foo1":"bar1","baz1":"qux1"}', | ||
:headers => json_content_type | ||
} | ||
options2 = { | ||
:body => '{"foo2":"bar2","baz2":"qux2"}', | ||
:headers => json_content_type | ||
} | ||
connection.should_receive(:post).with("/node", options1) | ||
connection.should_receive(:post).with("/node", options2) | ||
|
||
subject.create_multiple([ | ||
{:foo1 => "bar1", :baz1 => "qux1"}, | ||
{:foo2 => "bar2", :baz2 => "qux2"} | ||
]) | ||
end | ||
|
||
it "returns multiple nodes with attributes in an array" do | ||
connection.stub(:post).and_return("foo", "bar") | ||
subject.create_multiple([{},{}]).should == ["foo", "bar"] | ||
end | ||
|
||
# exotic? | ||
it "creates multiple with and without attributes" do | ||
options1 = { | ||
:body => '{"foo1":"bar1","baz1":"qux1"}', | ||
:headers => json_content_type | ||
} | ||
connection.should_receive(:post).with("/node", options1) | ||
connection.should_receive(:post).with("/node") | ||
|
||
subject.create_multiple([ | ||
{:foo1 => "bar1", :baz1 => "qux1"}, | ||
"not a hash" # ? | ||
]) | ||
end | ||
|
||
it "creates multiple empty nodes" do | ||
connection.should_receive(:post).with("/node").twice | ||
subject.create_multiple(2) | ||
end | ||
|
||
it "returns multiple empty nodes in an array" do | ||
connection.stub(:post).and_return("foo", "bar") | ||
subject.create_multiple(2).should == ["foo", "bar"] | ||
end | ||
|
||
end | ||
|
||
context "#create_multiple_threaded" do | ||
|
||
let(:connection) { stub(:max_threads => 2) } | ||
|
||
it "creates multiple with attributes" do | ||
options1 = { | ||
:body => '{"foo1":"bar1","baz1":"qux1"}', | ||
:headers => json_content_type | ||
} | ||
options2 = { | ||
:body => '{"foo2":"bar2","baz2":"qux2"}', | ||
:headers => json_content_type | ||
} | ||
connection.should_receive(:post).with("/node", options1) | ||
connection.should_receive(:post).with("/node", options2) | ||
|
||
subject.create_multiple_threaded([ | ||
{:foo1 => "bar1", :baz1 => "qux1"}, | ||
{:foo2 => "bar2", :baz2 => "qux2"} | ||
]) | ||
end | ||
|
||
# exotic? | ||
it "creates multiple with and without attributes" do | ||
options1 = { | ||
:body => '{"foo1":"bar1","baz1":"qux1"}', | ||
:headers => json_content_type | ||
} | ||
connection.should_receive(:post).with("/node", options1) | ||
connection.should_receive(:post).with("/node") | ||
|
||
subject.create_multiple_threaded([ | ||
{:foo1 => "bar1", :baz1 => "qux1"}, | ||
"not a hash" # ? | ||
]) | ||
end | ||
|
||
it "creates multiple empty nodes" do | ||
connection.should_receive(:post).with("/node").twice | ||
subject.create_multiple_threaded(2) | ||
end | ||
|
||
end | ||
|
||
private | ||
|
||
def json_content_type | ||
{"Content-Type"=>"application/json"} | ||
end | ||
|
||
end | ||
end | ||
end |