Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed small transport problem

  • Loading branch information...
commit 7525325061d7830bc50e67e1be70975f56e50cf5 1 parent c47fd68
@phifty authored
View
16 lib/allegro_graph/catalog.rb
@@ -3,8 +3,8 @@ module AllegroGraph
class Catalog
- attr_reader :server
- attr_reader :name
+ attr_reader :server
+ attr_accessor :name
def initialize(server, name, options = { })
@server = server
@@ -16,14 +16,22 @@ def ==(other)
other.is_a?(self.class) && self.server == other.server && self.root? == other.root? && self.name == other.name
end
- def url
- self.root? ? @server.url : "#{@server.url}/catalogs/#{@name}"
+ def path
+ self.root? ? "" : "/catalogs/#{@name}"
end
def root?
!!@root
end
+ def create!
+ raise StandardError, "cannot create root catalog!" if self.root?
+ @server.request :put, self.path, :expected_status_code => 201
+ rescue AllegroGraph::Transport::UnexpectedStatusCodeError => error
+ return false if error.status_code == 400
+ raise error
+ end
+
def repositories
[ ]
end
View
1  lib/allegro_graph/transport.rb
@@ -85,6 +85,7 @@ module JSONTransport
def self.request(http_method, url, options = { })
options[:headers] ||= { }
+ options[:headers]["Accept"] = "application/json"
options[:headers]["Content-Type"] = "application/json"
parse AuthorizedTransport.request(http_method, url, options)
end
View
21 spec/fake_transport.yml
@@ -17,11 +17,32 @@
:code: "200"
:body: "[unknown]"
-
+ :http_method: "put"
+ :url: "http://localhost:10035/catalogs/existing"
+ :headers:
+ "Authorization": "Basic dGVzdDp0ZXN0\n"
+ "Content-Type": "application/json"
+ "Accept": "application/json"
+ :response:
+ :code: "400"
+ :body: ""
+-
+ :http_method: "put"
+ :url: "http://localhost:10035/catalogs/not_existing"
+ :headers:
+ "Authorization": "Basic dGVzdDp0ZXN0\n"
+ "Content-Type": "application/json"
+ "Accept": "application/json"
+ :response:
+ :code: "201"
+ :body: ""
+-
:http_method: "get"
:url: "http://localhost:10035/catalogs"
:headers:
"Authorization": "Basic dGVzdDp0ZXN0\n"
"Content-Type": "application/json"
+ "Accept": "application/json"
:response:
:code: "200"
:body: ""
View
2  spec/fake_transport_helper.rb
@@ -30,7 +30,7 @@ def self.fake!
hash[:headers] == headers
end
raise StandardError, "no fake request found for [#{http_method} #{url} #{parameters.inspect} #{headers.inspect}]" unless request
- raise UnexpectedStatusCodeError, request[:response][:code].to_i if expected_status_code && expected_status_code.to_s != request[:response][:code]
+ raise transport_class::UnexpectedStatusCodeError, request[:response][:code].to_i if expected_status_code && expected_status_code.to_s != request[:response][:code]
request[:response][:body].dup
end
end
View
47 spec/integration/catalog_spec.rb
@@ -0,0 +1,47 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "allegro_graph"))
+
+describe AllegroGraph::Catalog do
+
+ use_real_transport!
+
+ before :each do
+ @server = AllegroGraph::Server.new :username => "test", :password => "test"
+ @catalog = AllegroGraph::Catalog.new @server, "test_catalog"
+ end
+
+ describe "create!" do
+
+ it "should raise a StandardError on root catalog" do
+ @catalog.stub!(:root?).and_return(true)
+ lambda do
+ @catalog.create!
+ end.should raise_error(StandardError)
+ end
+
+ it "should create the catalog" do
+ # @catalog.create!.should be_true
+ end
+
+ end
+
+ describe "exists?" do
+
+ it "should return false if not existing" do
+ #@catalog.exists?.should be_false
+ end
+
+ it "should return true if existing" do
+ #@catalog.create!
+ #@catalog.exists?.should be_true
+ end
+
+ end
+
+ describe "repositories" do
+
+
+
+ end
+
+end
View
36 spec/lib/allegro_graph/catalog_spec.rb
@@ -4,7 +4,7 @@
describe AllegroGraph::Catalog do
before :each do
- @server = AllegroGraph::Server.new
+ @server = AllegroGraph::Server.new :username => "test", :password => "test"
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
end
@@ -22,7 +22,7 @@
end
- describe "url" do
+ describe "path" do
context "for root catalog" do
@@ -31,7 +31,7 @@
end
it "should the root catalog url" do
- @catalog.url.should == "#{@server.url}"
+ @catalog.path.should == ""
end
end
@@ -39,7 +39,35 @@
context "for named catalog" do
it "should the named catalog url" do
- @catalog.url.should == "#{@server.url}/catalogs/test_catalog"
+ @catalog.path.should == "/catalogs/test_catalog"
+ end
+
+ end
+
+ end
+
+ describe "create!" do
+
+ context "for a catalog that already exists" do
+
+ before :each do
+ @catalog.name = "existing"
+ end
+
+ it "should return false" do
+ @catalog.create!.should be_false
+ end
+
+ end
+
+ context "for a catalog that not exists" do
+
+ before :each do
+ @catalog.name = "not_existing"
+ end
+
+ it "should return true" do
+ @catalog.create!.should be_false
end
end
View
2  spec/lib/allegro_graph/transport_spec.rb
@@ -92,7 +92,7 @@ def do_request(options = { })
it "should call Transport.request with extended headers" do
AllegroGraph::AuthorizedTransport.should_receive(:request).with(
- :get, "/", hash_including(:headers => { "Content-Type" => "application/json" })
+ :get, "/", hash_including(:headers => { "Accept" => "application/json", "Content-Type" => "application/json" })
)
AllegroGraph::JSONTransport.request :get, "/"
end
Please sign in to comment.
Something went wrong with that request. Please try again.