Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / jsbuilder / src / generators / app / files / lib / sencha-jasmine / matchers / Model.js
1 /**
2  * Sencha-specific matchers for convenient testing of Model expectations
3  */
4 beforeEach(function() {
5     this.addMatchers({
6         /**
7          * Sample usage:
8          * expect('User').toHaveMany('Product');
9          */
10         toHaveMany: function(expected) {
11             if (typeof this.actual == 'string') {
12                 this.actual = Ext.ModelManager.types[this.actual].prototype;
13             }
14             
15             var associations = this.actual.associations.items,
16                 length       = associations.length,
17                 association, i;
18             
19             for (i = 0; i < length; i++) {
20                 association = associations[i];
21                 
22                 if (association.associatedName == expected && association.type == 'hasMany') {
23                     return true;
24                 }
25             }
26             
27             return false;
28         },
29         
30         /**
31          * Sample usage:
32          * expect('Product').toBelongTo('User')
33          */
34         toBelongTo: function(expected) {
35             if (typeof this.actual == 'string') {
36                 this.actual = Ext.ModelManager.types[this.actual].prototype;
37             }
38             
39             var associations = this.actual.associations.items,
40                 length       = associations.length,
41                 association, i;
42             
43             for (i = 0; i < length; i++) {
44                 association = associations[i];
45                 
46                 if (association.associatedName == expected && association.type == 'belongsTo') {
47                     return true;
48                 }
49             }
50             
51             return false;
52         }
53     });
54 });