Permalink
Browse files

[fix] fixes #82

  • Loading branch information...
dscape committed May 25, 2012
1 parent 8091dcb commit baf3505e8acd587824ae6efb5a839479478462c4
Showing with 34 additions and 6 deletions.
  1. +18 −1 tests/att/pipe.js
  2. +9 −0 tests/fixtures/att/pipe.json
  3. BIN tests/fixtures/logo.png
  4. +7 −5 tests/helpers.js
View
@@ -18,7 +18,7 @@ specify("att_pipe:setup", timeout, function (assert) {
});
});
-specify("att_pipe:test", timeout, function (assert) {
+specify("att_pipe:write", timeout, function (assert) {
var buffer = new Buffer(pixel, 'base64')
, filename = path.join(__dirname, '.temp.bmp')
, ws = fs.createWriteStream(filename)
@@ -32,7 +32,24 @@ specify("att_pipe:test", timeout, function (assert) {
assert.equal(error, undefined, "Should store the pixel");
db.attachment.get("new", "att", {rev: bmp.rev}).pipe(ws);
});
+});
+
+specify("att_pipe:read", timeout, function (assert) {
+ var logo = __dirname + "/../fixtures/logo.png"
+ , rs = fs.createReadStream(logo)
+ , is = db.attachment.insert("nodejs", "logo.png", null, "image/png")
+ ;
+
+ is.on('end', function () {
+ db.attachment.get("nodejs", "logo.png", function (err, buffer) {
+ assert.equal(err, undefined, "Should get the logo");
+ assert.equal(
+ fs.readFileSync(logo).toString('base64'), buffer.toString('base64'),
+ "Data should remain unchanged");
+ });
+ });
+ rs.pipe(is);
});
specify("att_pipe:teardown", timeout, function (assert) {
@@ -14,6 +14,15 @@
, "status" : 200
, "buffer" : "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="
}
+, { "method" : "put"
+ , "path" : "/att_pipe/nodejs/logo.png"
+ , "body" : "*"
+ , "response" : "{ \"ok\": true, \"id\": \"new\", \"rev\": \"1-64b327\" }"
+ }
+, { "method" : "get"
+ , "path" : "/att_pipe/nodejs/logo.png"
+ , "buffer" : "logo.png"
+ }
, { "method" : "delete"
, "path" : "/att_pipe"
, "status" : 200
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -45,7 +45,7 @@ helpers.password = auth[1];
helpers.loadFixture = function helpersLoadFixture(filename, json) {
var contents = fs.readFileSync(
- path.join(__dirname, 'fixtures', filename), 'ascii');
+ path.join(__dirname, 'fixtures', filename), (json ? 'ascii' : null));
return json ? JSON.parse(contents): contents;
};
@@ -55,11 +55,13 @@ helpers.nock = function helpersNock(url, fixture) {
, nocks = helpers.loadFixture(fixture + '.json', true)
;
nocks.forEach(function(n) {
- var path = n.path
+ var npath = n.path
, method = n.method || "get"
, status = n.status || 200
, response = n.buffer
- ? new Buffer(n.buffer, 'base64')
+ ? endsWith(n.buffer, '.png')
+ ? helpers.loadFixture(n.buffer)
+ : new Buffer(n.buffer, 'base64')
: n.response || ""
, headers = n.headers || {}
, body = n.base64
@@ -76,9 +78,9 @@ helpers.nock = function helpersNock(url, fixture) {
if(body==="*") {
nock(url).filteringRequestBody(function(path) {
return "*";
- })[method](path, "*").reply(status, response, headers);
+ })[method](npath, "*").reply(status, response, headers);
} else {
- nock(url)[method](path, body).reply(status, response, headers);
+ nock(url)[method](npath, body).reply(status, response, headers);
}
});
nock(url).log(console.log);

0 comments on commit baf3505

Please sign in to comment.