Skip to content
Open
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
2 changes: 1 addition & 1 deletion facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ exports.Permissive = function(appliesTo, schema){
schema = schema || {quality:0.5};
var appliesToPrototype = appliesTo.prototype;
if(appliesToPrototype){
var schemaPrototype = schema.prototype = schema.prototype || {};
var schemaPrototype = schema.prototype = schema.prototype || appliesToPrototype;
schemaPrototype.__noSuchMethod__ = function(name, source, args, onlyIfAvailable){
if(appliesToPrototype[name]){
return facet.wrap(appliesToPrototype[name].apply(source, args));
Expand Down
13 changes: 5 additions & 8 deletions model.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
var Permissive = require("./facet").Permissive;

var DefaultStore = require("./stores").DefaultStore,
transaction = require("./transaction").transaction,
NotFoundError = require("./errors").NotFoundError,
defineProperty = require("./util/es5-helper").defineProperty,
JSONExt = require("./util/json-ext"),
fs = require("promised-io/fs");
JSONExt = require("./util/json-ext");

var Model = function(store, schema) {
if(typeof store == "string"){
Expand Down Expand Up @@ -35,7 +32,7 @@ var Model = function(store, schema) {
Model.Model = Model;
Model.Store = function(store){
return Model(store, {});//(store.getSchema ? store.getSchema() : {});
}
};

var modelPaths = {};
Model.initializeRoot = function(dataModel, addClass){
Expand Down Expand Up @@ -74,12 +71,12 @@ function setPath(model, path, name){
Model.createModelsFromModel = function(sourceModel, models, constructor){
// this allows you to create a set of models from another source model. This makes
// it easy to have a RESTful interface for creating new models
constructor = constructor || Model;
constructor = constructor || Model;
models = models || {};
sourceModel.query("").forEach(createSchema);
if(sourceModel.subscribe){
sourceModel.subscribe("*").observe(function(events){
createSchema(events.result);
createSchema(events.result);
});
}
function createSchema(schema){
Expand All @@ -88,7 +85,7 @@ Model.createModelsFromModel = function(sourceModel, models, constructor){
setPath(models[name] = constructor(schema), name, name);
}
return models;
}
};

Model.modelSchema = {
maxLimit: Infinity,
Expand Down
4 changes: 3 additions & 1 deletion tests/data/TestStore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{1:{id:1, foo:2, rand:0.7013372050189607}, 2:{id:2, foo:1, bar:"hi"}, 3:{id:3, foo:1, bar:"hello"}}
{id:1, foo:2, rand:0.7013372050189607},
{id:2, foo:1, bar:"hi"},
{id:3, foo:1, bar:"hello"},
15 changes: 9 additions & 6 deletions tests/facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ for(var i in permissiveTests){
}
exports.testExtraStaticMethod = function(){
assert.equal(permissiveFacet.extraStaticMethod(), 4);
}
};

var restrictiveFacet = Restrictive(model);
var restrictiveTests = CreateTests(restrictiveFacet);

exports.testGetRestrictive = restrictiveTests.testGet;
exports.testLoadRestrictive = restrictiveTests.testLoad;
exports.testSaveRestrictive = shouldFail(restrictiveTests.testSave);
exports.testMethodRestrictive = shouldFail(restrictiveTests.testMethod);
exports.testStaticMethodRestrictive = shouldFail(restrictiveTests.testStaticMethod);
restrictiveTests.testSave = shouldFail(restrictiveTests.testSave);
restrictiveTests.testMethod = shouldFail(restrictiveTests.testMethod);
restrictiveTests.testStaticMethod = shouldFail(restrictiveTests.testStaticMethod);
restrictiveTests.testQuery = shouldFail(restrictiveTests.testQuery);

for(i in restrictiveTests){
exports[i + "Restrictive"] = restrictiveTests[i];
}

function shouldFail(test){
return function(){
Expand Down
Loading