Blame view

js/lib/sencha-jasmine/matchers/Model.js 1.65 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
        }
    });
});