Skip to content

Commit

Permalink
All unit tests in datastore pass now
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Jolley committed May 22, 2011
1 parent ec5baea commit 9be078a
Show file tree
Hide file tree
Showing 97 changed files with 2,255 additions and 2,063 deletions.
11 changes: 9 additions & 2 deletions lib/attributes.js
@@ -1,5 +1,12 @@
// ==========================================================================
// Project: SproutCore DataStore
// Copyright: ©2006-2011 Strobe Inc. and contributors.
// Portions ©2008-2011 Apple Inc. All rights reserved.
// License: Licensed under MIT license (see license.js)
// ==========================================================================

require('sproutcore-datastore/attributes/child_attribute');
require('sproutcore-datastore/attributes/children_attribute');
require('sproutcore-datastore/attributes/many_attribute');
require('sproutcore-datastore/attributes/record_attribute');
require('sproutcore-datastore/attributes/child_attribute');
require('sproutcore-datastore/attributes/single_attribute');
require('sproutcore-datastore/attributes/children_attribute');
20 changes: 11 additions & 9 deletions lib/attributes/child_attribute.js
Expand Up @@ -8,12 +8,14 @@
require('sproutcore-datastore/system/record');
require('sproutcore-datastore/attributes/record_attribute');

var get = SC.get, set = SC.set;

