]>
git.proxmox.com Git - extjs.git/blob - extjs/packages/core/test/specs/data/schema/legacy-association/HasMany.js
1 describe("Ext.data.association.HasMany_legacy", function() {
5 function makeThread(id
) {
6 rec
= new spec
.Thread({
11 function defineThread(cfg
) {
12 Ext
.define('spec.Thread', {
13 extend
: 'Ext.data.Model',
14 fields
: ['id', 'name'],
21 beforeEach(function() {
22 Ext
.data
.Model
.schema
.setNamespace('spec');
23 Ext
.define('spec.Post', {
24 extend
: 'Ext.data.Model',
25 fields
: ['title', 'content', 'user_id', 'thread_id']
28 Ext
.define('spec.Site', {
29 extend
: 'Ext.data.Model',
33 Ext
.define('spec.User', {
34 extend
: 'Ext.data.Model',
35 fields
: ['id', 'name'],
40 afterEach(function() {
41 Ext
.undefine('spec.User');
42 Ext
.undefine('spec.Post');
43 Ext
.undefine('spec.Site');
44 Ext
.undefine('spec.Thread');
46 Ext
.data
.Model
.schema
.clear(true);
51 describe("declarations", function() {
52 afterEach(function() {
53 Ext
.undefine('spec.Foo');
56 var expectFn = function(key
) {
57 expect(Ext
.isFunction(spec
.Foo
.prototype[key
])).toBe(true);
60 it("should read a single string", function() {
61 Ext
.define('spec.Foo', {
62 extend
: 'Ext.data.Model',
68 it("should read an array of strings", function() {
69 Ext
.define('spec.Foo', {
70 extend
: 'Ext.data.Model',
71 hasMany
: ['spec.Post', 'spec.Site']
77 it("should read a single object", function() {
78 Ext
.define('spec.Foo', {
79 extend
: 'Ext.data.Model',
87 it("should read an array of objects", function() {
88 Ext
.define('spec.Foo', {
89 extend
: 'Ext.data.Model',
100 it("should read an associations array", function() {
101 Ext
.define('spec.Foo', {
102 extend
: 'Ext.data.Model',
115 it("should use the name parameter as the role", function() {
116 Ext
.define('spec.Foo', {
117 extend
: 'Ext.data.Model',
126 it("should accept a storeConfig when given a name", function() {
127 Ext
.define('spec.Foo', {
128 extend
: 'Ext.data.Model',
137 var o
= new spec
.Foo();
138 expect(o
.hosts().getTrackRemoved()).toBe(false);
141 it("should accept a storeConfig when given an associationKey", function() {
142 Ext
.define('spec.Foo', {
143 extend
: 'Ext.data.Model',
146 associationKey
: 'asdf',
152 var o
= new spec
.Foo();
153 expect(o
.posts().getTrackRemoved()).toBe(false);
157 describe("instance", function() {
158 var makeRec = function() {
159 rec
= new spec
.User({
164 var getStore = function() {
165 return rec
['posts']();
168 it("should return a store", function() {
170 expect(getStore().isStore
).toBe(true);
173 it("should set the appropriate model type", function() {
175 expect(getStore().model
).toBe(spec
.Post
);
178 it("should return the same store instance on multiple calls", function() {
181 expect(getStore()).toBe(s
);
184 it("should apply the storeConfig", function() {
191 var store
= getStore();
192 expect(store
.getAutoLoad()).toBe(true);
196 describe("autoLoad", function() {
197 it("should not load the store by default", function() {
199 var spy
= spyOn(Ext
.data
.ProxyStore
.prototype, 'load').andReturn();
201 expect(spy
.callCount
).toBe(0);
204 it("should load the store if configured with autoLoad: true", function() {
210 var spy
= spyOn(Ext
.data
.ProxyStore
.prototype, 'load').andReturn();
212 expect(spy
.callCount
).toBe(1);
216 describe("keys", function() {
218 describe("foreignKey", function() {
219 it("should default to {modelName}_id", function() {
221 var post
= getStore().add({})[0];
222 expect(post
.get('user_id')).toBe(3);
225 it("should accept a user value", function() {
227 foreignKey
: 'content'
230 var post
= getStore().add({})[0];
231 expect(post
.get('content')).toBe(3);
235 it("should set the primaryKey onto the foreignKey on add", function() {
237 var post
= getStore().add({
240 expect(post
.get('user_id')).toBe(3);
245 describe("reading nested with assocationKey", function() {
246 var getStore = function() {
250 it("should default the key to association name", function() {
251 var reader
= new Ext
.data
.reader
.Json({
265 var posts
= getStore();
266 expect(posts
.getCount()).toBe(2);
267 expect(posts
.first().get('title')).toBe('t1');
268 expect(posts
.last().get('title')).toBe('t2');
271 it("should read a complex association", function() {
273 associationKey
: 'nested.another[1].two'
276 var reader
= new Ext
.data
.reader
.Json({
296 var posts
= getStore();
297 expect(posts
.getCount()).toBe(2);
298 expect(posts
.first().get('title')).toBe('t1');
299 expect(posts
.last().get('title')).toBe('t2');
303 describe("inverse association", function() {
304 it("should set the record if it has an inverse belongsTo", function() {
305 Ext
.define('spec.Parent', {
306 extend
: 'Ext.data.Model',
308 hasMany
: 'spec.Child'
311 spyOn(Ext
.log
, 'warn');
313 Ext
.define('spec.Child', {
314 extend
: 'Ext.data.Model',
315 fields
: ['id', 'parent_id'],
316 belongsTo
: 'spec.Parent'
319 var reader
= new Ext
.data
.reader
.Json({
330 var children
= rec
.children();
331 expect(children
.first().getParent()).toBe(rec
);
333 Ext
.undefine('spec.Parent');
334 Ext
.undefine('spec.Child');