X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/jsbuilder/src/generators/app/files/lib/sencha-jasmine/matchers/Model.js diff --git a/jsbuilder/src/generators/app/files/lib/sencha-jasmine/matchers/Model.js b/jsbuilder/src/generators/app/files/lib/sencha-jasmine/matchers/Model.js new file mode 100644 index 00000000..0c91149a --- /dev/null +++ b/jsbuilder/src/generators/app/files/lib/sencha-jasmine/matchers/Model.js @@ -0,0 +1,54 @@ +/** + * Sencha-specific matchers for convenient testing of Model expectations + */ +beforeEach(function() { + this.addMatchers({ + /** + * Sample usage: + * expect('User').toHaveMany('Product'); + */ + toHaveMany: function(expected) { + if (typeof this.actual == 'string') { + this.actual = Ext.ModelManager.types[this.actual].prototype; + } + + var associations = this.actual.associations.items, + length = associations.length, + association, i; + + for (i = 0; i < length; i++) { + association = associations[i]; + + if (association.associatedName == expected && association.type == 'hasMany') { + return true; + } + } + + return false; + }, + + /** + * Sample usage: + * expect('Product').toBelongTo('User') + */ + toBelongTo: function(expected) { + if (typeof this.actual == 'string') { + this.actual = Ext.ModelManager.types[this.actual].prototype; + } + + var associations = this.actual.associations.items, + length = associations.length, + association, i; + + for (i = 0; i < length; i++) { + association = associations[i]; + + if (association.associatedName == expected && association.type == 'belongsTo') { + return true; + } + } + + return false; + } + }); +}); \ No newline at end of file