Skip to content

Commit

Permalink
making gremlin script parameter aware
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 7, 2012
1 parent ee2335e commit c1eef08
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ def execute_query(query)
result = post("/ext/CypherPlugin/graphdb/execute_query", options)
end

def execute_script(script)
options = { :body => "script=" + CGI::escape(script), :headers => {'Content-Type' => 'application/x-www-form-urlencoded'} }
def execute_script(script, params = {})
options = { :body => {:script => script, :params => params}.to_json , :headers => {'Content-Type' => 'application/json'} }
result = post("/ext/GremlinPlugin/graphdb/execute_script", options)
result == "null" ? nil : result
end
Expand Down
21 changes: 21 additions & 0 deletions spec/integration/rest_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@
root_node.should have_key("self")
root_node["self"].split('/').last.should == "0"
end

it "can get the a node" do
new_node = @neo.create_node
id = new_node["self"].split('/').last
existing_node = @neo.execute_script("g.v(#{id})")
existing_node.should_not be_nil
existing_node.should have_key("self")
existing_node["self"].split('/').last.should == id
end

it "can get the a node with a variable" do
new_node = @neo.create_node
id = new_node["self"].split('/').last
existing_node = @neo.execute_script("g.v(id)", {:id => id})
existing_node.should_not be_nil
existing_node.should have_key("self")
existing_node["self"].split('/').last.should == id
end



end

describe "execute cypher query" do
Expand Down

0 comments on commit c1eef08

Please sign in to comment.