/** @class
ChildAttribute is a subclass of `RecordAttribute` and handles to-one
relationships for child records.
When setting ( `.set()` ) the value of a toMany attribute, make sure
When setting ( `set()` ) the value of a toMany attribute, make sure
to pass in an array of `SC.Record` objects.
There are many ways you can configure a ManyAttribute:
Expand All @@ -35,7 +37,7 @@ SC.ChildAttribute = SC.RecordAttribute.extend(
/** @private - adapted for to one relationship */
toType: function(record, key, value) {
var ret = null, rel,
recordType = this.get('typeClass');
recordType = get(this, 'typeClass');

if (!record) {
throw 'SC.Child: Error during transform: Unable to retrieve parent record.';
Expand All @@ -60,8 +62,8 @@ SC.ChildAttribute = SC.RecordAttribute.extend(

if (ret) {
// Write the data hash of the nested record to the store.
sk = ret.get('storeKey');
store = ret.get('store');
sk = get(ret, 'storeKey');
store = get(ret, 'store');
record.writeAttribute(key, store.readDataHash(sk));
} else if (value) {
// If registration failed, just write the value.
Expand All @@ -81,19 +83,19 @@ SC.ChildAttribute = SC.RecordAttribute.extend(
@returns {Object} property value
*/
call: function(record, key, value) {
var attrKey = this.get('key') || key, cRef,
cacheKey = SC.keyFor('__kid__', SC.guidFor(this));
var attrKey = get(this, 'key') || key, cRef,
cacheKey = '__kid__'+SC.guidFor(this);
if (value !== undefined) {
// this.orphan(record, cacheKey, value);
value = this.fromType(record, key, value) ; // convert to attribute.
// record[cacheKey] = value;
} else {
value = record.readAttribute(attrKey);
if (SC.none(value) && (value = this.get('defaultValue'))) {
if (typeof value === SC.T_FUNCTION) {
if (SC.none(value) && (value = get(this, 'defaultValue'))) {
if (typeof value === 'function') {
value = this.defaultValue(record, key, this);
// write default value so it doesn't have to be executed again
if(record.attributes()) record.writeAttribute(attrKey, value, true);
if(get(record, 'attributes')) record.writeAttribute(attrKey, value, true);
}
} else value = this.toType(record, key, value);
}
Expand Down
18 changes: 10 additions & 8 deletions lib/attributes/children_attribute.js
Expand Up @@ -5,18 +5,20 @@
// License: Licensed under MIT license (see license.js)
// ==========================================================================

require('sproutcore-runtime');
require('sproutcore-metal');
require('sproutcore-datastore/system/record');
require('sproutcore-datastore/attributes/record_attribute');
require('sproutcore-datastore/attributes/child_attribute');
require('sproutcore-datastore/system/child_array');

var get = SC.get, set = SC.set;

/** @class
ChildrenAttribute is a subclass of ChildAttribute and handles to-many
relationships for child records.
When setting ( `.set()` ) the value of a toMany attribute, make sure
When setting ( `set()` ) the value of a toMany attribute, make sure
to pass in an array of SC.Record objects.
There are many ways you can configure a ChildrenAttribute:
Expand All @@ -35,10 +37,10 @@ SC.ChildrenAttribute = SC.ChildAttribute.extend(

/** @private - adapted for to many relationship */
toType: function(record, key, value) {
var attrKey = this.get('key') || key,
arrayKey = SC.keyFor('__kidsArray__', SC.guidFor(this)),
var attrKey = get(this, 'key') || key,
arrayKey = '__kidsArray__'+SC.guidFor(this),
ret = record[arrayKey],
recordType = this.get('typeClass'), rel;
recordType = get(this, 'typeClass'), rel;

// lazily create a ManyArray one time. after that always return the
// same object.
Expand All @@ -50,8 +52,8 @@ SC.ChildrenAttribute = SC.ChildAttribute.extend(
});

record[arrayKey] = ret ; // save on record
rel = record.get('relationships');
if (!rel) record.set('relationships', rel = []);
rel = get(record, 'relationships');
if (!rel) set(record, 'relationships', rel = []);
rel.push(ret); // make sure we get notified of changes...
}

Expand All @@ -61,7 +63,7 @@ SC.ChildrenAttribute = SC.ChildAttribute.extend(
// Default fromType is just returning itself
fromType: function(record, key, value){
var sk, store,
arrayKey = SC.keyFor('__kidsArray__', SC.guidFor(this)),
arrayKey = '__kidsArray__'+SC.guidFor(this),
ret = record[arrayKey];
if (record) {
record.writeAttribute(key, value);
Expand Down
22 changes: 12 additions & 10 deletions lib/attributes/many_attribute.js
Expand Up @@ -9,12 +9,14 @@ require('sproutcore-datastore/system/record');
require('sproutcore-datastore/attributes/record_attribute');
require('sproutcore-datastore/system/many_array');

var get = SC.get, set = SC.set;

/** @class
ManyAttribute is a subclass of `RecordAttribute` and handles to-many
relationships.
When setting ( `.set()` ) the value of a `toMany` attribute, make sure
When setting ( `set()` ) the value of a `toMany` attribute, make sure
to pass in an array of `SC.Record` objects.
There are many ways you can configure a `ManyAttribute`:
Expand Down Expand Up @@ -69,9 +71,9 @@ SC.ManyAttribute = SC.RecordAttribute.extend(

/** @private - adapted for to many relationship */
toType: function(record, key, value) {
var type = this.get('typeClass'),
attrKey = this.get('key') || key,
arrayKey = SC.keyFor('__manyArray__', SC.guidFor(this)),
var type = get(this, 'typeClass'),
attrKey = get(this, 'key') || key,
arrayKey = '__manyArray__'+SC.guidFor(this),
ret = record[arrayKey],
rel;

Expand All @@ -86,8 +88,8 @@ SC.ManyAttribute = SC.RecordAttribute.extend(
});

record[arrayKey] = ret ; // save on record
rel = record.get('relationships');
if (!rel) record.set('relationships', rel = []);
rel = get(record, 'relationships');
if (!rel) set(record, 'relationships', rel = []);
rel.push(ret); // make sure we get notified of changes...

}
Expand All @@ -101,9 +103,9 @@ SC.ManyAttribute = SC.RecordAttribute.extend(

if(!SC.isArray(value)) throw "Expects toMany attribute to be an array";

var len = value.get('length');
var len = get(value, 'length');
for(var i=0;i<len;i++) {
ret[i] = value.objectAt(i).get('id');
ret[i] = get(value.objectAt(i), 'id');
}

return ret;
Expand All @@ -123,7 +125,7 @@ SC.ManyAttribute = SC.RecordAttribute.extend(
@returns {void}
*/
inverseDidRemoveRecord: function(record, key, inverseRecord, inverseKey) {
var manyArray = record.get(key);
var manyArray = get(record, key);
if (manyArray) {
manyArray.removeInverseRecord(inverseRecord);
}
Expand All @@ -143,7 +145,7 @@ SC.ManyAttribute = SC.RecordAttribute.extend(
@returns {void}
*/
inverseDidAddRecord: function(record, key, inverseRecord, inverseKey) {
var manyArray = record.get(key);
var manyArray = get(record, key);
if (manyArray) {
manyArray.addInverseRecord(inverseRecord);
}
Expand Down

0 comments on commit 9be078a

Please sign in to comment.