extjs-mvc 0.4.0.j → 0.4.0.k

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/Rakefile +1 -1
  2. data/VERSION +1 -1
  3. data/lib/extjs-mvc.rb +0 -14
  4. data/lib/extjs-mvc/api.rb +14 -27
  5. data/lib/extjs-mvc/src/App.js +219 -0
  6. data/lib/extjs-mvc/src/MVC.js +260 -0
  7. data/lib/extjs-mvc/src/Presenter.js +52 -0
  8. data/lib/extjs-mvc/src/README.rdoc +69 -0
  9. data/lib/extjs-mvc/src/controller/Controller.js +278 -0
  10. data/lib/extjs-mvc/src/controller/CrudController.js +460 -0
  11. data/lib/extjs-mvc/src/lib/Array.js +26 -0
  12. data/lib/extjs-mvc/src/lib/Booter.js +417 -0
  13. data/lib/extjs-mvc/src/lib/ClassManager.js +191 -0
  14. data/lib/extjs-mvc/src/lib/ControllerClassManager.js +95 -0
  15. data/lib/extjs-mvc/src/lib/Dependencies.js +44 -0
  16. data/lib/extjs-mvc/src/lib/DispatchMatcher.js +98 -0
  17. data/lib/extjs-mvc/src/lib/Dispatcher.js +129 -0
  18. data/lib/extjs-mvc/src/lib/Environment.js +43 -0
  19. data/lib/extjs-mvc/src/lib/Inflector.js +155 -0
  20. data/lib/extjs-mvc/src/lib/ModelClassManager.js +19 -0
  21. data/lib/extjs-mvc/src/lib/Route.js +139 -0
  22. data/lib/extjs-mvc/src/lib/Router.js +282 -0
  23. data/lib/extjs-mvc/src/lib/String.js +94 -0
  24. data/lib/extjs-mvc/src/lib/ViewClassManager.js +229 -0
  25. data/lib/extjs-mvc/src/lib/notes.txt +32 -0
  26. data/lib/extjs-mvc/src/model/AdapterManager.js +30 -0
  27. data/lib/extjs-mvc/src/model/Association.js +26 -0
  28. data/lib/extjs-mvc/src/model/Base.js +63 -0
  29. data/lib/extjs-mvc/src/model/BelongsToAssociation.js +116 -0
  30. data/lib/extjs-mvc/src/model/Cache.js +131 -0
  31. data/lib/extjs-mvc/src/model/HasManyAssociation.js +160 -0
  32. data/lib/extjs-mvc/src/model/Model.js +331 -0
  33. data/lib/extjs-mvc/src/model/UrlBuilder.js +106 -0
  34. data/lib/extjs-mvc/src/model/adapters/AbstractAdapter.js +296 -0
  35. data/lib/extjs-mvc/src/model/adapters/MemoryAdapter.js +103 -0
  36. data/lib/extjs-mvc/src/model/adapters/RESTAdapter.js +345 -0
  37. data/lib/extjs-mvc/src/model/adapters/RESTJSONAdapter.js +68 -0
  38. data/lib/extjs-mvc/src/model/adapters/notes.txt +42 -0
  39. data/lib/extjs-mvc/src/model/associations/Association.js +192 -0
  40. data/lib/extjs-mvc/src/model/associations/notes.txt +87 -0
  41. data/lib/extjs-mvc/src/model/validations/Errors.js +136 -0
  42. data/lib/extjs-mvc/src/model/validations/Plugin.js +139 -0
  43. data/lib/extjs-mvc/src/model/validations/Validations.js +276 -0
  44. data/lib/extjs-mvc/src/notes/Charts.graffle +0 -0
  45. data/lib/extjs-mvc/src/overrides/Ext.Component.js +21 -0
  46. data/lib/extjs-mvc/src/overrides/Ext.extend.js +142 -0
  47. data/lib/extjs-mvc/src/spec/Array.spec.js +15 -0
  48. data/lib/extjs-mvc/src/spec/ExtMVC.spec.js +65 -0
  49. data/lib/extjs-mvc/src/spec/Model.spec.js +370 -0
  50. data/lib/extjs-mvc/src/spec/OS.spec.js +83 -0
  51. data/lib/extjs-mvc/src/spec/Router.spec.js +99 -0
  52. data/lib/extjs-mvc/src/spec/SpecHelper.js +106 -0
  53. data/lib/extjs-mvc/src/spec/String.spec.js +83 -0
  54. data/lib/extjs-mvc/src/spec/model/AbstractAdapter.spec.js +49 -0
  55. data/lib/extjs-mvc/src/spec/model/Associations.spec.js +99 -0
  56. data/lib/extjs-mvc/src/spec/model/Cache.spec.js +5 -0
  57. data/lib/extjs-mvc/src/spec/model/RESTAdapter.spec.js +19 -0
  58. data/lib/extjs-mvc/src/spec/model/ValidationErrors.spec.js +64 -0
  59. data/lib/extjs-mvc/src/spec/model/Validations.spec.js +166 -0
  60. data/lib/extjs-mvc/src/spec/model/ValidationsPlugin.spec.js +108 -0
  61. data/lib/extjs-mvc/src/spec/suite.html +60 -0
  62. data/lib/extjs-mvc/src/specs-old/JSSpec.css +216 -0
  63. data/lib/extjs-mvc/src/specs-old/JSSpec.js +1512 -0
  64. data/lib/extjs-mvc/src/specs-old/all.html +66 -0
  65. data/lib/extjs-mvc/src/specs-old/base.js +14 -0
  66. data/lib/extjs-mvc/src/specs-old/controller.js +17 -0
  67. data/lib/extjs-mvc/src/specs-old/diff_match_patch.js +1 -0
  68. data/lib/extjs-mvc/src/specs-old/model.js +70 -0
  69. data/lib/extjs-mvc/src/specs-old/route.js +38 -0
  70. data/lib/extjs-mvc/src/specs-old/router.js +59 -0
  71. data/lib/extjs-mvc/src/specs-old/string.js +22 -0
  72. data/lib/extjs-mvc/src/testrunner/JSpecFormatter.js +111 -0
  73. data/lib/extjs-mvc/src/testrunner/TestClient.js +181 -0
  74. data/lib/extjs-mvc/src/testrunner/TestGrid.js +351 -0
  75. data/lib/extjs-mvc/src/testrunner/TestRunner.js +110 -0
  76. data/lib/extjs-mvc/src/testrunner/TestViewport.js +94 -0
  77. data/lib/extjs-mvc/src/vendor.yml +30 -0
  78. data/lib/extjs-mvc/src/vendor/ext-3.1.1/vendor.yml +16 -0
  79. data/lib/extjs-mvc/src/view/FormWindow.js +184 -0
  80. data/lib/extjs-mvc/src/view/HasManyEditorGridPanel.js +211 -0
  81. data/lib/extjs-mvc/src/view/scaffold/Edit.js +46 -0
  82. data/lib/extjs-mvc/src/view/scaffold/Index.js +561 -0
  83. data/lib/extjs-mvc/src/view/scaffold/New.js +20 -0
  84. data/lib/extjs-mvc/src/view/scaffold/ScaffoldFormPanel.js +255 -0
  85. data/lib/{vendor.yml → extjs-mvc/vendor.yml} +0 -0
  86. data/test/app/vendor/extjs-mvc/App.js +219 -0
  87. data/test/app/vendor/extjs-mvc/MVC.js +260 -0
  88. data/test/app/vendor/extjs-mvc/Presenter.js +52 -0
  89. data/test/app/vendor/extjs-mvc/README.rdoc +69 -0
  90. data/test/app/vendor/extjs-mvc/controller/Controller.js +278 -0
  91. data/test/app/vendor/extjs-mvc/controller/CrudController.js +460 -0
  92. data/test/app/vendor/extjs-mvc/lib/Array.js +26 -0
  93. data/test/app/vendor/extjs-mvc/lib/Booter.js +417 -0
  94. data/test/app/vendor/extjs-mvc/lib/ClassManager.js +191 -0
  95. data/test/app/vendor/extjs-mvc/lib/ControllerClassManager.js +95 -0
  96. data/test/app/vendor/extjs-mvc/lib/Dependencies.js +44 -0
  97. data/test/app/vendor/extjs-mvc/lib/DispatchMatcher.js +98 -0
  98. data/test/app/vendor/extjs-mvc/lib/Dispatcher.js +129 -0
  99. data/test/app/vendor/extjs-mvc/lib/Environment.js +43 -0
  100. data/test/app/vendor/extjs-mvc/lib/Inflector.js +155 -0
  101. data/test/app/vendor/extjs-mvc/lib/ModelClassManager.js +19 -0
  102. data/test/app/vendor/extjs-mvc/lib/Route.js +139 -0
  103. data/test/app/vendor/extjs-mvc/lib/Router.js +282 -0
  104. data/test/app/vendor/extjs-mvc/lib/String.js +94 -0
  105. data/test/app/vendor/extjs-mvc/lib/ViewClassManager.js +229 -0
  106. data/test/app/vendor/extjs-mvc/lib/notes.txt +32 -0
  107. data/test/app/vendor/extjs-mvc/model/AdapterManager.js +30 -0
  108. data/test/app/vendor/extjs-mvc/model/Association.js +26 -0
  109. data/test/app/vendor/extjs-mvc/model/Base.js +63 -0
  110. data/test/app/vendor/extjs-mvc/model/BelongsToAssociation.js +116 -0
  111. data/test/app/vendor/extjs-mvc/model/Cache.js +131 -0
  112. data/test/app/vendor/extjs-mvc/model/HasManyAssociation.js +160 -0
  113. data/test/app/vendor/extjs-mvc/model/Model.js +331 -0
  114. data/test/app/vendor/extjs-mvc/model/UrlBuilder.js +106 -0
  115. data/test/app/vendor/extjs-mvc/model/adapters/AbstractAdapter.js +296 -0
  116. data/test/app/vendor/extjs-mvc/model/adapters/MemoryAdapter.js +103 -0
  117. data/test/app/vendor/extjs-mvc/model/adapters/RESTAdapter.js +345 -0
  118. data/test/app/vendor/extjs-mvc/model/adapters/RESTJSONAdapter.js +68 -0
  119. data/test/app/vendor/extjs-mvc/model/adapters/notes.txt +42 -0
  120. data/test/app/vendor/extjs-mvc/model/associations/Association.js +192 -0
  121. data/test/app/vendor/extjs-mvc/model/associations/notes.txt +87 -0
  122. data/test/app/vendor/extjs-mvc/model/validations/Errors.js +136 -0
  123. data/test/app/vendor/extjs-mvc/model/validations/Plugin.js +139 -0
  124. data/test/app/vendor/extjs-mvc/model/validations/Validations.js +276 -0
  125. data/test/app/vendor/extjs-mvc/notes/Charts.graffle +0 -0
  126. data/test/app/vendor/extjs-mvc/overrides/Ext.Component.js +21 -0
  127. data/test/app/vendor/extjs-mvc/overrides/Ext.extend.js +142 -0
  128. data/test/app/vendor/extjs-mvc/spec/Array.spec.js +15 -0
  129. data/test/app/vendor/extjs-mvc/spec/ExtMVC.spec.js +65 -0
  130. data/test/app/vendor/extjs-mvc/spec/Model.spec.js +370 -0
  131. data/test/app/vendor/extjs-mvc/spec/OS.spec.js +83 -0
  132. data/test/app/vendor/extjs-mvc/spec/Router.spec.js +99 -0
  133. data/test/app/vendor/extjs-mvc/spec/SpecHelper.js +106 -0
  134. data/test/app/vendor/extjs-mvc/spec/String.spec.js +83 -0
  135. data/test/app/vendor/extjs-mvc/spec/model/AbstractAdapter.spec.js +49 -0
  136. data/test/app/vendor/extjs-mvc/spec/model/Associations.spec.js +99 -0
  137. data/test/app/vendor/extjs-mvc/spec/model/Cache.spec.js +5 -0
  138. data/test/app/vendor/extjs-mvc/spec/model/RESTAdapter.spec.js +19 -0
  139. data/test/app/vendor/extjs-mvc/spec/model/ValidationErrors.spec.js +64 -0
  140. data/test/app/vendor/extjs-mvc/spec/model/Validations.spec.js +166 -0
  141. data/test/app/vendor/extjs-mvc/spec/model/ValidationsPlugin.spec.js +108 -0
  142. data/test/app/vendor/extjs-mvc/spec/suite.html +60 -0
  143. data/test/app/vendor/extjs-mvc/specs-old/JSSpec.css +216 -0
  144. data/test/app/vendor/extjs-mvc/specs-old/JSSpec.js +1512 -0
  145. data/test/app/vendor/extjs-mvc/specs-old/all.html +66 -0
  146. data/test/app/vendor/extjs-mvc/specs-old/base.js +14 -0
  147. data/test/app/vendor/extjs-mvc/specs-old/controller.js +17 -0
  148. data/test/app/vendor/extjs-mvc/specs-old/diff_match_patch.js +1 -0
  149. data/test/app/vendor/extjs-mvc/specs-old/model.js +70 -0
  150. data/test/app/vendor/extjs-mvc/specs-old/route.js +38 -0
  151. data/test/app/vendor/extjs-mvc/specs-old/router.js +59 -0
  152. data/test/app/vendor/extjs-mvc/specs-old/string.js +22 -0
  153. data/test/app/vendor/extjs-mvc/testrunner/JSpecFormatter.js +111 -0
  154. data/test/app/vendor/extjs-mvc/testrunner/TestClient.js +181 -0
  155. data/test/app/vendor/extjs-mvc/testrunner/TestGrid.js +351 -0
  156. data/test/app/vendor/extjs-mvc/testrunner/TestRunner.js +110 -0
  157. data/test/app/vendor/extjs-mvc/testrunner/TestViewport.js +94 -0
  158. data/test/app/vendor/extjs-mvc/vendor.yml +30 -0
  159. data/test/app/vendor/extjs-mvc/vendor/ext-3.1.1/vendor.yml +16 -0
  160. data/test/app/vendor/extjs-mvc/view/FormWindow.js +184 -0
  161. data/test/app/vendor/extjs-mvc/view/HasManyEditorGridPanel.js +211 -0
  162. data/test/app/vendor/extjs-mvc/view/scaffold/Edit.js +46 -0
  163. data/test/app/vendor/extjs-mvc/view/scaffold/Index.js +561 -0
  164. data/test/app/vendor/extjs-mvc/view/scaffold/New.js +20 -0
  165. data/test/app/vendor/extjs-mvc/view/scaffold/ScaffoldFormPanel.js +255 -0
  166. data/test/helper.rb +7 -1
  167. data/test/test_extjs-mvc.rb +46 -0
  168. metadata +167 -7
  169. data/test/test_extjs-mvc-gem.rb +0 -7
