-
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.
- Loading branch information
Showing
4 changed files
with
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Convenience matcher for matching JSON fields with a hash | ||
RSpec::Matchers.define :json_match do |field, expected| | ||
|
||
match do |actual| | ||
expected == JSON.parse(actual[field]) | ||
end | ||
|
||
failure_message_for_should do | ||
"expected JSON in field '#{@field}' to not match '#{@expected}'" | ||
end | ||
|
||
description do | ||
"JSON in field '#{field}' should match '#{expected.inspect}'" | ||
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
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,62 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
class Rest | ||
describe NodeRelationships do | ||
|
||
let(:connection) { stub(:configuration => "http://configuration") } | ||
subject { NodeRelationships.new(connection) } | ||
|
||
it "creates a relationship" do | ||
body_hash = { "type" => "some_type", | ||
"to" => "http://configuration/node/43", | ||
"data" => {"foo"=>"bar","baz"=>"qux"} | ||
} | ||
connection.should_receive(:post).with("/node/42/relationships", json_match(:body, body_hash)) | ||
|
||
subject.create("some_type", "42", "43", {:foo => "bar", :baz => "qux"}) | ||
end | ||
|
||
it "gets relationships" do | ||
connection.should_receive(:get).with("/node/42/relationships/all") | ||
subject.get("42") | ||
end | ||
|
||
it "gets relationships with direction" do | ||
connection.should_receive(:get).with("/node/42/relationships/in") | ||
subject.get("42", :in) | ||
end | ||
|
||
it "gets relationships with direction and type" do | ||
connection.should_receive(:get).with("/node/42/relationships/in/foo") | ||
subject.get("42", :in, "foo") | ||
end | ||
|
||
it "gets relationships with direction and types" do | ||
connection.should_receive(:get).with("/node/42/relationships/in/foo&bar") | ||
subject.get("42", :in, ["foo", "bar"]) | ||
end | ||
|
||
context "directions" do | ||
|
||
[ :incoming, "incoming", :in, "in" ].each do |direction| | ||
it "parses 'in' direction" do | ||
NodeRelationships.new(nil).parse_direction(direction).should == "in" | ||
end | ||
end | ||
|
||
[ :outgoing, "outgoing", :out, "out" ].each do |direction| | ||
it "parses 'out' direction" do | ||
NodeRelationships.new(nil).parse_direction(direction).should == "out" | ||
end | ||
end | ||
|
||
it "parses 'all' direction by default" do | ||
NodeRelationships.new(nil).parse_direction("foo").should == "all" | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |