Skip to content

Commit

Permalink
schemas can be passed directly
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed May 3, 2018
1 parent d779e28 commit 1352513
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions store.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ canReflect.assignMap(Store.prototype,{
}
});

function looksLikeAQueryLogic(obj){
return obj && ("identityKeys" in obj);
}

// ## fixture.store
// Make a store of objects to use when making requests against fixtures.
Expand All @@ -168,6 +171,8 @@ Store.make = function (count, make, queryLogic) {
if(typeof count === "number") {
if(!queryLogic) {
queryLogic = new QueryLogic({});
} else if(!looksLikeAQueryLogic(queryLogic)) {
queryLogic = new QueryLogic(queryLogic);
}
idProp = queryLogic.identityKeys()[0] || "id";
makeItems = function () {
Expand All @@ -193,6 +198,8 @@ Store.make = function (count, make, queryLogic) {
queryLogic = make;
if(!queryLogic) {
queryLogic = new QueryLogic({});
} else if(!looksLikeAQueryLogic(queryLogic)) {
queryLogic = new QueryLogic(queryLogic);
}
idProp = queryLogic.identityKeys()[0] || "id";
makeItems = makeMakeItems(count, idProp);
Expand Down
28 changes: 28 additions & 0 deletions test/store-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var QUnit = require('steal-qunit');
var fixture = require("can-fixture");
var QueryLogic = require("can-query-logic");
var canReflect = require("can-reflect");


QUnit.module("can-fixture.store");
Expand Down Expand Up @@ -46,3 +47,30 @@ QUnit.test("createInstance, destroyInstance, updateInstance", function(assert){
QUnit.start();
});
});

QUnit.test("anything with a schema will be converted to a queryLogic automatically", function(){
var store = fixture.store(
[ {_id: 0, name: "foo"} ],
{identity: ["id"]}
);

var res = store.get({_id: 0});
QUnit.ok(res, "an object works");

var type = canReflect.assignSymbols({},{
"can.getSchema": function(){
return {identity: ["id"]};
}
});

store = fixture.store(
[ {_id: 0, name: "foo"} ],
type
);

res = store.get({_id: 0});
QUnit.ok(res, "an object works");
//.then(function(){ QUnit.ok(true, "got data"); });


});

0 comments on commit 1352513

Please sign in to comment.