root/GearsORM/trunk/tests/test_inner_relations.html

Revision 338, 1.7 kB (checked in by uriel, 15 months ago)

*added events to model classes
*added test for model events
*small cleanup in model constructor

Line 
1<html>
2        <head>
3                <script src="../gears_init.js"></script>
4                <script src="../GearsORM.js"></script>
5                <script src="../GearsORM.Events.js"></script>
6                <script src="../GearsORM.ResultIterator.js"></script>
7                <script src="../GearsORM.Sql.js"></script>
8                <script src="../GearsORM.Fields.js"></script>
9                <script src="../GearsORM.Model.js"></script>
10                <script src="../GearsORM.Introspection.js"></script>
11                <script src="../GearsORM.Transaction.js"></script>
12                <script>
13                        GearsORM.dbName = "test.selfRelation";
14                        var TreeNode = new GearsORM.Model({
15                                name:"TreeNode",
16                                fields:
17                                {
18                                        data:new GearsORM.Fields.String({maxLength:25}),
19                                        parent:new GearsORM.Fields.OneToMany({related:"TreeNode",allowNull:true}),
20                                        childs:new GearsORM.Fields.ManyToOne({related:"TreeNode"})
21                                }
22                        });
23                        var Tests =
24                        {
25                                up:function()
26                                {
27                                        TreeNode.dropTable();
28                                        TreeNode.createTable();
29                                },
30                                "test that create with null and inner relation works":function()
31                                {
32                                        var root = new TreeNode({data:"i am the root",parent:null}).save();
33                                        var node1 = new TreeNode({data:"i am node 1",parent:root}).save();
34                                        var node2 = new TreeNode({data:"i am node 2",parent:root}).save();
35                                },
36                                "test that select works":function()
37                                {
38                                        UnitTest.assertEqual(2,new TreeNode(1).childs.select().toArray().length);
39                                },
40                                "test that remove works":function()
41                                {
42                                        var root = new TreeNode(1);
43                                        root.childs.remove();
44                                        UnitTest.assertEqual(0,root.childs.select().toArray().length);
45                                },
46                                down:function()
47                                {
48                                        TreeNode.dropTable();
49                                }
50                        };
51                </script>
52                <script src="unit_test.js"></script>
53        </head>
54        <body>
55               
56        </body>
57</html>
Note: See TracBrowser for help on using the browser.