Sha256: ded89dac581bd51293d7c388cd55a643253019451271d4643968a8c03fba8b9e

Contents?: true

Size: 1.32 KB

Versions: 20

Compression:

Stored size: 1.32 KB

Contents

var assert = require('assert'),
    fs = require('fs'),
    path = require('path'),
    async = require('async'),
    request = require('request');
    
var databases = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'databases.json'), 'utf8'));

var seed = exports;

seed.createDatabase = function (name, callback) {
  request({
    method: 'PUT',
    url: 'http://127.0.0.1:5984/' + name
  }, callback);
};

seed.deleteDatabase = function (name, callback) {
  request({
    method: 'DELETE',
    url: 'http://127.0.0.1:5984/' + name
  }, callback);
};

seed.seedDatabase = function (name, callback) {
  seed.deleteDatabase(name, function (err) {
    if (!databases[name]) {
      return callback(err);
    }
    
    function putDoc (doc, next) {
      request({
        method: 'PUT',
        url: 'http://127.0.0.1:5984/' + name + '/' + doc._id,
        body: JSON.stringify(doc)
      }, next);
    }
    
    seed.createDatabase(name, function () {
      async.forEach(databases[name], putDoc, callback);
    });
  });
};

seed.requireSeed = function () {
  return {
    "Tests require database seeding": {
      topic: function () {
        async.forEach(Object.keys(databases), seed.seedDatabase, this.callback)
      },
      "should respond with no errors": function (err) {
        assert.isTrue(!err);
      }
    }
  }
};

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
vulcan-0.6.1 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.6.0 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.5.0 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.4.0 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.3.0 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.2.5 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.2.4 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.2.3 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.2.2 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.2.1 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.2.0 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.1.6 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.1.5 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.1.4 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.1.3 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.1.2 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.1.1 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.1.0 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.0.3 server/node_modules/cradle/test/helpers/seed.js
vulcan-0.0.2 server/node_modules/cradle/test/helpers/seed.js