mirror of https://gitee.com/bigwinds/arangodb
Foxx Repository: byExample
This commit is contained in:
parent
cdf9415650
commit
7d432a8911
|
@ -94,6 +94,7 @@ function RepositoryMethodsSpec() {
|
||||||
modelData,
|
modelData,
|
||||||
data,
|
data,
|
||||||
example,
|
example,
|
||||||
|
cursor,
|
||||||
id,
|
id,
|
||||||
id_and_rev;
|
id_and_rev;
|
||||||
|
|
||||||
|
@ -103,6 +104,7 @@ function RepositoryMethodsSpec() {
|
||||||
id_and_rev = stub();
|
id_and_rev = stub();
|
||||||
modelData = stub();
|
modelData = stub();
|
||||||
example = stub();
|
example = stub();
|
||||||
|
cursor = stub();
|
||||||
model = stub();
|
model = stub();
|
||||||
data = stub();
|
data = stub();
|
||||||
collection = stub();
|
collection = stub();
|
||||||
|
@ -165,6 +167,26 @@ function RepositoryMethodsSpec() {
|
||||||
assertTrue(model instanceof ModelPrototype);
|
assertTrue(model instanceof ModelPrototype);
|
||||||
ModelPrototype.assertIsSatisfied();
|
ModelPrototype.assertIsSatisfied();
|
||||||
collection.assertIsSatisfied();
|
collection.assertIsSatisfied();
|
||||||
|
},
|
||||||
|
|
||||||
|
testByExample: function () {
|
||||||
|
expect(collection)
|
||||||
|
.toReceive("byExample")
|
||||||
|
.withArguments(example)
|
||||||
|
.andReturn(cursor);
|
||||||
|
|
||||||
|
allow(cursor)
|
||||||
|
.toReceive("toArray")
|
||||||
|
.andReturn([data]);
|
||||||
|
|
||||||
|
ModelPrototype = mockConstructor(data);
|
||||||
|
instance = new FoxxRepository(collection, { model: ModelPrototype });
|
||||||
|
|
||||||
|
var models = instance.byExample(example);
|
||||||
|
|
||||||
|
assertTrue(models[0] instanceof ModelPrototype);
|
||||||
|
ModelPrototype.assertIsSatisfied();
|
||||||
|
collection.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,9 +196,12 @@ _.extend(Repository.prototype, {
|
||||||
///
|
///
|
||||||
/// See the documentation of collection.
|
/// See the documentation of collection.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
byExample: function () {
|
byExample: function (example) {
|
||||||
'use strict';
|
'use strict';
|
||||||
this.collection.byExample.apply(this.collection, arguments);
|
var rawDocuments = this.collection.byExample(example).toArray();
|
||||||
|
return _.map(rawDocuments, function (rawDocument) {
|
||||||
|
return (new this.modelPrototype(rawDocument));
|
||||||
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue