From 482a905e55fe5f47f7c67dc6f50f323523f7cb64 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Thu, 27 Mar 2014 13:45:16 -0500 Subject: [PATCH] handle strings in batch --- lib/neography/rest/batch.rb | 6 +++--- spec/unit/rest/batch_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/neography/rest/batch.rb b/lib/neography/rest/batch.rb index 71c7113..10a5ad6 100644 --- a/lib/neography/rest/batch.rb +++ b/lib/neography/rest/batch.rb @@ -22,9 +22,9 @@ def do_batch(*args) end def get_batch(args) - if args[0].class == Symbol - send(("batch_" + args[0].to_s).to_sym, *args[1..-1]) - else + begin + send("batch_#{args[0]}".to_sym, *args[1..-1]) + rescue raise "Unknown option #{args[0]} - #{args}" end end diff --git a/spec/unit/rest/batch_spec.rb b/spec/unit/rest/batch_spec.rb index 8a3d629..669f376 100644 --- a/spec/unit/rest/batch_spec.rb +++ b/spec/unit/rest/batch_spec.rb @@ -16,6 +16,16 @@ class Rest subject.batch [:get_node, "foo"], [:get_node, "bar"] end + it "gets nodes without symbol" do + expected_body = [ + { "id" => 0, "method" => "GET", "to" => "/node/foo" }, + { "id" => 1, "method" => "GET", "to" => "/node/bar" } + ] + + subject.connection.should_receive(:post).with("/batch", json_match(:body, expected_body)) + subject.batch ["get_node", "foo"], [:get_node, "bar"] + end + it "creates nodes" do expected_body = [ { "id" => 0, "method" => "POST", "to" => "/node", "body" => { "foo" => "bar" } },