Created
January 31, 2011 16:21
-
-
Save tim-evans/804290 to your computer and use it in GitHub Desktop.
Addition to Many Attribute test to check that inheritance is actually working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test("inheritance is taken into account for related records", function () { | |
MyApp.Family = SC.Record.extend({ | |
people: SC.Record.toMany('MyApp.Person', { | |
inverse: 'family', | |
isMaster: NO | |
}) | |
}); | |
MyApp.Person = SC.Record.extend({ | |
family: SC.Record.toOne('MyApp.Family', { | |
inverse: 'people', | |
isMaster: YES | |
}) | |
}); | |
MyApp.Parent = MyApp.Person.extend(); | |
MyApp.Child = MyApp.Person.extend(); | |
SC.RunLoop.begin(); | |
MyApp.store.loadRecords(MyApp.Family, [ | |
{ guid: 'Simpsons', people: ['Homer', 'Marge', 'Bart', 'Lisa', 'Maggie'] } | |
]); | |
MyApp.store.loadRecords(MyApp.Parent, [ | |
{ guid: 'Homer', family: 'Simpsons' }, | |
{ guid: 'Marge', family: 'Simpsons' } | |
]); | |
MyApp.store.loadRecords(MyApp.Child, [ | |
{ guid: 'Bart', family: 'Simpsons' }, | |
{ guid: 'Lisa', family: 'Simpsons' }, | |
{ guid: 'Maggie', family: 'Simpsons' } | |
]); | |
SC.RunLoop.end(); | |
var theSimpsons = MyApp.store.find(MyApp.Family, 'Simpsons'); | |
equals(theSimpsons.getPath('people.length'), 5, | |
'there should be 5 people in the family'); | |
theSimpsons.get('people').forEach(function (person) { | |
ok(['Homer', 'Marge', 'Bart', 'Lisa', 'Maggie'].indexOf(person.get('guid')) !== -1, | |
'the person "%@" is an invalid person.'.fmt(person.get('guid'))); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment