From a82b765264ab106070586a00d4764c853d9fb64e Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Thu, 27 Mar 2014 05:02:56 -0500 Subject: [PATCH] Refactor Cypher --- lib/neography/rest.rb | 8 +------- lib/neography/rest/cypher.rb | 8 ++------ spec/unit/rest/cypher_spec.rb | 7 +++---- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 04034b3..086b27c 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -53,6 +53,7 @@ class Rest include RelationshipAutoIndexes include NodeTraversal include NodePaths + include Cypher extend Forwardable attr_reader :connection @@ -62,7 +63,6 @@ class Rest def initialize(options = ENV['NEO4J_URL'] || {}) @connection = Connection.new(options) - @cypher ||= Cypher.new(@connection) @gremlin ||= Gremlin.new(@connection) @extensions ||= Extensions.new(@connection) @batch ||= Batch.new(@connection) @@ -101,12 +101,6 @@ def get_relationship_end_node(rel) get_node(rel["end"]) end - # cypher query - - def execute_query(query, params = {}, cypher_options = nil) - @cypher.query(query, params, cypher_options) - end - # gremlin script def execute_script(script, params = {}) diff --git a/lib/neography/rest/cypher.rb b/lib/neography/rest/cypher.rb index 02ceb4a..1c8eec6 100644 --- a/lib/neography/rest/cypher.rb +++ b/lib/neography/rest/cypher.rb @@ -1,13 +1,9 @@ module Neography class Rest - class Cypher + module Cypher include Neography::Rest::Helpers - def initialize(connection) - @connection ||= connection - end - - def query(query, parameters = {}, cypher_options = nil) + def execute_query(query, parameters = {}, cypher_options = nil) options = { :body => { :query => query, diff --git a/spec/unit/rest/cypher_spec.rb b/spec/unit/rest/cypher_spec.rb index d8b894d..de9caaa 100644 --- a/spec/unit/rest/cypher_spec.rb +++ b/spec/unit/rest/cypher_spec.rb @@ -4,16 +4,15 @@ module Neography class Rest describe Cypher do - let(:connection) { double(:cypher_path => "/cypher") } - subject { Cypher.new(connection) } + subject { Neography::Rest.new } it "executes a cypher query" do options = { :body=>"{\"query\":\"SOME QUERY\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}", :headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true;charset=UTF-8"} } - connection.should_receive(:post).with("/cypher", options) - subject.query("SOME QUERY", { :foo => "bar", :baz => "qux" }) + subject.connection.should_receive(:post).with("/cypher", options) + subject.execute_query("SOME QUERY", { :foo => "bar", :baz => "qux" }) end end