Skip to content

Commit

Permalink
removing fakeweb, escaping execute_script for gremlin, adding execute…
Browse files Browse the repository at this point in the history
…_query for cypher, adding tests
  • Loading branch information
maxdemarzi committed Nov 4, 2011
1 parent 752924a commit 7a5c6a8
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 30 deletions.
13 changes: 7 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
PATH
remote: .
specs:
neography (0.0.13)
neography (0.0.15)
httparty (~> 0.7.3)
json
os
rubyzip

GEM
remote: http://rubygems.org/
specs:
crack (0.1.8)
diff-lcs (1.1.2)
fakeweb (1.3.0)
httparty (0.7.4)
httparty (0.7.8)
crack (= 0.1.8)
json (1.4.6)
json (1.4.6-java)
json (1.6.1)
net-http-spy (0.2.1)
os (0.9.4)
rake (0.8.7)
rspec (2.0.1)
rspec-core (~> 2.0.1)
Expand All @@ -27,13 +28,13 @@ GEM
rspec-mocks (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
rubyzip (0.9.4)

PLATFORMS
java
ruby

DEPENDENCIES
fakeweb (~> 1.3.0)
neography!
net-http-spy (= 0.2.1)
rake (~> 0.8.7)
Expand Down
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ To Use:
@neo.get_relationship_index(index, key, value) # exact query of the relationship index with the given key/value pair
@neo.find_relationship_index(index, key, value) # advanced query of the relationship index with the given key/value pair
@neo.find_relationship_index(index, query) # advanced query of the relationship index with the given query
@neo.execute_script(script) # sends an arbitrary Groovy script (through the Gremlin plugin)

@neo.execute_script("g.v(0)") # sends a Groovy script(through the Gremlin plugin)
@neo.execute_query("start n=node(0) return n") # sends a Cypher query (through the Cypher plugin)

@neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
@neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
Expand Down
1 change: 1 addition & 0 deletions lib/neography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def find_and_require_user_defined_code

DIRECTIONS = ["incoming", "in", "outgoing", "out", "all", "both"]

require 'cgi'
require 'httparty'
require 'json'
require 'logger'
Expand Down
13 changes: 9 additions & 4 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,22 @@ def get_paths(from, to, relationships, depth=1, algorithm="allPaths")
paths = post("/node/#{get_id(from)}/paths", options) || Array.new
end

def execute_script(script)
options = { :body => { :script => script } }
post("/ext/GremlinPlugin/graphdb/execute_script", options)
def execute_query(query)
options = { :body => {:query => query}.to_json, :headers => {'Content-Type' => 'application/json'} }
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'} }
result = post("/ext/GremlinPlugin/graphdb/execute_script", options)
result == "null" ? nil : result
end

private

def evaluate_response(response)
code = response.code
body = response.body

case code
when 200
@logger.debug "OK" if @log_enabled
Expand Down
1 change: 0 additions & 1 deletion neography.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Gem::Specification.new do |s|

s.add_development_dependency "rspec", "~> 2.0.0.beta.22"
s.add_development_dependency "net-http-spy", "0.2.1"
s.add_development_dependency "fakeweb", "~> 1.3.0"
s.add_development_dependency "rake", "~> 0.8.7"
s.add_dependency "httparty", "~> 0.7.3"
s.add_dependency "json"
Expand Down
26 changes: 26 additions & 0 deletions spec/integration/rest_plugin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Neography::Rest do
before(:each) do
@neo = Neography::Rest.new
end

describe "execute gremlin script" do
it "can get the root node id" do
root_node = @neo.execute_script("g.v(0)")
root_node.should have_key("self")
root_node["self"].split('/').last.should == "0"
end
end

describe "execute cypher query" do
it "can get the root node id" do
root_node = @neo.execute_query("start n=node(0) return n")
root_node.should have_key("data")
root_node.should have_key("columns")
root_node["data"][0][0].should have_key("self")
root_node["data"][0][0]["self"].split('/').last.should == "0"
end
end

end
13 changes: 1 addition & 12 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
require 'neography'
require 'fake_web'
require 'benchmark'

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

FakeWeb.allow_net_connect = false

# To test against a real database:
# 1. Make sure empty database is running on your test neo4j server (bin/neo4j start)
# 2. Uncomment the next two lines
FakeWeb.clean_registry
FakeWeb.allow_net_connect = true

# 3. If you want to see more, uncomment the next few lines
# If you want to see more, uncomment the next few lines
# require 'net-http-spy'
# Net::HTTP.http_logger_options = {:body => true} # just the body
# Net::HTTP.http_logger_options = {:verbose => true} # see everything
Expand Down
5 changes: 0 additions & 5 deletions spec/support/fake_root_spec.rb

This file was deleted.

0 comments on commit 7a5c6a8

Please sign in to comment.