Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0.2, 2.0.3
-
Fix Version/s: 2.0.4
-
Component/s: Persistence, Testing
-
Labels:
-
Environment:Windows 7 x64
-
Testcase included:yes
Description
The count() does not work properly on a domain object that extending an abstract class
The object is saved but the count() always return zero
After upgrading to 2.0.3 major part of our unit test failing due to this issue
attached a simple test case that show this behaviour (full grails project in zip file)
class Group {
String name
static hasMany = [members:Member]
static constraints = {
}
Collection members
}
import groovy.transform.ToString import java.util.Map @ToString (includeNames=true,includeFields=true,excludes="xmlProperties") abstract class Member { String name String externalId }
@ToString (includeNames=true,includeFields=true,excludes="xmlProperties") class SubMember extends Member { String extraName }
@TestFor(Group)
@Mock([SubMember])
class GroupTests {
Group group
SubMember subMember
@Before
void setUp() {
group = new Group(name:"my group")
subMember = new SubMember(name:"my name",extraName:"extra name")
group.addToMembers subMember
group.save(failOnError:true)
}
@Test
void testSampleStructure()
{
//check that the group is saved
assertEquals 1, Group.count()
//get the saved group
Group savedGroup = Group.findById(group.id)
//check its not null
assertNotNull savedGroup
//check that it has 1 member
assertEquals 1, savedGroup.members.size()
//somehow the count is always zero
assertEquals 1, SubMember.count()
}
}
Test result is :
| Failure: testSampleStructure(com.etrainu.GroupTests) |
| java.lang.AssertionError: expected:<1> but was:<0> at org.junit.Assert.fail(Assert.java:93) at org.junit.Assert.failNotEquals(Assert.java:647) at org.junit.Assert.assertEquals(Assert.java:128) at org.junit.Assert.assertEquals(Assert.java:472) at org.junit.Assert.assertEquals(Assert.java:456) at com.etrainu.GroupTests.testSampleStructure(GroupTests.groovy:40) |
| Completed 1 unit test, 1 failed in 9287ms |
This bug is obvious and well documented within this ticket. Could we please have this issue scheduled in 2.0.4