From 987f5f08f86f4a1c42ff08084278d3e97dcad485 Mon Sep 17 00:00:00 2001 From: Roel van Dijk Date: Sat, 8 Sep 2012 22:15:30 +0200 Subject: [PATCH] Add NodePaths specs. --- lib/neography/rest/node_paths.rb | 2 +- spec/unit/rest/node_paths_spec.rb | 80 +++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 spec/unit/rest/node_paths_spec.rb diff --git a/lib/neography/rest/node_paths.rb b/lib/neography/rest/node_paths.rb index 97e0947..1b0cb47 100644 --- a/lib/neography/rest/node_paths.rb +++ b/lib/neography/rest/node_paths.rb @@ -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 diff --git a/spec/unit/rest/node_paths_spec.rb b/spec/unit/rest/node_paths_spec.rb new file mode 100644 index 0000000..372509f --- /dev/null +++ b/spec/unit/rest/node_paths_spec.rb @@ -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