diff --git a/test/code/Organisation/type.properties b/test/code/Organisation/type.properties index b3841219..5110e567 100644 --- a/test/code/Organisation/type.properties +++ b/test/code/Organisation/type.properties @@ -19,6 +19,19 @@ range.order = person_name range.offset = 100 range.maxsize = 100 +generic = collection(Person) +generic.local.1 = $prototype +generic.foreign.1 = person_generic_prototype +generic.local.2 = $id +generic.foreign.2 = person_generic_id + +groupedGeneric = collection(Person) +groupedGeneric.local.1 = $prototype +groupedGeneric.foreign.1 = person_generic_prototype +groupedGeneric.local.2 = $id +groupedGeneric.foreign.2 = person_generic_id +groupredGeneric.group = person_name + name = org_name country = org_country diff --git a/test/code/Person/type.properties b/test/code/Person/type.properties index ccc29ad1..c10baede 100644 --- a/test/code/Person/type.properties +++ b/test/code/Person/type.properties @@ -12,3 +12,6 @@ dateOfBirth = person_dateofbirth organisation = object(Organisation) organisation.local = person_org_id organisation.foreign = org_id + +genericPrototype = person_generic_prototype +genericId = person_generic_id \ No newline at end of file diff --git a/test/db-mysql.sql b/test/db-mysql.sql index f2492706..b5559d90 100644 --- a/test/db-mysql.sql +++ b/test/db-mysql.sql @@ -1,15 +1,20 @@ -CREATE DATABASE helmaTest; +CREATE DATABASE IF NOT EXISTS helmaTest; USE helmaTest; GRANT ALL ON helmaTest.* TO helma@localhost IDENTIFIED BY 'secret'; +DROP TABLE IF EXISTS tb_person; +DROP TABLE IF EXISTS tb_organisation; + CREATE TABLE tb_person ( person_id MEDIUMINT(10) NOT NULL, person_name TINYTEXT, person_height TINYINT unsigned, person_dateofbirth DATETIME, person_org_id MEDIUMINT(10) unsigned, + person_generic_prototype VARCHAR(30), + person_generic_id MEDIUMINT(10) unsigned, PRIMARY KEY (person_id) ); diff --git a/test/tests/HopObjectGeneric.js b/test/tests/HopObjectGeneric.js new file mode 100644 index 00000000..9a9a335f --- /dev/null +++ b/test/tests/HopObjectGeneric.js @@ -0,0 +1,50 @@ +tests = [ + 'testSize' +]; + +var org; +var size = 16; + +function setup() { + org = new Organisation(); + org.name = "GenericOrg"; + var i = 0, person; + + function addPerson(collection) { + person = new Person(); + person.name = "GenericPerson " + i.format("00"); + collection.add(person); + i++; + } + + // add first half to both collections of transient parent ... + while (i < 4) + addPerson(org.generic); + while (i < 8) + addPerson(org.groupedGeneric); + root.organisations.add(org); + // ... second half to both collections of persistent parent. + while (i < 12) + addPerson(org.generic); + while (i < size) + addPerson(org.groupedGeneric); + + res.commit(); +} + +function testSize() { + assertEqual(org.generic.size(), size); + org.invalidate(); + assertEqual(org.generic.size(), size); +} + +function cleanup() { + var persons = org.generic.list(); + for each (var person in persons) { + if (person.groupname) + person.get(0).remove(); + else + person.remove(); + } + org.remove(); +}