From 30a94ffd5a6bd35f7ed7aa58e5e84511d07336c1 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Thu, 19 Dec 2013 10:00:43 -0500 Subject: [PATCH 1/2] fixes automatically quoting value in find_node_labels search --- lib/neography/rest/node_labels.rb | 2 +- lib/neography/rest/paths.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/neography/rest/node_labels.rb b/lib/neography/rest/node_labels.rb index 27968eb..85ab331 100644 --- a/lib/neography/rest/node_labels.rb +++ b/lib/neography/rest/node_labels.rb @@ -7,7 +7,7 @@ class NodeLabels add_path :base, "/labels" add_path :node, "/node/:id/labels" add_path :nodes, "/label/:label/nodes" - add_path :find, "/label/:label/nodes?:property=%22:value%22" + add_path :find, "/label/:label/nodes?:property=:value" add_path :delete, "/node/:id/labels/:label" def initialize(connection) diff --git a/lib/neography/rest/paths.rb b/lib/neography/rest/paths.rb index b322542..622f6e0 100644 --- a/lib/neography/rest/paths.rb +++ b/lib/neography/rest/paths.rb @@ -23,7 +23,11 @@ def add_path(key, path) def build_path(path, attributes) path.gsub(/:([\w_]*)/) do - encode(attributes[$1.to_sym].to_s) + if $1.to_sym == :value and attributes[$1.to_sym].class == String + encode("%22"+attributes[$1.to_sym].to_s+"%22") + else + encode(attributes[$1.to_sym].to_s) + end end end From 34a576d9f0ea5f266c91ddab4282a19b467ca14e Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Fri, 20 Dec 2013 15:00:56 -0500 Subject: [PATCH 2/2] added another test and fixed paths to not quote values outside of get params --- lib/neography/rest/paths.rb | 12 +++++++++--- spec/unit/rest/labels_spec.rb | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/neography/rest/paths.rb b/lib/neography/rest/paths.rb index 622f6e0..db05425 100644 --- a/lib/neography/rest/paths.rb +++ b/lib/neography/rest/paths.rb @@ -21,14 +21,20 @@ def add_path(key, path) end end + def build_path(path, attributes) - path.gsub(/:([\w_]*)/) do + p = String.new(path) + p.gsub!(/=:([\w_]*)/) do if $1.to_sym == :value and attributes[$1.to_sym].class == String - encode("%22"+attributes[$1.to_sym].to_s+"%22") + "=%22"+encode(attributes[$1.to_sym].to_s)+"%22"; else - encode(attributes[$1.to_sym].to_s) + "="+encode(attributes[$1.to_sym].to_s) end end + + p.gsub(/:([\w_]*)/) do + encode(attributes[$1.to_sym].to_s) + end end def encode(value) diff --git a/spec/unit/rest/labels_spec.rb b/spec/unit/rest/labels_spec.rb index dab5147..8939dbe 100644 --- a/spec/unit/rest/labels_spec.rb +++ b/spec/unit/rest/labels_spec.rb @@ -22,11 +22,16 @@ class Rest subject.get_nodes("person") end - it "find nodes for labels and property" do + it "find nodes for labels and property string" do connection.should_receive(:get).with("/label/person/nodes?name=%22max%22") subject.find_nodes("person", {:name => "max"}) end + it "find nodes for labels and property integer" do + connection.should_receive(:get).with("/label/person/nodes?age=26") + subject.find_nodes("person", {:age => 26}) + end + it "can add a label to a node" do options = { :body => '["Actor"]',