Permalink
Browse files

collection now an array-like thing

  • Loading branch information...
1 parent 66ea122 commit 3f700fc9de3cbbfb1b1512fe14ddbd5aecf22f39 @gushov committed Dec 9, 2012
Showing with 169 additions and 95 deletions.
  1. +87 −37 dist/lilmodel.js
  2. +2 −2 dist/lilmodel.min.js
  3. +29 −13 lib/lilmodel/collection.js
  4. +31 −23 lib/lilmodel/model.js
  5. +1 −1 package.json
  6. +19 −19 test/lilmodel-test.js
View
124 dist/lilmodel.js
@@ -1,4 +1,4 @@
-/*! lilmodel - v0.0.5 - 2012-12-07
+/*! lilmodel - v0.0.5 - 2012-12-09
* Copyright (c) 2012 August Hovland <gushov@gmail.com>; Licensed MIT */
(function (ctx) {
@@ -232,7 +232,25 @@ module.exports = {
}, true);
-provide('lilobj', function (require, module, exports) {
+provide('lilobj/arr', function (require, module, exports) {
+
+/*jshint curly:true, eqeqeq:true, immed:true, latedef:true,
+ newcap:true, noarg:true, sub:true, undef:true, boss:true,
+ strict:false, eqnull:true, browser:true, node:true */
+
+var obj = require('./obj');
+var _ = require('lil_');
+
+var arr = Object.create(Array.prototype);
+_.eachIn(obj, function (name, value) {
+ arr[name] = value;
+});
+
+module.exports = arr;
+
+
+}, true);
+provide('lilobj/obj', function (require, module, exports) {
/*jshint curly:true, eqeqeq:true, immed:true, latedef:true,
newcap:true, noarg:true, sub:true, undef:true, boss:true,
@@ -278,6 +296,22 @@ module.exports = {
}, true);
+provide('lilobj', function (require, module, exports) {
+
+/*jshint curly:true, eqeqeq:true, immed:true, latedef:true,
+ newcap:true, noarg:true, sub:true, undef:true, boss:true,
+ strict:false, eqnull:true, browser:true, node:true */
+
+var obj = require('./lilobj/obj');
+var arr = require('./lilobj/arr');
+
+module.exports = {
+ obj: obj,
+ arr: arr
+};
+
+
+}, true);
provide('vladiator', function (require, module, exports) {
@@ -369,18 +403,16 @@ provide('lilmodel/collection', function (require, module, exports) {
newcap:true, noarg:true, sub:true, undef:true, boss:true,
strict:false, eqnull:true, browser:true, node:true */
-var LilObj = require('lilobj');
+var arr = require('lilobj').arr;
var _ = require('lil_');
var syncr = require('./syncr');
-module.exports = LilObj.extend({
+module.exports = arr.extend({
construct: function (values) {
- this.$ = [];
-
_.each(values, function (value) {
- this.$.push(this.model.create(value));
+ this.push(this.model.create(value));
}, this);
this.validate();
@@ -391,9 +423,9 @@ module.exports = LilObj.extend({
var validation = { isValid: true, error: [] };
- _.each(this.$, function ($) {
+ _.each(this, function (model) {
- var v = $.validate();
+ var v = model.validate();
validation.error.push(v.error);
validation.isValid = validation.isValid && v.isValid;
@@ -412,27 +444,37 @@ module.exports = LilObj.extend({
model = this.model.create(obj);
}
- this.$.push(model);
+ this.push(model);
},
remove: function (query) {
- this.$ = this.$.filter(function (model) {
- return !_.match(model, query);
+ var index;
+
+ _.each(this, function (model, i) {
+
+ if (_.match(model, query)) {
+ index = i;
+ }
+
});
+ if (typeof index === 'number') {
+ this.splice(index, 1);
+ }
+
},
get: function (query) {
- return this.$.filter(function (model) {
+ return this.filter(function (model) {
return _.match(model, query);
});
},
each: function (next, ctx) {
- _.each(this.$, next, ctx);
+ _.each(this, next, ctx);
},
find: function (next, ctx) {
@@ -452,40 +494,48 @@ provide('lilmodel/model', function (require, module, exports) {
newcap:true, noarg:true, sub:true, undef:true, boss:true,
strict:false, eqnull:true, browser:true, node:true */
-var LilObj = require('lilobj');
+var obj = require('lilobj').obj;
var _ = require('lil_');
var vlad = require('vladiator');
var syncr = require('./syncr');
-module.exports = LilObj.extend({
+function getter(name) {
+ return this.$[name];
+}
- construct: function (values) {
+function setter(name, value) {
- this.$ = {};
- var props = _.mapIn(this.rules, function (name, value) {
+ var model = this.children && this.children[name];
- return {
+ if (model && model.create && typeof value === 'object') {
+ this.$[name] = model.create(value);
+ } else if (model && typeof value === 'object') {
+ this.$[name] = this.create(value);
+ } else if (!model) {
+ this.$[name] = value;
+ }
- enumerable : true,
+}
- get: function () {
- return this.$[name];
- },
+function parser(ctx, model, next) {
- set: function (value) {
+ return function (err, values) {
+ next.call(ctx, err, model.create(values || {}));
+ };
- var model = this.children && this.children[name];
+}
- if (model && model.create && typeof value === 'object') {
- this.$[name] = model.create(value);
- } else if (model && typeof value === 'object') {
- this.$[name] = this.create(value);
- } else if (!model) {
- this.$[name] = value;
- }
+module.exports = obj.extend({
- }
+ construct: function (values) {
+ this.$ = {};
+ var props = _.mapIn(this.rules, function (name, value) {
+
+ return {
+ enumerable: true,
+ get: getter.bind(this, name),
+ set: setter.bind(this, name)
};
}, this);
@@ -535,7 +585,7 @@ module.exports = LilObj.extend({
var validation = this.validate();
if (validation.isValid) {
- sync(method, this, next.bind(ctx));
+ sync(method, this, parser(ctx, this, next));
} else {
next.call(ctx, validation.error, this);
}
@@ -544,12 +594,12 @@ module.exports = LilObj.extend({
fetch: function (next, ctx) {
var sync = syncr();
- sync('fetch', this, next.bind(ctx));
+ sync('fetch', this, parser(ctx, this, next));
},
destroy: function (next, ctx) {
var sync = syncr();
- sync('destroy', this, next.bind(ctx));
+ sync('destroy', this, parser(ctx, this, next));
}
});
View
4 dist/lilmodel.min.js
@@ -1,3 +1,3 @@
-/*! lilmodel - v0.0.5 - 2012-12-07
+/*! lilmodel - v0.0.5 - 2012-12-09
* Copyright (c) 2012 August Hovland <gushov@gmail.com>; Licensed MIT */
-(function(e){"use strict";function r(e,t){if(t.indexOf(".")===-1)return t;t=t.split("/"),e=e?e.split("/"):[],e.pop(),t[0]==="."&&t.shift();while(t[0]==="..")t.shift(),e.pop();return e.concat(t).join("/")}var t={},n={};e.provide=function(e,r,i){return i?t[e]=r:n[e]=r},e.require=function(i,s){var o,u,a=s||i;return n[a]?n[a]:(o=n[a]={},u={exports:o},t[a](function(t){return e.require(t,r(a,t))},u,o),n[a]=u.exports)}})(this),provide("lil_",function(e,t,n){t.exports={typeOf:function(e){var t=typeof e;return t==="object"&&(t=Array.isArray(e)?"array":t,t=e===null?"null":t),t},each:function(e,t,n){e&&e.length&&e.forEach(t,n)},every:function(e,t,n){return e&&e.length?e.every(t,n):!1},map:function(e,t,n){return e&&e.length?e.map(t,n):[]},eachIn:function(e,t,n){var r=e?Object.keys(e):[];r.forEach(function(r,i){t.call(n,r,e[r],i)})},mapIn:function(e,t,n){var r={};return this.eachIn(e,function(e,n,i){r[e]=t.call(this,e,n,i)},n),r},walk:function(e,t,n,r){var i=this,s=function(e,t){i.eachIn(t,function(t,n){o(e[t],n,t,e)})},o=function(e,t,o,u){var a=i.typeOf(t);a==="object"?(!e&&u&&r&&(e=u[o]={}),s(e,t)):n.call(u,e,t,o)};o(e,t)},extend:function(e,t){return this.walk(e,t,function(e,t,n){this[n]=t},!0),e},defaults:function(e,t){return this.walk(e,t,function(e,t,n){e||(this[n]=t)},!0),e},match:function(e,t){var n=!0;return this.walk(e,t,function(e,t){n=e===t}),n},pick:function(e,t){var n={};return t=this.typeOf(t)==="array"?t:Object.keys(t),this.each(t,function(t){n[t]=e&&e[t]}),n},pushOn:function(e,t,n){e[t]&&typeof e[t].push=="function"?e[t].push(n):typeof e[t]=="undefined"&&(e[t]=[n])}}},!0),provide("lilobj",function(e,t,n){var r=e("lil_");t.exports={isA:function(e){function t(){}return t.prototype=e,this instanceof t},extend:function(e){var t=Object.create(this);return r.eachIn(e,function(e,n){t[e]=n}),t},create:function(){var e=Object.create(this);return e.construct!==undefined&&e.construct.apply(e,arguments),e}}},!0),provide("vladiator",function(e,t,n){var r=e("lil_"),i={required:function(e){return typeof e!="undefined"&&e!==null},array:function(e){return Array.isArray(e)},number:function(e){return typeof e=="number"},string:function(e){return typeof e=="string"},"boolean":function(e){return typeof e=="boolean"},length:function(e,t,n){var r=!t||e.length>=t,i=!n||e.length<=n;return r&&i},gte:function(e,t){return e>=t}},s=function(e,t){var n={isValid:!0};return(e[0]==="required"||i.required(t))&&r.every(e,function(e){var r,s=[];return typeof e!="string"?(r=e[0],s=e.slice(1)):r=e,s.unshift(t),i[r].apply(null,s)?!0:(n.isValid=!1,n.error=r,!1)}),n.$=t,n};t.exports=s},!0),provide("lilmodel/collection",function(e,t,n){var r=e("lilobj"),i=e("lil_"),s=e("./syncr");t.exports=r.extend({construct:function(e){this.$=[],i.each(e,function(e){this.$.push(this.model.create(e))},this),this.validate()},validate:function(){var e={isValid:!0,error:[]};return i.each(this.$,function(t){var n=t.validate();e.error.push(n.error),e.isValid=e.isValid&&n.isValid}),e},add:function(e){var t;e.isA&&e.isA(this.model)?t=e:t=this.model.create(e),this.$.push(t)},remove:function(e){this.$=this.$.filter(function(t){return!i.match(t,e)})},get:function(e){return this.$.filter(function(t){return i.match(t,e)})},each:function(e,t){i.each(this.$,e,t)},find:function(e,t){var n=s();n("find",this,e.bind(t))}})},!0),provide("lilmodel/model",function(e,t,n){var r=e("lilobj"),i=e("lil_"),s=e("vladiator"),o=e("./syncr");t.exports=r.extend({construct:function(e){this.$={};var t=i.mapIn(this.rules,function(e,t){return{enumerable:!0,get:function(){return this.$[e]},set:function(t){var n=this.children&&this.children[e];n&&n.create&&typeof t=="object"?this.$[e]=n.create(t):n&&typeof t=="object"?this.$[e]=this.create(t):n||(this.$[e]=t)}}},this);Object.defineProperties(this,t),e=i.pick(e,this.rules),i.defaults(e,this.defaults),i.eachIn(e,function(e,t){this[e]=t},this),this.validate()},validate:function(){var e={isValid:!0,error:{}};return i.eachIn(this.rules,function(t,n){var r=this[t],i;r&&r.validate?i=r.validate():(i=s(n,r),r=i.$),e.error[t]=i.error,e.isValid=e.isValid&&i.isValid},this),e},save:function(e,t){var n=o(),r=this.$._id?"update":"create",i=this.validate();i.isValid?n(r,this,e.bind(t)):e.call(t,i.error,this)},fetch:function(e,t){var n=o();n("fetch",this,e.bind(t))},destroy:function(e,t){var n=o();n("destroy",this,e.bind(t))}})},!0),provide("lilmodel/syncr",function(e,t,n){var r=function(e,t,n){n(null,t)};t.exports=function(e){return e&&(r=e),r}},!0),provide("lilmodel",function(e,t,n){var r=e("./lilmodel/syncr"),i=e("./lilmodel/model"),s=e("./lilmodel/collection");t.exports={syncr:r,model:i,collection:s}},!0);
+(function(e){"use strict";function r(e,t){if(t.indexOf(".")===-1)return t;t=t.split("/"),e=e?e.split("/"):[],e.pop(),t[0]==="."&&t.shift();while(t[0]==="..")t.shift(),e.pop();return e.concat(t).join("/")}var t={},n={};e.provide=function(e,r,i){return i?t[e]=r:n[e]=r},e.require=function(i,s){var o,u,a=s||i;return n[a]?n[a]:(o=n[a]={},u={exports:o},t[a](function(t){return e.require(t,r(a,t))},u,o),n[a]=u.exports)}})(this),provide("lil_",function(e,t,n){t.exports={typeOf:function(e){var t=typeof e;return t==="object"&&(t=Array.isArray(e)?"array":t,t=e===null?"null":t),t},each:function(e,t,n){e&&e.length&&e.forEach(t,n)},every:function(e,t,n){return e&&e.length?e.every(t,n):!1},map:function(e,t,n){return e&&e.length?e.map(t,n):[]},eachIn:function(e,t,n){var r=e?Object.keys(e):[];r.forEach(function(r,i){t.call(n,r,e[r],i)})},mapIn:function(e,t,n){var r={};return this.eachIn(e,function(e,n,i){r[e]=t.call(this,e,n,i)},n),r},walk:function(e,t,n,r){var i=this,s=function(e,t){i.eachIn(t,function(t,n){o(e[t],n,t,e)})},o=function(e,t,o,u){var a=i.typeOf(t);a==="object"?(!e&&u&&r&&(e=u[o]={}),s(e,t)):n.call(u,e,t,o)};o(e,t)},extend:function(e,t){return this.walk(e,t,function(e,t,n){this[n]=t},!0),e},defaults:function(e,t){return this.walk(e,t,function(e,t,n){e||(this[n]=t)},!0),e},match:function(e,t){var n=!0;return this.walk(e,t,function(e,t){n=e===t}),n},pick:function(e,t){var n={};return t=this.typeOf(t)==="array"?t:Object.keys(t),this.each(t,function(t){n[t]=e&&e[t]}),n},pushOn:function(e,t,n){e[t]&&typeof e[t].push=="function"?e[t].push(n):typeof e[t]=="undefined"&&(e[t]=[n])}}},!0),provide("lilobj/arr",function(e,t,n){var r=e("./obj"),i=e("lil_"),s=Object.create(Array.prototype);i.eachIn(r,function(e,t){s[e]=t}),t.exports=s},!0),provide("lilobj/obj",function(e,t,n){var r=e("lil_");t.exports={isA:function(e){function t(){}return t.prototype=e,this instanceof t},extend:function(e){var t=Object.create(this);return r.eachIn(e,function(e,n){t[e]=n}),t},create:function(){var e=Object.create(this);return e.construct!==undefined&&e.construct.apply(e,arguments),e}}},!0),provide("lilobj",function(e,t,n){var r=e("./lilobj/obj"),i=e("./lilobj/arr");t.exports={obj:r,arr:i}},!0),provide("vladiator",function(e,t,n){var r=e("lil_"),i={required:function(e){return typeof e!="undefined"&&e!==null},array:function(e){return Array.isArray(e)},number:function(e){return typeof e=="number"},string:function(e){return typeof e=="string"},"boolean":function(e){return typeof e=="boolean"},length:function(e,t,n){var r=!t||e.length>=t,i=!n||e.length<=n;return r&&i},gte:function(e,t){return e>=t}},s=function(e,t){var n={isValid:!0};return(e[0]==="required"||i.required(t))&&r.every(e,function(e){var r,s=[];return typeof e!="string"?(r=e[0],s=e.slice(1)):r=e,s.unshift(t),i[r].apply(null,s)?!0:(n.isValid=!1,n.error=r,!1)}),n.$=t,n};t.exports=s},!0),provide("lilmodel/collection",function(e,t,n){var r=e("lilobj").arr,i=e("lil_"),s=e("./syncr");t.exports=r.extend({construct:function(e){i.each(e,function(e){this.push(this.model.create(e))},this),this.validate()},validate:function(){var e={isValid:!0,error:[]};return i.each(this,function(t){var n=t.validate();e.error.push(n.error),e.isValid=e.isValid&&n.isValid}),e},add:function(e){var t;e.isA&&e.isA(this.model)?t=e:t=this.model.create(e),this.push(t)},remove:function(e){var t;i.each(this,function(n,r){i.match(n,e)&&(t=r)}),typeof t=="number"&&this.splice(t,1)},get:function(e){return this.filter(function(t){return i.match(t,e)})},each:function(e,t){i.each(this,e,t)},find:function(e,t){var n=s();n("find",this,e.bind(t))}})},!0),provide("lilmodel/model",function(e,t,n){function u(e){return this.$[e]}function a(e,t){var n=this.children&&this.children[e];n&&n.create&&typeof t=="object"?this.$[e]=n.create(t):n&&typeof t=="object"?this.$[e]=this.create(t):n||(this.$[e]=t)}function f(e,t,n){return function(r,i){n.call(e,r,t.create(i||{}))}}var r=e("lilobj").obj,i=e("lil_"),s=e("vladiator"),o=e("./syncr");t.exports=r.extend({construct:function(e){this.$={};var t=i.mapIn(this.rules,function(e,t){return{enumerable:!0,get:u.bind(this,e),set:a.bind(this,e)}},this);Object.defineProperties(this,t),e=i.pick(e,this.rules),i.defaults(e,this.defaults),i.eachIn(e,function(e,t){this[e]=t},this),this.validate()},validate:function(){var e={isValid:!0,error:{}};return i.eachIn(this.rules,function(t,n){var r=this[t],i;r&&r.validate?i=r.validate():(i=s(n,r),r=i.$),e.error[t]=i.error,e.isValid=e.isValid&&i.isValid},this),e},save:function(e,t){var n=o(),r=this.$._id?"update":"create",i=this.validate();i.isValid?n(r,this,f(t,this,e)):e.call(t,i.error,this)},fetch:function(e,t){var n=o();n("fetch",this,f(t,this,e))},destroy:function(e,t){var n=o();n("destroy",this,f(t,this,e))}})},!0),provide("lilmodel/syncr",function(e,t,n){var r=function(e,t,n){n(null,t)};t.exports=function(e){return e&&(r=e),r}},!0),provide("lilmodel",function(e,t,n){var r=e("./lilmodel/syncr"),i=e("./lilmodel/model"),s=e("./lilmodel/collection");t.exports={syncr:r,model:i,collection:s}},!0);
View
42 lib/lilmodel/collection.js
@@ -2,18 +2,24 @@
newcap:true, noarg:true, sub:true, undef:true, boss:true,
strict:false, eqnull:true, browser:true, node:true */
-var LilObj = require('lilobj');
+var arr = require('lilobj').arr;
var _ = require('lil_');
var syncr = require('./syncr');
-module.exports = LilObj.extend({
+function parser(ctx, model, next) {
- construct: function (values) {
+ return function (err, values) {
+ next.call(ctx, err, model.create(values || []));
+ };
+
+}
- this.$ = [];
+module.exports = arr.extend({
+
+ construct: function (values) {
_.each(values, function (value) {
- this.$.push(this.model.create(value));
+ this.push(this.model.create(value));
}, this);
this.validate();
@@ -24,9 +30,9 @@ module.exports = LilObj.extend({
var validation = { isValid: true, error: [] };
- _.each(this.$, function ($) {
+ _.each(this, function (model) {
- var v = $.validate();
+ var v = model.validate();
validation.error.push(v.error);
validation.isValid = validation.isValid && v.isValid;
@@ -45,33 +51,43 @@ module.exports = LilObj.extend({
model = this.model.create(obj);
}
- this.$.push(model);
+ this.push(model);
},
remove: function (query) {
- this.$ = this.$.filter(function (model) {
- return !_.match(model, query);
+ var index;
+
+ _.each(this, function (model, i) {
+
+ if (_.match(model, query)) {
+ index = i;
+ }
+
});
+ if (typeof index === 'number') {
+ this.splice(index, 1);
+ }
+
},
get: function (query) {
- return this.$.filter(function (model) {
+ return this.filter(function (model) {
return _.match(model, query);
});
},
each: function (next, ctx) {
- _.each(this.$, next, ctx);
+ _.each(this, next, ctx);
},
find: function (next, ctx) {
var sync = syncr();
- sync('find', this, next.bind(ctx));
+ sync('find', this, parser(ctx, this, next));
}
View
54 lib/lilmodel/model.js
@@ -2,40 +2,48 @@
newcap:true, noarg:true, sub:true, undef:true, boss:true,
strict:false, eqnull:true, browser:true, node:true */
-var LilObj = require('lilobj');
+var obj = require('lilobj').obj;
var _ = require('lil_');
var vlad = require('vladiator');
var syncr = require('./syncr');
-module.exports = LilObj.extend({
+function getter(name) {
+ return this.$[name];
+}
- construct: function (values) {
+function setter(name, value) {
- this.$ = {};
- var props = _.mapIn(this.rules, function (name, value) {
+ var model = this.children && this.children[name];
- return {
+ if (model && model.create && typeof value === 'object') {
+ this.$[name] = model.create(value);
+ } else if (model && typeof value === 'object') {
+ this.$[name] = this.create(value);
+ } else if (!model) {
+ this.$[name] = value;
+ }
- enumerable : true,
+}
- get: function () {
- return this.$[name];
- },
+function parser(ctx, model, next) {
- set: function (value) {
+ return function (err, values) {
+ next.call(ctx, err, model.create(values));
+ };
- var model = this.children && this.children[name];
+}
- if (model && model.create && typeof value === 'object') {
- this.$[name] = model.create(value);
- } else if (model && typeof value === 'object') {
- this.$[name] = this.create(value);
- } else if (!model) {
- this.$[name] = value;
- }
+module.exports = obj.extend({
- }
+ construct: function (values) {
+ this.$ = {};
+ var props = _.mapIn(this.rules, function (name, value) {
+
+ return {
+ enumerable: true,
+ get: getter.bind(this, name),
+ set: setter.bind(this, name)
};
}, this);
@@ -85,7 +93,7 @@ module.exports = LilObj.extend({
var validation = this.validate();
if (validation.isValid) {
- sync(method, this, next.bind(ctx));
+ sync(method, this, parser(ctx, this, next));
} else {
next.call(ctx, validation.error, this);
}
@@ -94,12 +102,12 @@ module.exports = LilObj.extend({
fetch: function (next, ctx) {
var sync = syncr();
- sync('fetch', this, next.bind(ctx));
+ sync('fetch', this, parser(ctx, this, next));
},
destroy: function (next, ctx) {
var sync = syncr();
- sync('destroy', this, next.bind(ctx));
+ sync('destroy', this, parser(ctx, this, next));
}
});
View
2 package.json
@@ -2,7 +2,7 @@
"author": "August Hovland <gushov@gmail.com>",
"name": "lilmodel",
"description": "A li'l model wrapper",
- "version": "0.0.5",
+ "version": "0.0.6",
"repository": {
"type": "git",
"url": "git://github.com/gushov/lilmodel.git"
View
38 test/lilmodel-test.js
@@ -8,23 +8,16 @@ var lilModel = typeof module !== 'undefined' ? require('../lib/lilmodel') : requ
buster.testCase("lilmodel", {
- "setUp": function () {
- this.syncStub = this.stub().callsArg(2);
- lilModel.syncr(this.syncStub);
- },
-
"should call sync on save when valid": function () {
+ var syncStub = this.stub().callsArg(2);
var nextSpy = this.spy();
- var Recipe = lilModel.model.extend({
+ lilModel.syncr(syncStub);
- defaults: {
- urlRoot: '/recipe'
- },
+ var Recipe = lilModel.model.extend({
rules: {
- urlRoot: ['required', 'string'],
name: ['required', 'string']
}
@@ -37,11 +30,11 @@ buster.testCase("lilmodel", {
var Chef = lilModel.model.extend({
defaults: {
- urlRoot: '/chef'
+ style: 'classic'
},
rules: {
- urlRoot: ['required', 'string'],
+ style: ['required', 'string'],
name: ['required', 'string'],
recipes: ['array'],
sousChef: ['object']
@@ -69,19 +62,26 @@ buster.testCase("lilmodel", {
var results = chef.recipes.get({ name: 'tacos' });
chef.recipes.remove({ name: 'meatball sauce' });
+ assert.equals(chef.name, 'gus');
+ assert.equals(chef.sousChef.name, 'zoe');
+
+ chef.name = 'august';
+ chef.sousChef = { name: 'zozo' };
var context = { me: 'gus' };
chef.save(nextSpy, context);
- assert.calledOnce(this.syncStub);
+ assert(syncStub.calledOnce);
+ // assert.calledOnce(syncStub); //fails in phantomjs
assert.calledOnce(nextSpy);
assert(nextSpy.calledOn(context));
- assert.equals(chef.name, 'gus');
- assert.equals(chef.sousChef.name, 'zoe');
- assert.equals(chef.recipes.$[0].name, 'tacos');
- assert.equals(chef.recipes.$[1].name, 'eggs');
- assert.equals(chef.recipes.$.length, 2);
+ assert.equals(chef.name, 'august');
+ assert.equals(chef.sousChef.name, 'zozo');
+ assert.equals(chef.sousChef.style, 'classic');
+ assert.equals(chef.recipes[0].name, 'tacos');
+ assert.equals(chef.recipes[1].name, 'eggs');
+ assert.equals(chef.recipes.length, 2);
assert.equals(results.length, 1);
- assert.equals(results[0], chef.recipes.$[0]);
+ assert.equals(results[0], chef.recipes[0]);
}

0 comments on commit 3f700fc

Please sign in to comment.