Skip to content

Use collection extensions #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion mongo-instances-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ Tinytest.add('instanceof - matches Mongo.Collection', function (test) {
test.instanceOf(Test, Mongo.Collection);
});

Tinytest.add('instanceof - Meteor.Collection matches Mongo.Collection', function (test) {
var collectionName = 'foo' + test.id;
var Test = new Meteor.Collection(collectionName);
test.instanceOf(Test, Mongo.Collection);
});

Tinytest.add('instanceof - Meteor.users matches (Mongo/Meteor).Collection', function (test) {
test.instanceOf(Meteor.users, Mongo.Collection);
test.instanceOf(Meteor.users, Meteor.Collection);
});

Tinytest.add('use New - keep behavior of Mongo.Collection', function (test) {
var collectionName = 'foo' + test.id;
function createWithoutNew() {
var Test = Mongo.Collection(collectionName);
}
test.throws(createWithoutNew, 'use "new" to construct a Mongo.Collection');
});
});
12 changes: 2 additions & 10 deletions mongo-instances.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
var instances = [];
var orig = Mongo.Collection;

Mongo.Collection = function(name, options) {
orig.call(this, name, options); // inherit orig

Meteor.addCollectionExtension(function (name, options) {
instances.push({
name: name,
instance: this,
options: options
});
};

Mongo.Collection.prototype = Object.create(orig.prototype);
Mongo.Collection.prototype.constructor = Mongo.Collection;

_.extend(Mongo.Collection, orig);
});

Mongo.Collection.get = function(name, options) {
options = options || {};
Expand Down
2 changes: 2 additions & 0 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ Package.describe({
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use(['mongo', 'underscore']);
api.use('lai:collection-extensions@0.1.1');
api.addFiles('mongo-instances.js');
});

Package.onTest(function(api) {
api.use('tinytest');
api.use('accounts-base');
api.use('dburles:mongo-collection-instances');
api.addFiles('mongo-instances-tests.js');
});