@@ -0,0 +1,65 @@
1
+ Screw.Unit(function() {
2
+ describe("ExtMVC", function() {
3
+ describe("environments", function() {
4
+ it("should default to the production environment", function() {
5
+ expect(ExtMVC.getCurrentEnvironment()).to(equal, 'production');
6
+ });
7
+
8
+ it("should return current environment settings", function() {
9
+ expect(ExtMVC.getCurrentEnvironmentSettings()).to(equal, {});
10
+ });
11
+
12
+ it("should allow retrieval of existing environment settings", function() {
13
+ var prod = ExtMVC.getEnvironmentSettings('production');
14
+ expect(prod).to(equal, {});
15
+ });
16
+
17
+ it("should allow specification of environment settings to an existing environment", function() {
18
+ expect(ExtMVC.getEnvironmentSettings('production')).to(equal, {});
19
+
20
+ ExtMVC.addEnvironmentSettings('production', {myKey: 'myValue'});
21
+ expect(ExtMVC.getEnvironmentSettings('production').myKey).to(equal, 'myValue');
22
+ });
23
+
24
+ it("should allow specification of environment settings to a new environment", function() {
25
+ var mySettings = {key: 'value'};
26
+ expect(ExtMVC.getEnvironmentSettings('newEnv')).to(equal, null);
27
+
28
+ ExtMVC.addEnvironmentSettings('newEnv', mySettings);
29
+ expect(ExtMVC.getEnvironmentSettings('newEnv')).to(equal, mySettings);
30
+ });
31
+
32
+ describe("when changing environment", function() {
33
+ it("should allow the current environment to be changed if the new environment is valid", function() {
34
+ expect(ExtMVC.getCurrentEnvironment()).to(equal, 'production');
35
+
36
+ //we need to add this environment first to make it valid
37
+ ExtMVC.addEnvironmentSettings('development', {key: 'value'});
38
+
39
+ ExtMVC.setCurrentEnvironment('development');
40
+ expect(ExtMVC.getCurrentEnvironment()).to(equal, 'development');
41
+ });
42
+
43
+ it("should not allow the current environment to be changed if the new environment does not exist", function() {
44
+ ExtMVC.setCurrentEnvironment('notReal');
45
+ expect(ExtMVC.getCurrentEnvironment()).to_not(equal, 'notReal');
46
+ });
47
+
48
+ it("should fire an environment-changed event", function() {
49
+ var newEnv = '', newConfig = {};
50
+ var devSettings = {key: 'value'};
51
+
52
+ //add another environment to be able to change to
53
+ ExtMVC.addEnvironmentSettings('development', devSettings);
54
+
55
+ ExtMVC.on('environment-changed', function(n, c) {newEnv = n; newConfig = c;}, this);
56
+
57
+ ExtMVC.setCurrentEnvironment('development');
58
+
59
+ expect(newEnv).to(equal, 'development');
60
+ expect(newConfig).to(equal, devSettings);
61
+ });
62
+ });
63
+ });
64
+ });
65
+ });
@@ -0,0 +1,370 @@
1
+ Screw.Unit(function() {
2
+ //keep track of the object to which models are currently assigned
3
+ var ns = ExtMVC.model.modelNamespace;
4
+
5
+ //Uses some test models set up in SpecHelper.js
6
+ user = new ns.User({
7
+ id: 100,
8
+ first_name: 'William',
9
+ last_name: 'Adama',
10
+ email: 'adama@bsg.net'
11
+ });
12
+
13
+ blogPost = new ns.BlogPost({
14
+ id: 1,
15
+ user_id: 100,
16
+ title: 'Test Post',
17
+ content: "Frak the odds, we're going to find her"
18
+ });
19
+
20
+ describe("Models", function() {
21
+ describe("when defining models", function() {
22
+ before(function() {
23
+ //we redefine these several times in these blocks so delete between each test
24
+ delete ns.AnotherModel;
25
+ delete ns.SpecialModel;
26
+ });
27
+
28
+ it("should create the model immediately if it does not extend any other models", function() {
29
+ expect(typeof ns.AnotherModel).to(equal, "undefined");
30
+
31
+ ExtMVC.model.define('AnotherModel', {fields: [{name: 'title', type: 'string'}]});
32
+ expect(typeof ns.AnotherModel).to(equal, "function");
33
+ });
34
+
35
+ describe("when checking to see if the model has already been defined", function() {
36
+ it("should return false when trying to define a new model", function() {
37
+ expect(ExtMVC.model.isAlreadyDefined('MySuperModel')).to(equal, false);
38
+ });
39
+
40
+ it("should return true when trying to define a model that already exists", function() {
41
+ expect(ExtMVC.model.isAlreadyDefined('User')).to(equal, true);
42
+ });
43
+
44
+ it("should return true when trying to define a model that is already in the pending creation queue", function() {
45
+ //Add a fake model that depends on another model which hasn't yet been created
46
+ ExtMVC.model.define("AnotherNewModel", {extend: "NonExistantModel"});
47
+
48
+ //AnotherNewModel hasn't actually been created at this point
49
+ expect(typeof ns.AnotherNewModel).to(equal, "undefined");
50
+ expect(ExtMVC.model.isAlreadyDefined('AnotherNewModel')).to(equal, true);
51
+ });
52
+ });
53
+
54
+ describe("which extend other models", function() {
55
+ after(function() {
56
+ delete ns.RichUser; delete ns.AnotherModel;
57
+ });
58
+
59
+ it("should create the model immediately if it extends a model that has already been defined", function() {
60
+ //make sure our superclass has been defined already
61
+ expect(typeof ns.User).to(equal, "function");
62
+
63
+ ExtMVC.model.define('RichUser', {extend: 'User', monies: 'many'});
64
+ expect(typeof ns.RichUser).to(equal, "function");
65
+ });
66
+
67
+ it("should not create the model immediately if the model it extends has not yet been defined", function() {
68
+ //make sure our superclass model hasn't been defined yet
69
+ expect(typeof ns.SpecialModel).to(equal, "undefined");
70
+
71
+ ExtMVC.model.define('AnotherModel', {fields: [{name: 'title', type: 'string'}], extend: 'SpecialModel'});
72
+
73
+ expect(typeof ns.AnotherModel).to(equal, "undefined");
74
+ });
75
+
76
+ it("should add the create config to an internal object if the model it extends has not yet been defined", function() {
77
+ var previousLength = ExtMVC.model.getModelsPendingDefinitionOf('SpecialModel').length;
78
+
79
+ ExtMVC.model.define('AnotherModel', {fields: [{name: 'title', type: 'string'}], extend: 'SpecialModel'});
80
+
81
+ var p = ExtMVC.model.getModelsPendingDefinitionOf('SpecialModel');
82
+ expect(p.length).to(equal, previousLength + 1);
83
+ expect(p[0].name).to(equal, 'AnotherModel');
84
+ });
85
+ });
86
+ });
87
+
88
+ describe("the pendingCreation queue", function() {
89
+ //add a couple of fake configs to the queue...
90
+ var peonUserConfig = {displayName: function() {return 'Peon';}};
91
+ var noobUserConfig = {displayName: function() {return 'Noob';}};
92
+
93
+ var m = ExtMVC.model;
94
+ m.pendingCreation = {'User': [
95
+ {name: 'PeonUser', config: peonUserConfig},
96
+ {name: 'NoobUser', config: noobUserConfig}
97
+ ]};
98
+
99
+ it("should return an array of all model definitions waiting for the creation of a given model", function() {
100
+ var p = ExtMVC.model.getModelsPendingDefinitionOf('User');
101
+
102
+ expect(p.length).to(equal, 2);
103
+ expect(p[0].name).to(equal, 'PeonUser');
104
+ expect(p[1].name).to(equal, 'NoobUser');
105
+ });
106
+
107
+ it("should add model definition objects to the queue", function() {
108
+ ExtMVC.model.setModelPendingDefinitionOf('User', 'NormalUser', {displayName: function() {return 'Normal';}});
109
+
110
+ var p = ExtMVC.model.getModelsPendingDefinitionOf('User');
111
+ expect(p.length).to(equal, 3);
112
+ expect(p[2].name).to(equal, 'NormalUser');
113
+ });
114
+ });
115
+
116
+ describe("when creating a model", function() {
117
+ before(function() {
118
+ ExtMVC.model.define('NewModel', {fields: [{name: 'name', type: 'string'}]});
119
+ });
120
+
121
+ after(function() {
122
+ delete ns.NewModel; delete ns.MyNewModel;
123
+ });
124
+
125
+ it("should create the model within ExtMVC.model.modelNamespace", function() {
126
+ expect(typeof ns.MyNewModel).to(equal, 'undefined');
127
+ ExtMVC.model.create('MyNewModel', {fields: [{name: 'title', type: 'string'}]});
128
+
129
+ expect(typeof ns.MyNewModel).to(equal, 'function');
130
+ });
131
+
132
+ it("make all defined methods available on that model", function() {
133
+ expect(typeof(user.displayName)).to(equal, "function");
134
+ });
135
+
136
+ it("should not make the special classMethods property available", function() {
137
+ expect(typeof(user.classMethods)).to(equal, "undefined");
138
+ });
139
+
140
+ it("should add all classMethods to the model class instead of each instance", function() {
141
+ expect(typeof(ns.User.testClassMethod)).to(equal, "function");
142
+ });
143
+
144
+ it("should default the primary key to 'id'", function() {
145
+ expect(user.primaryKey).to(equal, 'id');
146
+ });
147
+
148
+ it("should allow specification of a different primary key to 'id'", function() {
149
+ ExtMVC.model.create("SpecialModel", {
150
+ fields: [{name: 'someField', type: 'string'}],
151
+ primaryKey: 'someField'
152
+ });
153
+
154
+ var special = new ns.SpecialModel({someField: 'someValue'});
155
+
156
+ expect(special.primaryKey).to(equal, 'someField');
157
+ });
158
+
159
+ // it("should set its modelClass property as a reference to the class definition", function() {
160
+ // expect(user.modelClass).to(equal, ns.User);
161
+ // });
162
+
163
+ it("should inherit all functions from Ext.data.Record", function() {
164
+ var funcs = ['beginEdit', 'cancelEdit', 'clearError', 'commit', 'copy', 'endEdit', 'get',
165
+ 'getChanges', 'hasError', 'isModified', 'join', 'override', 'reject', 'set'];
166
+
167
+ var myInstance = new ns.NewModel({name: 'Ed'});
168
+
169
+ Ext.each(funcs, function(functionName) {
170
+ expect(typeof myInstance[functionName]).to(equal, "function");
171
+ }, this);
172
+ });
173
+
174
+ it("should inherit all properties from Ext.data.Record", function() {
175
+ var props = ['dirty', 'editing', 'error', 'id', 'modified'];
176
+
177
+ var myInstance = new ns.NewModel({name: 'Ed'});
178
+
179
+ Ext.each(props, function(propertyName) {
180
+ expect(typeof myInstance[propertyName]).to_not(equal, "undefined");
181
+ }, this);
182
+ });
183
+ });
184
+
185
+ describe("after creation", function() {
186
+ it("should check the pending creation array and create any models that depended on this model's existence", function() {
187
+ //TODO: Work out how to test that getModelsPendingDefinitionOf has definitely been called here
188
+
189
+ });
190
+ });
191
+
192
+ describe("A Model instance", function() {
193
+ var newUser = new ns.User({
194
+ first_name: 'Saul',
195
+ last_name: 'Tigh',
196
+ email: 'saul@tigh.net'
197
+ });
198
+
199
+ describe("which has not yet been saved for the first time (has no primary key set yet)", function() {
200
+ it("should should return true to newRecord()", function() {
201
+ expect(newUser.newRecord()).to(equal, true);
202
+ });
203
+
204
+ it("should assign constructor parameters to the data object like a normal Ext.data.Record", function() {
205
+ expect(newUser.data.first_name).to(equal, 'Saul');
206
+ expect(newUser.data.last_name).to(equal, 'Tigh');
207
+ expect(newUser.data.email).to(equal, 'saul@tigh.net');
208
+ });
209
+ });
210
+
211
+ describe("name functions", function() {
212
+ var lmn;
213
+
214
+ before(function() {
215
+ ExtMVC.model.define("LongModelName", {fields: [{}]});
216
+ lmn = new ns.LongModelName({});
217
+ });
218
+
219
+ after(function() {
220
+ delete ns.LongModelName;
221
+ });
222
+
223
+ it("should keep the modelName as defined", function() {
224
+ expect(newUser.modelName).to(equal, 'User');
225
+ expect((new ns.BlogPost()).modelName).to(equal, 'BlogPost');
226
+ });
227
+
228
+ it("should return a tablename based on the model name", function() {
229
+ expect(newUser.tableName).to(equal, 'users');
230
+ expect(lmn.tableName).to(equal, 'long_model_names');
231
+ });
232
+
233
+ it("should return a foreignKeyName based on the model name", function() {
234
+ expect(newUser.foreignKeyName).to(equal, "user_id");
235
+ expect(lmn.foreignKeyName).to(equal, 'long_model_name_id');
236
+ });
237
+ });
238
+
239
+ describe("which has already been saved (has a primary key set)", function() {
240
+ var existingUser = new ns.User({
241
+ first_name: 'Kara',
242
+ last_name: 'Thrace',
243
+ email: 'starbuck@bsg.net',
244
+ id: 1
245
+ });
246
+
247
+ it("should return false to newRecord()", function() {
248
+ expect(existingUser.newRecord()).to(equal, false);
249
+ });
250
+ });
251
+ });
252
+
253
+ describe("Extending another Model", function() {
254
+ ExtMVC.model.define("SuperUser", {
255
+ extend: 'User',
256
+ fields: [
257
+ {name: 'is_admin', type: 'boolean'},
258
+ {name: 'password', type: 'string'},
259
+
260
+ //here we are _re_defining User's email property to be a number
261
+ {name: 'email', type: 'number'}
262
+ ],
263
+
264
+ //overwrite superclass's version of this instance method
265
+ earlyJoiner: function() {
266
+ return true;
267
+ },
268
+
269
+ classMethods: {
270
+ //overwrite superclass's version of this class method
271
+ methodToOverwrite: function() {
272
+ return false;
273
+ }
274
+ }
275
+ });
276
+
277
+ var su = ns.SuperUser;
278
+ var newSu = new ns.SuperUser({first_name : 'Ed', last_name: 'Spencer'});
279
+
280
+ it("should inherit fields from the superclass", function() {
281
+ var superFieldCount = ns.User.prototype.fields.getCount();
282
+ var f = ns.SuperUser.prototype.fields;
283
+
284
+ //we added two additional fields in SuperUser definition (email is a _re_definition)
285
+ expect(f.getCount()).to(equal, superFieldCount + 2);
286
+ });
287
+
288
+ it("should overwrite any conflicting fields", function() {
289
+ var email = ns.SuperUser.prototype.fields.get('email');
290
+
291
+ expect(email.type).to(equal, "number");
292
+ });
293
+
294
+ it("should not overwrite the superclass's fields", function() {
295
+ var email = ns.User.prototype.fields.get('email');
296
+
297
+ expect(email.type).to(equal, "string");
298
+ });
299
+
300
+ it("should inherit instance methods from the superclass", function() {
301
+ expect(newSu.displayName()).to(equal, "Ed Spencer");
302
+ });
303
+
304
+ it("should overwrite conflicting instance methods", function() {
305
+ //the superclass' earlyJoiner method return false, test that this is overriden by subclass
306
+ expect(newSu.earlyJoiner()).to(equal, true);
307
+ });
308
+
309
+ it("should not overwrite the superclass's conflicting instance methods", function() {
310
+ newUser = new ns.User({id: 200});
311
+ expect(newUser.earlyJoiner()).to(equal, false);
312
+ });
313
+
314
+ it("should inherit class methods from the superclass", function() {
315
+ expect(typeof ns.SuperUser.testClassMethod).to(equal, "function");
316
+ });
317
+
318
+ it("should overwrite conflicting class methods", function() {
319
+ expect(ns.SuperUser.methodToOverwrite()).to(equal, false);
320
+ });
321
+
322
+ it("should not overwrite the superclass's conflicting class methods", function() {
323
+ expect(ns.User.methodToOverwrite()).to(equal, true);
324
+ });
325
+ });
326
+
327
+ describe("Plugins", function() {
328
+ var initializeCalled,
329
+ myPlugin = { initialize: Ext.emptyFn };
330
+
331
+ var normalPlugins = ExtMVC.model.plugins;
332
+
333
+ before(function() {
334
+ //clear out all plugins between tests
335
+ ExtMVC.model.plugins = [];
336
+ });
337
+
338
+ after(function() {
339
+ ExtMVC.model.plugins = normalPlugins;
340
+ });
341
+
342
+ it("should allow specification of new plugins", function() {
343
+ var p = ExtMVC.model.plugins;
344
+ expect(p.length).to(equal, 0);
345
+
346
+ ExtMVC.model.addPlugin(myPlugin);
347
+ expect(p.length).to(equal, 1);
348
+ });
349
+
350
+ it("should call each plugin's initialize method when a model is created", function() {
351
+ initializeCalled = false;
352
+ var initializeArgument;
353
+
354
+ //set up a fake plugin initializer to check that we're receiving a reference to the model
355
+ myPlugin.initialize = function(model) {
356
+ initializeCalled = true;
357
+ initializeArgument = model;
358
+ };
359
+
360
+ ExtMVC.model.addPlugin(myPlugin);
361
+
362
+ ExtMVC.model.define('AnotherModel', {fields: []});
363
+ expect(initializeCalled).to(equal, true);
364
+ expect(initializeArgument).to(equal, ns.AnotherModel);
365
+
366
+ delete ns.AnotherModel;
367
+ });
368
+ });
369
+ });
370
+ });
@@ -0,0 +1,83 @@
1
+ Screw.Unit(function() {
2
+ var os;
3
+ before(function() {
4
+ os = new ExtMVC.OS();
5
+ });
6
+
7
+ describe("An OS", function() {
8
+
9
+ it("should register controllers", function() {
10
+ expect(os.getController('index')).to(equal, null);
11
+
12
+ os.registerController('index', MVCTest.controllers.IndexController);
13
+ expect(os.controllers['index']).to(equal, MVCTest.controllers.IndexController);
14
+ });
15
+
16
+ it("should find and instantiate registered controllers", function() {
17
+ os.registerController('index', MVCTest.controllers.IndexController);
18
+ expect(os.getController('index') instanceof MVCTest.controllers.IndexController).to(equal, true);
19
+ });
20
+
21
+ describe("when Launching", function() {
22
+ it("should call onLaunch", function() {
23
+ var called = false;
24
+ os.onLaunch = function() {called = true;};
25
+
26
+ os.launch();
27
+
28
+ expect(called).to(equal, true);
29
+ });
30
+ });
31
+
32
+ describe("when creating the Router", function() {
33
+ it("should not overwrite the current router", function() {
34
+ os.router = 'not a real router';
35
+ os.initializeRouter();
36
+ expect(os.router).to(equal, 'not a real router');
37
+ });
38
+
39
+ it("should assign a new Router instance to this.router", function() {
40
+ os.initializeRouter();
41
+ expect(os.router instanceof ExtMVC.Router).to(equal, true);
42
+ });
43
+ });
44
+
45
+ describe("when Dispatching", function() {
46
+ var dispatchConfig = {controller: 'someController', action: 'new'};
47
+
48
+ it("should assign dispatchConfig to os.params", function() {
49
+ os.dispatch(dispatchConfig);
50
+ expect(os.params).to(equal, dispatchConfig);
51
+ });
52
+
53
+ it("should use index as the default action", function() {
54
+ os.dispatch({controller: 'someController'});
55
+ expect(os.params).to(equal, {controller: 'someController', action: 'index'});
56
+ });
57
+
58
+ it("should attempt to find the correct controller", function() {
59
+ var controllerName = "";
60
+
61
+ var correctResponse = os.getController('index');
62
+ os.getController = function(conName) {
63
+ controllerName = conName;
64
+ return correctResponse;
65
+ };
66
+
67
+ os.dispatch({controller: 'index'});
68
+ expect(controllerName).to(equal, "index");
69
+ });
70
+
71
+ it("should fire the correct action", function() {
72
+ var fired = false;
73
+
74
+ os.getController('index').registerAction('test', function() {
75
+ fired = true;
76
+ });
77
+
78
+ os.dispatch({controller: 'index', action: 'test'});
79
+ expect(fired).to(equal, true);
80
+ });
81
+ });
82
+ });
83
+ });