From 7f347e26cdbdc7258ee32c1a9f3a67266ba2c47e Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 26 Sep 2015 12:16:39 +0100 Subject: [PATCH] Archive using gather instance --- db/models/archivedGather.js | 5 +++++ spec/archivedGather.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/db/models/archivedGather.js b/db/models/archivedGather.js index b88160f..48100b0 100644 --- a/db/models/archivedGather.js +++ b/db/models/archivedGather.js @@ -17,6 +17,11 @@ archivedGatherSchema.static({ .sort({createdAt: -1}) .limit(5) .exec(callback); + }, + archive: function (gather, callback) { + this.create({ + gather: gather.toJson() + }, callback); } }); diff --git a/spec/archivedGather.js b/spec/archivedGather.js index 5e745c5..abd00a5 100644 --- a/spec/archivedGather.js +++ b/spec/archivedGather.js @@ -70,6 +70,19 @@ describe("ArchivedGather", () => { }); }); + describe(".archive", () => { + it ("archives a gather instance", done => { + ArchivedGather.archive(gather, (error, result) => { + if (error) return done(error); + assert.isDefined(result.createdAt); + let gather = result.gather; + assert.equal(gather.gatherers.length, 12); + assert.equal(gather.state, "done"); + done(); + }); + }); + }); + describe(".recent", () => { var gathers; beforeEach(done => {