forked from grails/gorm-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See grails#195 Note: test is not currently functional: failing to instantiate data service for test.
- Loading branch information
1 parent
c38b391
commit c06aae4
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...rm-mongodb/src/test/groovy/org/grails/datastore/gorm/mongo/EmbeddedWhereClauseSpec.groovy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.grails.datastore.gorm.mongo | ||
|
||
import grails.gorm.services.Service | ||
import grails.gorm.services.Where | ||
import grails.gorm.tests.GormDatastoreSpec | ||
import grails.persistence.Entity | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
import javax.persistence.Embeddable | ||
|
||
class EmbeddedWhereClauseSpec extends GormDatastoreSpec { | ||
|
||
@Autowired | ||
PersonAttributeDataService personAttributeDataService | ||
|
||
void "Can construct data service where clause on embedded object"() { | ||
given:"An object with an embedded field on it" | ||
def attribute = new PersonAttribute(contexts: [new AttributeContext(neighborhoodId: '1234')]) | ||
attribute.save() | ||
|
||
when:"We query using the autogenerated where clause" | ||
def response = personAttributeDataService.findByNeighborhoodId('1234') | ||
|
||
then:"The association is valid" | ||
response.size() == 1 | ||
response.first().contexts.first().neighborhoodId == '1234' | ||
|
||
} | ||
|
||
@Override | ||
List getDomainClasses() { | ||
[PersonAttribute] | ||
} | ||
} | ||
|
||
@Entity | ||
class PersonAttribute { | ||
String id | ||
List<AttributeContext> contexts = [] | ||
static embedded = ['contexts'] | ||
} | ||
|
||
@Embeddable | ||
class AttributeContext { | ||
|
||
String id | ||
String neighborhoodId | ||
|
||
static belongsTo = [attribute: PersonAttribute] | ||
|
||
} | ||
|
||
@Service(PersonAttribute) | ||
interface PersonAttributeDataService { | ||
@Where({ contexts { neighborhoodId == neighborhoodId } }) | ||
List<PersonAttribute> findByNeighborhoodId(String neighborhoodId) | ||
} |