Skip to content

Commit

Permalink
all files
Browse files Browse the repository at this point in the history
  • Loading branch information
dscape committed Oct 16, 2014
1 parent e91e3b9 commit ef3db5f
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 362 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
.DS_Store
*tmp.*
*.log
node_modules/
node_modules/
coverage/
13 changes: 13 additions & 0 deletions .jshintrc
@@ -0,0 +1,13 @@
{
"boss": true,
"node": true,
"strict": true,
"smarttabs": true,
"maxlen": 80,
"newcap": false,
"undef": true,
"unused": true,
"onecase": true,
"indent": 2,
"sub": true
}
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -17,4 +17,9 @@ npm run nock_off

check this [blogpost](http://writings.nunojob.com/2012/05/Mock-HTTP-Integration-Testing-in-Node.js-using-Nock-and-Specify.html) to learn more about how to write your own tests

[2]: http://github.com/dscape/nano/issues
change this
add NOCK_OFF
add DEBUG
base from message-queue

[2]: http://github.com/dscape/nano/issues
78 changes: 27 additions & 51 deletions package.json
@@ -1,48 +1,11 @@
{
"name": "nano",
"description": "minimalistic couchdb driver for node.js",
"license": "Apache 2.0",
"license": "apache 2.0",
"homepage": "http://github.com/dscape/nano",
"repository": "git://github.com/dscape/nano",
"version": "5.12.1",
"version": "6.0.0",
"author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)",
"contributors": [
"Thiago Arrais <thiago.arrais@gmail.com> (http://thiagoarrais.com)",
"Derek Perez <derek@derekperez.com> (http://blog.derekperez.com)",
"Patrick Heneise (http://patrickheneise.com)",
"Artur Konarski (http://tarantoga.com)",
"Pedro Teixeira <pedro.teixeira@gmail.com> (http://metaduck.com)",
"Tom Wilson <tom@jackhq.com> (http://jackhq.tumblr.com)",
"Dale Harvey <dale@arandomurl.com> (http://arandomurl.com)",
"Jan Lehnardt <jan@apache.org> (http://jan.prima.de/plok/)",
"InTheFiveByFive",
"Stéphane Alnet <stephane@shimaore.net> (http://blog.shimaore.net)",
"Cliffano Subagio (http://blog.cliffano.com)",
"Mark Hahn (http://hahnca.com)",
"Francesco Ceccon <francesco@ceccon.me> (http://francesco-cek.com/)",
"Oliver Leics (http://oleics.github.com)",
"Jonathan Mahoney (http://mahoney.eu)",
"Dominique Sandoz <dominique.sandoz@gmail.com>",
"John Lancaster <john.k.lancaster@gmail.com> (http://jlank.com)",
"Clemens Stolle (https://github.com/klaemo)",
"Jay Beavers <jay.beavers@microsoft.com> (http://jaybeavers.org)",
"Juraj Vitko",
"Paul Iannazzo <somethingitalian@gmail.com> (http://pppaul.me)",
"Sebastian Tiedtke <sebastiantiedtke@gmail.com>",
"Gregory T. Corrigan (https://github.com/corrigang)",
"Etienne Folio (https://github.com/Ornthalas)",
"John Chesley (http://chesl.es)",
"Damon Oehlman <damon@fluxant.com>",
"Patrick Paul-Hus (https://github.com/hydrozen)",
"Sven Lito <me@svenlito.com> (http://svenlito.com)",
"Gerrit Renker",
"Andreas Lappe <nd@off-pist.de>",
"Aram Kocharyan <akarmenia@gmail.com>",
"Jan Krems @jkrems",
"Owen Evans <owen@bgeek.net> (http://www.bgeek.net)",
"Johannes J. Schmidt <schmidt@netzmerk.com> (http://die-tf.de)",
"Alex Schenkman <alex@schenkman.info>"
],
"keywords": [
"couchdb",
"data",
Expand All @@ -54,23 +17,36 @@
"database"
],
"dependencies": {
"request": "~2.42.0",
"follow": "~0.11.2",
"errs": "~0.3.0",
"underscore": "~1.7.0"
"request": "^2.45.0",
"follow": "^0.11.2",
"errs": "^0.3.0",
"underscore": "^1.7.0",
"debug": "^2.0.0"
},
"devDependencies": {
"async": "~0.2.9",
"specify": "~1.2.0",
"nock": "~0.18.2"
"async": "^0.9.0",
"tape": "^3.0.0",
"istanbul": "^0.3.2",
"jshint": "^2.5.6",
"jscs": "^1.7.0",
"nock": "^0.48.0",
"endswith": "^0.0.0",
"tape-it": "^0.0.1"
},
"scripts": {
"test": "node node_modules/specify/bin/specify -e NOCK=on",
"compact": "node node_modules/specify/bin/specify -e NOCK=on -r compact",
"nock_off": "node node_modules/specify/bin/specify"
"test": "DEBUG=* NOCK_OFF=true istanbul cover tape tests/att/*.js",
"jshint": "jshint tests/att/*.js",
"codestyle": "jscs -p google tests/att/*.js",
"checkcoverage": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100"
},
"main": "./nano.js",
"engines": {
"node": ">=0.6.0"
}
"node": ">=0.8.0"
},
"pre-commit": [
"jshint",
"codestyle",
"test",
"checkcoverage"
]
}
68 changes: 24 additions & 44 deletions tests/att/destroy.js
@@ -1,52 +1,32 @@
var specify = require('specify')
, helpers = require('../helpers')
, timeout = helpers.timeout
, nano = helpers.nano
, nock = helpers.nock
;
'use strict';

