Skip to content

Commit

Permalink
Refactor Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 27, 2014
1 parent eecc51a commit 4a41a92
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
12 changes: 1 addition & 11 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Rest
include Cypher
include Gremlin
include Clean
include Extensions
extend Forwardable

attr_reader :connection
Expand All @@ -65,7 +66,6 @@ class Rest
def initialize(options = ENV['NEO4J_URL'] || {})
@connection = Connection.new(options)

@extensions ||= Extensions.new(@connection)
@batch ||= Batch.new(@connection)
@spatial ||= Spatial.new(@connection)
end
Expand Down Expand Up @@ -101,16 +101,6 @@ def get_relationship_end_node(rel)
get_node(rel["end"])
end

# unmanaged extensions

def post_extension(path, params = {}, headers = nil)
@extensions.post(path, params, headers)
end

def get_extension(path)
@extensions.get(path)
end

# batch

def batch(*args)
Expand Down
12 changes: 4 additions & 8 deletions lib/neography/rest/extensions.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
module Neography
class Rest
class Extensions
module Extensions
include Neography::Rest::Helpers

def initialize(connection)
@connection ||= connection
end

def get(path)

def get_extension(path)
@connection.get(path)
end

def post(path, body = {}, headers = nil)
def post_extension(path, body = {}, headers = nil)
options = {
:body => headers.nil? ? body.to_json : body,
:headers => headers || json_content_type.merge({'Accept' => 'application/json;stream=true'})
Expand Down
11 changes: 5 additions & 6 deletions spec/unit/rest/extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ module Neography
class Rest
describe Extensions do

let(:connection) { double }
subject { Extensions.new(connection) }
subject { Neography::Rest.new }

it "executes an extensions get query" do
path = "/unmanaged_extension/test"

connection.should_receive(:get).with(path)
subject.get("/unmanaged_extension/test")
subject.connection.should_receive(:get).with(path)
subject.get_extension("/unmanaged_extension/test")
end

it "executes an extensions post query" do
Expand All @@ -20,8 +19,8 @@ class Rest
:body=>"{\"foo\":\"bar\",\"baz\":\"qux\"}",
:headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true"}
}
connection.should_receive(:post).with(path, options)
subject.post("/unmanaged_extension/test", { :foo => "bar", :baz => "qux" })
subject.connection.should_receive(:post).with(path, options)
subject.post_extension("/unmanaged_extension/test", { :foo => "bar", :baz => "qux" })
end

end
Expand Down

0 comments on commit 4a41a92

Please sign in to comment.