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.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/extjs-mvc.rb +0 -14
- data/lib/extjs-mvc/api.rb +14 -27
- data/lib/extjs-mvc/src/App.js +219 -0
- data/lib/extjs-mvc/src/MVC.js +260 -0
- data/lib/extjs-mvc/src/Presenter.js +52 -0
- data/lib/extjs-mvc/src/README.rdoc +69 -0
- data/lib/extjs-mvc/src/controller/Controller.js +278 -0
- data/lib/extjs-mvc/src/controller/CrudController.js +460 -0
- data/lib/extjs-mvc/src/lib/Array.js +26 -0
- data/lib/extjs-mvc/src/lib/Booter.js +417 -0
- data/lib/extjs-mvc/src/lib/ClassManager.js +191 -0
- data/lib/extjs-mvc/src/lib/ControllerClassManager.js +95 -0
- data/lib/extjs-mvc/src/lib/Dependencies.js +44 -0
- data/lib/extjs-mvc/src/lib/DispatchMatcher.js +98 -0
- data/lib/extjs-mvc/src/lib/Dispatcher.js +129 -0
- data/lib/extjs-mvc/src/lib/Environment.js +43 -0
- data/lib/extjs-mvc/src/lib/Inflector.js +155 -0
- data/lib/extjs-mvc/src/lib/ModelClassManager.js +19 -0
- data/lib/extjs-mvc/src/lib/Route.js +139 -0
- data/lib/extjs-mvc/src/lib/Router.js +282 -0
- data/lib/extjs-mvc/src/lib/String.js +94 -0
- data/lib/extjs-mvc/src/lib/ViewClassManager.js +229 -0
- data/lib/extjs-mvc/src/lib/notes.txt +32 -0
- data/lib/extjs-mvc/src/model/AdapterManager.js +30 -0
- data/lib/extjs-mvc/src/model/Association.js +26 -0
- data/lib/extjs-mvc/src/model/Base.js +63 -0
- data/lib/extjs-mvc/src/model/BelongsToAssociation.js +116 -0
- data/lib/extjs-mvc/src/model/Cache.js +131 -0
- data/lib/extjs-mvc/src/model/HasManyAssociation.js +160 -0
- data/lib/extjs-mvc/src/model/Model.js +331 -0
- data/lib/extjs-mvc/src/model/UrlBuilder.js +106 -0
- data/lib/extjs-mvc/src/model/adapters/AbstractAdapter.js +296 -0
- data/lib/extjs-mvc/src/model/adapters/MemoryAdapter.js +103 -0
- data/lib/extjs-mvc/src/model/adapters/RESTAdapter.js +345 -0
- data/lib/extjs-mvc/src/model/adapters/RESTJSONAdapter.js +68 -0
- data/lib/extjs-mvc/src/model/adapters/notes.txt +42 -0
- data/lib/extjs-mvc/src/model/associations/Association.js +192 -0
- data/lib/extjs-mvc/src/model/associations/notes.txt +87 -0
- data/lib/extjs-mvc/src/model/validations/Errors.js +136 -0
- data/lib/extjs-mvc/src/model/validations/Plugin.js +139 -0
- data/lib/extjs-mvc/src/model/validations/Validations.js +276 -0
- data/lib/extjs-mvc/src/notes/Charts.graffle +0 -0
- data/lib/extjs-mvc/src/overrides/Ext.Component.js +21 -0
- data/lib/extjs-mvc/src/overrides/Ext.extend.js +142 -0
- data/lib/extjs-mvc/src/spec/Array.spec.js +15 -0
- data/lib/extjs-mvc/src/spec/ExtMVC.spec.js +65 -0
- data/lib/extjs-mvc/src/spec/Model.spec.js +370 -0
- data/lib/extjs-mvc/src/spec/OS.spec.js +83 -0
- data/lib/extjs-mvc/src/spec/Router.spec.js +99 -0
- data/lib/extjs-mvc/src/spec/SpecHelper.js +106 -0
- data/lib/extjs-mvc/src/spec/String.spec.js +83 -0
- data/lib/extjs-mvc/src/spec/model/AbstractAdapter.spec.js +49 -0
- data/lib/extjs-mvc/src/spec/model/Associations.spec.js +99 -0
- data/lib/extjs-mvc/src/spec/model/Cache.spec.js +5 -0
- data/lib/extjs-mvc/src/spec/model/RESTAdapter.spec.js +19 -0
- data/lib/extjs-mvc/src/spec/model/ValidationErrors.spec.js +64 -0
- data/lib/extjs-mvc/src/spec/model/Validations.spec.js +166 -0
- data/lib/extjs-mvc/src/spec/model/ValidationsPlugin.spec.js +108 -0
- data/lib/extjs-mvc/src/spec/suite.html +60 -0
- data/lib/extjs-mvc/src/specs-old/JSSpec.css +216 -0
- data/lib/extjs-mvc/src/specs-old/JSSpec.js +1512 -0
- data/lib/extjs-mvc/src/specs-old/all.html +66 -0
- data/lib/extjs-mvc/src/specs-old/base.js +14 -0
- data/lib/extjs-mvc/src/specs-old/controller.js +17 -0
- data/lib/extjs-mvc/src/specs-old/diff_match_patch.js +1 -0
- data/lib/extjs-mvc/src/specs-old/model.js +70 -0
- data/lib/extjs-mvc/src/specs-old/route.js +38 -0
- data/lib/extjs-mvc/src/specs-old/router.js +59 -0
- data/lib/extjs-mvc/src/specs-old/string.js +22 -0
- data/lib/extjs-mvc/src/testrunner/JSpecFormatter.js +111 -0
- data/lib/extjs-mvc/src/testrunner/TestClient.js +181 -0
- data/lib/extjs-mvc/src/testrunner/TestGrid.js +351 -0
- data/lib/extjs-mvc/src/testrunner/TestRunner.js +110 -0
- data/lib/extjs-mvc/src/testrunner/TestViewport.js +94 -0
- data/lib/extjs-mvc/src/vendor.yml +30 -0
- data/lib/extjs-mvc/src/vendor/ext-3.1.1/vendor.yml +16 -0
- data/lib/extjs-mvc/src/view/FormWindow.js +184 -0
- data/lib/extjs-mvc/src/view/HasManyEditorGridPanel.js +211 -0
- data/lib/extjs-mvc/src/view/scaffold/Edit.js +46 -0
- data/lib/extjs-mvc/src/view/scaffold/Index.js +561 -0
- data/lib/extjs-mvc/src/view/scaffold/New.js +20 -0
- data/lib/extjs-mvc/src/view/scaffold/ScaffoldFormPanel.js +255 -0
- data/lib/{vendor.yml → extjs-mvc/vendor.yml} +0 -0
- data/test/app/vendor/extjs-mvc/App.js +219 -0
- data/test/app/vendor/extjs-mvc/MVC.js +260 -0
- data/test/app/vendor/extjs-mvc/Presenter.js +52 -0
- data/test/app/vendor/extjs-mvc/README.rdoc +69 -0
- data/test/app/vendor/extjs-mvc/controller/Controller.js +278 -0
- data/test/app/vendor/extjs-mvc/controller/CrudController.js +460 -0
- data/test/app/vendor/extjs-mvc/lib/Array.js +26 -0
- data/test/app/vendor/extjs-mvc/lib/Booter.js +417 -0
- data/test/app/vendor/extjs-mvc/lib/ClassManager.js +191 -0
- data/test/app/vendor/extjs-mvc/lib/ControllerClassManager.js +95 -0
- data/test/app/vendor/extjs-mvc/lib/Dependencies.js +44 -0
- data/test/app/vendor/extjs-mvc/lib/DispatchMatcher.js +98 -0
- data/test/app/vendor/extjs-mvc/lib/Dispatcher.js +129 -0
- data/test/app/vendor/extjs-mvc/lib/Environment.js +43 -0
- data/test/app/vendor/extjs-mvc/lib/Inflector.js +155 -0
- data/test/app/vendor/extjs-mvc/lib/ModelClassManager.js +19 -0
- data/test/app/vendor/extjs-mvc/lib/Route.js +139 -0
- data/test/app/vendor/extjs-mvc/lib/Router.js +282 -0
- data/test/app/vendor/extjs-mvc/lib/String.js +94 -0
- data/test/app/vendor/extjs-mvc/lib/ViewClassManager.js +229 -0
- data/test/app/vendor/extjs-mvc/lib/notes.txt +32 -0
- data/test/app/vendor/extjs-mvc/model/AdapterManager.js +30 -0
- data/test/app/vendor/extjs-mvc/model/Association.js +26 -0
- data/test/app/vendor/extjs-mvc/model/Base.js +63 -0
- data/test/app/vendor/extjs-mvc/model/BelongsToAssociation.js +116 -0
- data/test/app/vendor/extjs-mvc/model/Cache.js +131 -0
- data/test/app/vendor/extjs-mvc/model/HasManyAssociation.js +160 -0
- data/test/app/vendor/extjs-mvc/model/Model.js +331 -0
- data/test/app/vendor/extjs-mvc/model/UrlBuilder.js +106 -0
- data/test/app/vendor/extjs-mvc/model/adapters/AbstractAdapter.js +296 -0
- data/test/app/vendor/extjs-mvc/model/adapters/MemoryAdapter.js +103 -0
- data/test/app/vendor/extjs-mvc/model/adapters/RESTAdapter.js +345 -0
- data/test/app/vendor/extjs-mvc/model/adapters/RESTJSONAdapter.js +68 -0
- data/test/app/vendor/extjs-mvc/model/adapters/notes.txt +42 -0
- data/test/app/vendor/extjs-mvc/model/associations/Association.js +192 -0
- data/test/app/vendor/extjs-mvc/model/associations/notes.txt +87 -0
- data/test/app/vendor/extjs-mvc/model/validations/Errors.js +136 -0
- data/test/app/vendor/extjs-mvc/model/validations/Plugin.js +139 -0
- data/test/app/vendor/extjs-mvc/model/validations/Validations.js +276 -0
- data/test/app/vendor/extjs-mvc/notes/Charts.graffle +0 -0
- data/test/app/vendor/extjs-mvc/overrides/Ext.Component.js +21 -0
- data/test/app/vendor/extjs-mvc/overrides/Ext.extend.js +142 -0
- data/test/app/vendor/extjs-mvc/spec/Array.spec.js +15 -0
- data/test/app/vendor/extjs-mvc/spec/ExtMVC.spec.js +65 -0
- data/test/app/vendor/extjs-mvc/spec/Model.spec.js +370 -0
- data/test/app/vendor/extjs-mvc/spec/OS.spec.js +83 -0
- data/test/app/vendor/extjs-mvc/spec/Router.spec.js +99 -0
- data/test/app/vendor/extjs-mvc/spec/SpecHelper.js +106 -0
- data/test/app/vendor/extjs-mvc/spec/String.spec.js +83 -0
- data/test/app/vendor/extjs-mvc/spec/model/AbstractAdapter.spec.js +49 -0
- data/test/app/vendor/extjs-mvc/spec/model/Associations.spec.js +99 -0
- data/test/app/vendor/extjs-mvc/spec/model/Cache.spec.js +5 -0
- data/test/app/vendor/extjs-mvc/spec/model/RESTAdapter.spec.js +19 -0
- data/test/app/vendor/extjs-mvc/spec/model/ValidationErrors.spec.js +64 -0
- data/test/app/vendor/extjs-mvc/spec/model/Validations.spec.js +166 -0
- data/test/app/vendor/extjs-mvc/spec/model/ValidationsPlugin.spec.js +108 -0
- data/test/app/vendor/extjs-mvc/spec/suite.html +60 -0
- data/test/app/vendor/extjs-mvc/specs-old/JSSpec.css +216 -0
- data/test/app/vendor/extjs-mvc/specs-old/JSSpec.js +1512 -0
- data/test/app/vendor/extjs-mvc/specs-old/all.html +66 -0
- data/test/app/vendor/extjs-mvc/specs-old/base.js +14 -0
- data/test/app/vendor/extjs-mvc/specs-old/controller.js +17 -0
- data/test/app/vendor/extjs-mvc/specs-old/diff_match_patch.js +1 -0
- data/test/app/vendor/extjs-mvc/specs-old/model.js +70 -0
- data/test/app/vendor/extjs-mvc/specs-old/route.js +38 -0
- data/test/app/vendor/extjs-mvc/specs-old/router.js +59 -0
- data/test/app/vendor/extjs-mvc/specs-old/string.js +22 -0
- data/test/app/vendor/extjs-mvc/testrunner/JSpecFormatter.js +111 -0
- data/test/app/vendor/extjs-mvc/testrunner/TestClient.js +181 -0
- data/test/app/vendor/extjs-mvc/testrunner/TestGrid.js +351 -0
- data/test/app/vendor/extjs-mvc/testrunner/TestRunner.js +110 -0
- data/test/app/vendor/extjs-mvc/testrunner/TestViewport.js +94 -0
- data/test/app/vendor/extjs-mvc/vendor.yml +30 -0
- data/test/app/vendor/extjs-mvc/vendor/ext-3.1.1/vendor.yml +16 -0
- data/test/app/vendor/extjs-mvc/view/FormWindow.js +184 -0
- data/test/app/vendor/extjs-mvc/view/HasManyEditorGridPanel.js +211 -0
- data/test/app/vendor/extjs-mvc/view/scaffold/Edit.js +46 -0
- data/test/app/vendor/extjs-mvc/view/scaffold/Index.js +561 -0
- data/test/app/vendor/extjs-mvc/view/scaffold/New.js +20 -0
- data/test/app/vendor/extjs-mvc/view/scaffold/ScaffoldFormPanel.js +255 -0
- data/test/helper.rb +7 -1
- data/test/test_extjs-mvc.rb +46 -0
- metadata +167 -7
- data/test/test_extjs-mvc-gem.rb +0 -7
@@ -0,0 +1,99 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("The Router", function() {
|
3
|
+
var router;
|
4
|
+
|
5
|
+
before(function() {
|
6
|
+
router = new ExtMVC.Router();
|
7
|
+
});
|
8
|
+
|
9
|
+
describe("connect", function() {
|
10
|
+
// it("should create a new Route", function() {
|
11
|
+
// var routeCreated = false;
|
12
|
+
// ExtMVC.Route = function() {routeCreated = true;};
|
13
|
+
//
|
14
|
+
// router.connect(':controller/:action');
|
15
|
+
// expect(routeCreated).to(equal, true);
|
16
|
+
// });
|
17
|
+
});
|
18
|
+
|
19
|
+
describe("name", function() {
|
20
|
+
before(function() {
|
21
|
+
router.name("myRoute", "myNamespace/:controller/:action");
|
22
|
+
});
|
23
|
+
|
24
|
+
// it("should create a new Route", function() {
|
25
|
+
// var routeCreated = false;
|
26
|
+
//
|
27
|
+
// ExtMVC.Route = ExtMVC.Route.prototype.constructor.createInterceptor(function() {
|
28
|
+
// routeCreated = true;
|
29
|
+
//
|
30
|
+
// return arguments;
|
31
|
+
// }, this);
|
32
|
+
//
|
33
|
+
// router.connect(':controller/:action');
|
34
|
+
// expect(routeCreated).to(equal, true);
|
35
|
+
// });
|
36
|
+
|
37
|
+
it("should make the route accessible as a named route", function() {
|
38
|
+
expect(typeof router.namedRoutes['myRoute']).to_not(equal, "undefined");
|
39
|
+
});
|
40
|
+
});
|
41
|
+
|
42
|
+
describe("root", function() {
|
43
|
+
before(function() {
|
44
|
+
router.root({controller: 'index', action: 'index'});
|
45
|
+
});
|
46
|
+
|
47
|
+
|
48
|
+
});
|
49
|
+
|
50
|
+
describe("recognising url strings", function() {
|
51
|
+
before(function() {
|
52
|
+
router.connect(":controller/:action/:id");
|
53
|
+
router.connect(":controller/:action");
|
54
|
+
});
|
55
|
+
|
56
|
+
it("should recognise :controller/:action/:id", function() {
|
57
|
+
expect(router.recognise("index/index")).to_not(equal, false);
|
58
|
+
});
|
59
|
+
|
60
|
+
it("should return the correct controller", function() {
|
61
|
+
expect(router.recognise("cont/act").controller).to(equal, "cont");
|
62
|
+
});
|
63
|
+
|
64
|
+
it("should return the correct action", function() {
|
65
|
+
expect(router.recognise("cont/act").action).to(equal, "act");
|
66
|
+
});
|
67
|
+
|
68
|
+
it("should return the correct id", function() {
|
69
|
+
expect(router.recognise("cont/act/100").id).to(equal, "100");
|
70
|
+
});
|
71
|
+
|
72
|
+
describe("more complex URLs", function() {
|
73
|
+
before(function() {
|
74
|
+
router.connect("myNamespace/:controller/anotherSegment/:action");
|
75
|
+
});
|
76
|
+
|
77
|
+
it("should recognise URLS with arbitrary text in the matcher", function() {
|
78
|
+
var url = "myNamespace/cont/anotherSegment/act";
|
79
|
+
expect(router.recognise(url).controller).to(equal, "cont");
|
80
|
+
expect(router.recognise(url).action).to(equal, "act");
|
81
|
+
});
|
82
|
+
|
83
|
+
describe("with match conditions", function() {
|
84
|
+
before(function() {
|
85
|
+
router.connect("myNamespace/:controller/:action/:id", {conditions: {':id': "[0-9]+"}});
|
86
|
+
});
|
87
|
+
|
88
|
+
it("should not recognise if the conditions are not met", function() {
|
89
|
+
expect(router.recognise("myNamespace/cont/act/notanumber")).to(equal, false);
|
90
|
+
});
|
91
|
+
|
92
|
+
it("should recognise if the conditions are met", function() {
|
93
|
+
expect(router.recognise("myNamespace/cont/act/150").id).to(equal, 150);
|
94
|
+
});
|
95
|
+
});
|
96
|
+
});
|
97
|
+
});
|
98
|
+
});
|
99
|
+
});
|
@@ -0,0 +1,106 @@
|
|
1
|
+
Ext.ns('MVCTest', 'MVCTest.models');
|
2
|
+
|
3
|
+
ExtMVC.model.modelNamespace = MVCTest.models;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @class MVCTest.models.User
|
7
|
+
* @extends ExtMVC.model
|
8
|
+
*/
|
9
|
+
ExtMVC.model.define("User", {
|
10
|
+
fields: [
|
11
|
+
{name: 'id', type: 'int'},
|
12
|
+
{name: 'first_name', type: 'string'},
|
13
|
+
{name: 'last_name', type: 'string'},
|
14
|
+
{name: 'email', type: 'string'}
|
15
|
+
],
|
16
|
+
hasMany: "BlogPost",
|
17
|
+
|
18
|
+
displayName: function() {
|
19
|
+
return String.format("{0} {1}", this.data.first_name, this.data.last_name);
|
20
|
+
},
|
21
|
+
|
22
|
+
//this is used to test instance method inheritance in Model.spec.js
|
23
|
+
earlyJoiner: function() {
|
24
|
+
return this.data.id < 100;
|
25
|
+
},
|
26
|
+
|
27
|
+
classMethods: {
|
28
|
+
testClassMethod: function() {
|
29
|
+
return "A Class Method";
|
30
|
+
},
|
31
|
+
|
32
|
+
//simple class method to test class method overwrites
|
33
|
+
methodToOverwrite: function() {
|
34
|
+
return true;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @class MVCTest.models.AdminUser
|
41
|
+
* @extends MVCTest.models.User
|
42
|
+
* A subclass of User, defining additional fields
|
43
|
+
*/
|
44
|
+
ExtMVC.model.define("AdminUser", {
|
45
|
+
extend: "User",
|
46
|
+
fields: [
|
47
|
+
{name: 'is_admin', type: 'bool'},
|
48
|
+
{name: 'password', type: 'string'}
|
49
|
+
]
|
50
|
+
});
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @class MVCTest.models.BlogPost
|
54
|
+
* @extends ExtMVC.model
|
55
|
+
*/
|
56
|
+
ExtMVC.model.define("BlogPost", {
|
57
|
+
fields: [
|
58
|
+
{name: 'id', type: 'int'},
|
59
|
+
{name: 'title', type: 'string'},
|
60
|
+
{name: 'content', type: 'string'},
|
61
|
+
{name: 'user_id', type: 'int'}
|
62
|
+
],
|
63
|
+
belongsTo: "User",
|
64
|
+
hasMany: "Comment",
|
65
|
+
|
66
|
+
instanceMethods: {
|
67
|
+
testInstanceMethod: Ext.emptyFn
|
68
|
+
}
|
69
|
+
});
|
70
|
+
|
71
|
+
/**
|
72
|
+
* @class MVCTest.models.Comment
|
73
|
+
* @extends ExtMVC.model
|
74
|
+
*/
|
75
|
+
ExtMVC.model.define("Comment", {
|
76
|
+
fields: [
|
77
|
+
{name: 'id', type: 'int'},
|
78
|
+
{name: 'blog_post_id', type: 'int'},
|
79
|
+
{name: 'content', type: 'string'}
|
80
|
+
],
|
81
|
+
belongsTo: "BlogPost"
|
82
|
+
});
|
83
|
+
|
84
|
+
MVCTest.OS = new ExtMVC.OS({
|
85
|
+
name: "MVCTest"
|
86
|
+
});
|
87
|
+
|
88
|
+
MVCTest.controllers = {};
|
89
|
+
|
90
|
+
/**
|
91
|
+
* @class MVCTest.controllers.IndexController
|
92
|
+
* @extends ExtMVC.Controller
|
93
|
+
* Fake controller for use in OS.spec.js, Controller.spec.js and CrudController.spec.js
|
94
|
+
*/
|
95
|
+
MVCTest.controllers.IndexController = Ext.extend(ExtMVC.Controller, {
|
96
|
+
constructor: function() {
|
97
|
+
//super
|
98
|
+
MVCTest.controllers.IndexController.superclass.constructor.call(this, {
|
99
|
+
viewsPackage: MVCTest.views.index
|
100
|
+
});
|
101
|
+
|
102
|
+
// this.actsAsCrudController(MVCTest.models.User);
|
103
|
+
}
|
104
|
+
});
|
105
|
+
|
106
|
+
Ext.ns('MVCTest.views.index');
|
@@ -0,0 +1,83 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("String Functions", function() {
|
3
|
+
it('should capitalize a string', function() {
|
4
|
+
expect("user".capitalize()).to(equal, "User");
|
5
|
+
});
|
6
|
+
|
7
|
+
it("should titleize a string", function() {
|
8
|
+
expect("a test sentence".titleize()).to(equal, "A Test Sentence");
|
9
|
+
});
|
10
|
+
|
11
|
+
it("should camelize a string", function() {
|
12
|
+
expect("an_underscored_string".camelize()).to(equal, "AnUnderscoredString");
|
13
|
+
});
|
14
|
+
|
15
|
+
it("should underscore a string", function() {
|
16
|
+
expect("A string with whitespaces".underscore()).to(equal, "a_string_with_whitespaces");
|
17
|
+
});
|
18
|
+
|
19
|
+
it("should underscore a camelized string", function() {
|
20
|
+
expect("ALongTableName".underscore()).to(equal, "a_long_table_name");
|
21
|
+
});
|
22
|
+
|
23
|
+
it("should delegate singularize to Inflector", function() {
|
24
|
+
//stub
|
25
|
+
var singularize_was_called = false;
|
26
|
+
ExtMVC.Inflector.singularize = function() {
|
27
|
+
singularize_was_called = true;
|
28
|
+
};
|
29
|
+
|
30
|
+
"users".singularize();
|
31
|
+
expect(singularize_was_called).to(equal, true);
|
32
|
+
});
|
33
|
+
|
34
|
+
it("should delegate pluralize to Inflector", function() {
|
35
|
+
//stub
|
36
|
+
var pluralize_was_called = false;
|
37
|
+
ExtMVC.Inflector.pluralize = function() {
|
38
|
+
pluralize_was_called = true;
|
39
|
+
};
|
40
|
+
|
41
|
+
"users".pluralize();
|
42
|
+
expect(pluralize_was_called).to(equal, true);
|
43
|
+
});
|
44
|
+
|
45
|
+
describe("toCurrency", function() {
|
46
|
+
var amount = "1234567.89";
|
47
|
+
|
48
|
+
it("should add commas as appropriate", function() {
|
49
|
+
expect(amount.toCurrency("£")).to(equal, "£1,234,567.89");
|
50
|
+
});
|
51
|
+
|
52
|
+
it("should use dollars by default", function() {
|
53
|
+
expect(amount.toCurrency()).to(equal, "$1,234,567.89");
|
54
|
+
});
|
55
|
+
});
|
56
|
+
|
57
|
+
describe("escaping HTML", function() {
|
58
|
+
var html = '<span>"fish & chips"</span>';
|
59
|
+
var escaped = html.escapeHTML();
|
60
|
+
|
61
|
+
it("should escape left angle brackets", function() {
|
62
|
+
expect(escaped).to_not(match, /</);
|
63
|
+
});
|
64
|
+
|
65
|
+
it("should escape right angle brackets", function() {
|
66
|
+
expect(escaped).to_not(match, />/);
|
67
|
+
});
|
68
|
+
|
69
|
+
it("should escape double-quotes", function() {
|
70
|
+
expect(escaped).to_not(match, /\"/);
|
71
|
+
});
|
72
|
+
|
73
|
+
it("should escape ampersands", function() {
|
74
|
+
expect(escaped).to(match, /(&[^a]|&[^a][^m]|&[^a][^m][^p]|&[^a][^m][^p][^;])/);
|
75
|
+
});
|
76
|
+
|
77
|
+
it("should escape a string correctly", function() {
|
78
|
+
expect(escaped).to(equal, "<span>"fish & chips"</span>");
|
79
|
+
});
|
80
|
+
});
|
81
|
+
|
82
|
+
});
|
83
|
+
});
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("The Abstract Adapter", function() {
|
3
|
+
var ns = ExtMVC.Model.modelNamespace;
|
4
|
+
|
5
|
+
describe("instance methods", function() {
|
6
|
+
it("should add instance methods to Ext.data.Record's prototype", function() {
|
7
|
+
var p = Ext.data.Record.prototype;
|
8
|
+
|
9
|
+
Ext.each(['save', 'destroy', 'update'], function(methodName) {
|
10
|
+
expect(typeof p[methodName]).to(equal, 'function');
|
11
|
+
}, this);
|
12
|
+
});
|
13
|
+
|
14
|
+
describe("the save method", function() {
|
15
|
+
|
16
|
+
});
|
17
|
+
});
|
18
|
+
|
19
|
+
describe("class methods", function() {
|
20
|
+
it("should add class methods to each model class", function() {
|
21
|
+
Ext.each(['create', 'build', 'find', 'destroy'], function(methodName) {
|
22
|
+
for (var model in ns) {
|
23
|
+
expect(typeof ns[model][methodName]).to(equal, 'function');
|
24
|
+
}
|
25
|
+
}, this);
|
26
|
+
});
|
27
|
+
});
|
28
|
+
|
29
|
+
describe("hasMany association methods", function() {
|
30
|
+
it("should add the correct methods to the hasMany prototype", function() {
|
31
|
+
var p = ExtMVC.Model.plugin.association.HasMany.prototype;
|
32
|
+
|
33
|
+
Ext.each(['create', 'build', 'find', 'destroy'], function(methodName) {
|
34
|
+
expect(typeof p[methodName]).to(equal, 'function');
|
35
|
+
}, this);
|
36
|
+
});
|
37
|
+
});
|
38
|
+
|
39
|
+
describe("belongsTo association methods", function() {
|
40
|
+
it("should add the correct methods to the hasMany prototype", function() {
|
41
|
+
var p = ExtMVC.Model.plugin.association.HasMany.prototype;
|
42
|
+
|
43
|
+
Ext.each(['find', 'destroy'], function(methodName) {
|
44
|
+
expect(typeof p[methodName]).to(equal, 'function');
|
45
|
+
}, this);
|
46
|
+
});
|
47
|
+
});
|
48
|
+
});
|
49
|
+
});
|
@@ -0,0 +1,99 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
//keep track of the object to which models are currently assigned
|
3
|
+
var ns = ExtMVC.Model.modelNamespace;
|
4
|
+
|
5
|
+
describe("Associations", function() {
|
6
|
+
ExtMVC.Model.define("AssocUser", {
|
7
|
+
fields: [],
|
8
|
+
hasMany: "AssocPost"
|
9
|
+
});
|
10
|
+
|
11
|
+
ExtMVC.Model.define("AssocPost", {
|
12
|
+
fields: [],
|
13
|
+
hasMany: "AssocComment",
|
14
|
+
belongsTo: "AssocUser"
|
15
|
+
});
|
16
|
+
|
17
|
+
ExtMVC.Model.define("AssocComment", {
|
18
|
+
fields: [],
|
19
|
+
belongsTo: {
|
20
|
+
associatedClass: "AssocPost",
|
21
|
+
associationName: 'posts',
|
22
|
+
extend: {
|
23
|
+
myMethod: function() {}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
describe("The Associations plugin", function() {
|
29
|
+
var associations = ExtMVC.Model.plugin.association,
|
30
|
+
model = ns.AssocPost,
|
31
|
+
commentModel = ns.AssocComment;
|
32
|
+
|
33
|
+
it("should add a hasMany relationship where defined", function() {
|
34
|
+
expect(model.prototype.AssocComments instanceof associations.HasMany).to(equal, true);
|
35
|
+
});
|
36
|
+
|
37
|
+
it("should add a belongsTo relationship where defined", function() {
|
38
|
+
expect(model.prototype.AssocUser instanceof associations.BelongsTo).to(equal, true);
|
39
|
+
});
|
40
|
+
|
41
|
+
it("should allow customisation of association names", function() {
|
42
|
+
expect(commentModel.prototype.posts instanceof associations.BelongsTo).to(equal, true);
|
43
|
+
});
|
44
|
+
});
|
45
|
+
|
46
|
+
describe("A Base association", function() {
|
47
|
+
/**
|
48
|
+
* Create an association between BlogPost and User.
|
49
|
+
* In practice we never actually instantiate Base associations as they don't
|
50
|
+
* do very much, instead use a subclass such as HasMany or BelongsTo
|
51
|
+
*/
|
52
|
+
var assoc = new ExtMVC.Model.plugin.association.Base(ns.BlogPost, ns.User, {
|
53
|
+
extend: {
|
54
|
+
myProperty: 'property',
|
55
|
+
myFunction: function() { return 'result'; }
|
56
|
+
}
|
57
|
+
});
|
58
|
+
|
59
|
+
it("should maintain a reference to its owner class", function() {
|
60
|
+
expect(assoc.ownerClass).to(equal, ns.BlogPost);
|
61
|
+
});
|
62
|
+
|
63
|
+
it("should maintain a reference to its associated class", function() {
|
64
|
+
expect(assoc.associatedClass).to(equal, ns.User);
|
65
|
+
});
|
66
|
+
|
67
|
+
it("should add extension properties to the association", function() {
|
68
|
+
expect(assoc.myProperty).to(equal, 'property');
|
69
|
+
expect(assoc.myFunction()).to(equal, 'result');
|
70
|
+
});
|
71
|
+
});
|
72
|
+
|
73
|
+
describe("A BelongsTo association", function() {
|
74
|
+
//blog post belongs to user
|
75
|
+
var assoc = new ExtMVC.Model.plugin.association.BelongsTo(ns.BlogPost, ns.User);
|
76
|
+
|
77
|
+
it("should set a default association name", function() {
|
78
|
+
expect(assoc.name).to(equal, 'user');
|
79
|
+
});
|
80
|
+
|
81
|
+
it("should set a default foreign key", function() {
|
82
|
+
expect(assoc.foreignKey).to(equal, 'user_id');
|
83
|
+
});
|
84
|
+
});
|
85
|
+
|
86
|
+
describe("A HasMany association", function() {
|
87
|
+
//user has many blog posts
|
88
|
+
var assoc = new ExtMVC.Model.plugin.association.HasMany(ns.User, ns.BlogPost);
|
89
|
+
|
90
|
+
it("should set a default association name", function() {
|
91
|
+
expect(assoc.name).to(equal, 'blog_posts');
|
92
|
+
});
|
93
|
+
|
94
|
+
it("should set a default foreign key", function() {
|
95
|
+
expect(assoc.foreignKey).to(equal, 'user_id');
|
96
|
+
});
|
97
|
+
});
|
98
|
+
});
|
99
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("The REST adapter", function() {
|
3
|
+
var ns = ExtMVC.Model.modelNamespace;
|
4
|
+
|
5
|
+
var rest = new ExtMVC.Model.plugin.adapter.RESTAdapter(),
|
6
|
+
savedInst = new ns.User({title: 'Ed', id: 100}),
|
7
|
+
newInst = new ns.User({title: 'Nick'});
|
8
|
+
|
9
|
+
describe("the instanceUrl method", function() {
|
10
|
+
it("should return a url including the ID if the primary key is set", function() {
|
11
|
+
expect(rest.instanceUrl(savedInst)).to(equal, '/users/100');
|
12
|
+
});
|
13
|
+
|
14
|
+
it("should return a generic url for this model if the primary key is not set", function() {
|
15
|
+
expect(rest.instanceUrl(newInst)).to(equal, '/users');
|
16
|
+
});
|
17
|
+
});
|
18
|
+
});
|
19
|
+
});
|