Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch '1.x'

  • Loading branch information...
commit f12e58bc9f549398f295a8457f40c07236d288e5 2 parents 21b151a + ae3311d
Tom Widmer tomwidmer authored
35 grails-datastore-gorm-mongo/src/test/groovy/org/grails/datastore/gorm/mongo/DBObjectConversionSpec.groovy
@@ -78,6 +78,41 @@ class DBObjectConversionSpec extends GormDatastoreSpec {
78 78 Boat.count() == 1
79 79 }
80 80
  81 + void "Test that an entity can be round-tripped to dbo and back"() {
  82 + given:"A domain model with embedded associations that have non-embedded associations"
  83 + createCrew()
  84 +
  85 + when:"The model is converted to a dbo and back"
  86 + Boat boat = Boat.findAll().get(0).dbo as Boat
  87 +
  88 + then:"The copy matches the original"
  89 + boat != null
  90 + boat.name == "The Float"
  91 + boat.captain != null
  92 + boat.captain.name == 'Bob'
  93 + boat.crew.size() == 2
  94 + boat.crew[0].name == 'Fred'
  95 + boat.crew[0].captain != null
  96 + boat.crew[0].captain.name == 'Bob'
  97 + boat.captain.shipmates.size() == 1
  98 +
  99 + when:"The association is updated"
  100 + boat.crew.pop()
  101 + boat.save(flush: true)
  102 + boat = boat.dbo as Boat
  103 +
  104 + then:"The model is correct"
  105 + boat != null
  106 + boat.name == "The Float"
  107 + boat.captain != null
  108 + boat.captain.name == 'Bob'
  109 + boat.crew.size() == 1
  110 + boat.crew[0].name == 'Fred'
  111 + boat.crew[0].captain != null
  112 + boat.crew[0].captain.name == 'Bob'
  113 + boat.captain.shipmates.size() == 1
  114 + }
  115 +
81 116 private createCrew() {
82 117 final captain = new Captain(name: "Bob").save()
83 118 final firstMate = new Sailor(name: "Jim", captain: captain)
6 grails-datastore-mongo/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoEntityPersister.java
@@ -135,7 +135,7 @@ protected void setEmbeddedCollection(final DBObject nativeEntry, final String ke
135 135 return;
136 136 }
137 137
138   - nativeEntry.put(key, embeddedEntries.toArray());
  138 + nativeEntry.put(key, embeddedEntries);
139 139 }
140 140
141 141 /**
@@ -198,8 +198,8 @@ protected void loadEmbeddedCollection(EmbeddedCollection embeddedCollection,
198 198 instances = new HashSet<Object>();
199 199 }
200 200
201   - if (embeddedInstances instanceof BasicDBList) {
202   - BasicDBList list = (BasicDBList)embeddedInstances;
  201 + if (embeddedInstances instanceof List) {
  202 + List list = (List)embeddedInstances;
203 203 for (Object dbo : list) {
204 204 if (dbo instanceof BasicDBObject) {
205 205 BasicDBObject nativeEntry = (BasicDBObject)dbo;

0 comments on commit f12e58b

Please sign in to comment.
Something went wrong with that request. Please try again.