var mock = nock(helpers.couch, "att/destroy")
, db = nano.use("att_destroy")
;
var helpers = require('../helpers');
var harness = helpers.harness();
var it = harness.it;

specify("att_destroy:setup", timeout, function (assert) {
nano.db.create("att_destroy", function (err) {
assert.equal(err, undefined, "Failed to create database");
});
});

specify("att_destroy:test", timeout, function (assert) {
db.attachment.insert("new", "att", "Hello World!", "text/plain",
function (error, att) {
assert.equal(error, undefined, "Should store the attachment");
assert.equal(att.ok, true, "Response should be ok");
assert.ok(att.rev, "Should have a revision number");
db.attachment.destroy("new", "att", att.rev, function(error, response) {
assert.equal(error, undefined, "Should delete the attachment");
assert.equal(response.ok, true, "Response should be ok");
assert.equal(response.id, "new", "Id should be new");
});
});
});

specify("att_destroy:att_name_missing", timeout, function (assert) {
db.attachment.insert("new2", "att2", "Hello World!", "text/plain",
function (error, att) {
assert.equal(error, undefined, "Should store the attachment");
assert.equal(att.ok, true, "Response should be ok");
assert.ok(att.rev, "Should have a revision number");
db.attachment.destroy("new", false, att.rev, function(error, response) {
assert.equal(error.errid, "bad_params", "Should throw error because att_name is not a string");
assert.equal(response, undefined, "No response should be given");
it('should be able to insert a new plain text attachment', function(assert) {
var locals = this;
locals.db.attachment.insert('new',
'att', 'Hello World!', 'text/plain', function(error, att) {
assert.equal(error, null, 'store the attachment');
assert.equal(att.ok, true, 'response ok');
assert.ok(att.rev, 'have a revision number');
locals.db.attachment.destroy('new', 'att',
att.rev, function(error, response) {
assert.equal(error, null, 'delete the attachment');
assert.equal(response.ok, true, 'response ok');
assert.equal(response.id, 'new', '`id` should be `new`');
assert.end();
});
});
});

specify("att_destroy:teardown", timeout, function (assert) {
nano.db.destroy("att_destroy", function (err) {
assert.equal(err, undefined, "Failed to destroy database");
assert.ok(mock.isDone(), "Some mocks didn't run");
it('should fail destroying with a bad filename', function(assert) {
var locals = this;
locals.db.attachment.destroy('new', false, true, function(error, response) {
assert.equal(error.errid, 'bad_params',
'`att_name` should be a string');
assert.equal(response, undefined, 'no response should be given');
assert.end();
});
});

specify.run(process.argv.slice(2));
71 changes: 27 additions & 44 deletions tests/att/get.js
@@ -1,54 +1,37 @@
var specify = require('specify')
, helpers = require('../helpers')
, timeout = helpers.timeout
, nano = helpers.nano
, nock = helpers.nock
;
'use strict';

var mock = nock(helpers.couch, "att/get")
, db = nano.use("att_get")
;
var helpers = require('../helpers');
var harness = helpers.harness();
var it = harness.it;


specify("att_get:setup", timeout, function (assert) {
nano.db.create("att_get", function (err) {
assert.equal(err, undefined, "Failed to create database");
});
});

specify("att_get:test_string", timeout, function (assert) {
db.attachment.insert("new_string", "att", "Hello", "text/plain",
it('should be able to fetch an attachment', function(assert) {
var locals = this;
locals.db.attachment.insert('new_string', 'att', 'Hello', 'text/plain',
function(error, hello) {
assert.equal(error, undefined, "Should store hello");
assert.equal(hello.ok, true, "Response should be ok");
assert.ok(hello.rev, "Should have a revision number");
db.attachment.get("new_string", "att",
function (error, helloWorld) {
assert.equal(error, undefined, "Should get the hello");
assert.equal("Hello", helloWorld, "string is reflexive");
assert.equal(error, null, 'should store `hello`');
assert.equal(hello.ok, true, 'response ok');
assert.ok(hello.rev, 'should have a revision number');
locals.db.attachment.get('new_string', 'att',
function(error, helloWorld) {
assert.equal(error, null, 'should get `hello`');
assert.equal('Hello', helloWorld.toString(), 'string is reflexive');
assert.end();
});
});
});

specify("att_get:test_binary", timeout, function (assert) {
db.attachment.insert("new_binary", "att", new Buffer("123"), "text/plain",
function(error, hello) {
assert.equal(error, undefined, "Should store 123");
assert.equal(hello.ok, true, "Response should be ok");
assert.ok(hello.rev, "Should have a revision number");
db.attachment.get("new_binary", "att",
function (error, binaryData) {
assert.equal(error, undefined, "Should get the binary data");
assert.equal("123", binaryData, "binary data is reflexive");
it('should insert and fetch a binary file', function(assert) {
var locals = this;
locals.db.attachment.insert('new_binary', 'att',
new Buffer('123'), 'text/plain', function(error, hello) {
assert.equal(error, null, 'should store `123`');
assert.equal(hello.ok, true, 'response ok');
assert.ok(hello.rev, 'should have a revision number');
locals.db.attachment.get('new_binary', 'att',
function(error, binaryData) {
assert.equal(error, null, 'should get the binary data');
assert.equal('123', binaryData.toString(), 'binary data is reflexive');
assert.end();
});
});
});

specify("att_get:teardown", timeout, function (assert) {
nano.db.destroy("att_get", function (err) {
assert.equal(err, undefined, "Failed to destroy database");
assert.ok(mock.isDone(), "Some mocks didn't run");
});
});

specify.run(process.argv.slice(2));
45 changes: 13 additions & 32 deletions tests/att/insert.js
@@ -1,34 +1,15 @@
var specify = require('specify')
, helpers = require('../helpers')
, timeout = helpers.timeout
, nano = helpers.nano
, nock = helpers.nock
;

var mock = nock(helpers.couch, "att/insert")
, db = nano.use("att_insert")
;

specify("att_insert:setup", timeout, function (assert) {
nano.db.create("att_insert", function (err) {
assert.equal(err, undefined, "Failed to create database");
});
});

specify("att_insert:test", timeout, function (assert) {
db.attachment.insert("new", "att", "Hello World!", "text/plain",
function (error, att) {
assert.equal(error, undefined, "Should store the attachment");
assert.equal(att.ok, true, "Response should be ok");
assert.ok(att.rev, "Should have a revision number");
'use strict';

var helpers = require('../helpers');
var harness = helpers.harness();
var it = harness.it;

it('should be able to insert a simple attachment', function(assert) {
this.db.attachment.insert('new', 'att', 'Hello World!', 'text/plain',
function(error, att) {
assert.equal(error, null, 'should store the attachment');
assert.equal(att.ok, true, 'response ok');
assert.ok(att.rev, 'should have a revision');
assert.end();
});
});

specify("att_insert:teardown", timeout, function (assert) {
nano.db.destroy("att_insert", function (err) {
assert.equal(err, undefined, "Failed to destroy database");
assert.ok(mock.isDone(), "Some mocks didn't run");
});
});

specify.run(process.argv.slice(2));

0 comments on commit ef3db5f

Please sign in to comment.