I setup a db in mongodb called spotlight. To connect to that database, I use the following environment setup in DataSource.groovy:
grails {
mongo {
host = "localhost"
port = 27017
}
}
environments {
development { // MongoDB instance running without --auth flag.
grails {
mongo {
databaseName = "spotlight"
}
}
}
test {
grails { // MongoDB instance running without --auth flag.
mongo {
databaseName = "spotlight"
}
}
}
}
This is my unit test class:
@TestMixin(MongoDbTestMixin)
class BiographySpec extends Specification {
def setup() {
}
def cleanup() {
}
void "given a bio then find() returns that bio object"() {
given:
mongoDomain([Biography])
Biography bio = new Biography()
def nameOf1stImage = "firstImage.png"
def nameOf2ndImage = "secondImage.png"
def nameInBio = "star"
def descriptionOfBio = "a description"
def id = 0;
bio.firstImage = nameOf1stImage
bio.secondImage = nameOf2ndImage
bio.name = nameInBio
bio.description = descriptionOfBio
bio.images = [nameOf1stImage,nameOf2ndImage]
when:
bio.save(flush:true);
id = bio.id
then:
Biography bioFromDb = bio.get(id)
bioFromDb.firstImage == nameOf1stImage
bioFromDb.secondImage == nameOf2ndImage
bioFromDb.name == nameInBio
bioFromDb.description == descriptionOfBio
}
}
I ran grails test-app, and grails created a biography document in test db, not spotlight db. Is there anything wrong with the way I configure environments setttings in DataSource.groovy ?
Thank you
Aucun commentaire:
Enregistrer un commentaire