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,64 @@
1
+ Screw.Unit(function() {
2
+ describe("A Validation Errors object", function() {
3
+ var errors = new ExtMVC.Model.validation.Errors();
4
+
5
+ before(function() {
6
+ //make sure we clear out any errors between each test
7
+ errors.clear();
8
+ });
9
+
10
+ it("should contain an object of all errors", function() {
11
+ expect(errors.all).to(equal, {});
12
+ });
13
+
14
+ it("should clear current errors out", function() {
15
+ //add some fake errors
16
+ errors.all = {'title': ['must be present'], 'text': ['is too short']};
17
+
18
+ errors.clear();
19
+ expect(errors.all).to(equal, {});
20
+ });
21
+
22
+ describe("when retrieving errors by field name or for a form", function() {
23
+ before(function() {
24
+ errors.add('title', 'must be present');
25
+ errors.add('title', 'is too short');
26
+ errors.add('title', 'is quite boring');
27
+ errors.add('text', 'is a hideous diatribe');
28
+ });
29
+
30
+ it("should allow retrieval of errors per field via the forField method", function() {
31
+ expect(errors.forField('title')).to(equal, ['must be present', 'is too short', 'is quite boring']);
32
+ });
33
+
34
+ it("should return a human readable form for errors on a given field", function() {
35
+ expect(errors.forField('title', true)).to(equal, 'must be present, is too short and is quite boring');
36
+ expect(errors.forField('text', true)).to(equal, 'is a hideous diatribe');
37
+ });
38
+
39
+ it("should return the errors in a format suitable for displaying on a FormPanel", function() {
40
+ var formErrors = {'title': 'must be present, is too short and is quite boring', 'text': 'is a hideous diatribe'};
41
+ expect(errors.forForm()).to(equal, formErrors);
42
+ });
43
+ });
44
+
45
+ it("should allow addition of new errors", function() {
46
+ expect(errors.forField('title').length).to(equal, 0);
47
+
48
+ errors.add('title', 'must be present');
49
+ expect(errors.forField('title').length).to(equal, 1);
50
+
51
+ errors.add('title', 'is too short');
52
+ expect(errors.forField('title').length).to(equal, 2);
53
+ });
54
+
55
+ it("should be valid if there are no errors", function() {
56
+ expect(errors.isValid()).to(equal, true);
57
+ });
58
+
59
+ it("should not be valid if there are errors present", function() {
60
+ errors.add('title', 'has serious problems');
61
+ expect(errors.isValid()).to(equal, false);
62
+ });
63
+ });
64
+ });
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Tests the validations framework and the built-in validations
3
+ */
4
+ Screw.Unit(function() {
5
+ describe("Validation Classes", function() {
6
+ //keep track of the object to which models are currently assigned
7
+ var ns = ExtMVC.Model.modelNamespace;
8
+
9
+ ExtMVC.Model.define('SomeModel', {
10
+ fields: [
11
+ {name: 'title', type: 'string'},
12
+ {name: 'text', type: 'string'},
13
+ {name: 'price', type: 'number'}
14
+ ]
15
+ });
16
+
17
+ var myInstance = new ns.SomeModel({});
18
+ var V = ExtMVC.Model.validation;
19
+
20
+ describe("Validates Presence Of", function() {
21
+ var v = new V.ValidatesPresenceOf(ns.SomeModel, 'title');
22
+
23
+ it("should not be valid if not present", function() {
24
+ expect(v.isValid(myInstance)).to(equal, false);
25
+ });
26
+
27
+ it("should not be valid if an empty string", function() {
28
+ myInstance.set('title', '');
29
+ expect(v.isValid(myInstance)).to(equal, false);
30
+ });
31
+
32
+ it("should be valid if any value is present", function() {
33
+ myInstance.set('title', 'My Title');
34
+ expect(v.isValid(myInstance)).to(equal, true);
35
+
36
+ myInstance.set('title', {'some': 'object'});
37
+ expect(v.isValid(myInstance)).to(equal, true);
38
+ });
39
+
40
+ it("should return a default message", function() {
41
+ expect(v.message).to(equal, 'must be present');
42
+ });
43
+
44
+ it("should allow specification of a customised message", function() {
45
+ var v = new V.ValidatesPresenceOf(ns.SomeModel, 'title', {message: 'My Message'});
46
+ expect(v.message).to(equal, 'My Message');
47
+ });
48
+ });
49
+
50
+ describe("Validates Numericality Of", function() {
51
+ var v = new V.ValidatesNumericalityOf(ns.SomeModel, 'price');
52
+
53
+ it("should pass if the field is a number", function() {
54
+ myInstance.set('price', 9.99);
55
+ expect(v.isValid(myInstance)).to(equal, true);
56
+ });
57
+
58
+ it("should fail if the field is not a number", function() {
59
+ myInstance.set('price', 'not a number!');
60
+ expect(v.isValid(myInstance)).to(equal, false);
61
+
62
+ expect(v.message).to(equal, 'must be a number');
63
+ });
64
+ });
65
+
66
+ describe("Validates Length Of", function() {
67
+ var v = new V.ValidatesLengthOf(ns.SomeModel, 'title', {minimum: 5, maximum: 9});
68
+
69
+ it("should fail if the field is too short", function() {
70
+ myInstance.set('title', 'a');
71
+ expect(v.isValid(myInstance)).to(equal, false);
72
+ expect(v.message).to(equal, 'is too short');
73
+ });
74
+
75
+ it("should fail if the field is too long", function() {
76
+ myInstance.set('title', 'a very long title');
77
+ expect(v.isValid(myInstance)).to(equal, false);
78
+ expect(v.message).to(equal, 'is too long');
79
+ });
80
+
81
+ it("should pass if the field is an acceptable length", function() {
82
+ //minimum
83
+ myInstance.set('title', 'Adama');
84
+ expect(v.isValid(myInstance)).to(equal, true);
85
+
86
+ //maximum
87
+ myInstance.set('title', 'President');
88
+ expect(v.isValid(myInstance)).to(equal, true);
89
+
90
+ //in between
91
+ myInstance.set('title', 'Colonel');
92
+ expect(v.isValid(myInstance)).to(equal, true);
93
+ });
94
+ });
95
+
96
+ describe("Validates Inclusion Of", function() {
97
+ var v = new V.ValidatesInclusionOf(ns.SomeModel, 'title', {allowed: ['test', 'title', 'another title']});
98
+
99
+ it("should pass if the field is one of the allowed values", function() {
100
+ Ext.each(['test', 'title', 'another title'], function(allowedTitle) {
101
+ myInstance.set('title', allowedTitle);
102
+ expect(v.isValid(myInstance)).to(equal, true);
103
+ }, this);
104
+ });
105
+
106
+ it("should fail if the field is not one of the allowed values", function() {
107
+ myInstance.set('title', 'not an allowed title ');
108
+ expect(v.isValid(myInstance)).to(equal, false);
109
+ });
110
+
111
+ it("should generate a meaningful message", function() {
112
+ expect(v.message).to(equal, 'must be one of test, title or another title');
113
+ });
114
+
115
+ it("should allow setting of a custom message", function() {
116
+ var v = new V.ValidatesInclusionOf(ns.SomeModel, 'title', {allowed: [], message: 'My Message'});
117
+ expect(v.message).to(equal, 'My Message');
118
+ });
119
+ });
120
+
121
+ describe("Validates Exclusion Of", function() {
122
+ var v = new V.ValidatesExclusionOf(ns.SomeModel, 'title', {disallowed: ['test', 'title', 'another title']});
123
+
124
+ it("should pass if the field is not one of the disallowed values", function() {
125
+ myInstance.set('title', 'This is allowed');
126
+ expect(v.isValid(myInstance)).to(equal, true);
127
+ });
128
+
129
+ it("should fail if the field is one of the disallowed values", function() {
130
+ Ext.each(['test', 'title', 'another title'], function(disallowedTitle) {
131
+ myInstance.set('title', disallowedTitle);
132
+ expect(v.isValid(myInstance)).to(equal, false);
133
+ }, this);
134
+ });
135
+
136
+ it("should generate a meaningful message", function() {
137
+ expect(v.message).to(equal, 'must not be test, title or another title');
138
+ });
139
+
140
+ it("should allow setting of a custom message", function() {
141
+ var v = new V.ValidatesExclusionOf(ns.SomeModel, 'title', {disallowed: [], message: 'My Message'});
142
+ expect(v.message).to(equal, 'My Message');
143
+ });
144
+ });
145
+
146
+ describe("Validates Format Of", function() {
147
+ var v = new V.ValidatesFormatOf(ns.SomeModel, 'title', {regex: /[A-Za-z]*\. [A-Za-z]/});
148
+
149
+ it("should pass if the regex matches", function() {
150
+ myInstance.set('title', 'Mr. Bean');
151
+
152
+ expect(v.isValid(myInstance)).to(equal, true);
153
+ });
154
+
155
+ it("should fail if the regex does not match", function() {
156
+ myInstance.set('title', 'Ed');
157
+
158
+ expect(v.isValid(myInstance)).to(equal, false);
159
+ });
160
+
161
+ it("should supply a default message", function() {
162
+ expect(v.message).to(equal, 'is invalid');
163
+ });
164
+ });
165
+ });
166
+ });
@@ -0,0 +1,108 @@
1
+ Screw.Unit(function() {
2
+ describe("The Validations Plugin", function() {
3
+ var ns = ExtMVC.Model.modelNamespace;
4
+
5
+ delete ns.ValidatedModel;
6
+ ExtMVC.Model.define("ValidatedModel", {
7
+ fields: [
8
+ {name: 'title', type: 'string'},
9
+ {name: 'text', type: 'string'},
10
+ {name: 'price', type: 'number'}
11
+ ],
12
+ validatesPresenceOf: ['title', 'text'],
13
+ validatesNumericalityOf: 'price',
14
+ validatesLengthOf: {field: 'title', minimum: 5, maximum: 10}
15
+ });
16
+
17
+ var validations = ns.ValidatedModel.prototype.validations;
18
+
19
+ it("should add a validations array to each model prototype", function() {
20
+ expect(Ext.isArray(validations)).to(equal, true);
21
+ });
22
+
23
+ it("should populate the validations array with the correct validations", function() {
24
+ expect(validations.length).to(equal, 4);
25
+ });
26
+
27
+ it("should create each validation with a reference to the parent model", function() {
28
+ Ext.each(validations, function(validation) {
29
+ expect(validation.ownerClass).to(equal, ns.ValidatedModel);
30
+ }, this);
31
+ });
32
+
33
+ it("should add an errors object to each model instance", function() {
34
+ //make sure it goes on the instance, not the prototype
35
+ expect(typeof ns.ValidatedModel.prototype.errors == 'undefined').to(equal, true);
36
+
37
+ var myInstance = new ns.ValidatedModel({});
38
+ expect(myInstance.errors instanceof ExtMVC.Model.validation.Errors).to(equal, true);
39
+ });
40
+
41
+ describe("the isValid method", function() {
42
+ /**
43
+ * Not sure if this is the best place to test this code. The isValid method is defined
44
+ * in ExtMVC.Model.validation.Plugin and applied to Ext.data.Record's prototype. As this
45
+ * means each Model instance has it available, that's how it's being tested here...
46
+ */
47
+ var validInstance = new ns.ValidatedModel({
48
+ title: 'Title',
49
+ text: 'My Text',
50
+ price: 9.99
51
+ });
52
+
53
+ it("should clear any existing errors", function() {
54
+ //add a fake error to make sure it gets cleared
55
+ validInstance.errors.add('title', 'fake error');
56
+ expect(validInstance.errors.all).to_not(equal, {});
57
+
58
+ validInstance.isValid();
59
+ expect(validInstance.errors.all).to(equal, {});
60
+ });
61
+
62
+ it("should return true if there were no errors", function() {
63
+ expect(validInstance.isValid()).to(equal, true);
64
+ });
65
+
66
+ describe("if there were any errors", function() {
67
+ var invalidInstance = new ns.ValidatedModel({
68
+ price: 'test'
69
+ });
70
+
71
+ it("should return false", function() {
72
+ expect(invalidInstance.isValid()).to(equal, false);
73
+ });
74
+
75
+ it("should add the errors to the errors object", function() {
76
+ invalidInstance.isValid();
77
+
78
+ //we're expecting an error on title, text and price here
79
+ Ext.each(['title', 'text', 'price'], function(field) {
80
+ expect(invalidInstance.errors.forField(field).length).to(equal, 1);
81
+ }, this);
82
+ });
83
+ });
84
+ });
85
+
86
+ describe("the buildValidation method", function() {
87
+ var constructor = ExtMVC.Model.validation.ValidatesPresenceOf,
88
+ validation = ExtMVC.Model.validation.Plugin.buildValidation(constructor, 'somefield'),
89
+ validation2 = ExtMVC.Model.validation.Plugin.buildValidation(constructor, {field: 'anotherfield', message: 'test'});
90
+
91
+ it("should return an instance of the correct type", function() {
92
+ expect(validation instanceof constructor).to(equal, true);
93
+ });
94
+
95
+ it("should assign the field correctly if passed as a string", function() {
96
+ expect(validation.field).to(equal, 'somefield');
97
+ });
98
+
99
+ it("should assign the field correctly if passed inside a config object", function() {
100
+ expect(validation2.field).to(equal, 'anotherfield');
101
+ });
102
+
103
+ it("should pass config options except field to the validation's constructor", function() {
104
+ expect(validation2.message).to(equal, 'test');
105
+ });
106
+ });
107
+ });
108
+ });
@@ -0,0 +1,60 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html>
5
+ <head>
6
+ <link type="text/css" rel="stylesheet" href="../vendor/screw-unit/lib/screw.css" />
7
+ <title>Ext MVC Spec Suite</title>
8
+ </head>
9
+ <body>
10
+ <div id="dom_test" style="position: absolute; left: -9999"></div>
11
+
12
+ <!-- Library code (not directly part of the app) -->
13
+ <div id="libs">
14
+ <!-- Screw Unit -->
15
+ <script type="text/javascript" src="../vendor/screw-unit/lib/jquery-1.2.3.js"></script>
16
+ <script type="text/javascript" src="../vendor/screw-unit/lib/jquery.fn.js"></script>
17
+ <script type="text/javascript" src="../vendor/screw-unit/lib/jquery.print.js"></script>
18
+ <script type="text/javascript" src="../vendor/screw-unit/lib/screw.builder.js"></script>
19
+ <script type="text/javascript" src="../vendor/screw-unit/lib/screw.matchers.js"></script>
20
+ <script type="text/javascript" src="../vendor/screw-unit/lib/screw.events.js"></script>
21
+ <script type="text/javascript" src="../vendor/screw-unit/lib/screw.behaviors.js"></script>
22
+
23
+ <!-- ExtJS -->
24
+ <!-- <script type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-8.js"></script> -->
25
+ <script type="text/javascript" src="../vendor/ext-base.js"></script>
26
+ <script type="text/javascript" src="../vendor/ext-all-debug.js"></script>
27
+
28
+ <!-- Ext MVC -->
29
+ <script type="text/javascript" src="../ext-mvc-all.js"></script>
30
+ </div>
31
+
32
+ <!-- Specs -->
33
+ <div id="specs">
34
+ <script type="text/javascript" src="SpecHelper.js"></script>
35
+
36
+ <!-- General MVC specs -->
37
+ <script type="text/javascript" src="ExtMVC.spec.js"></script>
38
+ <script type="text/javascript" src="OS.spec.js"></script>
39
+
40
+ <!-- Model specs -->
41
+ <script type="text/javascript" src="Model.spec.js"></script>
42
+ <script type="text/javascript" src="model/Validations.spec.js"></script>
43
+ <script type="text/javascript" src="model/ValidationErrors.spec.js"></script>
44
+ <script type="text/javascript" src="model/ValidationsPlugin.spec.js"></script>
45
+
46
+ <script type="text/javascript" src="model/Associations.spec.js"></script>
47
+
48
+ <script type="text/javascript" src="model/AbstractAdapter.spec.js"></script>
49
+ <script type="text/javascript" src="model/RESTAdapter.spec.js"></script>
50
+
51
+ <!-- Router specs -->
52
+ <script type="text/javascript" src="Router.spec.js"></script>
53
+
54
+ <!-- Augmentation specs -->
55
+ <script type="text/javascript" src="String.spec.js"></script>
56
+ <script type="text/javascript" src="Array.spec.js"></script>
57
+ </div>
58
+
59
+ </body>
60
+ </html>
@@ -0,0 +1,216 @@
1
+ @CHARSET "UTF-8";
2
+
3
+ /* --------------------
4
+ * @Layout
5
+ */
6
+
7
+ html {
8
+ overflow: hidden;
9
+ }
10
+
11
+ body, #jsspec_container {
12
+ overflow: hidden;
13
+ padding: 0;
14
+ margin: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ }
18
+
19
+ #title {
20
+ padding: 0;
21
+ margin: 0;
22
+ position: absolute;
23
+ top: 0px;
24
+ left: 0px;
25
+ width: 100%;
26
+ height: 40px;
27
+ overflow: hidden;
28
+ }
29
+
30
+ #list {
31
+ padding: 0;
32
+ margin: 0;
33
+ position: absolute;
34
+ top: 40px;
35
+ left: 0px;
36
+ bottom: 0px;
37
+ overflow: auto;
38
+ width: 250px;
39
+ _height:expression(document.body.clientHeight-40);
40
+ }
41
+
42
+ #log {
43
+ padding: 0;
44
+ margin: 0;
45
+ position: absolute;
46
+ top: 40px;
47
+ left: 250px;
48
+ right: 0px;
49
+ bottom: 0px;
50
+ overflow: auto;
51
+ _height:expression(document.body.clientHeight-40);
52
+ _width:expression(document.body.clientWidth-250);
53
+ }
54
+
55
+
56
+
57
+ /* --------------------
58
+ * @Decorations and colors
59
+ */
60
+ * {
61
+ padding: 0;
62
+ margin: 0;
63
+ font-family: "Lucida Grande", Helvetica, sans-serif;
64
+ }
65
+
66
+ li {
67
+ list-style: none;
68
+ }
69
+
70
+ /* hiding subtitles */
71
+ h2 {
72
+ display: none;
73
+ }
74
+
75
+ /* title section */
76
+ div#title {
77
+ padding: 0em 0.5em;
78
+ }
79
+
80
+ div#title h1 {
81
+ font-size: 1.5em;
82
+ float: left;
83
+ }
84
+
85
+ div#title ul li {
86
+ float: left;
87
+ padding: 0.5em 0em 0.5em 0.75em;
88
+ }
89
+
90
+ div#title p {
91
+ float:right;
92
+ margin-right:1em;
93
+ font-size: 0.75em;
94
+ }
95
+
96
+ /* spec container */
97
+ ul.specs {
98
+ margin: 0.5em;
99
+ }
100
+ ul.specs li {
101
+ margin-bottom: 0.1em;
102
+ }
103
+
104
+ /* spec title */
105
+ ul.specs li h3 {
106
+ font-weight: bold;
107
+ font-size: 0.75em;
108
+ padding: 0.2em 1em;
109
+ cursor: pointer;
110
+ _cursor: hand;
111
+ }
112
+
113
+ /* example container */
114
+ ul.examples li {
115
+ border-style: solid;
116
+ border-width: 0px 0px 1px 5px;
117
+ margin: 0.2em 0em 0.2em 1em;
118
+ }
119
+
120
+ /* example title */
121
+ ul.examples li h4 {
122
+ font-weight: normal;
123
+ font-size: 0.75em;
124
+ margin-left: 1em;
125
+ }
126
+
127
+ /* example explaination */
128
+ ul.examples li div {
129
+ padding: 1em 2em;
130
+ font-size: 0.75em;
131
+ }
132
+
133
+ /* styles for ongoing, success, failure, error */
134
+ div.success, div.success a {
135
+ color: #FFFFFF;
136
+ background-color: #65C400;
137
+ }
138
+
139
+ ul.specs li.success h3, ul.specs li.success h3 a {
140
+ color: #FFFFFF;
141
+ background-color: #65C400;
142
+ }
143
+
144
+ ul.examples li.success, ul.examples li.success a {
145
+ color: #3D7700;
146
+ background-color: #DBFFB4;
147
+ border-color: #65C400;
148
+ }
149
+
150
+ div.exception, div.exception a {
151
+ color: #FFFFFF;
152
+ background-color: #C20000;
153
+ }
154
+
155
+ ul.specs li.exception h3, ul.specs li.exception h3 a {
156
+ color: #FFFFFF;
157
+ background-color: #C20000;
158
+ }
159
+
160
+ ul.examples li.exception, ul.examples li.exception a {
161
+ color: #C20000;
162
+ background-color: #FFFBD3;
163
+ border-color: #C20000;
164
+ }
165
+
166
+ div.ongoing, div.ongoing a {
167
+ color: #000000;
168
+ background-color: #FFFF80;
169
+ }
170
+
171
+ ul.specs li.ongoing h3, ul.specs li.ongoing h3 a {
172
+ color: #000000;
173
+ background-color: #FFFF80;
174
+ }
175
+
176
+ ul.examples li.ongoing, ul.examples li.ongoing a {
177
+ color: #000000;
178
+ background-color: #FFFF80;
179
+ border-color: #DDDD00;
180
+ }
181
+
182
+
183
+
184
+ /* --------------------
185
+ * values
186
+ */
187
+ .number_value, .string_value, .regexp_value, .boolean_value, .dom_value {
188
+ font-family: monospace;
189
+ color: blue;
190
+ }
191
+ .object_value, .array_value {
192
+ line-height: 2em;
193
+ padding: 0.1em 0.2em;
194
+ margin: 0.1em 0;
195
+ }
196
+ .date_value {
197
+ font-family: monospace;
198
+ color: olive;
199
+ }
200
+ .undefined_value, .null_value {
201
+ font-style: italic;
202
+ color: blue;
203
+ }
204
+ .dom_attr_name {
205
+ }
206
+ .dom_attr_value {
207
+ color: red;
208
+ }
209
+ .dom_path {
210
+ font-size: 0.75em;
211
+ color: gray;
212
+ }
213
+ strong {
214
+ font-weight: normal;
215
+ background-color: #FFC6C6;
216
+ }