Skip to content

Commit

Permalink
Add NodePaths specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdvdijk committed Sep 8, 2012
1 parent 26f9e0e commit 987f5f0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/neography/rest/node_paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_all(from, to, relationships, depth, algorithm)
"algorithm" => get_algorithm(algorithm)
}.to_json,
:headers => json_content_type
}
}
@connection.post(all_path(:id => get_id(from)), options) || []
end

Expand Down
80 changes: 80 additions & 0 deletions spec/unit/rest/node_paths_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'spec_helper'

module Neography
class Rest
describe NodePaths do

let(:connection) { stub(:configuration => "http://configuration") }
subject { NodePaths.new(connection) }

it "gets a shortest path between two nodes" do
expected_body = {
"to" => "http://configuration/node/43",
"relationships" => "relationships",
"max_depth" => 3,
"algorithm" => "shortestPath"
}

connection.should_receive(:post).with("/node/42/path", json_match(:body, expected_body))

subject.get("42", "43", "relationships", 3, "shortestPath")
end

it "gets all shortest paths between two nodes" do
expected_body = {
"to" => "http://configuration/node/43",
"relationships" => "relationships",
"max_depth" => 3,
"algorithm" => "shortestPath"
}

connection.should_receive(:post).with("/node/42/paths", json_match(:body, expected_body))

subject.get_all("42", "43", "relationships", 3, "shortestPath")
end

it "gets all shortest weighted paths between two nodes" do
expected_body = {
"to" => "http://configuration/node/43",
"relationships" => "relationships",
"cost_property" => "cost",
"max_depth" => 3,
"algorithm" => "shortestPath"
}

connection.should_receive(:post).with("/node/42/paths", json_match(:body, expected_body))

subject.shortest_weighted("42", "43", "relationships", "cost", 3, "shortestPath")
end

context "algorithm" do

subject { NodePaths.new(nil) }

[ :shortest, "shortest", :shortestPath, "shortestPath", :short, "short" ].each do |algorithm|
it "parses shortestPath" do
subject.send(:get_algorithm, algorithm).should == "shortestPath"
end
end

[ :allSimplePaths, "allSimplePaths", :simple, "simple" ].each do |algorithm|
it "parses allSimplePaths" do
subject.send(:get_algorithm, algorithm).should == "allSimplePaths"
end
end

[ :dijkstra, "dijkstra" ].each do |algorithm|
it "parses dijkstra" do
subject.send(:get_algorithm, algorithm).should == "dijkstra"
end
end

it "parses allPaths by default" do
subject.send(:get_algorithm, "foo").should == "allPaths"
end

end

end
end
end

0 comments on commit 987f5f0

Please sign in to comment.