Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / 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 (file)
index 0000000..0c91149
--- /dev/null
@@ -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