1
0
Fork 0

Foxx Repository: byId (Test: Ugly)

This commit is contained in:
Lucas Dohmen 2013-09-16 14:39:55 +02:00
parent 5fdcdbf283
commit bbcd9a152a
2 changed files with 37 additions and 1 deletions

View File

@ -91,6 +91,7 @@ function RepositoryMethodsSpec() {
ModelPrototype,
model,
modelData,
data,
example,
id,
id_and_rev;
@ -102,6 +103,7 @@ function RepositoryMethodsSpec() {
modelData = stub();
example = stub();
model = stub();
data = stub();
collection = stub();
id = stub();
@ -146,6 +148,38 @@ function RepositoryMethodsSpec() {
instance.removeByExample(example);
collection.assertIsSatisfied();
},
testById: function () {
expect(collection)
.toReceive("document")
.withArguments(id);
instance.byId(id);
collection.assertIsSatisfied();
},
testByIdReturnValue: function () {
var calledWith;
allow(collection)
.toReceive("document")
.andReturn(data);
ModelPrototype = function (arg) {
if (this.constructor === ModelPrototype) {
calledWith = arg;
}
};
instance = new FoxxRepository(collection, { model: ModelPrototype });
model = instance.byId(id);
// This checks if it was called with the correct arguments
// and using new
assertEqual(calledWith, data);
}
};
}

View File

@ -184,8 +184,10 @@ _.extend(Repository.prototype, {
///
/// See the documentation of collection.
////////////////////////////////////////////////////////////////////////////////
byId: function () {
byId: function (id) {
'use strict';
var data = this.collection.document(id);
return (new this.modelPrototype(data));
},
////////////////////////////////////////////////////////////////////////////////