mirror of https://gitee.com/bigwinds/arangodb
fix for wrong cid
This commit is contained in:
parent
be33a5c44f
commit
fd1ab94663
|
@ -432,7 +432,7 @@ int RestVocbaseBaseHandler::useCollection (string const& name, bool create) {
|
|||
generateError(HttpResponse::BAD,
|
||||
TRI_ERROR_HTTP_CORRUPTED_JSON,
|
||||
"collection identifier is empty");
|
||||
return false;
|
||||
return TRI_set_errno(TRI_ERROR_HTTP_CORRUPTED_JSON);
|
||||
}
|
||||
|
||||
// try to find the collection
|
||||
|
@ -451,7 +451,14 @@ int RestVocbaseBaseHandler::useCollection (string const& name, bool create) {
|
|||
}
|
||||
|
||||
// and use the collection
|
||||
return TRI_UseCollectionVocBase(_vocbase, const_cast<TRI_vocbase_col_s*>(_collection));
|
||||
int res = TRI_UseCollectionVocBase(_vocbase, const_cast<TRI_vocbase_col_s*>(_collection));
|
||||
|
||||
if (res == TRI_ERROR_NO_ERROR) {
|
||||
_documentCollection = _collection->_collection;
|
||||
assert(_documentCollection != 0);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -4,16 +4,17 @@ require './avocadodb.rb'
|
|||
describe AvocadoDB do
|
||||
prefix = "rest_create-document"
|
||||
|
||||
context "creating a document in a collection" do
|
||||
context "creating a document:" do
|
||||
|
||||
################################################################################
|
||||
## error handling
|
||||
################################################################################
|
||||
|
||||
context "error handling" do
|
||||
context "error handling:" do
|
||||
it "returns an error if url contains a suffix" do
|
||||
cmd = "/document/123456"
|
||||
doc = AvocadoDB.post(cmd)
|
||||
body = "{}"
|
||||
doc = AvocadoDB.post(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
|
@ -21,12 +22,13 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-superfluous-suffix")
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-superfluous-suffix")
|
||||
end
|
||||
|
||||
it "returns an error if collection idenifier is missing" do
|
||||
cmd = "/document"
|
||||
doc = AvocadoDB.post(cmd)
|
||||
body = "{}"
|
||||
doc = AvocadoDB.post(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
|
@ -34,12 +36,13 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-missing-cid")
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-missing-cid")
|
||||
end
|
||||
|
||||
it "returns an error if the collection identifier is unknown" do
|
||||
cmd = "/document?collection=123456"
|
||||
doc = AvocadoDB.post(cmd)
|
||||
body = "{}"
|
||||
doc = AvocadoDB.post(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(404)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
|
@ -47,12 +50,13 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-unknown-cid")
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-cid")
|
||||
end
|
||||
|
||||
it "returns an error if the collection name is unknown" do
|
||||
cmd = "/document?collection=unknown_collection"
|
||||
doc = AvocadoDB.post(cmd)
|
||||
body = "{}"
|
||||
doc = AvocadoDB.post(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(404)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
|
@ -60,7 +64,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-unknown-name")
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-name")
|
||||
end
|
||||
|
||||
it "returns an error if the JSON body is corrupted" do
|
||||
|
@ -92,7 +96,7 @@ describe AvocadoDB do
|
|||
## known collection identifier, waitForSync = true
|
||||
################################################################################
|
||||
|
||||
context "known collection identifier, waitForSync = true" do
|
||||
context "known collection identifier, waitForSync = true:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
@ -142,7 +146,7 @@ describe AvocadoDB do
|
|||
## known collection identifier, waitForSync = false
|
||||
################################################################################
|
||||
|
||||
context "known collection identifier, waitForSync = false" do
|
||||
context "known collection identifier, waitForSync = false:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionUnsynced"
|
||||
@cid = AvocadoDB.create_collection(@cn, false)
|
||||
|
@ -192,7 +196,7 @@ describe AvocadoDB do
|
|||
## known collection name
|
||||
################################################################################
|
||||
|
||||
context "known collection name" do
|
||||
context "known collection name:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
@ -242,7 +246,7 @@ describe AvocadoDB do
|
|||
## unknown collection name
|
||||
################################################################################
|
||||
|
||||
context "unknown collection name" do
|
||||
context "unknown collection name:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionNamed#{Time.now.to_i}"
|
||||
end
|
||||
|
|
|
@ -4,13 +4,13 @@ require './avocadodb.rb'
|
|||
describe AvocadoDB do
|
||||
prefix = "rest_delete-document"
|
||||
|
||||
context "delete a document in a collection" do
|
||||
context "delete a document:" do
|
||||
|
||||
################################################################################
|
||||
## error handling
|
||||
################################################################################
|
||||
|
||||
context "error handling" do
|
||||
context "error handling:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
@ -119,7 +119,7 @@ describe AvocadoDB do
|
|||
## deleting documents
|
||||
################################################################################
|
||||
|
||||
context "deleting documents" do
|
||||
context "deleting documents:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
|
|
@ -4,13 +4,13 @@ require './avocadodb.rb'
|
|||
describe AvocadoDB do
|
||||
prefix = "rest_read-document"
|
||||
|
||||
context "reading a document in a collection" do
|
||||
context "reading a document:" do
|
||||
|
||||
################################################################################
|
||||
## error handling
|
||||
################################################################################
|
||||
|
||||
context "error handling" do
|
||||
context "error handling:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
@ -79,7 +79,7 @@ describe AvocadoDB do
|
|||
## reading documents
|
||||
################################################################################
|
||||
|
||||
context "reading documents" do
|
||||
context "reading a document:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
@ -252,7 +252,7 @@ describe AvocadoDB do
|
|||
## reading all documents
|
||||
################################################################################
|
||||
|
||||
context "reading all documents" do
|
||||
context "reading all documents:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionAll"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
@ -354,7 +354,7 @@ describe AvocadoDB do
|
|||
## checking document
|
||||
################################################################################
|
||||
|
||||
context "checking a document" do
|
||||
context "checking a document:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
|
|
@ -4,13 +4,13 @@ require './avocadodb.rb'
|
|||
describe AvocadoDB do
|
||||
prefix = "rest_update-document"
|
||||
|
||||
context "update a document in a collection" do
|
||||
context "update a document:" do
|
||||
|
||||
################################################################################
|
||||
## error handling
|
||||
################################################################################
|
||||
|
||||
context "error handling" do
|
||||
context "error handling:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
@ -22,7 +22,8 @@ describe AvocadoDB do
|
|||
|
||||
it "returns an error if document handle is missing" do
|
||||
cmd = "/document"
|
||||
doc = AvocadoDB.put(cmd)
|
||||
body = "{}"
|
||||
doc = AvocadoDB.put(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
|
@ -30,14 +31,15 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-missing-handle")
|
||||
AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-missing-handle")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
||||
it "returns an error if document handle is corrupted" do
|
||||
cmd = "/document/123456"
|
||||
doc = AvocadoDB.put(cmd)
|
||||
body = "{}"
|
||||
doc = AvocadoDB.put(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
|
@ -45,14 +47,15 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-bad-handle")
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-bad-handle")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
||||
it "returns an error if document handle is corrupted" do
|
||||
cmd = "/document//123456"
|
||||
doc = AvocadoDB.put(cmd)
|
||||
body = "{}"
|
||||
doc = AvocadoDB.put(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
|
@ -60,14 +63,15 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-bad-handle2")
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-bad-handle2")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
||||
it "returns an error if collection identifier is unknown" do
|
||||
cmd = "/document/123456/234567"
|
||||
doc = AvocadoDB.put(cmd)
|
||||
body = "{}"
|
||||
doc = AvocadoDB.put(cmd, :body => body)
|
||||
|
||||
doc.code.should eq(404)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
|
@ -75,7 +79,7 @@ describe AvocadoDB do
|
|||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-unknown-cid")
|
||||
AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-cid")
|
||||
|
||||
AvocadoDB.size_collection(@cid).should eq(0)
|
||||
end
|
||||
|
@ -130,7 +134,7 @@ describe AvocadoDB do
|
|||
## updating documents
|
||||
################################################################################
|
||||
|
||||
context "updating documents" do
|
||||
context "updating document:" do
|
||||
before do
|
||||
@cn = "UnitTestsCollectionBasics"
|
||||
@cid = AvocadoDB.create_collection(@cn)
|
||||
|
|
|
@ -343,9 +343,6 @@ TRI_collection_t* TRI_CreateCollection (TRI_collection_t* collection,
|
|||
char* tmp2;
|
||||
int res;
|
||||
|
||||
// generate a collection identifier
|
||||
parameter->_cid = TRI_NewTickVocBase();
|
||||
|
||||
// sanity check
|
||||
if (sizeof(TRI_df_header_marker_t) + sizeof(TRI_df_footer_marker_t) > parameter->_maximalSize) {
|
||||
TRI_set_errno(TRI_ERROR_AVOCADO_DATAFILE_FULL);
|
||||
|
|
Loading…
Reference in New Issue