Merge pull request #2415 from ether/write-delay

delay write to fix copypad -- bad practice but due to db.set not allowin...
pull/2416/head
John McLear 2014-12-29 15:10:49 +01:00
commit 565097efb4
2 changed files with 133 additions and 9 deletions

View File

@ -461,7 +461,6 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
// if the pad exists, we should abort, unless forced.
function(callback)
{
console.log("destinationID", destinationID, force);
padManager.doesPadExists(destinationID, function (err, exists)
{
if(ERR(err, callback)) return;
@ -470,9 +469,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
{
if (!force)
{
console.log("erroring out without force");
console.error("erroring out without force");
callback(new customError("destinationID already exists","apierror"));
console.log("erroring out without force - after");
console.error("erroring out without force - after");
return;
}
else // exists and forcing
@ -521,12 +520,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
function(callback)
{
var revHead = _this.head;
//console.log(revHead);
for(var i=0;i<=revHead;i++)
{
db.get("pad:"+sourceID+":revs:"+i, function (err, rev) {
//console.log("HERE");
if (ERR(err, callback)) return;
db.set("pad:"+destinationID+":revs:"+i, rev);
});
@ -538,10 +534,8 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
function(callback)
{
var authorIDs = _this.getAllAuthors();
authorIDs.forEach(function (authorID)
{
console.log("authors");
authorManager.addPad(authorID, destinationID);
});
@ -555,7 +549,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
if(destGroupID) db.setSub("group:" + destGroupID, ["pads", destinationID], 1);
// Initialize the new pad (will update the listAllPads cache)
padManager.getPad(destinationID, null, callback)
setTimeout(function(){
padManager.getPad(destinationID, null, callback) // this runs too early.
},10);
}
// series
], function(err)

View File

@ -61,6 +61,16 @@ describe('Permission', function(){
-> setText(padId)
-> getLastEdited(padID) -- Should be when setText was performed
-> padUsers(padID) -- Should be when setText was performed
-> setText(padId, "hello world")
-> getLastEdited(padID) -- Should be when pad was made
-> getText(padId) -- Should be "hello world"
-> movePad(padID, newPadId) -- Should provide consistant pad data
-> getText(newPadId) -- Should be "hello world"
-> movePad(newPadID, originalPadId) -- Should provide consistant pad data
-> getText(originalPadId) -- Should be "hello world"
-> getLastEdited(padID) -- Should not be 0
*/
describe('deletePad', function(){
@ -265,7 +275,125 @@ describe('padUsers', function(){
});
})
describe('deletePad', function(){
it('deletes a Pad', function(done) {
api.get(endPoint('deletePad')+"&padID="+testPadId)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Pad Deletion failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
var originalPadId = testPadId;
var newPadId = makeid();
describe('createPad', function(){
it('creates a new Pad with text', function(done) {
api.get(endPoint('createPad')+"&padID="+testPadId)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Pad Creation failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('setText', function(){
it('Sets text on a pad Id', function(done) {
api.get(endPoint('setText')+"&padID="+testPadId+"&text=hello world")
.expect(function(res){
if(res.body.code !== 0) throw new Error("Pad Set Text failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('getText', function(){
it('Gets text on a pad Id', function(done) {
api.get(endPoint('getText')+"&padID="+testPadId)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Pad Get Text failed")
if(res.body.data.text !== "hello world\n") throw new Error("Pad Text not set properly");
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('getLastEdited', function(){
it('Gets when pad was last edited', function(done) {
api.get(endPoint('getLastEdited')+"&padID="+testPadId)
.expect(function(res){
if(res.body.lastEdited === 0) throw new Error("Get Last Edited Failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('movePad', function(){
it('Move a Pad to a different Pad ID', function(done) {
api.get(endPoint('movePad')+"&sourceID="+testPadId+"&destinationID="+newPadId+"&force=true")
.expect(function(res){
console.log(res.body);
if(res.body.code !== 0) throw new Error("Moving Pad Failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('getText', function(){
it('Gets text on a pad Id', function(done) {
api.get(endPoint('getText')+"&padID="+newPadId)
.expect(function(res){
if(res.body.data.text !== "hello world\n") throw new Error("Pad Get Text failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('movePad', function(){
it('Move a Pad to a different Pad ID', function(done) {
api.get(endPoint('movePad')+"&sourceID="+newPadId+"&destinationID="+testPadId+"&force=false")
.expect(function(res){
if(res.body.code !== 0) throw new Error("Moving Pad Failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('getText', function(){
it('Gets text on a pad Id', function(done) {
api.get(endPoint('getText')+"&padID="+testPadId)
.expect(function(res){
if(res.body.data.text !== "hello world\n") throw new Error("Pad Get Text failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('getLastEdited', function(){
it('Gets when pad was last edited', function(done) {
api.get(endPoint('getLastEdited')+"&padID="+testPadId)
.expect(function(res){
if(res.body.lastEdited === 0) throw new Error("Get Last Edited Failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
/*
-> movePadForce Test
*/
var endPoint = function(point){
return '/api/'+apiVersion+'/'+point+'?apikey='+apiKey;