Skip to content

Commit

Permalink
handle strings in batch
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 27, 2014
1 parent 6fd53ff commit 482a905
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/neography/rest/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

This comment has been minimized.

Copy link
@kwent

kwent Mar 27, 2014

Contributor

BTW Shouldn't raise a Neography::UnknownBatchOption exception instead than StandardError ( Cleaner ) ?

This comment has been minimized.

Copy link
@maxdemarzi

maxdemarzi Mar 27, 2014

Author Owner

Send me a pull request. If I write one more line of code this week my fingers are gonna fall off.

end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/rest/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" } },
Expand Down

0 comments on commit 482a905

Please sign in to comment.